[NUI.Gadget] Use bin directory (#6454)
authorhjhun <36876573+hjhun@users.noreply.github.com>
Mon, 18 Nov 2024 02:15:47 +0000 (11:15 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 27 Nov 2024 04:59:55 +0000 (13:59 +0900)
The gadget mount path will be changed to the 'bin/.res_mount'.
If it's applied, the NUIGadgetManager can remount the resources.

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetAssembly.cs
src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs
src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs

index 29d67e0a502bc6c8d186f5c9eb45ef62c31951f1..424ca30cf0b5559139a97b0a5c3a78db5b8eafb0 100644 (file)
@@ -47,6 +47,7 @@ namespace Tizen.NUI
         private readonly string _assemblyPath;
         private WeakReference _assemblyRef;
         private Assembly _assembly = null;
+        private bool _loaded = false;
 
         internal NUIGadgetAssembly(string assemblyPath) { _assemblyPath = assemblyPath; }
 
@@ -54,7 +55,7 @@ namespace Tizen.NUI
         {
             lock (_assemblyLock)
             {
-                if (_assembly != null)
+                if (_loaded)
                 {
                     return;
                 }
@@ -62,15 +63,17 @@ namespace Tizen.NUI
                 Log.Warn("Load(): " + _assemblyPath + " ++");
                 NUIGadgetAssemblyLoadContext context = new NUIGadgetAssemblyLoadContext();
                 _assemblyRef = new WeakReference(context);
-                using (FileStream stream = new FileStream(_assemblyPath, FileMode.Open, FileAccess.Read))
-                {
-                    _assembly = context.LoadFromStream(stream);
-                }
+                string directoryPath = SystemIO.Path.GetDirectoryName(_assemblyPath);
+                string fileName = SystemIO.Path.GetFileNameWithoutExtension(_assemblyPath);
+                string nativeImagePath = directoryPath + "/.native_image/" + fileName + ".ni.dll";
+                Log.Debug("NativeImagePath=" + nativeImagePath + ", AssemblyPath=" + _assemblyPath);
+                _assembly = context.LoadFromNativeImagePath(nativeImagePath, _assemblyPath);
                 Log.Warn("Load(): " + _assemblyPath + " --");
+                _loaded = true;
             }
         }
 
-        internal bool IsLoaded { get { return _assembly != null; } }
+        internal bool IsLoaded { get { return _loaded; } }
 
         internal NUIGadget CreateInstance(string className)
         {
@@ -90,7 +93,7 @@ namespace Tizen.NUI
         {
             lock (_assemblyLock)
             {
-                if (_assembly == null)
+                if (!_loaded)
                 {
                     return;
                 }
@@ -101,7 +104,7 @@ namespace Tizen.NUI
                     (_assemblyRef.Target as NUIGadgetAssemblyLoadContext).Unload();
                 }
 
-                _assembly = null;
+                _loaded = false;
                 Log.Warn("Unload(): " + _assemblyPath + " --");
             }
         }
index 3f7bda02f3fd0c0295730ddadfbc7416c833cb0e..ca3f7d05b04bfdabe806c616026c89eea497d010 100755 (executable)
@@ -71,10 +71,10 @@ namespace Tizen.NUI
         }
 
         /// <summary>
-        /// Gets the allowed resource path of the gadget.
+        /// Gets the gadget resource path of the gadget.
         /// </summary>
         /// <since_tizen> 12 </since_tizen>
-        public string AllowedResourcePath
+        public string GadgetResourcePath
         {
             get; private set;
         }
@@ -196,11 +196,16 @@ namespace Tizen.NUI
                 Log.Warn("Failed to destroy package info. error = " + errorCode);
             }
 
-            info.ResourcePath = SystemIO.Path.GetDirectoryName(Application.Current.ApplicationInfo.ExecutablePath) + "/";
-            info.AllowedResourcePath = SystemIO.Path.GetDirectoryName(Application.Current.DirectoryInfo.Resource) + "/mount/allowed/" + info.ResourceType + "/";
-            if (!Directory.Exists(info.AllowedResourcePath))
+            info.ResourcePath = SystemIO.Path.GetDirectoryName(Application.Current.ApplicationInfo.ExecutablePath) + "/.res_mount/";
+            if (!Directory.Exists(info.ResourcePath))
             {
-                info.AllowedResourcePath = SystemIO.Path.GetDirectoryName(Application.Current.DirectoryInfo.Resource) + "/mount/allowed/";
+                info.ResourcePath = SystemIO.Path.GetDirectoryName(Application.Current.ApplicationInfo.ExecutablePath) + "/";
+            }
+
+            info.GadgetResourcePath = info.ResourcePath + info.ResourceType + "/";
+            if (!Directory.Exists(info.GadgetResourcePath))
+            {
+                info.GadgetResourcePath = info.ResourcePath;
             }
             return info;
         }
index c93087b52018c551bf6952320f14ae754dbeb8ae..2d3f2de87ce7b10441f9d7eec6a00026b93ab387 100755 (executable)
@@ -243,10 +243,10 @@ namespace Tizen.NUI
                     {
                         if (info.NUIGadgetAssembly == null || !info.NUIGadgetAssembly.IsLoaded)
                         {
-                            Log.Warn("NUIGadgetAssembly.Load(): " + info.AllowedResourcePath + info.ExecutableFile + " ++");
-                            info.NUIGadgetAssembly = new NUIGadgetAssembly(info.AllowedResourcePath + info.ExecutableFile);
+                            Log.Warn("NUIGadgetAssembly.Load(): " + info.GadgetResourcePath + info.ExecutableFile + " ++");
+                            info.NUIGadgetAssembly = new NUIGadgetAssembly(info.GadgetResourcePath + info.ExecutableFile);
                             info.NUIGadgetAssembly.Load();
-                            Log.Warn("NUIGadgetAssembly.Load(): " + info.AllowedResourcePath + info.ExecutableFile + " --");
+                            Log.Warn("NUIGadgetAssembly.Load(): " + info.GadgetResourcePath + info.ExecutableFile + " --");
                         }
                     }
                 }