Add packageType on Install
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 9 Feb 2017 12:20:31 +0000 (21:20 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 9 Feb 2017 12:20:31 +0000 (21:20 +0900)
Change-Id: Ic124718c0a97044e06313e3b3abb7fff406af6ab
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index 40ea1fb..136d1c9
@@ -17,6 +17,7 @@
 using System;
 using System.Collections.Generic;
 using System.Threading.Tasks;
+using System.IO;
 
 namespace Tizen.Applications
 {
@@ -276,6 +277,31 @@ namespace Tizen.Applications
         /// <privilege>http://tizen.org/privilege/packagemanager.admin</privilege>
         public static bool Install(string packagePath, string expansionPackagePath)
         {
+            PackageType type;
+            string extension = Path.GetExtension(packagePath);
+
+            if (extension.Contains("tpk"))
+            {
+                type = PackageType.TPK;
+            }
+            else
+            {
+                type = PackageType.WGT;
+            }
+
+            return Install(packagePath, expansionPackagePath, type);
+        }
+
+        /// <summary>
+        /// Installs package located at the given path
+        /// </summary>
+        /// <param name="packagePath">Absolute path for the package to be installed</param>
+        /// <param name="expansionPackagePath">Optional - Absolute path for the expansion package to be installed</param>
+        /// <param name="type">Package type for the package to be installed</param>
+        /// <returns>Returns true if installtion is successful, false otherwise.</returns>
+        /// <privilege>http://tizen.org/privilege/packagemanager.admin</privilege>
+        public static bool Install(string packagePath, string expansionPackagePath, PackageType type)
+        {
             IntPtr requestHandle;
             var err = Interop.PackageManager.PackageManagerRequestCreate(out requestHandle);
             if (err != Interop.PackageManager.ErrorCode.None)
@@ -284,6 +310,14 @@ namespace Tizen.Applications
                 return false;
             }
 
+            err = Interop.PackageManager.PackageManagerRequestSetType(requestHandle, type.ToString().ToLower());
+            if (err != Interop.PackageManager.ErrorCode.None)
+            {
+                Log.Warn(LogTag, string.Format("Failed to install package. Error in setting request package type. err = {0}", err));
+                Interop.PackageManager.PackageManagerRequestDestroy(requestHandle);
+                return false;
+            }
+
             if (!string.IsNullOrEmpty(expansionPackagePath))
             {
                 err = Interop.PackageManager.PackageManagerRequestSetTepPath(requestHandle, expansionPackagePath);