2 * Copyright (c) 2017 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.
19 using Tizen.Internals.Errors;
21 namespace Tizen.Applications
24 /// The class for getting the resource path.
26 /// <since_tizen> 3 </since_tizen>
27 public static class ResourceManager
30 /// Enumeration for the resource category.
32 /// <since_tizen> 3 </since_tizen>
33 public enum Category : int
56 private static ErrorCode AppResourceManagerGet(Category category, string id, out string path)
62 err = Interop.AppCommon.AppResourceManagerGet(
63 (Interop.AppCommon.ResourceCategory)category, id, out path);
65 catch (System.TypeLoadException)
67 err = Interop.AppCommon.LegacyAppResourceManagerGet(
68 (Interop.AppCommon.ResourceCategory)category, id, out path);
75 /// Converts resource ID to the path name.
77 /// <param name="category">Category to search.</param>
78 /// <param name="id">ID to search.</param>
79 /// <returns>Found resource path.</returns>
80 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
81 /// <since_tizen> 3 </since_tizen>
82 public static string GetPath(Category category, string id)
85 ErrorCode err = AppResourceManagerGet(category, id, out path);
89 case ErrorCode.InvalidParameter:
90 throw new InvalidOperationException("Invalid parameter");
92 case ErrorCode.OutOfMemory:
93 throw new InvalidOperationException("Out-of-memory at unmanaged code");
95 case ErrorCode.IoError:
96 throw new InvalidOperationException("IO error at unmanaged code");
103 /// Converts resource ID to the path name.
105 /// <param name="category">Category to search.</param>
106 /// <param name="id">ID to search.</param>
107 /// <returns>Found resource path or null when the resource doesn't exist.</returns>
108 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
109 /// <since_tizen> 3 </since_tizen>
110 public static string TryGetPath(Category category, string id)
116 if (Application.Current != null)
118 res = Application.Current.DirectoryInfo.Resource + "res.xml";
122 res = Interop.AppCommon.AppGetResourcePath() + "res.xml";
125 if (!File.Exists(res))
128 err = AppResourceManagerGet(category, id, out path);
131 case ErrorCode.InvalidParameter:
132 throw new InvalidOperationException("Invalid parameter");
134 case ErrorCode.OutOfMemory:
135 throw new InvalidOperationException("Out-of-memory at unmanaged code");
137 case ErrorCode.IoError: