Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NUI.Gadget] Modify resource path #6685

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading