Don't call native API when res.xml does not exist
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.Common / Tizen.Applications / ResourceManager.cs
index c20840a..d300c57 100755 (executable)
  */
 
 using System;
+using System.IO;
 using Tizen.Internals.Errors;
 
 namespace Tizen.Applications
 {
     /// <summary>
-    /// Class for getting resource path.
+    /// The class for getting the resource path.
     /// </summary>
     public static class ResourceManager
     {
         /// <summary>
-        /// Enumeration for Resource category.
+        /// Enumeration for the resource category.
         /// </summary>
         public enum Category : int
         {
@@ -69,12 +70,12 @@ namespace Tizen.Applications
         }
 
         /// <summary>
-        /// Converts resource ID to path name.
+        /// Converts resource ID to the path name.
         /// </summary>
-        /// <param name="category">Category to search</param>
-        /// <param name="id">ID to search</param>
-        /// <returns>Found resource path</returns>
-        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions</exception>
+        /// <param name="category">Category to search.</param>
+        /// <param name="id">ID to search.</param>
+        /// <returns>Found resource path.</returns>
+        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
         public static string GetPath(Category category, string id)
         {
             string path;
@@ -96,17 +97,31 @@ namespace Tizen.Applications
         }
 
         /// <summary>
-        /// Converts resource ID to path name.
+        /// Converts resource ID to the path name.
         /// </summary>
-        /// <param name="category">Category to search</param>
-        /// <param name="id">ID to search</param>
-        /// <returns>Found resource path or null when the resource doesn't exist</returns>
-        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions</exception>
+        /// <param name="category">Category to search.</param>
+        /// <param name="id">ID to search.</param>
+        /// <returns>Found resource path or null when the resource doesn't exist.</returns>
+        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
         public static string TryGetPath(Category category, string id)
         {
             string path;
-            ErrorCode err = AppResourceManagerGet(category, id, out path);
+            ErrorCode err;
+            string res;
+
+            if (Application.Current != null)
+            {
+                res = Application.Current.DirectoryInfo.Resource + "res.xml";
+            }
+            else
+            {
+                res = Interop.AppCommon.AppGetResourcePath() + "res.xml";
+            }
+
+            if (!File.Exists(res))
+                return null;
 
+            err = AppResourceManagerGet(category, id, out path);
             switch (err)
             {
                 case ErrorCode.InvalidParameter: