[INST] Install Manager Unzip logic is changed. 92/19792/1
authorMoonkyu Kang <moonkyu82.kang@samsung.com>
Fri, 18 Apr 2014 01:36:56 +0000 (10:36 +0900)
committerMoonkyu Kang <moonkyu82.kang@samsung.com>
Fri, 18 Apr 2014 01:36:56 +0000 (10:36 +0900)
Change-Id: I4cc0c0b62c5326afd07bc3255b1ce4587b8dd53a
Signed-off-by: Moonkyu Kang <moonkyu82.kang@samsung.com>
13 files changed:
InstallManager_java/src/org/tizen/installmanager/cli/CliUnzipImage.java
InstallManager_java/src/org/tizen/installmanager/lib/linux/LinuxSDKPackageFormat.java
InstallManager_java/src/org/tizen/installmanager/lib/linux/LinuxSDKPackageFormat_ori.java [new file with mode: 0644]
InstallManager_java/src/org/tizen/installmanager/ui/InstallManagerWindow.java
InstallManager_java/src/org/tizen/installmanager/ui/dialog/UnzipImageDialog.java
InstallManager_java/src/org/tizen/installmanager/util/ISdkConstant.java [new file with mode: 0644]
InstallManager_java/src/org/tizen/installmanager/util/unzip/ApacheSdkUnzip.java [new file with mode: 0644]
InstallManager_java/src/org/tizen/installmanager/util/unzip/ApacheUnzipThread.java [new file with mode: 0644]
InstallManager_java/src/org/tizen/installmanager/util/unzip/SevenZipSdkUnzip.java [new file with mode: 0644]
InstallManager_java/src/org/tizen/installmanager/util/unzip/UnzipSDK.java [new file with mode: 0644]
InstallManager_java/src/org/tizen/installmanager/util/unzip/UnzipUtil.java [new file with mode: 0644]
InstallManager_java/src/org/tizen/installmanager/util/unzip/Zip4jSdkUnzip.java [new file with mode: 0644]
InstallManager_java/src/org/tizen/installmanager/util/unzip/Zip4jUnzipThread.java [new file with mode: 0644]

index 8a106f9..ccf487f 100644 (file)
@@ -30,23 +30,22 @@ package org.tizen.installmanager.cli;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
 import java.util.zip.ZipInputStream;
 
 import org.tizen.installmanager.core.Config;
 import org.tizen.installmanager.core.IMFatalException;
 import org.tizen.installmanager.core.InstallManagerConstants;
-import org.tizen.installmanager.lib.Log;
 import org.tizen.installmanager.lib.ErrorController.ErrorCode;
+import org.tizen.installmanager.lib.Log;
 import org.tizen.installmanager.lib.Registry;
 import org.tizen.installmanager.pkg.lib.PackageManager;
+import org.tizen.installmanager.util.ISdkConstant;
 import org.tizen.installmanager.util.PathUtil;
 import org.tizen.installmanager.util.ResourceHandler;
+import org.tizen.installmanager.util.unzip.UnzipUtil;
 
 /**
  * This class works for extracting SDK image file by cli.
@@ -54,18 +53,16 @@ import org.tizen.installmanager.util.ResourceHandler;
   */
 public class CliUnzipImage {
        private int totalWork;
-    private UNZIP_RESULT result;
-    private String sdkTempDir = null;
+       private UNZIP_RESULT result;
+       private String sdkTempDir = null;
        private File imageFile = null; // SDK Image File
-    final static int BUF_SIZE = 65536;
-    final static int EMPTY_SIZE = 0;
     
-    public enum UNZIP_FILE_STYLE {IMAGE, PATCH};
-    public enum UNZIP_RESULT {FAIL, ERROR, SUCCESS};
+   public enum UNZIP_FILE_STYLE {IMAGE, PATCH};
+   public enum UNZIP_RESULT {FAIL, ERROR, SUCCESS};
     
        public CliUnzipImage(File file) {
                imageFile = file;
-               totalWork = getEntryCount(file);
+               totalWork = UnzipUtil.getEntryCount(file);
        }
        
        /**
@@ -130,20 +127,15 @@ public class CliUnzipImage {
      * @throws Exception
      */
     private long unzipImageFile() {
-               final File sdkTempDirFile = new File(sdkTempDir);
-               if (!sdkTempDirFile.exists()) {
-                       if (sdkTempDirFile.mkdirs()) {
-                               Log.log("Success to create SDK temporary directory " + sdkTempDirFile);
-                       } else {
-                               Log.err("Fail to create SDK temporary directory " + sdkTempDirFile);
-                       }
+               File targetDir = new File(sdkTempDir);
+               if(UnzipUtil.checkTempDirectory(targetDir) == ISdkConstant.ERROR){
+                       Log.err("Fail to create SDK temporary directory.");
+                       return 1;
                }
                
-               File targetDir = sdkTempDirFile;
-               
-        FileInputStream fis = null;
-        ZipInputStream zis = null;
-        ZipEntry zipEntry = null;
+               FileInputStream fis = null;
+               ZipInputStream zis = null;
+               ZipEntry zipEntry = null;
                int work = 1;
                int cnt = 0;
         
@@ -160,15 +152,12 @@ public class CliUnzipImage {
                                                Log.err("Fail to create file ==> " + targetFile);
                                        }
                                } else { // File case
-                                       // Make parent directory
-//                                     File parent = new File(targetFile.getParent());
                                        File parent = PathUtil.makeParent(targetFile.getAbsolutePath());
                                        
                                        if (!parent.getAbsolutePath().equalsIgnoreCase(sdkTempDir)) {
                                                cnt = PathUtil.getParentCnt(fileNameToUnzip);                                           
                                        }
-
-                                       if (0 > unzipEntry(zis, targetFile)) {
+                                       if (0 > UnzipUtil.unzipEntry(zis, targetFile)) {
                                                System.out.println(zipEntry.getName() + " ..... done.");
                                                if (cnt == 0) {
                                                        work++;                                                 
@@ -205,57 +194,6 @@ public class CliUnzipImage {
                ResourceHandler.closeObjectSilently(fis);
                }
     }
-
-    /**
-     * Extract a zip entry.
-     * @param zis Zip Input Stream
-     * @param targetFile Target file after unzip image file.
-     * @return
-     * @throws FileNotFoundException, IOException
-     */
-    private int unzipEntry(ZipInputStream zis, File targetFile) throws FileNotFoundException, IOException {
-        FileOutputStream fos = null;
-        int readByte = 0;
-        
-        try {
-            fos = new FileOutputStream(targetFile);
-
-            byte[] buffer = new byte[BUF_SIZE];
-            while ((readByte = zis.read(buffer)) != -1) {
-                fos.write(buffer, 0, readByte);
-            }
-        } finally {
-               ResourceHandler.closeObjectSilently(fos);
-        }
-        return readByte;
-    }
-       
-       /**
-        * Get total number of zip entry.
-        * @param imageFile SDK Image File.
-        * @return
-        */
-       private int getEntryCount(File imageFile) {
-               ZipFile zipFile = null;
-               int sizeOfZipfile = EMPTY_SIZE;
-               
-               try {
-                       zipFile = new ZipFile(imageFile);
-                       sizeOfZipfile = zipFile.size();
-               } catch (ZipException e) {
-                       // Check zip file already.
-                       sizeOfZipfile = EMPTY_SIZE;
-                       Log.err("This exception must not take place in SDK Image file.");
-                       Log.ExceptionLog(e);
-               } catch (IOException e) {
-                       sizeOfZipfile = EMPTY_SIZE;
-                       Log.ExceptionLog(e);
-               } finally {
-                       ResourceHandler.closeObjectSilently(zipFile);
-               }
-               
-               return sizeOfZipfile;
-       }
        
        private void setUnzipResult(UNZIP_RESULT unzipResult) {
                result = unzipResult;
index fa1e5f3..c4e79c4 100644 (file)
@@ -31,17 +31,20 @@ package org.tizen.installmanager.lib.linux;
 import java.io.File;\r
 \r
 import org.tizen.installmanager.core.IMFatalException;\r
+import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
 import org.tizen.installmanager.lib.IIMProgressMonitor;\r
 import org.tizen.installmanager.lib.Log;\r
 import org.tizen.installmanager.lib.SDKPackageFormat;\r
-import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
 import org.tizen.installmanager.util.IMShellCommandFail;\r
 import org.tizen.installmanager.util.ShellUtil;\r
+import org.tizen.installmanager.util.unzip.ApacheSdkUnzip;\r
+import org.tizen.installmanager.util.unzip.UnzipSDK;\r
 \r
 /**\r
  * Manages to unpack package of tizen sdk for linux.\r
  * \r
  * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+ * @author Moonkyu Kang <moonkyu82.kang@samsung.com>\r
  * \r
  */\r
 public class LinuxSDKPackageFormat extends SDKPackageFormat {\r
@@ -50,8 +53,7 @@ public class LinuxSDKPackageFormat extends SDKPackageFormat {
        @Override\r
        public long unZip(File fileFullPath, File targetDir,\r
                        IIMProgressMonitor monitor) {\r
-               Log.log("Unpack " + fileFullPath + " to " + targetDir);\r
-\r
+               Log.log("Unpack " + fileFullPath + " to " + targetDir);         \r
                checkExtension = getPackageType(fileFullPath.getAbsolutePath());\r
 \r
                if (!fileFullPath.exists()) {\r
@@ -76,28 +78,58 @@ public class LinuxSDKPackageFormat extends SDKPackageFormat {
 \r
                int exitValue = ERROR;\r
 \r
-               try {\r
-                       if (checkExtension == PackageType.ZIP) {\r
-                               exitValue = sendCommand(\r
-                                               "unzip -o " + fileFullPath.getAbsolutePath() + " -d "\r
-                                                               + targetDir.getAbsolutePath(),\r
-                                               fileFullPath.getAbsolutePath(), PackageType.ZIP,\r
-                                               monitor);\r
-                               unzipReturnValue(exitValue);\r
-                       } else if (checkExtension == PackageType.TAR_GZ) {\r
+               if (checkExtension == PackageType.ZIP){\r
+//                     UnzipSDK unzipSdk = new Zip4jSdkUnzip();\r
+//                     return unzipSdk.unzipPackageFile(fileFullPath.getAbsolutePath(), targetDir.getAbsolutePath());\r
+//                     UnzipSDK unzipSdk = new SevenZipSdkUnzip();\r
+//                     return unzipSdk.unzipPackageFile(fileFullPath.getAbsolutePath(), targetDir.getAbsolutePath());\r
+                       UnzipSDK unzipSdk = new ApacheSdkUnzip();\r
+                       return unzipSdk.unzipPackageFile(fileFullPath.getAbsolutePath(), targetDir.getAbsolutePath());                  \r
+                       \r
+               } else if (checkExtension == PackageType.TAR_GZ) {\r
+                       try {\r
                                exitValue = sendCommand(\r
                                                "tar xvf " + fileFullPath.getAbsolutePath() + " -C "\r
                                                                + targetDir.getAbsolutePath(),\r
                                                fileFullPath.getAbsolutePath(), PackageType.TAR_GZ,\r
                                                monitor);\r
                                tarReturnValue(exitValue);\r
-                       } else {\r
-                               throw new IMFatalException(ErrorCode.UNKNOWN_PACKAGE_EXTENSION);\r
+\r
+                       } catch (IMShellCommandFail e) {\r
+                               Log.ExceptionLog(e);\r
+                               return ERROR;\r
                        }\r
-               } catch (IMShellCommandFail e) {\r
-                       Log.ExceptionLog(e);\r
-                       return ERROR;\r
+               } else {\r
+                       throw new IMFatalException(ErrorCode.UNKNOWN_PACKAGE_EXTENSION);\r
                }\r
+               \r
+//             try {\r
+//                     if (checkExtension == PackageType.ZIP) {\r
+//                             long startTime = System.currentTimeMillis();\r
+//                             exitValue = sendCommand(\r
+//                                             "unzip -o " + fileFullPath.getAbsolutePath() + " -d "\r
+//                                                             + targetDir.getAbsolutePath(),\r
+//                                             fileFullPath.getAbsolutePath(), PackageType.ZIP,\r
+//                                             monitor);\r
+//                             unzipReturnValue(exitValue);\r
+//                             long finishedTime = System.currentTimeMillis();\r
+//                             System.out.println("extracting time : "+ (finishedTime - startTime));\r
+//                             \r
+//                     } else if (checkExtension == PackageType.TAR_GZ) {\r
+//                             exitValue = sendCommand(\r
+//                                             "tar xvf " + fileFullPath.getAbsolutePath() + " -C "\r
+//                                                             + targetDir.getAbsolutePath(),\r
+//                                             fileFullPath.getAbsolutePath(), PackageType.TAR_GZ,\r
+//                                             monitor);\r
+//                             tarReturnValue(exitValue);\r
+//                     } else {\r
+//                             throw new IMFatalException(ErrorCode.UNKNOWN_PACKAGE_EXTENSION);\r
+//                     }\r
+//             } catch (IMShellCommandFail e) {\r
+//                     Log.ExceptionLog(e);\r
+//                     return ERROR;\r
+//             }\r
+\r
 \r
                return SUCCESS;\r
        }\r
diff --git a/InstallManager_java/src/org/tizen/installmanager/lib/linux/LinuxSDKPackageFormat_ori.java b/InstallManager_java/src/org/tizen/installmanager/lib/linux/LinuxSDKPackageFormat_ori.java
new file mode 100644 (file)
index 0000000..c4c491b
--- /dev/null
@@ -0,0 +1,204 @@
+/*\r
+ *  InstallManager\r
+ *\r
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Contact: \r
+ * Wooyoung Cho <wooyoung1.cho@samsung.com>\r
+ * Shihyun Kim <shihyun.kim@samsung.com>\r
+ * Taeyoung Son <taeyoung2.son@samsung.com>\r
+ * Yongsung kim <yongsung1.kim@samsung.com>\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ * Contributors:\r
+ * - S-Core Co., Ltd\r
+ *\r
+ */\r
+\r
+package org.tizen.installmanager.lib.linux;\r
+\r
+import java.io.File;\r
+\r
+import org.tizen.installmanager.core.IMFatalException;\r
+import org.tizen.installmanager.lib.IIMProgressMonitor;\r
+import org.tizen.installmanager.lib.Log;\r
+import org.tizen.installmanager.lib.SDKPackageFormat;\r
+import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
+import org.tizen.installmanager.util.IMShellCommandFail;\r
+import org.tizen.installmanager.util.ShellUtil;\r
+\r
+/**\r
+ * Manages to unpack package of tizen sdk for linux.\r
+ * \r
+ * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+ * \r
+ */\r
+public class LinuxSDKPackageFormat_ori extends SDKPackageFormat {\r
+       private PackageType checkExtension;\r
+\r
+       @Override\r
+       public long unZip(File fileFullPath, File targetDir,\r
+                       IIMProgressMonitor monitor) {\r
+               Log.log("Unpack " + fileFullPath + " to " + targetDir);\r
+\r
+               checkExtension = getPackageType(fileFullPath.getAbsolutePath());\r
+\r
+               if (!fileFullPath.exists()) {\r
+                       Log.err("Package file is not exsisting");\r
+                       return ERROR;\r
+               } else if (checkExtension == PackageType.ELSE) {\r
+                       Log.err("Package extension is not '.zip' or '.tar.gz'");\r
+                       return ERROR;\r
+               }\r
+\r
+               if (targetDir == null || !targetDir.isAbsolute()) {\r
+                       return ERROR;\r
+               }\r
+\r
+               if (!targetDir.exists()) {\r
+                       if (targetDir.mkdirs()) {\r
+                               Log.log("Success to create directory ==> " + targetDir);\r
+                       } else {\r
+                               Log.err("Fail to create directory ==> " + targetDir);\r
+                       }\r
+               }\r
+\r
+               int exitValue = ERROR;\r
+\r
+               try {\r
+                       if (checkExtension == PackageType.ZIP) {\r
+                               exitValue = sendCommand(\r
+                                               "unzip -o " + fileFullPath.getAbsolutePath() + " -d "\r
+                                                               + targetDir.getAbsolutePath(),\r
+                                               fileFullPath.getAbsolutePath(), PackageType.ZIP,\r
+                                               monitor);\r
+                               unzipReturnValue(exitValue);\r
+                       } else if (checkExtension == PackageType.TAR_GZ) {\r
+                               exitValue = sendCommand(\r
+                                               "tar xvf " + fileFullPath.getAbsolutePath() + " -C "\r
+                                                               + targetDir.getAbsolutePath(),\r
+                                               fileFullPath.getAbsolutePath(), PackageType.TAR_GZ,\r
+                                               monitor);\r
+                               tarReturnValue(exitValue);\r
+                       } else {\r
+                               throw new IMFatalException(ErrorCode.UNKNOWN_PACKAGE_EXTENSION);\r
+                       }\r
+               } catch (IMShellCommandFail e) {\r
+                       Log.ExceptionLog(e);\r
+                       return ERROR;\r
+               }\r
+\r
+               return SUCCESS;\r
+       }\r
+\r
+       private int sendCommand(String command, String path, PackageType type, IIMProgressMonitor monitor) throws IMShellCommandFail {\r
+       LinuxShellInstalledListParser parser = null;\r
+       \r
+       if (mFileOutput != null) {\r
+                parser = new LinuxShellInstalledListParser(type);\r
+               parser.setFileOutputStream(mFileOutput);\r
+               parser.setProgress(monitor);\r
+       }\r
+       \r
+       int exitValue = ShellUtil.execute(command, null, null, parser);\r
+       \r
+       return exitValue;\r
+    }\r
+\r
+       /**\r
+        * extract tar error case.\r
+        * \r
+        * @param exitValue\r
+        * @return\r
+        * @throws IMShellCommandFail\r
+        */\r
+       private static boolean tarReturnValue(int exitValue)\r
+                       throws IMShellCommandFail {\r
+               if (exitValue == 0) {\r
+                       return true;\r
+               } else {\r
+                       throw new IMShellCommandFail();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * extract zip error case.\r
+        * \r
+        * @param exitValue\r
+        * @return\r
+        * @throws IMShellCommandFail\r
+        */\r
+       private static boolean unzipReturnValue(int exitValue)\r
+                       throws IMShellCommandFail {\r
+               switch (exitValue) {\r
+               case 0:\r
+                       return true;\r
+               case 1:\r
+                       Log.err("one or more warning errors were encountered, but processing completed  successfully  anyway."\r
+                                       + "This  includes  zipfiles  where one or more files was skipped due to unsupported compression "\r
+                                       + "method or encryption with an unknown password.");\r
+                       throw new IMShellCommandFail();\r
+               case 2:\r
+                       Log.err("a generic error in the zipfile format was detected.  Processing may have completed"\r
+                                       + "successfully anyway; some broken zipfiles created by other archivers have simple work-arounds.");\r
+                       throw new IMShellCommandFail();\r
+               case 3:\r
+                       Log.err("a severe error in the zipfile format was detected.  Processing probably failed immediately.");\r
+                       throw new IMShellCommandFail();\r
+               case 4:\r
+                       Log.err("unzip was unable to allocate memory for one or more buffers during program initialization.");\r
+                       throw new IMShellCommandFail();\r
+               case 5:\r
+                       Log.err("unzip was unable to allocate memory or unable to obtain a tty to read the decryption password(s).");\r
+                       throw new IMShellCommandFail();\r
+               case 6:\r
+                       Log.err("unzip was unable to allocate memory during decompression to disk.");\r
+                       throw new IMShellCommandFail();\r
+               case 7:\r
+                       Log.err("unzip was unable to allocate memory during in-memory decompression.");\r
+                       throw new IMShellCommandFail();\r
+               case 8:\r
+                       Log.err("[currently not used]");\r
+                       throw new IMShellCommandFail();\r
+               case 9:\r
+                       Log.err("the specified zipfiles were not found.");\r
+                       throw new IMShellCommandFail();\r
+               case 10:\r
+                       Log.err("invalid options were specified on the command line.");\r
+                       throw new IMShellCommandFail();\r
+               case 11:\r
+                       Log.err("no matching files were found.");\r
+                       throw new IMShellCommandFail();\r
+               case 50:\r
+                       Log.err("the disk is (or was) full during extraction.");\r
+                       throw new IMShellCommandFail();\r
+               case 51:\r
+                       Log.err("the end of the ZIP archive was encountered prematurely.");\r
+                       throw new IMShellCommandFail();\r
+               case 80:\r
+                       Log.err("the user aborted unzip prematurely with control-C (or similar)");\r
+                       throw new IMShellCommandFail();\r
+               case 81:\r
+                       Log.err("testing or extraction of one or more files failed due to unsupported compression methods  or unsupported decryption.");\r
+                       throw new IMShellCommandFail();\r
+               case 82:\r
+                       Log.err("no  files  were  found due to bad decryption password(s).  (If even one file is successfully"\r
+                                       + "processed, however, the exit status is 1.)");\r
+                       throw new IMShellCommandFail();\r
+               default:\r
+                       Log.err("Unknown exit value");\r
+                       throw new IMFatalException("Unknown exit value after unzip");\r
+               }\r
+       }\r
+}\r
index b58be1a..10c958d 100644 (file)
@@ -142,8 +142,8 @@ public class InstallManagerWindow extends ApplicationWindow {
         */\r
        public InstallManagerWindow() {\r
                super(null);\r
-               setShellStyle(SWT.SHELL_TRIM);\r
-               setShellStyle(SWT.BORDER | SWT.TITLE);\r
+               //setShellStyle(SWT.SHELL_TRIM);\r
+               setShellStyle(SWT.BORDER | SWT.TITLE | SWT.SHELL_TRIM);\r
        }\r
 \r
        /**\r
index cb0de68..9cf5850 100644 (file)
@@ -30,8 +30,6 @@ package org.tizen.installmanager.ui.dialog;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipException;
@@ -40,20 +38,22 @@ import java.util.zip.ZipInputStream;
 
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.ProgressBar;
 import org.eclipse.swt.widgets.Shell;
 import org.tizen.installmanager.core.IMFatalException;
-import org.tizen.installmanager.lib.Log;
 import org.tizen.installmanager.lib.ErrorController.ErrorCode;
+import org.tizen.installmanager.lib.Log;
 import org.tizen.installmanager.ui.InstallManagerWindow;
 import org.tizen.installmanager.ui.dialog.MessageBoxDlg.DialogType;
+import org.tizen.installmanager.util.ISdkConstant;
 import org.tizen.installmanager.util.PathUtil;
 import org.tizen.installmanager.util.ResourceHandler;
+import org.tizen.installmanager.util.unzip.UnzipUtil;
 
 /**
  * This class work for extracting SDK Image file.
@@ -65,22 +65,21 @@ public class UnzipImageDialog extends Dialog {
        private ProgressBar mProgressBar = null;
        private Label mNameLabel = null;
        private int totalWork;
-    private UNZIP_RESULT result;
-    private UnzipImageThread uiThread;
-    private String sdkTempDir = null;
+       private UNZIP_RESULT result;
+       private UnzipImageThread uiThread;
+       private String sdkTempDir = null;
 
        private File imageFile = null; // SDK Image File
-    final static int BUF_SIZE = 65536;
-    final static int EMPTY_SIZE = 0;
+       
     
-    public enum UNZIP_RESULT {FAIL, ERROR, SUCCESS};
+   public enum UNZIP_RESULT {FAIL, ERROR, SUCCESS};
 
        protected UnzipImageDialog(Shell parent, File file, String targetTemp) {
                super(parent);
                setShellStyle(SWT.None | SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
                imageFile = file;
                parent.getShell().setImage(PathUtil.getImageFromResource("/res/icons/SDK_icon.png"));
-               totalWork = getEntryCount(file);
+               totalWork = UnzipUtil.getEntryCount(file);
                sdkTempDir = targetTemp;
        }
        
@@ -243,20 +242,15 @@ public class UnzipImageDialog extends Dialog {
      * @throws Exception
      */
     private long unzipImageFile(Composite composite) {
-               final File sdkTempDirFile = new File(sdkTempDir);
-               if (!sdkTempDirFile.exists()) {
-                       if (sdkTempDirFile.mkdirs()) {
-                               Log.log("Success to create SDK temporary directory " + sdkTempDirFile);
-                       } else {
-                               Log.err("Fail to create SDK temporary directory " + sdkTempDirFile);
-                       }
+               File targetDir = new File(sdkTempDir);
+               if(UnzipUtil.checkTempDirectory(targetDir) == ISdkConstant.ERROR){
+                       Log.err("Fail to create SDK temporary directory.");
+                       return 1;
                }
                
-               File targetDir = sdkTempDirFile;
-               
-        FileInputStream fis = null;
-        ZipInputStream zis = null;
-        ZipEntry zipEntry = null;
+               FileInputStream fis = null;
+               ZipInputStream zis = null;
+               ZipEntry zipEntry = null;
         
         try {
                        fis = new FileInputStream(imageFile);
@@ -275,8 +269,9 @@ public class UnzipImageDialog extends Dialog {
                                        // Make parent directory
                                        File parent = new File(targetFile.getParent());
                                        parent.mkdir();
-                                       setProgress(++i, composite, zipEntry.getName()); // Increase progress bar.
-                                       unzipEntry(zis, targetFile);
+                                       // Increase progress bar.
+                                       setProgress(++i, composite, zipEntry.getName());
+                                       UnzipUtil.unzipEntry(zis, targetFile);
                                }
                        }
                        
@@ -300,29 +295,9 @@ public class UnzipImageDialog extends Dialog {
                }
     }
 
-    /**
-     * Extract a zip entry.
-     * @param zis Zip Input Stream
-     * @param targetFile Target file after unzip image file.
-     * @return
-     * @throws FileNotFoundException, IOException
-     */
-    private int unzipEntry(ZipInputStream zis, File targetFile) throws FileNotFoundException, IOException {
-        FileOutputStream fos = null;
-        int readByte = 0;
-        
-        try {
-            fos = new FileOutputStream(targetFile);
 
-            byte[] buffer = new byte[BUF_SIZE];
-            while ((readByte = zis.read(buffer)) != -1) {
-                fos.write(buffer, 0, readByte);
-            }
-        } finally {
-               ResourceHandler.closeObjectSilently(fos);
-        }
-        return readByte;
-    }
+
+
        
     /**
      * Make progress bar step by step on each work.
@@ -364,35 +339,8 @@ public class UnzipImageDialog extends Dialog {
                                }
                        }
                });                     
-       }
-       
-       /**
-        * Get total number of zip entry.
-        * @param imageFile SDK Image File.
-        * @return
-        */
-       private int getEntryCount(File imageFile) {
-               ZipFile zipFile = null;
-               int sizeOfZipfile = EMPTY_SIZE;
-               
-               try {
-                       zipFile = new ZipFile(imageFile);
-                       sizeOfZipfile = zipFile.size();
-               } catch (ZipException e) {
-                       // Check zip file already.
-                       sizeOfZipfile = EMPTY_SIZE;
-                       Log.err("This exception must not take place in SDK Image file.");
-                       Log.ExceptionLog(e);
-               } catch (IOException e) {
-                       sizeOfZipfile = EMPTY_SIZE;
-                       Log.ExceptionLog(e);
-               } finally {
-                       ResourceHandler.closeObjectSilently(zipFile);
-               }
-               
-               return sizeOfZipfile;
-       }
-       
+       }       
+
        private void setUnzipResult(UNZIP_RESULT unzipResult) {
                result = unzipResult;
        }
diff --git a/InstallManager_java/src/org/tizen/installmanager/util/ISdkConstant.java b/InstallManager_java/src/org/tizen/installmanager/util/ISdkConstant.java
new file mode 100644 (file)
index 0000000..40326ab
--- /dev/null
@@ -0,0 +1,6 @@
+package org.tizen.installmanager.util;
+
+public interface ISdkConstant {
+       public static final int SUCCESS = 1;
+       public static final int ERROR = -1;
+}
diff --git a/InstallManager_java/src/org/tizen/installmanager/util/unzip/ApacheSdkUnzip.java b/InstallManager_java/src/org/tizen/installmanager/util/unzip/ApacheSdkUnzip.java
new file mode 100644 (file)
index 0000000..181391c
--- /dev/null
@@ -0,0 +1,110 @@
+package org.tizen.installmanager.util.unzip;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Enumeration;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.zip.ZipException;
+
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
+import org.apache.commons.compress.archivers.zip.ZipFile;
+import org.apache.commons.compress.utils.IOUtils;
+import org.tizen.installmanager.lib.Log;
+/**
+ * 
+ * @author Moonkyu Kang <moonkyu82.kang@samsung.com>
+ *
+ */
+public class ApacheSdkUnzip extends UnzipSDK {
+       
+       
+
+       @Override
+       public long unzipPackageFile(String fileFullPath, String targetFullPath) {
+       
+               final File sdkTempDirFile = new File(targetFullPath);
+               if (!sdkTempDirFile.exists()) {
+                       sdkTempDirFile.mkdirs();
+               }
+               
+               ZipFile zipFile = null;
+               try {
+                       zipFile = new ZipFile(fileFullPath);
+                       Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
+                       ExecutorService executor = Executors.newFixedThreadPool(5);
+                       long startTime = System.currentTimeMillis();
+                       while (entries.hasMoreElements()) {
+                               ZipArchiveEntry element = entries.nextElement();
+                               String fileNameToUnzip = element.getName();
+                               File targetFile = new File(targetFullPath, fileNameToUnzip);
+                               if (element.isDirectory()) {// Directory case
+                                       if (!targetFile.mkdir()) { // Make directory
+                                               System.out.println("Fail to create file ==> "
+                                                               + targetFile);
+                                       }
+                               } else {
+                                       Runnable worker = new ApacheUnzipThread(targetFile,
+                                                       element, zipFile);
+                                       executor.execute(worker);
+                               }
+                       }
+                       executor.shutdown();
+                       while (!executor.isTerminated()) {
+                       }
+                       long finishedTime = System.currentTimeMillis();
+                       System.out.println("extracting time : "
+                                       + (finishedTime - startTime));
+               } catch (IOException e1) {
+                       try {
+                               throw new Exception("FAIL_TO_EXTRACT_SDK_IMAGE_FILE");
+                       } catch (Exception e) {
+                               Log.err("FAIL_TO_EXTRACT_SDK_IMAGE_FILE");
+                       }
+               } finally {
+                       if (zipFile != null) {
+                               try {
+                                       zipFile.close();
+                               } catch (IOException e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+                       }
+               }               
+               return SUCCESS;
+       }
+       
+       private long copyFile(File targetFile,ZipArchiveEntry element,ZipFile zipFile){
+               OutputStream fos = null;
+               InputStream inputStream = null;
+               try {
+                       fos = new FileOutputStream(targetFile);
+                       inputStream = zipFile.getInputStream(element);
+                       IOUtils.copy(inputStream, fos);
+                       if ((element.getUnixMode() & 0100) != 0) {
+                               targetFile.setExecutable(true);                                         
+                       }
+               } catch (FileNotFoundException e) {
+                       e.printStackTrace();
+                       return ERROR;
+               } catch (ZipException e) {
+                       return ERROR;
+               } catch (IOException e) {
+                       return ERROR;
+               }finally{
+                       if(inputStream != null){
+                               IOUtils.closeQuietly(inputStream);
+                       }
+                       if(fos != null){
+                               IOUtils.closeQuietly(fos);
+                       }
+               }
+               return SUCCESS;
+       }
+
+
+}
diff --git a/InstallManager_java/src/org/tizen/installmanager/util/unzip/ApacheUnzipThread.java b/InstallManager_java/src/org/tizen/installmanager/util/unzip/ApacheUnzipThread.java
new file mode 100644 (file)
index 0000000..86670ea
--- /dev/null
@@ -0,0 +1,68 @@
+package org.tizen.installmanager.util.unzip;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.zip.ZipException;
+
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
+import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
+import org.apache.commons.compress.archivers.zip.ZipFile;
+import org.apache.commons.compress.utils.IOUtils;
+
+import sun.nio.ch.ThreadPool;
+
+public class ApacheUnzipThread implements Runnable{
+
+       protected final static int ERROR = -1;
+       protected final static int SUCCESS = 1;
+       
+
+       private File targetFile;
+       private ZipArchiveEntry element;
+       ZipFile zipFile;
+       
+       public ApacheUnzipThread(File targetFile,ZipArchiveEntry element,ZipFile zipFile){
+               this.targetFile = targetFile;
+               this.element = element;
+               this.zipFile = zipFile;
+       }
+       
+
+       @Override
+       public void run() {             
+               uzZipFile();            
+       }
+       
+       private long uzZipFile(){
+               OutputStream fos = null;
+               InputStream inputStream = null;
+               try {
+                       fos = new FileOutputStream(targetFile);
+                       inputStream = zipFile.getInputStream(element);
+                       IOUtils.copy(inputStream, fos);
+                       if ((element.getUnixMode() & 0100) != 0) {
+                               targetFile.setExecutable(true);                                         
+                       }
+               } catch (FileNotFoundException e) {
+                       e.printStackTrace();
+                       return ERROR;
+               } catch (ZipException e) {
+                       return ERROR;
+               } catch (IOException e) {
+                       return ERROR;
+               }finally{
+                       if(inputStream != null){
+                               IOUtils.closeQuietly(inputStream);
+                       }
+                       if(fos != null){
+                               IOUtils.closeQuietly(fos);
+                       }
+               }
+               return SUCCESS;
+       }
+}
diff --git a/InstallManager_java/src/org/tizen/installmanager/util/unzip/SevenZipSdkUnzip.java b/InstallManager_java/src/org/tizen/installmanager/util/unzip/SevenZipSdkUnzip.java
new file mode 100644 (file)
index 0000000..58bd60d
--- /dev/null
@@ -0,0 +1,324 @@
+package org.tizen.installmanager.util.unzip;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.RandomAccessFile;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import net.sf.sevenzipjbinding.ExtractAskMode;
+import net.sf.sevenzipjbinding.ExtractOperationResult;
+import net.sf.sevenzipjbinding.IArchiveExtractCallback;
+import net.sf.sevenzipjbinding.ISequentialOutStream;
+import net.sf.sevenzipjbinding.ISevenZipInArchive;
+import net.sf.sevenzipjbinding.PropID;
+import net.sf.sevenzipjbinding.SevenZip;
+import net.sf.sevenzipjbinding.SevenZipException;
+import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream;
+import net.sf.sevenzipjbinding.simple.ISimpleInArchive;
+import net.sf.sevenzipjbinding.simple.ISimpleInArchiveItem;
+/**
+ * 
+ * @author Moonkyu Kang <moonkyu82.kang@samsung.com>
+ *
+ */
+public class SevenZipSdkUnzip extends UnzipSDK {
+       
+       private String filterRegex = filterToRegex("*");
+       
+       
+       static class ExtractionException extends Exception {
+               private static final long serialVersionUID = -5108931481040742838L;
+               ExtractionException(String msg) {
+                       super(msg);
+               }
+               public ExtractionException(String msg, Exception e) {
+                       super(msg, e);
+               }
+       }
+       class ExtractCallback implements IArchiveExtractCallback {
+               private ISevenZipInArchive inArchive;
+               private int index;
+               private OutputStream outputStream;
+               private File file;
+               private ExtractAskMode extractAskMode;
+               private boolean isFolder;
+               private String outputDirectoryFile;
+               ExtractCallback(ISevenZipInArchive inArchive,String outputDirectoryFile) {
+                       this.inArchive = inArchive;
+                       this.outputDirectoryFile = outputDirectoryFile;
+               }
+               @Override
+               public void setTotal(long total) throws SevenZipException {
+               }
+               @Override
+               public void setCompleted(long completeValue) throws SevenZipException {
+               }
+               @Override
+               public ISequentialOutStream getStream(int index,
+                               ExtractAskMode extractAskMode) throws SevenZipException {
+                       closeOutputStream();
+                       this.index = index;
+                       this.extractAskMode = extractAskMode;
+                       this.isFolder = (Boolean) inArchive.getProperty(index,
+                                       PropID.IS_FOLDER);
+                       if (extractAskMode != ExtractAskMode.EXTRACT) {
+                               // Skipped files or files being tested
+                               return null;
+                       }
+                       String path = (String) inArchive.getProperty(index, PropID.PATH);
+                       file = new File(outputDirectoryFile, path);
+                       if (isFolder) {
+                               createDirectory(file);
+                               return null;
+                       }
+                       createDirectory(file.getParentFile());
+                       try {
+                               outputStream = new FileOutputStream(file);
+                       } catch (FileNotFoundException e) {
+                               throw new SevenZipException("Error opening file: "
+                                               + file.getAbsolutePath(), e);
+                       }
+                       ISimpleInArchive simpleInterface = inArchive.getSimpleInterface();
+                       ISimpleInArchiveItem item = simpleInterface.getArchiveItem(index);
+                       String binaryString = Integer.toBinaryString(item.getAttributes());
+                       if(binaryString.charAt(9) == '1'){
+                               file.setExecutable(true);
+                       }
+
+                       return new ISequentialOutStream() {
+                               public int write(byte[] data) throws SevenZipException {
+                                       try {
+                                               outputStream.write(data);
+                                       } catch (IOException e) {
+                                               throw new SevenZipException("Error writing to file: "
+                                                               + file.getAbsolutePath());
+                                       }
+                                       
+                                       return data.length; // Return amount of consumed data
+                               }
+                       };
+                       
+               }
+               private void createDirectory(File parentFile) throws SevenZipException {
+                       File test = new File(parentFile.getAbsolutePath());
+                       
+                       if (!test.exists()) {
+                               if (!test.mkdirs()) {   
+                                       if(!test.exists()){
+                                               throw new SevenZipException("Error creating directory: "
+                                                               + test.getAbsolutePath());
+                                       }
+                               }
+                       }
+               }
+               private void closeOutputStream() throws SevenZipException {
+                       if (outputStream != null) {
+                               try {
+                                       outputStream.close();
+                                       outputStream = null;
+                               } catch (IOException e) {
+                                       throw new SevenZipException("Error closing file: "
+                                                       + file.getAbsolutePath());
+                               }
+                       }
+               }
+               @Override
+               public void prepareOperation(ExtractAskMode extractAskMode)
+                               throws SevenZipException {
+               }
+               @Override
+               public void setOperationResult(
+                               ExtractOperationResult extractOperationResult)
+                               throws SevenZipException {
+                       closeOutputStream();
+                       String path = (String) inArchive.getProperty(index, PropID.PATH);
+                       if (extractOperationResult != ExtractOperationResult.OK) {
+                               throw new SevenZipException("Invalid file: " + path);
+                       }       
+                       if (!isFolder) {
+                               switch (extractAskMode) {
+                               case EXTRACT:
+                                       //System.out.println("Extracted " + path);
+                                       break;
+                               case TEST:
+                                       System.out.println("Tested " + path);
+                               default:
+                               }
+                       }
+               }
+       }
+       
+       
+       
+
+       @Override
+       public long unzipPackageFile(String fileFullPath, String targetFullPath) {
+       
+               long startTime = System.currentTimeMillis();
+               // Target Directory!!!
+               final File sdkTempDirFile = new File(targetFullPath);
+               if (!sdkTempDirFile.exists()) {
+                       sdkTempDirFile.mkdirs();
+               }
+               try {
+                       checkArchiveFile(fileFullPath);
+               } catch (ExtractionException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+               try {
+                       prepareOutputDirectory(targetFullPath);
+               } catch (ExtractionException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+               try {
+                       extractArchive(fileFullPath,targetFullPath);
+               } catch (ExtractionException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+               
+               long finishedTime = System.currentTimeMillis();
+               System.out.println("extracting time : "+ (finishedTime - startTime));
+               return SUCCESS;
+       }
+       
+       private String filterToRegex(String string) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       private void checkArchiveFile(String archive) throws ExtractionException {
+               if (!new File(archive).exists()) {
+                       throw new ExtractionException("Archive file not found: " + archive);
+               }
+               if (!new File(archive).canRead()) {
+                       System.out.println("Can't read archive file: " + archive);
+               }
+       }
+       
+       private void prepareOutputDirectory(String outputDirectory) throws ExtractionException {
+               File outputDirectoryFile = new File(outputDirectory);
+               if (!outputDirectoryFile.exists()) {
+                       outputDirectoryFile.mkdirs();
+               } 
+       }
+       
+       public void extractArchive(String archive,String targetPath) throws ExtractionException {
+               RandomAccessFile randomAccessFile;
+               boolean ok = false;
+               try {
+                       randomAccessFile = new RandomAccessFile(archive, "r");
+               } catch (FileNotFoundException e) {
+                       throw new ExtractionException("File not found", e);
+               }
+               try {
+                       extractArchive(randomAccessFile,targetPath);
+                       ok = true;
+               } finally {
+                       try {
+                               randomAccessFile.close();
+                       } catch (Exception e) {
+                               if (ok) {
+                                       throw new ExtractionException("Error closing archive file",
+                                                       e);
+                               }
+                       }
+               }
+       }
+       private void extractArchive(RandomAccessFile file,String targetPath)
+                       throws ExtractionException {
+               ISevenZipInArchive inArchive;
+               boolean ok = false;
+               try {
+                       inArchive = SevenZip.openInArchive(null,
+                                       new RandomAccessFileInStream(file));
+               } catch (SevenZipException e) {
+                       throw new ExtractionException("Error opening archive", e);
+               }
+               try {
+                       
+                       int[] ids = null; // All items
+                       if (filterRegex != null) {
+                               ids = filterIds(inArchive, filterRegex);
+                       }
+                       inArchive.extract(ids, false, new ExtractCallback(inArchive,targetPath));
+                       
+                       ok = true;
+               } catch (SevenZipException e) {
+                       StringBuilder stringBuilder = new StringBuilder();
+                       stringBuilder.append("Error extracting archive '");
+                       stringBuilder.append(targetPath);
+                       stringBuilder.append("': ");
+                       stringBuilder.append(e.getMessage());
+                       if (e.getCause() != null) {
+                               stringBuilder.append(" (");
+                               stringBuilder.append(e.getCause().getMessage());
+                               stringBuilder.append(')');
+                       }
+                       String message = stringBuilder.toString();
+                       throw new ExtractionException(message, e);
+               } finally {
+                       try {
+                               inArchive.close();
+                       } catch (SevenZipException e) {
+                               if (ok) {
+                                       throw new ExtractionException("Error closing archive", e);
+                               }
+                       }
+               }
+       }
+       private static int[] filterIds(ISevenZipInArchive inArchive, String regex) throws SevenZipException {
+               List<Integer> idList = new ArrayList<Integer>();
+               
+               int numberOfItems = inArchive.getNumberOfItems();
+               
+               Pattern pattern = Pattern.compile(regex);
+               for (int i = 0; i < numberOfItems; i++) {
+                       String path = (String) inArchive.getProperty(i, PropID.PATH);
+                       String fileName = new File(path).getName();
+                       if (pattern.matcher(fileName).matches()) {
+                               idList.add(i);
+                       }
+               }
+               
+               int[] result = new int[idList.size()];
+               for (int i = 0; i < result.length; i++) {
+                       result[i] = idList.get(i);
+               }
+               return result ;
+       }
+       
+
+
+
+}
diff --git a/InstallManager_java/src/org/tizen/installmanager/util/unzip/UnzipSDK.java b/InstallManager_java/src/org/tizen/installmanager/util/unzip/UnzipSDK.java
new file mode 100644 (file)
index 0000000..0b29260
--- /dev/null
@@ -0,0 +1,39 @@
+package org.tizen.installmanager.util.unzip;
+
+public abstract class UnzipSDK {
+       protected final static int BIG_EDIAN = 1;
+       protected final static int Little_EDIAN = 2;    
+       protected final static int ERROR = -1;
+       protected final static int SUCCESS = 1;
+               
+       
+       protected short BytesToShort(byte[] Value,int Order)
+        {
+         short newValue = 0;
+         byte[] temp = Value;
+         
+         temp = ChangeByteOrder(temp,Order);
+         
+            newValue |= (((short)temp[0])<<8)&0xFF00;
+            newValue |= (((short)temp[1]))&0xFF;
+         return newValue;
+        };
+       
+       private byte[] ChangeByteOrder(byte[] value, int Order) {
+               int idx = value.length;
+               byte[] Temp = new byte[idx];
+
+               if (Order == BIG_EDIAN) {
+                       Temp = value;
+               }
+
+               else if (Order == Little_EDIAN) {
+                       for (int i = 0; i < idx; i++) {
+                               Temp[i] = value[idx - (i + 1)];
+                       }
+               }
+               return Temp;
+       };
+       
+       public abstract long unzipPackageFile(String fileFullPath, String targetFullPath);      
+}
diff --git a/InstallManager_java/src/org/tizen/installmanager/util/unzip/UnzipUtil.java b/InstallManager_java/src/org/tizen/installmanager/util/unzip/UnzipUtil.java
new file mode 100644 (file)
index 0000000..d1f06e1
--- /dev/null
@@ -0,0 +1,88 @@
+package org.tizen.installmanager.util.unzip;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipInputStream;
+
+import org.tizen.installmanager.lib.Log;
+import org.tizen.installmanager.util.ISdkConstant;
+import org.tizen.installmanager.util.ResourceHandler;
+
+public class UnzipUtil {
+       final static int BUF_SIZE = 65536;
+       final static int EMPTY_SIZE = 0;
+       
+    /**
+     * Extract a zip entry.
+     * @param zis Zip Input Stream
+     * @param targetFile Target file after unzip image file.
+     * @return
+     * @throws FileNotFoundException, IOException
+     */
+    public static int unzipEntry(ZipInputStream zis, File targetFile) throws FileNotFoundException, IOException {
+               FileOutputStream fos = null;
+               int readByte = 0;
+
+               try {
+                       fos = new FileOutputStream(targetFile);
+
+                       byte[] buffer = new byte[BUF_SIZE];
+                       while ((readByte = zis.read(buffer)) != -1) {
+                               fos.write(buffer, 0, readByte);
+                       }
+               } finally {
+                       ResourceHandler.closeObjectSilently(fos);
+               }
+               return readByte;
+    }
+    
+       /**
+        * Get total number of zip entry.
+        * @param imageFile SDK Image File.
+        * @return
+        */
+       public static int getEntryCount(File imageFile) {
+               ZipFile zipFile = null;
+               int sizeOfZipfile = EMPTY_SIZE;
+               
+               try {
+                       zipFile = new ZipFile(imageFile);
+                       sizeOfZipfile = zipFile.size();
+               } catch (ZipException e) {
+                       // Check zip file already.
+                       sizeOfZipfile = EMPTY_SIZE;
+                       Log.err("This exception must not take place in SDK Image file.");
+                       Log.ExceptionLog(e);
+               } catch (IOException e) {
+                       sizeOfZipfile = EMPTY_SIZE;
+                       Log.ExceptionLog(e);
+               } finally {
+                       ResourceHandler.closeObjectSilently(zipFile);
+               }
+               
+               return sizeOfZipfile;
+       }
+       
+       public static int checkTempDirectory(File sdkTempDirFile) {
+               if (sdkTempDirFile != null && !sdkTempDirFile.exists()) {
+                       if (sdkTempDirFile.mkdirs()) {
+                               Log.log("Success to create SDK temporary directory " + sdkTempDirFile);
+                               return ISdkConstant.SUCCESS;
+                       } else {
+                               Log.err("Fail to create SDK temporary directory " + sdkTempDirFile);
+                               return ISdkConstant.ERROR;
+                       }
+               }else if (sdkTempDirFile != null && sdkTempDirFile.exists()){
+                       Log.log("SDK temporary directory is aready exists.");
+                       return ISdkConstant.SUCCESS;
+               }else{
+                       Log.err("Fail to create SDK temporary directory.");
+                       return ISdkConstant.ERROR;
+               }
+               
+       }
+}
diff --git a/InstallManager_java/src/org/tizen/installmanager/util/unzip/Zip4jSdkUnzip.java b/InstallManager_java/src/org/tizen/installmanager/util/unzip/Zip4jSdkUnzip.java
new file mode 100644 (file)
index 0000000..2d98b63
--- /dev/null
@@ -0,0 +1,56 @@
+package org.tizen.installmanager.util.unzip;
+
+import java.io.File;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.tizen.installmanager.lib.Log;
+
+import net.lingala.zip4j.core.ZipFile;
+import net.lingala.zip4j.exception.ZipException;
+import net.lingala.zip4j.model.FileHeader;
+
+public class Zip4jSdkUnzip extends UnzipSDK {
+
+       @Override
+       public long unzipPackageFile(String fileFullPath, String targetFullPath) {
+               try {                   
+                       ZipFile zipfile = new ZipFile(fileFullPath);
+                       long startTime = System.currentTimeMillis();
+                       @SuppressWarnings("unchecked")
+                       List<FileHeader> fileHeaders = (List<FileHeader>)zipfile.getFileHeaders();
+                       if(fileHeaders != null){                                
+                               for (FileHeader fileHeader : fileHeaders) {                                     
+                                       unzip(targetFullPath, zipfile, fileHeader);
+                               }
+                               long finishedTime = System.currentTimeMillis();
+                               System.out.println("extracting time : "+ (finishedTime - startTime));
+                       }else{                                  
+                               return ERROR;
+                       }                       
+               } catch (ZipException e) {
+                       Log.ExceptionLog(e);
+                       return ERROR;
+               }
+               return SUCCESS;         
+       }
+
+       private void unzip(String targetFullPath, ZipFile zipfile,
+                       FileHeader fileHeader) throws ZipException {
+               zipfile.extractFile(fileHeader, targetFullPath);
+               if(!fileHeader.isDirectory()){
+                       byte[] externalFileAttr = fileHeader.getExternalFileAttr();
+                       if(externalFileAttr != null && externalFileAttr.length > 0){
+                               short bytesToShort = BytesToShort(externalFileAttr,
+                                               Little_EDIAN);
+                               if ((bytesToShort & 0100) != 0) {
+                                       File f = new File(targetFullPath,
+                                                       fileHeader.getFileName());
+                                       f.setExecutable(true);
+                               }
+                       }
+               }
+       }
+
+}
diff --git a/InstallManager_java/src/org/tizen/installmanager/util/unzip/Zip4jUnzipThread.java b/InstallManager_java/src/org/tizen/installmanager/util/unzip/Zip4jUnzipThread.java
new file mode 100644 (file)
index 0000000..4e4c4ab
--- /dev/null
@@ -0,0 +1,91 @@
+package org.tizen.installmanager.util.unzip;
+import java.io.File;
+
+import net.lingala.zip4j.core.ZipFile;
+import net.lingala.zip4j.exception.ZipException;
+import net.lingala.zip4j.model.FileHeader;
+
+/**
+ * Cannot use thread in zip4j
+ * @author kahros2
+ *
+ */
+
+public class Zip4jUnzipThread implements Runnable{
+
+       protected final static int ERROR = -1;
+       protected final static int SUCCESS = 1;
+       protected final static int BIG_EDIAN = 1;
+       protected final static int Little_EDIAN = 2;
+
+       private String targetFullPath;
+       ZipFile zipFile;
+       FileHeader fileHeader;
+       
+       public Zip4jUnzipThread(String targetFullPath, ZipFile zipfile,
+                       FileHeader fileHeader){
+               this.targetFullPath = targetFullPath;
+               this.fileHeader = fileHeader;
+               this.zipFile = zipfile;
+       }
+       
+
+       @Override
+       public void run() {             
+               unZipFile();            
+       }
+       
+       private long unZipFile(){
+               try {
+                       zipFile.extractFile(fileHeader, targetFullPath);
+                       if(!fileHeader.isDirectory()){
+                               byte[] externalFileAttr = fileHeader.getExternalFileAttr();
+                               if(externalFileAttr != null && externalFileAttr.length > 0){
+                                       short bytesToShort = BytesToShort(externalFileAttr,
+                                                       Little_EDIAN);
+                                       if ((bytesToShort & 0100) != 0) {
+                                               File f = new File(targetFullPath,
+                                                               fileHeader.getFileName());
+                                               f.setExecutable(true);
+                                       }
+                               }
+                       }                       
+               } catch (ZipException e) {
+                       System.out.println("Error!!!!");
+                       System.out.println(e.getMessage());
+                       return ERROR;
+               }
+               
+               return SUCCESS;
+       }
+       
+       private short BytesToShort(byte[] Value,int Order)
+        {
+         short newValue = 0;
+         byte[] temp = Value;
+         
+         temp = ChangeByteOrder(temp,Order);
+         
+            newValue |= (((short)temp[0])<<8)&0xFF00;
+            newValue |= (((short)temp[1]))&0xFF;
+         return newValue;
+        };
+       
+       private byte[] ChangeByteOrder(byte[] value, int Order) {
+               int idx = value.length;
+               byte[] Temp = new byte[idx];
+
+               if (Order == BIG_EDIAN) {
+                       Temp = value;
+               }
+
+               else if (Order == Little_EDIAN) {
+                       for (int i = 0; i < idx; i++) {
+                               Temp[i] = value[idx - (i + 1)];
+                       }
+               }
+               return Temp;
+       };
+       
+
+}