[NUI.Gadget] Modify NUIGadgetManager Implementation (#6093)
authorhjhun <36876573+hjhun@users.noreply.github.com>
Tue, 23 Apr 2024 06:05:10 +0000 (15:05 +0900)
committerGitHub <noreply@github.com>
Tue, 23 Apr 2024 06:05:10 +0000 (15:05 +0900)
* [NUI.Gadget] Modify NUIGadget implementation

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
* [NUI.Gadget] Use filename instead of full path

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
* [NUI.Gadget] Add a missing exception handling

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
---------

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

index 6a959cb..fda1346 100755 (executable)
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
-using System.IO;
 using System.Reflection;
 using System.Runtime.InteropServices;
 using Tizen.Applications;
 
+using SystemIO = System.IO;
+
 namespace Tizen.NUI
 {
     /// <summary>
@@ -34,22 +35,13 @@ namespace Tizen.NUI
         private const string MetadataUIGadgetDll = "http://tizen.org/metadata/ui-gadget/dll";
         private const string MetadataUIGadgetResourceDll = "http://tizen.org/metadata/ui-gadget/resource/dll";
         private const string MetadataUIGadgetResourceClassName = "http://tizen.org/metadata/ui-gadget/resource/class-name";
-        private string _resourcePath = string.Empty;
 
         internal NUIGadgetInfo(string packageId)
         {
             PackageId = packageId;
             Log.Warn("PackageId: " + PackageId);
-            AllowedPath = Application.Current.DirectoryInfo.Resource + "mount/allowed/";
-            Log.Warn("AllowedPath: " + AllowedPath);
-            GlobalPath = Application.Current.DirectoryInfo.Resource + "mount/global/";
-            Log.Warn("GlobalPath: " + GlobalPath);
         }
 
-        private string AllowedPath { get; set; }
-
-        private string GlobalPath { get; set; }
-
         /// <summary>
         /// Gets the package ID of the gadget.
         /// </summary>
@@ -74,22 +66,7 @@ namespace Tizen.NUI
         /// <since_tizen> 10 </since_tizen>
         public string ResourcePath
         {
-            get
-            {
-                if (!string.IsNullOrEmpty(_resourcePath))
-                    return _resourcePath;
-
-                if (File.Exists(GlobalPath + ExecutableFile))
-                {
-                    _resourcePath = GlobalPath;
-                }
-                else if (File.Exists(AllowedPath + ExecutableFile))
-                {
-                    _resourcePath = AllowedPath;
-                }
-
-                return _resourcePath;
-            }
+            get; private set;
         }
 
         /// <summary>
@@ -199,6 +176,7 @@ namespace Tizen.NUI
                 Log.Warn("Failed to destroy package info. error = " + errorCode);
             }
 
+            info.ResourcePath = SystemIO.Path.GetDirectoryName(Application.Current.ApplicationInfo.ExecutablePath) + "/";
             return info;
         }
     }
index f5986e3..653bfb4 100755 (executable)
@@ -23,6 +23,8 @@ using System.ComponentModel;
 using System.Runtime.InteropServices;
 using System.Reflection;
 
+using SystemIO = System.IO;
+
 namespace Tizen.NUI
 {
     /// <summary>
@@ -37,10 +39,10 @@ namespace Tizen.NUI
 
         static NUIGadgetManager()
         {
-            IntPtr resPkgIds = Interop.Libc.GetEnviornmentVariable("RES_PKGIDS");
-            if (resPkgIds != IntPtr.Zero)
+            IntPtr gadgetPkgIds = Interop.Libc.GetEnviornmentVariable("GADGET_PKGIDS");
+            if (gadgetPkgIds != IntPtr.Zero)
             {
-                string packages = Marshal.PtrToStringAnsi(resPkgIds);
+                string packages = Marshal.PtrToStringAnsi(gadgetPkgIds);
                 if (string.IsNullOrEmpty(packages))
                 {
                     Log.Warn("There is no resource packages");
@@ -54,6 +56,10 @@ namespace Tizen.NUI
                         {
                             _gadgetInfos.Add(info.ResourceType, info);
                         }
+                        else
+                        {
+                            Log.Error("Failed to create NUIGadgetInfo. package=" + packageId);
+                        }
                     }
                 }
             }
@@ -151,6 +157,10 @@ namespace Tizen.NUI
             {
                 throw new InvalidOperationException(e.Message);
             }
+            catch (BadImageFormatException e)
+            {
+                throw new InvalidOperationException(e.Message);
+            }
         }
 
         private static void Load(NUIGadgetInfo info)
@@ -164,9 +174,9 @@ namespace Tizen.NUI
             {
                 if (info.Assembly == null)
                 {
-                    Log.Warn("NUIGadgetAssembly.Load(): " + info.ResourcePath + info.ExecutableFile + " ++");
-                    info.Assembly = Assembly.Load(File.ReadAllBytes(info.ResourcePath + info.ExecutableFile));
-                    Log.Warn("NUIGadgetAssembly.Load(): " + info.ResourcePath + info.ExecutableFile + " --");
+                    Log.Warn("Assembly.Load(): " + info.ResourcePath + info.ExecutableFile + " ++");
+                    info.Assembly = Assembly.Load(SystemIO.Path.GetFileNameWithoutExtension(info.ExecutableFile));
+                    Log.Warn("Assembly.Load(): " + info.ResourcePath + info.ExecutableFile + " --");
                 }
             }
         }
@@ -196,6 +206,10 @@ namespace Tizen.NUI
             {
                 throw new InvalidOperationException(e.Message);
             }
+            catch (BadImageFormatException e)
+            {
+                throw new InvalidOperationException(e.Message);
+            }
 
             NUIGadget gadget = info.Assembly.CreateInstance(className, true) as NUIGadget;
             if (gadget == null)