diff --git a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs index ca3f7d05b04..91d068dd4c0 100755 --- a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs +++ b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs @@ -107,37 +107,69 @@ public string GadgetResourcePath /// 12 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 metadata = new Dictionary(); int callback(string key, string value, IntPtr userData) { @@ -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; } }