Skip to content

Commit

Permalink
[NUI.Gadget] Modify loading assembly of NUIGadget (#6417)
Browse files Browse the repository at this point in the history
* [NUI.Gadget] Modify loading assembly of NUIGadget

Signed-off-by: Hwankyu Jhun <[email protected]>

* [NUI.Gadget] Fix wrong implementation

Signed-off-by: Hwankyu Jhun <[email protected]>

* [NUI.Gadget] Fix resource path

The AllowedResourcePath is added for backward compatibility.

Signed-off-by: Hwankyu Jhun <[email protected]>

---------

Signed-off-by: Hwankyu Jhun <[email protected]>
  • Loading branch information
hjhun authored Oct 28, 2024
1 parent 4cda61e commit 8748a5b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ internal void Load()
Log.Warn("Load(): " + _assemblyPath + " ++");
NUIGadgetAssemblyLoadContext context = new NUIGadgetAssemblyLoadContext();
_assemblyRef = new WeakReference(context);
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);
using (FileStream stream = new FileStream(_assemblyPath, FileMode.Open, FileAccess.Read))
{
_assembly = context.LoadFromStream(stream);
}
Log.Warn("Load(): " + _assemblyPath + " --");
}
}
Expand Down Expand Up @@ -107,4 +106,4 @@ internal void Unload()
}
}
}
}
}
15 changes: 15 additions & 0 deletions src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using Tizen.Applications;
Expand Down Expand Up @@ -69,6 +70,15 @@ public string ResourcePath
get; private set;
}

/// <summary>
/// Gets the allowed resourced path of the gadget.
/// </summary>
/// <since_tizen> 12 </since_tizen>
public string AllowedResourcePath
{
get; private set;
}

/// <summary>
/// Gets the executable file of the gadget.
/// </summary>
Expand Down Expand Up @@ -183,6 +193,11 @@ int callback(string key, string value, IntPtr userData)
}

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.AllowedResourcePath = SystemIO.Path.GetDirectoryName(Application.Current.DirectoryInfo.Resource) + "/mount/allowed/";
}
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.ResourcePath + info.ExecutableFile + " ++");
info.NUIGadgetAssembly = new NUIGadgetAssembly(info.ResourcePath + info.ExecutableFile);
Log.Warn("NUIGadgetAssembly.Load(): " + info.AllowedResourcePath + info.ExecutableFile + " ++");
info.NUIGadgetAssembly = new NUIGadgetAssembly(info.AllowedResourcePath + info.ExecutableFile);
info.NUIGadgetAssembly.Load();
Log.Warn("NUIGadgetAssembly.Load(): " + info.ResourcePath + info.ExecutableFile + " --");
Log.Warn("NUIGadgetAssembly.Load(): " + info.AllowedResourcePath + info.ExecutableFile + " --");
}
}
}
Expand Down

0 comments on commit 8748a5b

Please sign in to comment.