From 6047bfcd96a4d56646eae5fd4e33b9d3ae1e39ec Mon Sep 17 00:00:00 2001 From: hjhun <36876573+hjhun@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:05:10 +0900 Subject: [PATCH] [NUI.Gadget] Modify NUIGadgetManager Implementation (#6093) * [NUI.Gadget] Modify NUIGadget implementation Signed-off-by: Hwankyu Jhun * [NUI.Gadget] Use filename instead of full path Signed-off-by: Hwankyu Jhun * [NUI.Gadget] Add a missing exception handling Signed-off-by: Hwankyu Jhun --------- Signed-off-by: Hwankyu Jhun --- src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs | 30 +++------------------- src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs | 26 ++++++++++++++----- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs index 6a959cb..fda1346 100755 --- a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs +++ b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs @@ -17,11 +17,12 @@ 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 { /// @@ -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; } - /// /// Gets the package ID of the gadget. /// @@ -74,22 +66,7 @@ namespace Tizen.NUI /// 10 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; } /// @@ -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; } } diff --git a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs index f5986e3..653bfb4 100755 --- a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs +++ b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs @@ -23,6 +23,8 @@ using System.ComponentModel; using System.Runtime.InteropServices; using System.Reflection; +using SystemIO = System.IO; + namespace Tizen.NUI { /// @@ -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) -- 2.7.4