From 44e9e16e054aa7469d28a9b56424ade95f15f7d4 Mon Sep 17 00:00:00 2001 From: hjhun <36876573+hjhun@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:15:47 +0900 Subject: [PATCH] [NUI.Gadget] Use bin directory (#6454) 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 --- .../Tizen.NUI/NUIGadgetAssembly.cs | 19 +++++++++++-------- .../Tizen.NUI/NUIGadgetInfo.cs | 17 +++++++++++------ .../Tizen.NUI/NUIGadgetManager.cs | 6 +++--- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetAssembly.cs b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetAssembly.cs index 29d67e0a5..424ca30cf 100644 --- a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetAssembly.cs +++ b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetAssembly.cs @@ -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 + " --"); } } diff --git a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs index 3f7bda02f..ca3f7d05b 100755 --- a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs +++ b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs @@ -71,10 +71,10 @@ namespace Tizen.NUI } /// - /// Gets the allowed resource path of the gadget. + /// Gets the gadget resource path of the gadget. /// /// 12 - 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; } diff --git a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs index c93087b52..2d3f2de87 100755 --- a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs +++ b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs @@ -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 + " --"); } } } -- 2.34.1