2 * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using System.ComponentModel;
21 using System.Runtime.InteropServices;
22 using Tizen.Applications;
27 /// This class provides properties to get information the gadget.
29 /// <since_tizen> 10 </since_tizen>
30 [EditorBrowsable(EditorBrowsableState.Never)]
31 public class NUIGadgetInfo
33 private const string MetadataUIGadgetDll = "http://tizen.org/metadata/ui-gadget/dll";
34 private const string MetadataUIGadgetResourceDll = "http://tizen.org/metadata/ui-gadget/resource/dll";
35 private const string MetadataUIGadgetResourceClassName = "http://tizen.org/metadata/ui-gadget/resource/class-name";
36 private string _resourcePath = string.Empty;
38 internal NUIGadgetInfo(string packageId)
40 PackageId = packageId;
41 Log.Warn("PackageId: " + PackageId);
42 AllowedPath = Application.Current.DirectoryInfo.Resource + "mount/allowed/";
43 Log.Warn("AllowedPath: " + AllowedPath);
44 GlobalPath = Application.Current.DirectoryInfo.Resource + "mount/global/";
45 Log.Warn("GlobalPath: " + GlobalPath);
48 private string AllowedPath { get; set; }
50 private string GlobalPath { get; set; }
53 /// Gets the package ID of the gadget.
55 /// <since_tizen> 10 </since_tizen>
56 public string PackageId { get; private set; }
59 /// Gets the resource type of the gadget.
61 /// <since_tizen> 10 </since_tizen>
62 public string ResourceType { get; private set; }
65 /// Gets the resource version of the gadget.
67 /// <since_tizen> 10 </since_tizen>
68 public string ResourceVersion { get; private set; }
71 /// Gets the resource path of the gadget.
73 /// <since_tizen> 10 </since_tizen>
74 public string ResourcePath
78 if (!string.IsNullOrEmpty(_resourcePath))
81 if (File.Exists(GlobalPath + ExecutableFile))
83 _resourcePath = GlobalPath;
85 else if (File.Exists(AllowedPath + ExecutableFile))
87 _resourcePath = AllowedPath;
95 /// Gets the executable file of the gadget.
97 /// <since_tizen> 10 </since_tizen>
98 public string ExecutableFile { get; internal set; }
101 /// Gets the metadata of the gadget.
103 /// <since_tizen> 10 </since_tizen>
104 public IDictionary<string, string> Metadata { get; private set; }
106 internal string ResourceFile { get; set; }
108 internal string ResourceClassName { get; set; }
110 internal static NUIGadgetInfo CreateNUIGadgetInfo(string packageId)
112 Interop.PackageManagerInfo.ErrorCode errorCode = Interop.PackageManagerInfo.PackageInfoGet(packageId, out IntPtr handle);
113 if (errorCode != Interop.PackageManagerInfo.ErrorCode.None)
115 Log.Error("Failed to get package info. error = " + errorCode);
119 NUIGadgetInfo info = new NUIGadgetInfo(packageId);
121 errorCode = Interop.PackageManagerInfo.PackageInfoGetResourceType(handle, out IntPtr resourceTypePtr);
122 if (errorCode != Interop.PackageManagerInfo.ErrorCode.None)
124 Log.Error("Failed to get resource type. error = " + errorCode);
128 info.ResourceType = Marshal.PtrToStringAnsi(resourceTypePtr);
131 errorCode = Interop.PackageManagerInfo.PackageInfoGetResourceVersion(handle, out IntPtr resourceVersionPtr);
132 if (errorCode != Interop.PackageManagerInfo.ErrorCode.None)
134 Log.Error("Failed to get resource version. error = " + errorCode);
138 info.ResourceVersion = Marshal.PtrToStringAnsi(resourceVersionPtr);
141 Dictionary<string, string> metadata = new Dictionary<string, string>();
142 int callback(string key, string value, IntPtr userData)
144 Log.Info("key: " + key + ", value: " + value);
147 if (!metadata.ContainsKey(key))
149 metadata.Add(key, value);
155 errorCode = Interop.PackageManagerInfo.PackageInfoForeachMetadata(handle, callback, IntPtr.Zero);
156 if (errorCode != Interop.PackageManagerInfo.ErrorCode.None)
158 Log.Error("Failed to retrieve meatadata. error = " + errorCode);
161 info.Metadata = metadata;
163 if (info.Metadata.TryGetValue(MetadataUIGadgetDll, out string executableFile))
165 info.ExecutableFile = executableFile;
166 Log.Info("ExecutableFile: " + info.ExecutableFile);
170 Log.Error("Failed to find metadata. " + MetadataUIGadgetDll);
173 if (info.Metadata.TryGetValue(MetadataUIGadgetResourceDll, out string resourceFile))
175 info.ResourceFile = resourceFile;
176 Log.Info("LocaleFile: " + info.ResourceFile);
180 Log.Warn("There is no locale dll");
183 if (info.Metadata.TryGetValue(MetadataUIGadgetResourceClassName, out string resourceClassName))
185 info.ResourceClassName = resourceClassName;
186 Log.Info("LocaleClassName: " + info.ResourceClassName);
190 Log.Warn("There is no locale class");
193 errorCode = Interop.PackageManagerInfo.PackageInfoDestroy(handle);
194 if (errorCode != Interop.PackageManagerInfo.ErrorCode.None)
196 Log.Warn("Failed to destroy package info. error = " + errorCode);