return false;\r
}\r
\r
- mConfig.setTargetDir(targetDir);\r
- mConfig.setSdkDatatDir(Registry.sdkDataPath);\r
+\r
+ //kmk-Just do same job in "initializeTargetDir(targetDir);" \r
+// mConfig.setTargetDir(targetDir);\r
+// mConfig.setSdkDatatDir(Registry.sdkDataPath);\r
\r
if (monitor != null) {\r
monitor.workedRefresh();\r
ErrorCode.CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY);\r
}\r
\r
- List<File> missingFiles = findMissingFiles(pack, monitor);\r
- if (missingFiles.size() > 0) {\r
- Log.err("Some files are not moved properly: " + missingFiles);\r
- throw new IMFatalException(ErrorCode.FIND_MISSING_FILES);\r
- } else {\r
- Log.log("All files moved properly.");\r
- }\r
+ // kmk - remove unnecessary step\r
+// List<File> missingFiles = findMissingFiles(pack, monitor);\r
+// if (missingFiles.size() > 0) {\r
+// Log.err("Some files are not moved properly: " + missingFiles);\r
+// throw new IMFatalException(ErrorCode.FIND_MISSING_FILES);\r
+// } else {\r
+// Log.log("All files moved properly.");\r
+// }\r
\r
if (!executeInstallScript(pack, monitor, tempDir)) {\r
Log.err("Fail to execute install script.");\r
// return true;\r
// }\r
\r
- /**\r
- * @param pack\r
- * @return list of files which are not moved normally\r
- */\r
- private List<File> findMissingFiles(Package pack, IIMProgressMonitor monitor) {\r
- LinkedList<File> missingFiles = new LinkedList<File>();\r
- \r
- if (pack == null) {\r
- return missingFiles;\r
- }\r
- \r
- if (monitor != null) {\r
- monitor.workedInstallProgress("Verify that the file exists", 0);\r
- }\r
- \r
- File listFile = new File(getInstalledFileListPath(pack));\r
- InputStream is = null;\r
- BufferedReader in = null;\r
- try {\r
- is = new FileInputStream(listFile);\r
- in = new BufferedReader(new InputStreamReader(is, "UTF-8"));\r
- String line;\r
- while ((line = in.readLine()) != null) {\r
- File tmp = new File(PathUtil.getFromInstalledPath(line));\r
- if (!tmp.exists()) {\r
- if (Platform.isWindows()) {\r
- missingFiles.add(tmp);\r
- } else if (Platform.isLinux() || Platform.isMacOS()) {\r
- // check if it is broken link\r
- try {\r
- int exitCode = ShellUtil.execute("ls " + tmp, null);\r
- if (exitCode == 0) {\r
- Log.log("broken link " + tmp\r
- + " but no problem");\r
- } else {\r
- Log.err(tmp + " not exist.");\r
- missingFiles.add(tmp);\r
- }\r
- } catch (IMShellCommandFail e) {\r
- Log.err("Failed to check file exists");\r
- Log.ExceptionLog(e);\r
- }\r
- } else {\r
- throw new IMFatalException(\r
- ErrorCode.UNSUPPORTED_PLATFORM);\r
- }\r
- }\r
- }\r
- } catch (IOException e) {\r
- Log.err("Installer.findMissingFiles() Cannot check file list: "\r
- + listFile.getAbsolutePath());\r
- throw new IMFatalException(\r
- ErrorCode.CANNOT_CHECK_INSTLLED_FILE_LIST);\r
- } finally {\r
- if (in != null) {\r
- try {\r
- in.close();\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- }\r
- }\r
- \r
- if (is != null) {\r
- try {\r
- is.close();\r
- } catch (IOException e) {\r
- Log.ExceptionLog(e);\r
- }\r
- }\r
- }\r
- return missingFiles;\r
- }\r
+ // kmk - remove unnecessary method\r
+// /**\r
+// * @param pack\r
+// * @return list of files which are not moved normally\r
+// */ \r
+// private List<File> findMissingFiles(Package pack, IIMProgressMonitor monitor) {\r
+// LinkedList<File> missingFiles = new LinkedList<File>();\r
+// \r
+// if (pack == null) {\r
+// return missingFiles;\r
+// }\r
+// \r
+// if (monitor != null) {\r
+// monitor.workedInstallProgress("Verify that the file exists", 0);\r
+// }\r
+// \r
+// File listFile = new File(getInstalledFileListPath(pack));\r
+// InputStream is = null;\r
+// BufferedReader in = null;\r
+// try {\r
+// is = new FileInputStream(listFile);\r
+// in = new BufferedReader(new InputStreamReader(is, "UTF-8"));\r
+// String line;\r
+// while ((line = in.readLine()) != null) {\r
+// File tmp = new File(PathUtil.getFromInstalledPath(line));\r
+// if (!tmp.exists()) {\r
+// if (Platform.isWindows()) {\r
+// missingFiles.add(tmp);\r
+// } else if (Platform.isLinux() || Platform.isMacOS()) {\r
+// // check if it is broken link\r
+// try {\r
+// int exitCode = ShellUtil.execute("ls " + tmp, null);\r
+// if (exitCode == 0) {\r
+// Log.log("broken link " + tmp\r
+// + " but no problem");\r
+// } else {\r
+// Log.err(tmp + " not exist.");\r
+// missingFiles.add(tmp);\r
+// }\r
+// } catch (IMShellCommandFail e) {\r
+// Log.err("Failed to check file exists");\r
+// Log.ExceptionLog(e);\r
+// }\r
+// } else {\r
+// throw new IMFatalException(\r
+// ErrorCode.UNSUPPORTED_PLATFORM);\r
+// }\r
+// }\r
+// }\r
+// } catch (IOException e) {\r
+// Log.err("Installer.findMissingFiles() Cannot check file list: "\r
+// + listFile.getAbsolutePath());\r
+// throw new IMFatalException(\r
+// ErrorCode.CANNOT_CHECK_INSTLLED_FILE_LIST);\r
+// } finally {\r
+// if (in != null) {\r
+// try {\r
+// in.close();\r
+// } catch (IOException e) {\r
+// Log.ExceptionLog(e);\r
+// }\r
+// }\r
+// \r
+// if (is != null) {\r
+// try {\r
+// is.close();\r
+// } catch (IOException e) {\r
+// Log.ExceptionLog(e);\r
+// }\r
+// }\r
+// }\r
+// return missingFiles;\r
+// }\r
\r
/**\r
* Set script running process' environment variables.\r
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
-import org.tizen.installmanager.util.unzip.Zip4jSdkUnzip;\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
@Override\r
public long unZip(File fileFullPath, File targetDir,\r
IIMProgressMonitor monitor) {\r
- Log.log("Unpack " + fileFullPath + " to " + targetDir); \r
+ Log.log("Unpack " + fileFullPath + " to " + targetDir);\r
+\r
checkExtension = getPackageType(fileFullPath.getAbsolutePath());\r
\r
if (!fileFullPath.exists()) {\r
\r
int exitValue = ERROR;\r
\r
- if (checkExtension == PackageType.ZIP){\r
- UnzipSDK unzipSdk = new Zip4jSdkUnzip(); \r
- return unzipSdk.unzipPackageFile(fileFullPath.getAbsolutePath(), targetDir.getAbsolutePath(),monitor); \r
- } else if (checkExtension == PackageType.TAR_GZ) {\r
- try {\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
-\r
- } catch (IMShellCommandFail e) {\r
- Log.ExceptionLog(e);\r
- return ERROR;\r
+ } else {\r
+ throw new IMFatalException(ErrorCode.UNKNOWN_PACKAGE_EXTENSION);\r
}\r
- } else {\r
- throw new IMFatalException(ErrorCode.UNKNOWN_PACKAGE_EXTENSION);\r
+ } catch (IMShellCommandFail e) {\r
+ Log.ExceptionLog(e);\r
+ return ERROR;\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
+++ /dev/null
-/*\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
package org.tizen.installmanager.lib.win;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
import org.tizen.installmanager.core.IMFatalException;
import org.tizen.installmanager.lib.ErrorController.ErrorCode;
import org.tizen.installmanager.lib.IIMProgressMonitor;
import org.tizen.installmanager.lib.Log;
import org.tizen.installmanager.lib.SDKPackageFormat;
-import org.tizen.installmanager.util.unzip.ApacheSdkUnzip;
-import org.tizen.installmanager.util.unzip.UnzipSDK;
/**
* Manages to unpack package of tizen sdk for windows.
* @author Shihyun Kim <shihyun.kim@samsung.com>
+ * @author Moonkyu Kang <moonkyu82.kang@samsung.com>
*
*/
public class WindowsSDKPackageFormat extends SDKPackageFormat{
return ERROR;
}
Log.log(fileFullPath + " exists.");
-
- if (targetDir == null || !targetDir.isAbsolute()) {
- return ERROR;
- }
-
- Log.log(targetDir + " is not null and absolute.");
-
- if (!targetDir.exists()) {
- Log.log(targetDir + " does not exist. InstallManager will make target directory.");
- if (targetDir.mkdirs()) {
- Log.log("Success to create directory ==> " + targetDir);
- } else {
- Log.err("Fail to create directory ==> " + targetDir);
- }
- }
-
- UnzipSDK unzipSdk = new ApacheSdkUnzip();
- return unzipSdk.unzipPackageFile(fileFullPath.getAbsolutePath(), targetDir.getAbsolutePath(),monitor);
-
- //long ret = unZipPackage(fileFullPath, targetDir, monitor);
- //closeFileOutput();
- //return ret;
+ return unZipPackage(fileFullPath, targetDir, monitor);
}
- private long unZipPackage(File fileFullPath, File targetDir, IIMProgressMonitor monitor) {
- ZipInputStream zipInStream = null;
- FileOutputStream zipOutput = null;
- ZipEntry zipEntry = null;
-
- try {
- zipInStream = new ZipInputStream(new FileInputStream(fileFullPath));
- zipEntry = zipInStream.getNextEntry();
-
- long totalUnZipSize = 0;
- while (zipEntry != null) {
- String targetPath = targetDir.getAbsolutePath() + File.separator + zipEntry.getName();
-
- // make directory
- File targetFile = new File(targetPath);
- if (targetFile.exists() && targetFile.isDirectory()) {
- writeFileList(zipEntry.getName());
- zipEntry = zipInStream.getNextEntry();
- continue;
- }
-
- File parentFile = targetFile.getParentFile();
- if (!parentFile.exists()) {
- if (parentFile.mkdirs()) {
- Log.log("Success to create parent directory ==> " + parentFile);
- } else {
- Log.err("Fail to create parent directory ==> " + parentFile);
- }
- }
-
- if (targetPath.endsWith("/")) {// zipEntry.isDirectory
- File target = new File(targetPath);
- if (target.mkdir()) {
- Log.log("Success to create target directory ==> " + target);
- //System.out.println("Success to create target directory ==> " + target);
- } else {
- Log.err("Fail to create target directory ==> " + target);
- }
- zipInStream.closeEntry();
- writeFileList(zipEntry.getName());
- zipEntry = zipInStream.getNextEntry();
- continue;
- }
-
- zipOutput = new FileOutputStream(targetPath);
-
- byte[] zipBuf = new byte[BUF_SIZE];
- int readByte = 0;
-
- while ((readByte = zipInStream.read(zipBuf)) >= 0) {
- zipOutput.write(zipBuf, 0, readByte);
-
- if (monitor != null) {
- monitor.workedInstallSize(readByte);
- }
- totalUnZipSize += readByte;
- }
-
- writeFileList(zipEntry.getName());
-
- if (zipOutput != null) {
- zipOutput.close();
- }
-
- if (zipEntry != null) {
- zipInStream.closeEntry();
- }
- zipEntry = zipInStream.getNextEntry();
- }
-
- return totalUnZipSize;
- } catch (IOException e) {
- Log.ExceptionLog(e);
- if (zipEntry != null) {
- Log.err("Fail to unpack " + zipEntry.getName());
- }
-
- return ERROR;
- } catch (Throwable e) {
- Log.ExceptionLog(e);
- return ERROR;
- } finally {
- try {
- if (zipOutput != null) {
- zipOutput.flush();
- zipOutput.close();
- }
- } catch (IOException e) {
- if (zipEntry != null) {
- Log.err("Fail to close output stream : "
- + zipEntry.getName());
- } else {
- Log.ExceptionLog(e);
- }
- }
-
- try {
- if (zipInStream != null) {
- zipInStream.closeEntry();
- }
- } catch (IOException e) {
- if (zipEntry != null) {
- Log.err("Fail to close output stream : "
- + zipEntry.getName());
- } else {
- Log.ExceptionLog(e);
- }
- }
-
- if (zipInStream != null) {
- try {
- zipInStream.close();
- } catch (IOException e) {
- Log.ExceptionLog(e);
- }
- }
-
- try {
- if (mFileOutput != null) {
- mFileOutput.close();
- }
- } catch (IOException e) {
- if (zipEntry != null) {
- Log.err("Fail to close output stream : "
- + zipEntry.getName());
- } else {
- Log.ExceptionLog(e);
- }
- }
-
- closeFileOutput();
- }
- }
+private long unZipPackage(File fileFullPath, File targetDir, IIMProgressMonitor monitor) {
+
+ ZipFile zipFile = null;
+ FileOutputStream zipOutStream = null;
+ InputStream zis = null;
+ long totalUnZipSize = 0;
+ List<String> installedFileList = new ArrayList<String>();
+
+ try {
+ zipFile = new ZipFile(fileFullPath);
+ @SuppressWarnings("unchecked")
+ Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zipFile
+ .entries();
+ while (entries.hasMoreElements()) {
+ ZipEntry zipEntry = entries.nextElement();
+
+ if (zipEntry.isDirectory()) {
+ installedFileList.add(zipEntry.getName());
+ continue;
+ } else {
+ // Unzip files in "data" directory to target directory
+ String targetPathWithOutTempDir = targetDir.getParent();
+ String targetPath = null;
+ if (zipEntry.getName().startsWith("data/")) {
+ String fileName = zipEntry.getName().substring(5);
+ targetPath = targetPathWithOutTempDir + File.separator
+ + fileName;
+ } else {
+ targetPath = targetDir.getAbsolutePath()
+ + File.separator + zipEntry.getName();
+ }
+
+ // Prepare file for write
+ File targetFile = new File(targetPath);
+
+ // create parent directory
+ File parentFile = targetFile.getParentFile();
+ if (!parentFile.exists()) {
+ if (parentFile.mkdirs()) {
+ Log.log("Success to create parent directory ==> "
+ + parentFile);
+ } else {
+ Log.err("Fail to create parent directory ==> "
+ + parentFile);
+ }
+ }
+
+ // Write zip file to target File
+
+ zipOutStream = new FileOutputStream(targetPath);
+ zis = zipFile.getInputStream(zipEntry);
+ byte[] zipBuf = new byte[BUF_SIZE];
+ int readByte = 0;
+
+ while ((readByte = zis.read(zipBuf)) >= 0) {
+ zipOutStream.write(zipBuf, 0, readByte);
+ totalUnZipSize += readByte;
+ }
+
+ installedFileList.add(zipEntry.getName());
+
+ if (zipOutStream != null) {
+ zipOutStream.close();
+ }
+
+ if (zis != null) {
+ zis.close();
+ }
+ }
+ }
+ writeFileList(installedFileList);
+ } catch (ZipException e1) {
+ Log.ExceptionLog(e1);
+ } catch (IOException e1) {
+ Log.ExceptionLog(e1);
+ }finally{
+ try {
+ if(zis != null && zis.available() > 0){
+ try {
+ zis.close();
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ }
+ }
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ }
+
+ if(zipFile != null){
+ try {
+ zipFile.close();
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ }
+ }
+ if(zipOutStream != null){
+ try {
+ zipOutStream.flush();
+ zipOutStream.close();
+ } catch (IOException e) {
+ Log.ExceptionLog(e);
+ }
+ }
+ closeFileOutput();
+ }
+ closeFileOutput();
+ return totalUnZipSize;
+ }
- private void writeFileList(String filePath) {
- if (filePath == null || filePath.equals("")) {
- return;
+private void writeFileList(List<String> installedFileList) {
+
+ for (String filePath : installedFileList) {
+ if (filePath == null || filePath.equals("")) {
+ continue;
}
filePath = removeDataDirectory(filePath);
if (filePath == null || filePath.equals("")) {
- return;
+ continue;
}
if (mFileOutput == null) {
- return;
+ continue;
}
try {
Log.err("Fail to unpack " + filePath);
throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);
}
- }
+ }
+}
private String removeDataDirectory(String filePath) {
if (filePath == null || filePath.equals("")) {
+++ /dev/null
-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.IIMProgressMonitor;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.util.ISdkConstant;
-/**
- *
- * @author Moonkyu Kang <moonkyu82.kang@samsung.com>
- *
- */
-public class ApacheSdkUnzip extends UnzipSDK {
-
-
-
- @Override
- public long unzipPackageFile(String fileFullPath, String targetFullPath,IIMProgressMonitor monitor) {
-
- 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();
- File targetFile = new File(targetFullPath, element.getName());
- if (element.isDirectory()) {// Directory case
- if (!targetFile.exists()) {
- if (!targetFile.mkdirs()) { // Make directory
- if (targetFile.exists()) {
- System.out.println("Already exists : "
- + targetFile.getAbsolutePath());
- } else {
- System.out
- .println("Not file exists!!!,Fail to create file ==> "
- + targetFile.getAbsolutePath());
- }
- }
- } else {
- System.out.println("Already exists : "
- + targetFile.getAbsolutePath());
- }
- } 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 ISdkConstant.SUCCESS;
- }
-}
+++ /dev/null
-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.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;
-
-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;
- File parent = new File(targetFile.getParent());
- parent.mkdirs();
- if(!this.targetFile.exists()){
- try {
- targetFile.createNewFile();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- 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);
- long copy = IOUtils.copy(inputStream, fos);
- if ((element.getUnixMode() & 0100) != 0) {
- targetFile.setExecutable(true);
- }
-
- } catch (FileNotFoundException e) {
- Log.err("FileNotFoundException - Path: " + targetFile.getAbsolutePath());
- System.out.println("FileNotFoundException - Path: " + targetFile.getAbsolutePath());
- return ERROR;
- } catch (ZipException e) {
- System.out.println("ZipException - Path: " + targetFile.getAbsolutePath());
- Log.err("ZipException - Path: " + targetFile.getAbsolutePath());
- return ERROR;
- } catch (IOException e) {
- System.out.println("IOException - Path: " + targetFile.getAbsolutePath());
- Log.err("IOException - Path: " + targetFile.getAbsolutePath());
- return ERROR;
- }finally{
- if(inputStream != null){
- IOUtils.closeQuietly(inputStream);
- }
- if(fos != null){
- IOUtils.closeQuietly(fos);
- }
- }
- return SUCCESS;
- }
-}
+++ /dev/null
-package org.tizen.installmanager.util.unzip;
-
-import org.tizen.installmanager.lib.IIMProgressMonitor;
-
-public abstract class UnzipSDK {
- protected final static int BIG_EDIAN = 1;
- protected final static int Little_EDIAN = 2;
-
- 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,IIMProgressMonitor monitor);
-}
+++ /dev/null
-package org.tizen.installmanager.util.unzip;
-
-import java.io.File;
-import java.util.List;
-
-import net.lingala.zip4j.core.ZipFile;
-import net.lingala.zip4j.exception.ZipException;
-import net.lingala.zip4j.model.FileHeader;
-
-import org.tizen.installmanager.lib.IIMProgressMonitor;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.util.ISdkConstant;
-
-
-
-public class Zip4jSdkUnzip extends UnzipSDK {
-
- @Override
- public long unzipPackageFile(String fileFullPath, String targetFullPath,IIMProgressMonitor monitor) {
- 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);
- monitor.workedInstallSize(fileHeader.getUncompressedSize());
- }
- long finishedTime = System.currentTimeMillis();
- System.out.println("extracting time : "+ (finishedTime - startTime));
- }else{
- return ISdkConstant.ERROR;
- }
- } catch (ZipException e) {
- Log.ExceptionLog(e);
- return ISdkConstant.ERROR;
- }
- return ISdkConstant.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);
- }
- }
- }
- }
-
-}