Skip to content

Commit

Permalink
[NUI.Gadget] Modify resource path
Browse files Browse the repository at this point in the history
Signed-off-by: Hwankyu Jhun <[email protected]>
  • Loading branch information
hjhun authored and dongsug-song committed Feb 25, 2025
1 parent ea9b34b commit bfac1f3
Showing 1 changed file with 79 additions and 41 deletions.
120 changes: 79 additions & 41 deletions src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,37 +107,69 @@ public string GadgetResourcePath
/// <since_tizen> 12 </since_tizen>
public NUIGadgetAssembly NUIGadgetAssembly { get; set; }

internal static NUIGadgetInfo CreateNUIGadgetInfo(string packageId)
private static void SetGadgetResourcePath(NUIGadgetInfo info)
{
Interop.PackageManagerInfo.ErrorCode errorCode = Interop.PackageManagerInfo.PackageInfoGet(packageId, out IntPtr handle);
if (errorCode != Interop.PackageManagerInfo.ErrorCode.None)
info.GadgetResourcePath = info.ResourcePath + info.ResourceType + "/";
if (!Directory.Exists(info.GadgetResourcePath))
{
Log.Error("Failed to get package info. error = " + errorCode);
return null;
info.GadgetResourcePath = info.ResourcePath;
}
}

NUIGadgetInfo info = new NUIGadgetInfo(packageId);
private static void SetResourcePath(NUIGadgetInfo info)
{
info.ResourcePath = SystemIO.Path.GetDirectoryName(Application.Current.ApplicationInfo.ExecutablePath) + "/.res_mount/gadget/";
if (!Directory.Exists(info.ResourcePath))
{
info.ResourcePath = SystemIO.Path.GetDirectoryName(Application.Current.ApplicationInfo.ExecutablePath) + "/.res_mount/";
if (!Directory.Exists(info.ResourcePath))
{
info.ResourcePath = SystemIO.Path.GetDirectoryName(Application.Current.ApplicationInfo.ExecutablePath) + "/";
}
}
}

errorCode = Interop.PackageManagerInfo.PackageInfoGetResourceType(handle, out IntPtr resourceTypePtr);
if (errorCode != Interop.PackageManagerInfo.ErrorCode.None)
private static void SetResourceClassName(NUIGadgetInfo info)
{
if (info.Metadata.TryGetValue(MetadataUIGadgetResourceClassName, out string resourceClassName))
{
Log.Error("Failed to get resource type. error = " + errorCode);
info.ResourceClassName = resourceClassName;
Log.Info("LocaleClassName: " + info.ResourceClassName);
}
else
{
info.ResourceType = Marshal.PtrToStringAnsi(resourceTypePtr);
Log.Warn("There is no locale class");
}
}

errorCode = Interop.PackageManagerInfo.PackageInfoGetResourceVersion(handle, out IntPtr resourceVersionPtr);
if (errorCode != Interop.PackageManagerInfo.ErrorCode.None)
private static void SetResourceFile(NUIGadgetInfo info)
{
if (info.Metadata.TryGetValue(MetadataUIGadgetResourceDll, out string resourceFile))
{
Log.Error("Failed to get resource version. error = " + errorCode);
info.ResourceFile = resourceFile;
Log.Info("LocaleFile: " + info.ResourceFile);
}
else
{
info.ResourceVersion = Marshal.PtrToStringAnsi(resourceVersionPtr);
Log.Warn("There is no locale dll");
}
}

private static void SetExecutableFile(NUIGadgetInfo info)
{
if (info.Metadata.TryGetValue(MetadataUIGadgetDll, out string executableFile))
{
info.ExecutableFile = executableFile;
Log.Info("ExecutableFile: " + info.ExecutableFile);
}
else
{
Log.Error("Failed to find metadata. " + MetadataUIGadgetDll);
}
}

private static void SetMetadata(NUIGadgetInfo info, IntPtr handle)
{
Dictionary<string, string> metadata = new Dictionary<string, string>();
int callback(string key, string value, IntPtr userData)
{
Expand All @@ -152,61 +184,67 @@ int callback(string key, string value, IntPtr userData)
return 0;
}

errorCode = Interop.PackageManagerInfo.PackageInfoForeachMetadata(handle, callback, IntPtr.Zero);
Interop.PackageManagerInfo.ErrorCode errorCode = Interop.PackageManagerInfo.PackageInfoForeachMetadata(handle, callback, IntPtr.Zero);
if (errorCode != Interop.PackageManagerInfo.ErrorCode.None)
{
Log.Error("Failed to retrieve meatadata. error = " + errorCode);
}

info.Metadata = metadata;
}

if (info.Metadata.TryGetValue(MetadataUIGadgetDll, out string executableFile))
private static void SetResourceVersion(NUIGadgetInfo info, IntPtr handle)
{
Interop.PackageManagerInfo.ErrorCode errorCode = Interop.PackageManagerInfo.PackageInfoGetResourceVersion(handle, out IntPtr resourceVersionPtr);
if (errorCode != Interop.PackageManagerInfo.ErrorCode.None)
{
info.ExecutableFile = executableFile;
Log.Info("ExecutableFile: " + info.ExecutableFile);
Log.Error("Failed to get resource version. error = " + errorCode);
}
else
{
Log.Error("Failed to find metadata. " + MetadataUIGadgetDll);
info.ResourceVersion = Marshal.PtrToStringAnsi(resourceVersionPtr);
}
}

if (info.Metadata.TryGetValue(MetadataUIGadgetResourceDll, out string resourceFile))
private static void SetResourceType(NUIGadgetInfo info, IntPtr handle)
{
Interop.PackageManagerInfo.ErrorCode errorCode = Interop.PackageManagerInfo.PackageInfoGetResourceType(handle, out IntPtr resourceTypePtr);
if (errorCode != Interop.PackageManagerInfo.ErrorCode.None)
{
info.ResourceFile = resourceFile;
Log.Info("LocaleFile: " + info.ResourceFile);
Log.Error("Failed to get resource type. error = " + errorCode);
}
else
{
Log.Warn("There is no locale dll");
info.ResourceType = Marshal.PtrToStringAnsi(resourceTypePtr);
}
}

if (info.Metadata.TryGetValue(MetadataUIGadgetResourceClassName, out string resourceClassName))
{
info.ResourceClassName = resourceClassName;
Log.Info("LocaleClassName: " + info.ResourceClassName);
}
else
internal static NUIGadgetInfo CreateNUIGadgetInfo(string packageId)
{
Interop.PackageManagerInfo.ErrorCode errorCode = Interop.PackageManagerInfo.PackageInfoGet(packageId, out IntPtr handle);
if (errorCode != Interop.PackageManagerInfo.ErrorCode.None)
{
Log.Warn("There is no locale class");
Log.Error("Failed to get package info. error = " + errorCode);
return null;
}

NUIGadgetInfo info = new NUIGadgetInfo(packageId);

SetResourceType(info, handle);
SetResourceVersion(info, handle);
SetMetadata(info, handle);

errorCode = Interop.PackageManagerInfo.PackageInfoDestroy(handle);
if (errorCode != Interop.PackageManagerInfo.ErrorCode.None)
{
Log.Warn("Failed to destroy package info. error = " + errorCode);
}

info.ResourcePath = SystemIO.Path.GetDirectoryName(Application.Current.ApplicationInfo.ExecutablePath) + "/.res_mount/";
if (!Directory.Exists(info.ResourcePath))
{
info.ResourcePath = SystemIO.Path.GetDirectoryName(Application.Current.ApplicationInfo.ExecutablePath) + "/";
}

info.GadgetResourcePath = info.ResourcePath + info.ResourceType + "/";
if (!Directory.Exists(info.GadgetResourcePath))
{
info.GadgetResourcePath = info.ResourcePath;
}
SetExecutableFile(info);
SetResourceFile(info);
SetResourceClassName(info);
SetResourcePath(info);
SetGadgetResourcePath(info);
return info;
}
}
Expand Down

0 comments on commit bfac1f3

Please sign in to comment.