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 public static class ResourceManager
29 /// Enumeration for the resource category.
31 public enum Category : int
54 private static ErrorCode AppResourceManagerGet(Category category, string id, out string path)
60 err = Interop.AppCommon.AppResourceManagerGet(
61 (Interop.AppCommon.ResourceCategory)category, id, out path);
63 catch (System.TypeLoadException)
65 err = Interop.AppCommon.LegacyAppResourceManagerGet(
66 (Interop.AppCommon.ResourceCategory)category, id, out path);
73 /// Converts resource ID to the path name.
75 /// <param name="category">Category to search.</param>
76 /// <param name="id">ID to search.</param>
77 /// <returns>Found resource path.</returns>
78 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
79 public static string GetPath(Category category, string id)
82 ErrorCode err = AppResourceManagerGet(category, id, out path);
86 case ErrorCode.InvalidParameter:
87 throw new InvalidOperationException("Invalid parameter");
89 case ErrorCode.OutOfMemory:
90 throw new InvalidOperationException("Out-of-memory at unmanaged code");
92 case ErrorCode.IoError:
93 throw new InvalidOperationException("IO error at unmanaged code");
100 /// Converts resource ID to the path name.
102 /// <param name="category">Category to search.</param>
103 /// <param name="id">ID to search.</param>
104 /// <returns>Found resource path or null when the resource doesn't exist.</returns>
105 /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
106 public static string TryGetPath(Category category, string id)
112 if (Application.Current != null)
114 res = Application.Current.DirectoryInfo.Resource + "res.xml";
118 res = Interop.AppCommon.AppGetResourcePath() + "res.xml";
121 if (!File.Exists(res))
124 err = AppResourceManagerGet(category, id, out path);
127 case ErrorCode.InvalidParameter:
128 throw new InvalidOperationException("Invalid parameter");
130 case ErrorCode.OutOfMemory:
131 throw new InvalidOperationException("Out-of-memory at unmanaged code");
133 case ErrorCode.IoError: