Skip to content

Commit

Permalink
[NUI.Gadget] Use bin directory (#6454)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
hjhun authored Nov 18, 2024
1 parent 86b6c2a commit fbd68a8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
19 changes: 11 additions & 8 deletions src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,33 @@ public class NUIGadgetAssembly
private readonly string _assemblyPath;
private WeakReference _assemblyRef;
private Assembly _assembly = null;
private bool _loaded = false;

internal NUIGadgetAssembly(string assemblyPath) { _assemblyPath = assemblyPath; }

internal void Load()
{
lock (_assemblyLock)
{
if (_assembly != null)
if (_loaded)
{
return;
}

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)
{
Expand All @@ -90,7 +93,7 @@ internal void Unload()
{
lock (_assemblyLock)
{
if (_assembly == null)
if (!_loaded)
{
return;
}
Expand All @@ -101,7 +104,7 @@ internal void Unload()
(_assemblyRef.Target as NUIGadgetAssemblyLoadContext).Unload();
}

_assembly = null;
_loaded = false;
Log.Warn("Unload(): " + _assemblyPath + " --");
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public string ResourcePath
}

/// <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;
}
Expand Down Expand Up @@ -196,11 +196,16 @@ int callback(string key, string value, IntPtr userData)
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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ private static void Load(NUIGadgetInfo info, bool useDefaultContext)
{
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 + " --");
}
}
}
Expand Down

0 comments on commit fbd68a8

Please sign in to comment.