INST : proceed install and download at the same time 94/11694/1
authorshihyun.kim <shihyun.kim@samsung.com>
Sun, 3 Nov 2013 09:13:41 +0000 (18:13 +0900)
committershihyun.kim <shihyun.kim@samsung.com>
Sun, 3 Nov 2013 09:13:41 +0000 (18:13 +0900)
Change-Id: I4a6a4bd111d92718999217fd35ff75ed8121b1a8
Signed-off-by: shihyun.kim <shihyun.kim@samsung.com>
16 files changed:
InstallManager_java/src/org/tizen/installmanager/core/InstallManager.java
InstallManager_java/src/org/tizen/installmanager/core/Installer.java
InstallManager_java/src/org/tizen/installmanager/core/Options.java
InstallManager_java/src/org/tizen/installmanager/core/Performance.java
InstallManager_java/src/org/tizen/installmanager/lib/ErrorController.java
InstallManager_java/src/org/tizen/installmanager/lib/IIMProgressMonitor.java
InstallManager_java/src/org/tizen/installmanager/lib/linux/LinuxSDKPackageFormat.java
InstallManager_java/src/org/tizen/installmanager/lib/linux/LinuxShellInstalledListParser.java
InstallManager_java/src/org/tizen/installmanager/lib/win/WindowsSDKPackageFormat.java
InstallManager_java/src/org/tizen/installmanager/pkg/lib/PackageManager.java
InstallManager_java/src/org/tizen/installmanager/pkg/model/InstConfig.java
InstallManager_java/src/org/tizen/installmanager/pkg/model/Package.java
InstallManager_java/src/org/tizen/installmanager/ui/InstallManagerWindow.java
InstallManager_java/src/org/tizen/installmanager/ui/page/InstallingPage.java
InstallManager_java/src/org/tizen/installmanager/ui/page/UninstallingPage.java
InstallManager_java/src/org/tizen/installmanager/ui/page/ViewController.java

index 6cbf6b0..5495834 100644 (file)
-/*
- *  InstallManager
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: 
- * Wooyoung Cho <wooyoung1.cho@samsung.com>
- * Shihyun Kim <shihyun.kim@samsung.com>
- * Taeyoung Son <taeyoung2.son@samsung.com>
- * Yongsung kim <yongsung1.kim@samsung.com>
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-package org.tizen.installmanager.core;
-
-import java.io.File;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.net.URL;
-import java.security.MessageDigest;
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.tizen.installmanager.lib.Checksum;
-import org.tizen.installmanager.lib.Downloader;
-import org.tizen.installmanager.lib.ErrorController;
-import org.tizen.installmanager.lib.ErrorController.InfoCode;
-import org.tizen.installmanager.lib.IIMProgressMonitor;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.lib.Platform;
-import org.tizen.installmanager.lib.Registry;
-import org.tizen.installmanager.lib.ErrorController.ErrorCode;
-import org.tizen.installmanager.lib.exception.IMNetworkException;
-import org.tizen.installmanager.lib.win.WindowsProgramController;
-import org.tizen.installmanager.pkg.lib.PackageManager;
-import org.tizen.installmanager.pkg.model.Package;
-import org.tizen.installmanager.pkg.model.PackageSet;
-import org.tizen.installmanager.ui.page.InstallingPage.InstallProgressMonitor;
-import org.tizen.installmanager.util.IMShellCommandFail;
-import org.tizen.installmanager.util.PathUtil;
-import org.tizen.installmanager.util.ShellUtil;
-
-/**
- * This class contains the main business logic of Install Manager. Use singleton
- * instance.
- * 
- * @author Shihyun Kim <shihyun.kim@samsung.com>
- */
-public class InstallManager {
-
-       private static final InstallManager mInstallManager = new InstallManager();
-
-       private Config mConfig = null;
-       private static Downloader mDownloader = new Downloader();
-       private PackageManager packageManager;
-
-       // windows path
-       private static String WINDOWS_INSTALL_MANAGER_INSTALL_SCRIPT = "/res/desktop_directory/install.vbs";
-       private static String WINDOWS_INSTALL_MANAGER_REMOVE_SCRIPT = "/res/desktop_directory/remove.vbs";
-       private static String WINDOWS_MAKE_SHORTCUT_PATH = "/res/desktop_directory/makeshortcut.vbs";
-       private static String WINDOWS_REMOVE_SHORTCUT_PATH = "/res/desktop_directory/removeshortcut.vbs";
-
-       // linux script
-       private static String LINUX_INSTALL_MANAGER_INSTALL_SCRIPT = "/res/desktop_directory/install.sh";
-       private static String LINUX_INSTALL_MANAGER_REMOVE_SCRIPT = "/res/desktop_directory/remove.sh";
-       private static String LINUX_MAKE_SHORTCUT_PATH = "/res/desktop_directory/makeshortcut.sh";
-       private static String LINUX_REMOVE_SHORTCUT_PATH = "/res/desktop_directory/removeshortcut.sh";
-       private static String LINUX_TSUDO_PATH = "/res/desktop_directory/tsudo.sh";
-
-       private File makeShortCutFile = null;
-       private File removeShortCutFile = null;
-       private File tSudoFile = null;
-
-       private static String REMOVE_ALL_PACKAGES = "Remove all packages...";
-       private static String REMOVE_ALL_SDK_FILES = "Remove all SDK files...";
-       private InstallManager() {
-       }
-
-       /**
-        * @return singleton instance of <code>InstallManager</code>
-        */
-       public static InstallManager getInstance() {
-               return mInstallManager;
-       }
-
-       /**
-        * Load config file
-        */
-       public void initConfig() {
-               if (mConfig != null) {
-                       if (Config.isSupportMultiSDK()) {
-                               if (!Registry.getInstalledPath().isEmpty()) {
-                                       mConfig.setTargetDir(Registry.getInstalledPath());
-                               }
-                       } else {
-                               return;
-                       }
-               } else {
-                       mConfig = Config.getInstance();
-
-                       if (Options.doReplaceRepository) {
-                               Log.log("Replace repository => " + Options.repository);
-                               mConfig.getConfigFile().setRepository(Options.repository);
-                               mConfig.saveConfig();
-                       }
-                       
-                       if (Options.distribution != null && !Options.distribution.isEmpty()) {
-                               mConfig.getConfigFile().setDistribution(Options.distribution);
-                               mConfig.saveConfig();
-                       }
-
-                       if (mConfig.getConfigFile() == null) {
-                               Log.log("Loading config file failed");
-                               throw new IMFatalException("Loading configuration file failed");
-                       }
-                       
-                       if (!Registry.getInstalledPath().isEmpty()) {
-                               mConfig.setTargetDir(Registry.getInstalledPath());
-                       }
-                       mConfig.setSdkDatatDir(Registry.getSdkDataPath());
-               }
-       }
-       
-       /**
-        * Initialize packages information.
-        */
-       public void initPackageList() {
-               Collection<String> repositoryURLs = mConfig.getSDKPackageServerList();
-
-               initPackageManager(repositoryURLs);
-       }
-
-       private void initPackageManager(Collection<String> repositoryURLs) {
-               File installedPackageListFile = null;
-               if (Registry.targetPath != "") {
-                       installedPackageListFile = new File(PathUtil.get(
-                                       PathUtil.get(Registry.targetPath, Config.INFO_DIRECTORY),
-                                       Config.INSTALLED_PACKAGE_LIST_FILE_NAME));
-               } else {
-                       installedPackageListFile = new File(PathUtil.get(
-                                       PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),
-                                       Config.INSTALLED_PACKAGE_LIST_FILE_NAME));
-               }
-
-               try {
-                       if (installedPackageListFile.exists()) {
-                               this.packageManager = PackageManager.getInstance(installedPackageListFile, repositoryURLs);
-                       } else {
-                               this.packageManager = PackageManager.getInstance(null, repositoryURLs);
-                       }
-               } catch (IOException e) {
-                       Log.err("Cannot load package manager =>" + installedPackageListFile
-                                       + ", " + repositoryURLs);
-                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_FILE);
-               }
-       }
-       
-       /**
-        * Initialize distribution and snapshot information
-        */
-       public boolean initDistribution() {
-               DistributionController controller = 
-                       DistributionController.getInstance(mConfig.getSDKRepositoryList());
-       
-               boolean initResult = controller.init();
-               Log.log("Init Distribution result => " + initResult);
-               
-               //First distribution that read from config file is recognized as the distribution installed.  
-               String installedDistribution = Config.getInstance().getConfigFile().getDistribution();
-               controller.setInstalledDistribution(installedDistribution);
-
-               return initResult;
-       }
-       
-       
-       /**
-        * Initialize installmanager. It performs that read config file, make
-        * temporary files and load package list from repository.
-        * 
-        * @return <code>true</code> if initialize success to install or uninstall.
-        */
-       public void init() {
-               initConfig();
-               
-               cleanPackageDir();
-               
-               initDistribution();
-               if (Config.status == Config.Status.INSTALL) {
-                       checkOldSDK();                  
-               }
-               initPackageList();
-               initConfigurationFile();
-               checkNewPackageServer();
-       }
-       
-       /**
-        * If packageServer has multi SDK packages, set Config.isNewPackageServer true. otherwise false.
-        * InstallManager can be used old SDK installation.
-        */
-       private void checkNewPackageServer() {
-               if (packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME) == null) {
-                       Config.isNewPackageServer = false;
-                       Log.log("PackageServer has old SDK packages.");
-               } else {
-                       Config.isNewPackageServer = true;
-                       Log.log("PackageServer has new SDK packages(Multi SDK).");
-               }
-       }
-       
-       private void initConfigurationFile() {
-               copyMakeShortCutFile();
-               copyRemoveShortCutFile();
-               
-               // Linux has several kinds such as Ubuntu, Fedora, etc. So, If installation needs super user's
-               // permission, sudo command depends on machine. Therefore, Installmanager gives a tsudo command 
-               // which does not need to care of machine post install script for package.
-               if (Platform.isLinux()) {
-                       copyTizenSudoFile();
-               }
-       }
-       
-       /**
-        * Delete temporary files related installmanager.
-        */
-       public static void deleteTempFile() {
-
-               File tmpDir = new File(PathUtil.getTempFileParent());
-               File[] tmpFiles = tmpDir.listFiles(new FilenameFilter() {
-                       @Override
-                       public boolean accept(File dir, String name) {
-                               boolean found = false;
-                               String[] prefix = { "makeshortcut", "removeshortcut",
-                                               "installmanager.repository", "Packages",
-                                               "tizen_installmanager", "checkJavaInstallation",
-                                               "install" };
-                               for (String pref : prefix) {
-                                       found = name.startsWith(pref);
-                                       if (found == true) {
-                                               return true;
-                                       }
-                               }
-                               return found;
-                       }
-               });
-               
-               if (tmpFiles != null) {
-                       for (File f : tmpFiles) {
-                               if (!f.delete()) {
-                                       Log.err("Fail to delete file ==> " + f);
-                               }
-                       }
-               }
-       }
-
-       /**
-        * Copy make shortcut file from resource to temp directory.
-        */
-       private void copyMakeShortCutFile() {
-               try {
-                       if (Platform.isLinux()) {
-                               makeShortCutFile = PathUtil.getTempFileFromResource(
-                                               LINUX_MAKE_SHORTCUT_PATH, "makeshortcut", ".sh");
-                       } else if (Platform.isWindows()) {
-                               makeShortCutFile = PathUtil.getTempFileFromResource(
-                                               WINDOWS_MAKE_SHORTCUT_PATH, "makeshortcut", ".vbs");
-                       } else if (Platform.isMacOS()) {
-                               makeShortCutFile = PathUtil.getTempFileFromResource(
-                                               LINUX_MAKE_SHORTCUT_PATH, "makeshortcut", ".sh");
-                       } else {
-                               throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
-                       }
-                       
-                       if (makeShortCutFile.exists()) {
-                               makeShortCutFile.setExecutable(true);
-                       }
-               } catch (IOException e) {
-                       Log.err("Installer cannot make 'makeshortcut script' file.");
-                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_SHORTCUT);
-               }
-       }
-
-       /**
-        * Copy remove shortcut file from resource to temp directory.
-        */
-       private void copyRemoveShortCutFile() {
-               try {
-                       if (Platform.isLinux()) {
-                               removeShortCutFile = PathUtil.getTempFileFromResource(
-                                               LINUX_REMOVE_SHORTCUT_PATH, "removeshortcut", ".sh");
-                       } else if (Platform.isWindows()) {
-                               removeShortCutFile = PathUtil.getTempFileFromResource(
-                                               WINDOWS_REMOVE_SHORTCUT_PATH, "removeshortcut", ".vbs");
-                       } else if (Platform.isMacOS()) {
-                               removeShortCutFile = PathUtil.getTempFileFromResource(
-                                               LINUX_REMOVE_SHORTCUT_PATH, "removeshortcut", ".sh");
-                       } else {
-                               throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
-                       }
-                       removeShortCutFile.setExecutable(true);
-               } catch (IOException e) {
-                       Log.err("Installer cannot make 'makeshortcut script' file.");
-                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_SHORTCUT);
-               }
-       }
-       
-       /**
-        * Copy remove shortcut file from resource to temp directory.
-        */
-       private void copyTizenSudoFile() {
-               try {
-                       tSudoFile = PathUtil.getTempFileFromResource(LINUX_TSUDO_PATH, "tsudo", ".sh");
-                       tSudoFile.setExecutable(true);
-               } catch (IOException e) {
-                       Log.err("Installer cannot make 'tsudo.sh' file.");
-                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_TSUDO);
-               }
-       }
-       
-       /**
-        * get make shortcut File instance.
-        * 
-        * @return File instance of makeshortcut script.
-        */
-       public File getTSudo() {
-               return tSudoFile;
-       }
-
-       /**
-        * Get temporary file path.(makeshortcut script, Packages list, Installer
-        * log)
-        * 
-        * @return temporary file path, if not exist makeshortcut file, return empty
-        *         string.
-        */
-       public String getTSudoPath() {
-               if (getTSudo() == null) {
-                       return "";
-               } else {
-                       return getTSudo().getAbsolutePath();
-               }
-       }
-
-       /**
-        * get make shortcut File instance.
-        * 
-        * @return File instance of makeshortcut script.
-        */
-       public File getMakeShortCut() {
-               return makeShortCutFile;
-       }
-
-       /**
-        * Get temporary file path.(makeshortcut script, Packages list, Installer
-        * log)
-        * 
-        * @return temporary file path, if not exist makeshortcut file, return empty
-        *         string.
-        */
-       public String getMakeShortCutPath() {
-               if (getMakeShortCut() == null) {
-                       return "";
-               } else {
-                       return getMakeShortCut().getAbsolutePath();
-               }
-       }
-
-       /**
-        * Get temporary file path.(rmoveshortcut script, Packages list, Installer
-        * log)
-        * 
-        * @return temporary file path, if not exist removeshortcut file, return
-        *         emptry string.
-        */
-       public String getRemoveShortCutPath() {
-               if (getRemoveShortCut() == null) {
-                       return "";
-               } else {
-                       return getRemoveShortCut().getAbsolutePath();
-               }
-       }
-
-       /**
-        * Get remove shortcut File instance.
-        * 
-        * @return File instance of removeshortcut script.
-        */
-       public File getRemoveShortCut() {
-               return removeShortCutFile;
-       }
-
-       /**
-        * Get Config instance
-        * 
-        * @return
-        */
-       public Config getConfig() {
-               return mConfig;
-       }
-
-       /**
-        * Get PackageManager instance.
-        * 
-        * @return
-        */
-       public PackageManager getPackageManager() {
-               return packageManager;
-       }
-       
-       /**
-        * Check old SDK is installed for compatibility.
-        */
-       private void checkOldSDK() {
-               Log.log("Check old SDK.");
-               if (Registry.getOldInstalledPath() != "") { // Old SDK is installed.
-                       if (Registry.getInstalledPath() != null && !Registry.getInstalledPath().isEmpty()) {
-                               // Old SDK is installed but new SDK is also installed, so environment does not need to
-                               // set new SDK environment.
-                               Log.log("Old SDK is installed but new SDK is also installed. => " + Registry.getInstalledPath());
-                               return;
-                       } else {
-                               Log.log("Old SDK is installed. => " + Registry.getOldInstalledPath());
-                               setCurrentSDKEnvironment(Registry.getOldInstalledPath());
-                       }                       
-               } else {
-                       return;
-               }
-       }
-       
-       /**
-        * If old SDK is installed and new SDK is not installed, installmanager set environment for new SDK running properly.
-        * @param targetPath SDK installed path.
-        */
-       private void setCurrentSDKEnvironment(String targetPath) {
-               Log.log("Set new SDK environment from old SDK.");
-               Registry.sdkDataPath = Config.getConfigHome();
-               
-               if (targetPath == null || targetPath.isEmpty()) {
-                       Log.err("Install path is invalid: " + targetPath
-                                       + ". This might be a bug of IM");
-                       throw new IMFatalException(ErrorCode.INVALID_INSTALL_PATH);
-               } else {
-                       Registry.exportInstallPath(targetPath);
-                       Registry.exportMultiInstallPath(targetPath, true);                      
-               }
-               
-               // Make sdk.info file into target directory for compatibility.
-               Registry.saveSDKInfo(targetPath);
-               // Remove tizensdkpath file in 'tizen-sdk-data'.
-//             Registry.removeOldRegistry();
-       }
-
-       /**
-        * Download packages
-        * 
-        * @param packagesToDownload
-        *            Set of packages to download
-        * @param monitor
-        * @return <code>true</code> if download success.
-        * @throws IMExitException
-        */
-       public boolean downloadPackages(PackageSet downloadPkgSet,
-                       InstallProgressMonitor monitor) throws IMExitException, IMNetworkException{
-               Log.log("InstallManager download start => " + downloadPkgSet);
-
-               long totalSize = 0;
-               for (Package pkg : downloadPkgSet) {
-                       totalSize += pkg.getPackageSize();
-               }
-
-               if (monitor != null) {
-                       monitor.workedRefresh();
-                       int total = (int) (totalSize / 1024);
-                       monitor.beginTask("", total);
-               }
-
-               for (Package pkg : downloadPkgSet) {
-
-                       if (monitor != null) {
-                               monitor.workedDownload(pkg.getPackageName());
-                       } else {
-                               if (Options.doInstallNoUI) {
-                                       System.out.println(pkg.getPackageName() + " is downloading...");
-                               }
-                       }
-
-                       if (monitor != null && monitor.isCanceled()) {
-                               Log.log("download canceled");
-                               throw new IMInstallCancelException();
-                       }
-
-                       String fileName = pkg.getFileName();
-                       boolean downloadResult = downloadPackage(pkg, PathUtil.addURLPath(mConfig.getDownloadPkgPath(), fileName), monitor);
-
-                       if (!downloadResult) {
-                               Log.err("InstallManager download fail => " + pkg);
-                               return false;
-                       }
-               }
-
-               if (monitor != null) {
-                       monitor.workedProgressbar(100);
-               }
-
-               return true;
-       }
-
-       /**
-        * Download package.
-        * 
-        * @param packageToDownload
-        * @param fileDownloadTargetPath
-        * @param monitor
-        * @return <code>true</code> if success
-        */
-       public boolean downloadPackage(Package packageToDownload,
-                       String fileDownloadTargetPath, IIMProgressMonitor monitor) throws IMNetworkException{
-               Log.log("Download package '" + packageToDownload + "'");
-
-               if (packageToDownload == null || fileDownloadTargetPath == null
-                               || fileDownloadTargetPath.isEmpty()) {
-                       Log.err("InstallManager.downloadPackage(): Invalid package: "
-                                       + packageToDownload + ": This might be a bug of IM");
-                       throw new IMFatalException(
-                                       ErrorCode.PACKAGE_NOT_EXIST_TO_INSTALL_OR_UNINSTALL);
-               }
-
-               // Check cache foler
-               if (existInCacheFolder(packageToDownload, fileDownloadTargetPath, monitor)) {
-                       if (monitor != null) {
-                               if (monitor.isCanceled()) {
-                                       throw new IMFatalException(ErrorCode.CANCEL);
-                               } else {
-                                       monitor.workedChecksum(packageToDownload.getPackageSize());
-                               }
-                       }
-                       Log.log("Found in cache");
-
-                       return true;
-               }
-
-               // TODO : refactoring.
-               long size = 0;
-               if (Options.onlyDownload) {
-                       System.out.print("Downloading package => " + packageToDownload  + " .......");
-               }
-               Log.log("start download package: " + packageToDownload);
-               URL packageUrl = packageToDownload.getURL();
-               
-               if (monitor != null) {
-                       monitor.workedDownload(packageToDownload.getPackageName());
-               }
-               size = mDownloader.download(packageUrl, fileDownloadTargetPath,
-                               monitor);
-               
-               if (size >= 0) {
-                       if (Options.onlyDownload) {
-                               System.out.println(" done.");
-                       }
-                       Log.log("finish download");
-               } else {                        
-                       Log.err("download failed => " + packageToDownload.getURL());
-                       
-                       PathUtil.remove(fileDownloadTargetPath);
-                       
-                       String errMsg = "";
-                       if (monitor.isCanceled()) {
-                               errMsg = ErrorController.getErrorMessage();
-                       } else {
-                               errMsg = "Fail to get '" + 
-                                               packageToDownload.getPackageName() + "'."  +
-                                               "\n(" + ErrorController.getErrorMessage() + ")";
-                       }
-                       throw new IMFatalException(errMsg);
-               }
-
-               if (Options.doPackageValidation) {
-                       Log.log("Validate package");
-                       if (!checkPackageSize(packageToDownload, size)) {
-                               Log.err("The expected size of package => " + packageToDownload.getPackageSize());
-                               Log.err("Package size error. downloaded size => " + size);
-                               
-                               PathUtil.remove(fileDownloadTargetPath);
-                               
-                               throw new IMFatalException(ErrorCode.PACKAGE_WRONG_SIZE);
-                       }
-
-                       // TODO :
-                       if (!checkFileChecksum(packageToDownload,
-                                       mDownloader.getFileChecksum())) {
-                               Log.err("The expected checksum of package => " + packageToDownload.getSHA256());
-                               Log.err("Package checksum error downloaded checksum => "
-                                               + mDownloader.getFileChecksum());
-                               
-                               PathUtil.remove(fileDownloadTargetPath);
-                               
-                               throw new IMFatalException(ErrorCode.PACKAGE_WRONG_CHECKSUM);
-                       }
-               }
-
-               return true;
-       }
-
-       /**
-        * @param pkg
-        * @param filePath
-        * @return <code>true</code> if the package is already downloaded to the
-        *         file path
-        */
-       private boolean existInCacheFolder(Package pkg, String filePath, IIMProgressMonitor monitor) {
-               File file = new File(filePath);
-
-               if (!file.exists()) {
-                       return false;
-               }
-               
-               if (monitor != null) {
-                       monitor.workedChecksum(pkg.getPackageName());
-               }
-
-               if (Options.doPackageValidation) {
-                       if (Checksum.getSHA256(filePath) != null) {
-                               return checkFileChecksum(pkg, Checksum.getSHA256(filePath));                            
-                       } else {
-                               return false;
-                       }
-               } else {
-                       return true;
-               }
-       }
-
-       private boolean checkPackageSize(Package pkg, long size) {
-               if (pkg.getPackageSize() == size) {
-                       return true;
-               }
-               return false;
-       }
-
-       private boolean checkFileChecksum(Package pkg, MessageDigest mDigest) {
-
-               if (pkg.getSHA256() == null || pkg.getSHA256().isEmpty()) {
-                       return false;
-               }
-
-               if (mDigest.getAlgorithm().equals(Checksum.SHA_256_TYPE)) {
-                       return (pkg.getSHA256().equalsIgnoreCase(Checksum
-                                       .messageDigestToString(mDigest)));
-               } else {
-                       // TODO there's no checksum field in package.
-                       return false;
-               }
-       }
-
-       /**
-        * Package installation management
-        * 
-        * @param pkg
-        *            package to install.
-        * @param targetDir
-        *            target directory to install.
-        * @param monitor
-        * @return
-        */
-       public boolean install(Package pkg, String targetDir,
-                       IIMProgressMonitor monitor) {
-               Log.log("Install package '" + pkg + "'");
-
-               if (monitor != null) {
-                       monitor.workedProcess(pkg.getPackageName());
-               } else {
-                       if (Options.doInstallNoUI) {
-                               System.out.println(pkg.getPackageName() + " is installing...");
-                       }
-               }
-
-               Installer installer = new Installer();
-               boolean bResult = installer.install(pkg, targetDir, monitor);
-
-               if (bResult) {
-                       // save installed package list
-                       packageManager.addPackageToInstalledPackages(pkg);
-                       packageManager.saveInstalledList(PathUtil.get(
-                                       PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),
-                                       Config.INSTALLED_PACKAGE_LIST_FILE_NAME));
-               } else {
-                       Log.err("InstallManager.install() install fail => " + pkg);
-                       return false;
-               }
-               return bResult;
-       }
-
-       /**
-        * Packages Installation management. 
-        * Download and install packages.
-        * 
-        * @param packagesToInstall
-        * @param targetDir
-        * @param monitor
-        * @return
-        * @throws IMExitException
-        */
-       public boolean install(PackageSet installablePackages, final String targetDir,
-                       InstallProgressMonitor monitor) throws IMExitException, IMNetworkException{
-               Log.log("InstallManager.install() installable packages : " + installablePackages);
-               
-               //performance measurement
-               Performance.sdkPackageSize = packageManager.getTotalSizeOfInstallablePackages(installablePackages, true);
-               
-               if (installablePackages == null || targetDir == null || targetDir.isEmpty()) {
-                       Log.err("packaegs => " + installablePackages + ", targetDir => "
-                                       + targetDir);
-                       return false;
-               }
-               
-               mConfig.setTargetDir(targetDir);
-               mConfig.setSdkDatatDir(Registry.sdkDataPath);
-               
-               Performance.setDownloadStartTime();
-               
-               // download packages from repository
-               if (downloadPackages(installablePackages, monitor)) {
-                       Log.log("Success to download packages from repository.");
-               } else {
-                       Log.err("Fail to download packages from repository.");
-                       if (!Options.doResumeDownloading) {
-                               removePackagesDir();
-                       }
-                       
-                       return false;
-               }
-               
-               // wait if cancel confirm dialog is showing. wait until user press
-               // button(cancel or not).
-               if (monitor != null) {
-                       while (monitor.checkCancelAndDisableCancelButton() == false) {
-                               if (monitor.isCanceled()) {
-                                       throw new IMInstallCancelException();
-                               }
-                       }
-               }
-               
-               Performance.setDownloadEndTime();
-
-               Performance.setInstallationStartTime();
-               // save target directory
-               initializeTargetDir(targetDir);
-               
-               //if distribution is changed, remove all packages and install.
-               if (packageManager.isReInstallable()) {
-                       removeAllPackages(monitor);
-               } else {
-                       // remove missing packages
-                       if (!packageManager.isRepoPackagesEmpty()) {
-                               // Remove missing packages only network installation.
-                               if (Config.fromWhere == Config.ConfDialog.SNAPSHOT) {
-                                       removeMissingPackages(monitor);                                 
-                               }
-                       }
-
-                       // remove conflict packages
-                       if (!removeConflictPackages(installablePackages, monitor)) {
-                               Log.err("Cannot remove conflict package");
-                               throw new IMFatalException(
-                                               ErrorCode.CONFIG_CANNOT_REMOVE_CONFLICT_PACKAGES);
-                       }
-
-                       boolean result = false;
-                       //If Options.snapshot is true, remove installed packages that differernt version from installable packages.
-                       if (Options.snapshot) {
-                               result = removeDifferentVersionPackages(installablePackages, monitor);
-                       } else {
-                               result = removeUpdatablePackages(installablePackages, monitor);
-                       }
-                       
-                       if (!result) {
-                               Log.err("Cannot remove updatable package");
-                               throw new IMFatalException(
-                                               ErrorCode.CONFIG_CANNOT_REMOVE_UPDATABLE_PACKAGES);
-                       }
-               }
-
-               //start installation
-               if (monitor != null) {
-                       monitor.beginTask("Installing", installablePackages.size() + 1);
-               }
-
-               // make start menu
-               makeShortcutMenu();
-               
-               // if you cannot get installmanager from repository, install from local.
-               if (!packageManager.existsPackage(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME)) {
-                       Log.log("Cannot find install-manager from repository.");
-                       if (!installInstallManagerFromLocal(targetDir)) {
-                               Log.err("Cannot install install-manager from local directory.");
-                       }
-               }
-
-               int i = 0;
-               for (Package pkg : installablePackages) {
-                       if (monitor != null) {
-                               monitor.workedProcess(pkg.getPackageName());
-                               monitor.worked(++i);
-                       }
-
-                       if (!install(pkg, targetDir, monitor)) {
-                               Log.log("Installation fail => " + pkg);
-                               
-                               if (!Options.doResumeDownloading) {
-                                       removePackagesDir();
-                               }
-                               
-                               throw new IMFatalException(ErrorCode.INSTALLATION_FAIL);
-                       }
-               }
-
-               // remove temp directory
-               String tempDir = targetDir + File.separator + Config.TEMP_DIRECTORY;
-               PathUtil.remove(tempDir);
-
-               // save config file
-               mConfig.saveConfig();
-               
-               // save sdk version.
-               saveSDKVersion();
-
-               // Delete installed packages
-               if (Options.doRemovePackages) {
-                       removePackagesDir();
-               }
-
-               // move InstallManager to target directory
-               if (monitor != null) {
-                       monitor.workedSubTitle("Move to target directory...");
-               }
-               
-               if (Config.status == Config.Status.INSTALL) {
-                       Registry.exportMultiInstallPath(targetDir, true);                       
-               }
-               
-               //show reboot message in linux platform.
-               if (Platform.isLinux() || Platform.isMacOS()) {
-                       ErrorController.setInfoCode(InfoCode.RESTART_THE_COMPUTER);
-               }
-               
-               Performance.setInstallationEndTime();
-               
-               return true;
-       }
-       
-       private boolean installInstallManagerFromLocal(String sdkPath) {
-               Log.log("Install install-manager from local. => " + sdkPath);
-               String targetDir = PathUtil.get(sdkPath, InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME);
-               
-               File targetDirFile = new File(targetDir);
-               
-               if (!targetDirFile.exists()) {
-                       targetDirFile.mkdirs();
-               }
-               
-               try {
-                       if (Platform.isLinux()) {
-                               installInstallManagerFromLocalInLinux(targetDir);                       
-                       } else if (Platform.isWindows()) {
-                               installInstallManagerFromLocalInWindows(targetDir);
-                       } else if (Platform.isMacOS()) {
-                               installInstallManagerFromLocalInMac(targetDir);
-                       } else {
-                               throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
-                       }
-                       
-                       File toInstallManagerImage = new File(PathUtil.get(Registry.getInstalledPath(), InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME, InstallManagerConstants.INSTALLMANAGER_SHORTCUT_IMAGE_NAME));
-                       PathUtil.writeFileFromInputStream(PathUtil.getResourceAsStream(InstallManagerConstants.INSTALLMANAGER_SHORTCUT_IMAGE_PATH), toInstallManagerImage);
-                       
-                       File toDesktopFile = new File(PathUtil.get(Registry.getInstalledPath(), InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME, InstallManagerConstants.DESKTOP_SHORTCUT_IMAGE_NAME));
-                       PathUtil.writeFileFromInputStream(PathUtil.getResourceAsStream(InstallManagerConstants.DESKTOP_SHORTCUT_IMAGE_PATH), toDesktopFile);
-
-               } catch (IOException e) {
-                       Log.ExceptionLog(e);
-                       return false;
-               }
-               
-               //execute install script
-               File installScript = getInstallScript();
-               if (installScript != null && installScript.exists()) {
-                       installScript.setExecutable(true);
-                       
-                       Installer installer = new Installer();
-                       try {
-                               installer.executeScript(installScript);
-                               return true;
-                       } catch (IMShellCommandFail e) {
-                               Log.ExceptionLog(e);
-                       }
-               }
-               return false;
-       }
-       
-       private void installInstallManagerFromLocalInLinux(String targetDir) {
-               try {
-                       //copy excutable file to target directory
-                       PathUtil.copy(PathUtil.get(Options.executablePath, InstallManagerConstants.INSTALLMANAGER_BINARY_NAME), targetDir);
-                       
-                       //copy library file to target directory
-                       PathUtil.copy(PathUtil.get(PathUtil.getCurrentDir(), InstallManagerConstants.INSTALLMANAGER_JAR_FILE_NAME), targetDir);
-               } catch (IOException e) {
-                       Log.ExceptionLog(e);
-               }
-       }
-       
-       private void installInstallManagerFromLocalInWindows(String targetDir) {
-               installInstallManagerFromLocalInLinux(targetDir);
-       }
-
-       private void installInstallManagerFromLocalInMac(String targetDir) {
-               String parentDir = PathUtil.getParentDirectory(PathUtil.getCurrentDir(), 4);
-               
-               String imExecutableAppDirPath =  PathUtil.get(parentDir, InstallManagerConstants.INSTALLMANAGER_EXECUTALBE_DIR_NAME_FOR_MAC);
-               String command = "cp -rf " + imExecutableAppDirPath + " " + targetDir;
-               
-               try {
-                       ShellUtil.execute(command);
-               } catch (IMShellCommandFail e) {
-                       Log.ExceptionLog(e);
-                       Log.err(command);
-                       throw new IMFatalException(ErrorCode.CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY);
-               }
-               
-               String imExecutableBinaryPath = PathUtil.get(parentDir, InstallManagerConstants.INSTALLMANAGER_EXECUTALBE_FILE_NAME_FOR_LINUX);
-               command = "cp -rf " + imExecutableBinaryPath + " " + targetDir;
-               
-               try {
-                       ShellUtil.execute(command);
-               } catch (IMShellCommandFail e) {
-                       Log.ExceptionLog(e);
-                       return;
-               }
-               
-               String imJarFilePath = PathUtil.get(parentDir, InstallManagerConstants.INSTALLMANAGER_JAR_FILE_NAME);
-               command = "cp -rf " + imJarFilePath + " " + targetDir;
-               
-               try {
-                       ShellUtil.execute(command);
-               } catch (IMShellCommandFail e) {
-                       Log.ExceptionLog(e);
-                       return;
-               }
-       }
-       
-       private void removeMissingPackages(IIMProgressMonitor monitor) {
-               PackageSet missingPackages = packageManager
-                               .getMissingPackagesFromRepository();
-               Log.log("Remove missing packages => " + missingPackages);
-
-               if (monitor != null) {
-                       monitor.workedTitle("Remove Missing Packages");
-               }
-
-               for (Package pkg : missingPackages) {
-                       if (!removePackage(pkg, monitor)) {
-                               Log.err("Cannot remove missing package");
-                               throw new IMFatalException(
-                                               ErrorCode.CANNOT_REMOVE_MISSING_PACKAGE);
-                       }
-               }
-       }
-
-       private boolean removeConflictPackages(PackageSet installableMetaPkgs,
-                       IIMProgressMonitor monitor) {
-               PackageSet conflictPackages = packageManager
-                               .getConflictPackagesInUpdate(installableMetaPkgs);
-               Log.log("Remove conflict packages => " + conflictPackages);
-               
-               if (conflictPackages.isEmpty()) {
-                       return true;
-               }
-
-               if (monitor != null) {
-                       monitor.workedTitle("Remove Conflict Packages");
-               }
-
-               return remove(conflictPackages);
-       }
-
-       private boolean removeDifferentVersionPackages(PackageSet installablePackages, 
-                       IIMProgressMonitor monitor) {
-               PackageSet updatablePackages = packageManager
-                               .getdifferentVersionFromInstalledPackages(installablePackages);
-               
-               if (updatablePackages.isEmpty()) {
-                       return true;
-               }
-
-               Log.log("Remove packages in snapshot => " + updatablePackages);
-
-               if (monitor != null) {
-                       monitor.workedTitle("Remove updatable Packages...");
-               }
-
-               return remove(updatablePackages);
-       }
-       private boolean removeUpdatablePackages(PackageSet installablePackages,
-                       IIMProgressMonitor monitor) {
-               PackageSet updatablePackages = packageManager
-                               .getUpdatablePackagesInUpdate(installablePackages);
-               
-               if (updatablePackages.isEmpty()) {
-                       return true;
-               }
-
-               Log.log("Remove updatable packages => " + updatablePackages);
-
-               if (monitor != null) {
-                       monitor.workedTitle("Remove updatable Packages");
-               }
-
-               return remove(updatablePackages);
-       }
-
-       private boolean remove(PackageSet packages) {
-               for (Package pkg : packages) {
-
-                       if (removePackage(pkg, null)) {
-                               continue;
-                       } else {
-                               Log.err("Cannot remove package => " + pkg);
-                               return false;
-                       }
-               }
-
-               return true;
-       }
-
-       /**
-        * Initializes target directory
-        * 
-        * @param targetDir
-        *            path to SDK target directory
-        */
-       public void initializeTargetDir(String targetDir) {
-               Log.log("Initialize target dir. " + targetDir);
-               // Make target directory
-               File targetDirFile = new File(targetDir);
-               if (!targetDirFile.exists()) {
-                       if (!targetDirFile.mkdirs()) {
-                               Log.err("Fail to create file ==> " + targetDirFile);
-                       }
-               }
-
-               // Keep target path in system
-               Registry.exportInstallPath(targetDir);
-
-               // Keep target path for later use
-               mConfig.setTargetDir(targetDir);
-               mConfig.setSdkDatatDir(Registry.sdkDataPath);
-
-               // Make .info directory
-               if (!mConfig.makeInfoDirectory()) {
-                       Log.err(Config.CONFIG_HOME_PATH + " cannot create.");
-                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_CONFIG_FILE);
-               }
-       }
-       
-       /**
-        * Save installed SDK version.
-        */
-       public void saveSDKVersion() {
-               Registry.saveInstallVersion(mConfig.getConfigFile().getInstallManagerVersion());
-       }
-
-       /**
-        * Make tizen menu and installmanager shortcut.
-        */
-       private void makeShortcutMenu() {
-               Log.log("InstallManager make shortcut menu.");
-
-               // execute install script.
-               File installScript = getInstallScript();
-               if (installScript != null) {
-                       installScript.setExecutable(true);
-
-                       Installer installer = new Installer();
-                       try {
-                               installer.executeScript(installScript);
-                       } catch (IMShellCommandFail e) {
-                               // TODO
-                               Log.ExceptionLog(e);
-                       }
-               }
-       }
-
-       /**
-        * Get install script from resource according to each platform.
-        * 
-        * @return
-        */
-       private File getInstallScript() {
-               try {
-                       if (Platform.isLinux()) {
-                               return PathUtil.getTempFileFromResource(
-                                               LINUX_INSTALL_MANAGER_INSTALL_SCRIPT, "im_install", ".sh");
-                       } else if (Platform.isWindows()) {
-                               return PathUtil.getTempFileFromResource(
-                                               WINDOWS_INSTALL_MANAGER_INSTALL_SCRIPT, "im_install",
-                                               ".vbs");
-                       } else if (Platform.isMacOS()) {
-                               return null;
-                       } else {
-                               throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
-                       }
-               } catch (IOException e) {
-                       Log.err("Cannot execute InstallManager's install script.");
-                       Log.ExceptionLog(e);
-                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_SHORTCUT);
-               }
-       }
-
-       private void removeInstallManager() {
-               Log.log("InstallManager.removeInstallManager");
-
-               String installManagerDirectory = PathUtil.get(Registry.getInstalledPath(), InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME);
-               PathUtil.remove(installManagerDirectory);
-
-               if (Registry.getInstalledPath().isEmpty()) {
-                       return;
-               }
-       }
-
-       private void removeShortcutMenu() {
-               File removeScript = getRemoveScript();
-
-               if (removeScript == null) {
-                       return;
-               }
-
-               removeScript.setExecutable(true);
-
-               Installer installer = new Installer();
-               try {
-                       installer.executeScript(removeScript);
-               } catch (IMShellCommandFail e) {
-                       Log.err("Cannot execute InstallManager's remove script.");
-                       Log.ExceptionLog(e);
-               }
-       }
-
-       private File getRemoveScript() {
-               try {
-                       if (Platform.isLinux()) {
-                               return PathUtil.getTempFileFromResource(
-                                               LINUX_INSTALL_MANAGER_REMOVE_SCRIPT, "im_remove", ".sh");
-                       } else if (Platform.isWindows()) {
-                               return PathUtil
-                                               .getTempFileFromResource(
-                                                               WINDOWS_INSTALL_MANAGER_REMOVE_SCRIPT,
-                                                               "im_remove", ".vbs");
-                       } else if (Platform.isMacOS()) {
-                               return null;
-                       } else {
-                               throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
-                       }
-               } catch (IOException e) {
-                       // TODO Auto-generated catch block
-                       Log.err("Cannot get InstallManager's remove script.");
-                       Log.ExceptionLog(e);
-                       return null;
-               }
-       }
-
-       
-       /*
-       private void copyInstallManagerToTargetDirectoryForMac() {
-               Log.log("Copy InstallManager to target in MAC platform");
-
-               //get '.app' directory
-               String fromPath = PathUtil.getParentDirectory(PathUtil.getCurrentDir(), 3);
-               if (fromPath == null) {
-                       Log.err("Cannot get parent directory => " + PathUtil.getCurrentDir());
-                       return;
-               }
-               
-               File fromFile = new File(fromPath);
-
-               if (Registry.getInstalledPath() == null
-                               || Registry.getInstalledPath().equals("")) {
-                       Log.err("Cannot find target dir");
-                       return;
-               }
-
-               File toFile = getInstalledAppPath();
-               if (!toFile.exists()) {
-                       if (!toFile.mkdirs()) {
-                               Log.err("Fail to create file ==> " + toFile);
-                       }
-               }
-
-               if (fromFile.getAbsolutePath().equals(toFile.getAbsolutePath())) {
-                       return;
-               }
-
-               try {
-                       PathUtil.copy(fromFile, toFile);
-               } catch (IOException e) {
-                       Log.ExceptionLog(e);
-                       return;
-               }
-               
-               // copy InstallManager script to {target dir}/install-manager/
-               File installManagerScript = new File(PathUtil.get(Registry.getInstalledPath(),
-                               Config.INSTALL_MANAGER_DIRECTORY,
-                               Config.INSTALL_MANAGER_APP_JAVA,
-                               Config.EXECUTE_FILE_NAME_OF_INSTALL_MANAGER ));
-               File targetDir = new File(PathUtil.get(Registry.getInstalledPath(),
-                               Config.INSTALL_MANAGER_DIRECTORY));
-               try {
-                       PathUtil.copy(installManagerScript, targetDir);
-               } catch (IOException e) {
-                       Log.ExceptionLog(e);
-                       return;
-               }
-               
-               //remove binary directory in target directory
-               String removableBinaryPath = PathUtil.get(toFile.getAbsolutePath()
-                                                                 , "Contents"
-                                                                 , "Resources"
-                                                                 , "Java"
-                                                                 , "binary");
-               
-               PathUtil.remove(removableBinaryPath);
-       }
-       
-       private File getInstalledAppPath() {
-               String appPath = Registry.getInstalledPath() + File.separator
-                               + Config.INSTALL_MANAGER_DIRECTORY + File.separator
-                               + Config.INSTALL_MANAGER_APP;
-               
-               return new File(appPath);
-       } */
-
-       /**
-        * Remove trash packages which are used during installation using SDK image.
-        */
-       private void cleanPackageDir() {
-               // remove binary directory. TODO remove INSTALL_MANAGER_TEMP_DIRECTORY
-               if (PathUtil.remove(PathUtil.get(Config.INSTALL_MANAGER_TEMP_DIRECTORY, 
-                               Config.INSTALL_MANAGER_DOWNLOAD_DIRECTORY_NAME,
-                               Config.INSTALL_MANAGER_IMAGE_DOWNLOAD_DIRECTORY_NAME))) {
-                       Log.log("Success to remove trash SDK image package binaries.");
-               } else {
-                       Log.err("Fail to remove trash SDK image package binaries.");
-               }
-       }
-       
-       public void removePackagesDir() {
-               // remove binary directory. TODO remove INSTALL_MANAGER_TEMP_DIRECTORY
-               if (PathUtil.remove(PathUtil.get(Config.INSTALL_MANAGER_TEMP_DIRECTORY,
-                               Config.INSTALL_MANAGER_DOWNLOAD_DIRECTORY_NAME))) {
-                       Log.log("Success to remove downloaded package binaries.");
-               } else {
-                       Log.err("Fail to remove downloaded package binaries.");
-               }
-       }
-
-       /**
-        * Package uninstallation management
-        * 
-        * @param pkg
-        * @param monitor
-        * @return
-        */
-       public boolean removePackage(Package pkg, IIMProgressMonitor monitor) {
-               Log.log("InstallManager package remove start  => " + pkg);
-
-               if (pkg == null) {
-                       return false;
-               }
-
-               if (monitor != null) {
-                       monitor.workedTitle(pkg.getPackageName());
-               }
-               
-               if (Options.doRemoveNoUI || Options.doInstallNoUI) {
-                       System.out.println(pkg.getPackageName() + " is uninstalling...");
-               }
-
-               Installer installer = new Installer();
-
-               boolean bResult = installer.uninstall(pkg, monitor);
-
-               // Remove packages in installed package list without result.
-               // We don't know that failed packages are working well.
-               packageManager.exceptPackageFromInstalledPackages(pkg);
-               packageManager.saveInstalledList(PathUtil.get(
-                               PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),
-                               Config.INSTALLED_PACKAGE_LIST_FILE_NAME));
-
-               Log.log(pkg + " remove end => " + bResult);
-               return bResult;
-       }
-
-       /**
-        * Packages uninstallation management
-        * 
-        * @param pkg
-        * @param monitor
-        * @return
-        */
-       public boolean removePackages(PackageSet metasToRemove,
-                       IIMProgressMonitor monitor) {
-               Log.log("InstallManager Packages remove Start => " + metasToRemove);
-
-               if (metasToRemove == null) {
-                       return false;
-               }
-
-               PackageSet pkgsToRemove = packageManager.getToRemovePackagesInRemove(metasToRemove);
-               
-               Log.log("Remove packages: " + pkgsToRemove);
-
-               if (monitor != null) {
-                       monitor.beginTask("Uninstalling...", pkgsToRemove.size() + 1);
-               }
-
-               int i = 0;
-               for (Package pkg : pkgsToRemove) {
-                       if (monitor != null) {
-                               monitor.workedProcess(pkg.getPackageName());
-                               monitor.worked(++i);
-                       }
-
-                       if (removePackage(pkg, monitor)) {
-                               continue;
-                       } else {
-                               Log.log("Remove fail but make progress=> " + pkg);
-                       }
-               }
-
-               // if you remove all packages, delete targetDirectory and config File.
-               if (!packageManager.existInstalledMetaPackages()) {
-                       Log.log("Installed meta packages do not exist");
-                       if (monitor != null) {
-                               monitor.workedSubTitle("Remove target directory...");
-                               monitor.worked(pkgsToRemove.size());
-                       }
-
-                       if (packageManager.existInstalledPackages()) {
-                               Log.log("Installed meta packages do not exist, but some packages exist.");
-                               removeAll(monitor);
-                       } else {
-                               // not exist to remove
-                               removeSDK(monitor);
-                       }
-               }
-
-               Log.log("InstallManager packages remove success. return => " + true);
-               return true;
-       }
-       
-       /**
-        * Remove all of packages.
-        * 
-        * @param monitor
-        */
-       public void removeAll(IIMProgressMonitor monitor) {
-               Log.log("InstallManager.removeAll()");
-
-               removeAllPackages(monitor);
-               removeSDK(monitor);
-       }
-       
-       private void removeAllPackages(IIMProgressMonitor monitor) {
-               Log.log("Remove all packages.");
-               
-               if (monitor != null) {
-                       monitor.workedTitle(REMOVE_ALL_PACKAGES);
-               }
-               
-               PackageSet removablePackages = packageManager.getInstalledPackages();
-
-               for (Package pkg : removablePackages) {
-                       if (!removePackage(pkg, monitor)) {
-                               Log.err("InstallManager.removeAll remove fail => " + pkg);
-                       }
-               }
-       }
-
-       /**
-        * Remove All of TizenSDK files.
-        */
-       public void removeSDK(IIMProgressMonitor monitor) {
-               Log.log("InstallManager removeSDK start");
-               
-               if (monitor != null) {
-                       monitor.workedTitle(REMOVE_ALL_SDK_FILES);
-               }
-
-               removeInstallManager();
-               removeShortcutMenu();
-               removeChangeLog();
-               removeInfoDirectory();
-               checkTargetDirAndRemove();
-//             Registry.removeRegistry();
-               if (Config.isSupportMultiSDK()) {
-                       Registry.removeMultiSDKInfo(Config.getSelectedSDKPath());                       
-               } else {
-                       Registry.removeMultiSDKInfo(Registry.getInstalledPath());
-               }
-
-
-               // do not remove config home because it has log files
-               Log.log("InstallManager removeSDK end");
-       }
-
-       private void checkTargetDirAndRemove() {
-               File targetDir = new File(Registry.getInstalledPath());
-               if (canRemoveTargetDir(targetDir)) {
-                       removeTargetDirectory();
-               } else {
-                       Log.err("Cannot delete target directory => "
-                                       + targetDir.getAbsolutePath());
-               }
-       }
-
-       /**
-        * Check status that target directory can remove or not.
-        * 
-        * @param targetDir
-        * @return
-        */
-       private boolean canRemoveTargetDir(File targetDir) {
-               if (targetDir.exists()) {
-                       File[] fileList = targetDir.listFiles();
-                       if ((fileList == null || fileList.length <= 0)
-                                       || (fileList.length == 1 && fileList[0].getName().equals(
-                                                       Config.OLD_INSTALL_MANAGER_DIRECTORY))) {
-                               return true;
-                       } else {
-                               ArrayList<String> fileNames = new ArrayList<String>();
-                               for (File file : fileList) {
-                                       fileNames.add(file.getName());
-                               }
-                               Log.err("The SDK directory is not empty => " + fileNames);
-                               return false;
-                       }
-               } else {
-                       Log.err("The SDK direcotry is already removed");
-                       return false;
-               }
-       }
-
-       private void removeChangeLog() {
-               File releaseNoteFile = new File(
-                               PathUtil.getFromInstalledPath(Config.RELEASE_NOTE));
-
-               if (releaseNoteFile.exists()) {
-                       PathUtil.remove(releaseNoteFile);
-               }
-       }
-
-       private void removeInfoDirectory() {
-               // remove info directory in $HOME/tizen-sdk-data
-               File infoDirFile = new File(
-                               PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY));
-               if (infoDirFile.exists()) {
-                       PathUtil.remove(infoDirFile);
-               }
-
-               // remove info directory in target directory
-               File targetInfoFile = new File(
-                               PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY));
-
-               if (targetInfoFile.exists()) {
-                       PathUtil.remove(targetInfoFile);
-               }
-       }
-
-       /**
-        * Remove target directory.
-        */
-       public void removeTargetDirectory() {
-               Log.log("InstallManager remove target directory start");
-
-               if (Platform.CURRENT_PLATFORM == Platform.LINUX_32
-                               || Platform.CURRENT_PLATFORM == Platform.LINUX_64
-                               || Platform.CURRENT_PLATFORM == Platform.MACOS_64) {
-                       PathUtil.remove(Registry.getInstalledPath());
-               } else if (Platform.CURRENT_PLATFORM == Platform.WINDOWS_32
-                               || Platform.CURRENT_PLATFORM == Platform.WINDOWS_64) {
-                       if (!WindowsProgramController.removeRunningDir(Registry
-                                       .getInstalledPath())) {
-                               Log.err("Cannot remove target directory");
-                       }
-               } else {
-                       throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
-               }
-
-               Log.log("InstallManager remove target directory end");
-       }
-
-       /**
-        * Singleton and global downloader shared and used by every components in IM
-        * 
-        * @return singleton downloader object
-        */
-       public static Downloader getDownloader() {
-               return InstallManager.mDownloader;
-       }
-}
+/*\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.core;\r
+\r
+import java.io.File;\r
+import java.io.FilenameFilter;\r
+import java.io.IOException;\r
+import java.io.UnsupportedEncodingException;\r
+import java.net.URL;\r
+import java.net.URLEncoder;\r
+import java.security.MessageDigest;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.LinkedList;\r
+\r
+import org.tizen.installmanager.lib.Checksum;\r
+import org.tizen.installmanager.lib.Downloader;\r
+import org.tizen.installmanager.lib.ErrorController;\r
+import org.tizen.installmanager.lib.ErrorController.InfoCode;\r
+import org.tizen.installmanager.lib.IIMProgressMonitor;\r
+import org.tizen.installmanager.lib.Log;\r
+import org.tizen.installmanager.lib.Platform;\r
+import org.tizen.installmanager.lib.Registry;\r
+import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
+import org.tizen.installmanager.lib.exception.IMNetworkException;\r
+import org.tizen.installmanager.lib.win.WindowsProgramController;\r
+import org.tizen.installmanager.pkg.lib.PackageManager;\r
+import org.tizen.installmanager.pkg.model.Package;\r
+import org.tizen.installmanager.pkg.model.PackageSet;\r
+import org.tizen.installmanager.ui.page.InstallingPage.InstallProgressMonitor;\r
+import org.tizen.installmanager.util.IMShellCommandFail;\r
+import org.tizen.installmanager.util.PathUtil;\r
+import org.tizen.installmanager.util.ShellUtil;\r
+\r
+/**\r
+ * This class contains the main business logic of Install Manager. Use singleton\r
+ * instance.\r
+ * \r
+ * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+ */\r
+public class InstallManager {\r
+\r
+       private static final InstallManager mInstallManager = new InstallManager();\r
+\r
+       private Config mConfig = null;\r
+       private static Downloader mDownloader = new Downloader();\r
+       private PackageManager packageManager;\r
+\r
+       // windows path\r
+       private static String WINDOWS_INSTALL_MANAGER_INSTALL_SCRIPT = "/res/desktop_directory/install.vbs";\r
+       private static String WINDOWS_INSTALL_MANAGER_REMOVE_SCRIPT = "/res/desktop_directory/remove.vbs";\r
+       private static String WINDOWS_MAKE_SHORTCUT_PATH = "/res/desktop_directory/makeshortcut.vbs";\r
+       private static String WINDOWS_REMOVE_SHORTCUT_PATH = "/res/desktop_directory/removeshortcut.vbs";\r
+\r
+       // linux script\r
+       private static String LINUX_INSTALL_MANAGER_INSTALL_SCRIPT = "/res/desktop_directory/install.sh";\r
+       private static String LINUX_INSTALL_MANAGER_REMOVE_SCRIPT = "/res/desktop_directory/remove.sh";\r
+       private static String LINUX_MAKE_SHORTCUT_PATH = "/res/desktop_directory/makeshortcut.sh";\r
+       private static String LINUX_REMOVE_SHORTCUT_PATH = "/res/desktop_directory/removeshortcut.sh";\r
+       private static String LINUX_TSUDO_PATH = "/res/desktop_directory/tsudo.sh";\r
+\r
+       private File makeShortCutFile = null;\r
+       private File removeShortCutFile = null;\r
+       private File tSudoFile = null;\r
+\r
+       private static String REMOVE_ALL_PACKAGES = "Remove all packages...";\r
+       private static String REMOVE_ALL_SDK_FILES = "Remove all SDK files...";\r
+\r
+       private Thread installThread = null;\r
+       private LinkedList<Package> installBuffer = new LinkedList<Package>();\r
+\r
+       private InstallManager() {\r
+       }\r
+\r
+       /**\r
+        * @return singleton instance of <code>InstallManager</code>\r
+        */\r
+       public static InstallManager getInstance() {\r
+               return mInstallManager;\r
+       }\r
+\r
+       /**\r
+        * Load config file\r
+        */\r
+       public void initConfig() {\r
+               if (mConfig != null) {\r
+                       if (Config.isSupportMultiSDK()) {\r
+                               if (!Registry.getInstalledPath().isEmpty()) {\r
+                                       mConfig.setTargetDir(Registry.getInstalledPath());\r
+                               }\r
+                       } else {\r
+                               return;\r
+                       }\r
+               } else {\r
+                       mConfig = Config.getInstance();\r
+\r
+                       if (Options.doReplaceRepository) {\r
+                               Log.log("Replace repository => " + Options.repository);\r
+                               mConfig.getConfigFile().setRepository(Options.repository);\r
+                               mConfig.saveConfig();\r
+                       }\r
+                       \r
+                       if (Options.distribution != null && !Options.distribution.isEmpty()) {\r
+                               mConfig.getConfigFile().setDistribution(Options.distribution);\r
+                               mConfig.saveConfig();\r
+                       }\r
+\r
+                       if (mConfig.getConfigFile() == null) {\r
+                               Log.log("Loading config file failed");\r
+                               throw new IMFatalException("Loading configuration file failed");\r
+                       }\r
+\r
+                       if (!Registry.getInstalledPath().isEmpty()) {\r
+                               mConfig.setTargetDir(Registry.getInstalledPath());\r
+                       }\r
+                       mConfig.setSdkDatatDir(Registry.getSdkDataPath());\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Initialize packages information.\r
+        */\r
+       public void initPackageList() {\r
+               Collection<String> repositoryURLs = mConfig.getSDKPackageServerList();\r
+\r
+               initPackageManager(repositoryURLs);\r
+       }\r
+\r
+       private void initPackageManager(Collection<String> repositoryURLs) {\r
+               File installedPackageListFile = null;\r
+               if (Registry.targetPath != "") {\r
+                       installedPackageListFile = new File(PathUtil.get(\r
+                                       PathUtil.get(Registry.targetPath, Config.INFO_DIRECTORY),\r
+                                       Config.INSTALLED_PACKAGE_LIST_FILE_NAME));\r
+               } else {\r
+                       installedPackageListFile = new File(PathUtil.get(\r
+                                       PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),\r
+                                       Config.INSTALLED_PACKAGE_LIST_FILE_NAME));\r
+               }\r
+\r
+               try {\r
+                       if (installedPackageListFile.exists()) {\r
+                               this.packageManager = PackageManager.getInstance(\r
+                                               installedPackageListFile, repositoryURLs);\r
+                       } else {\r
+                               this.packageManager = PackageManager.getInstance(null,\r
+                                               repositoryURLs);\r
+                       }\r
+               } catch (IOException e) {\r
+                       Log.err("Cannot load package manager =>" + installedPackageListFile\r
+                                       + ", " + repositoryURLs);\r
+                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_FILE);\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Initialize distribution and snapshot information\r
+        */\r
+       public boolean initDistribution() {\r
+               DistributionController controller = DistributionController\r
+                               .getInstance(mConfig.getSDKRepositoryList());\r
+\r
+               boolean initResult = controller.init();\r
+               Log.log("Init Distribution result => " + initResult);\r
+\r
+               // First distribution that read from config file is recognized as the\r
+               // distribution installed.\r
+               String installedDistribution = Config.getInstance().getConfigFile()\r
+                               .getDistribution();\r
+               controller.setInstalledDistribution(installedDistribution);\r
+\r
+               return initResult;\r
+       }\r
+\r
+       /**\r
+        * Initialize installmanager. It performs that read config file, make\r
+        * temporary files and load package list from repository.\r
+        * \r
+        * @return <code>true</code> if initialize success to install or uninstall.\r
+        */\r
+       public void init() {\r
+               initConfig();\r
+\r
+               cleanPackageDir();\r
+\r
+               initDistribution();\r
+               if (Config.status == Config.Status.INSTALL) {\r
+                       checkOldSDK();\r
+               }\r
+               initPackageList();\r
+               initConfigurationFile();\r
+               checkNewPackageServer();\r
+       }\r
+\r
+       /**\r
+        * If packageServer has multi SDK packages, set Config.isNewPackageServer\r
+        * true. otherwise false. InstallManager can be used old SDK installation.\r
+        */\r
+       private void checkNewPackageServer() {\r
+               if (packageManager\r
+                               .getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME) == null) {\r
+                       Config.isNewPackageServer = false;\r
+                       Log.log("PackageServer has old SDK packages.");\r
+               } else {\r
+                       Config.isNewPackageServer = true;\r
+                       Log.log("PackageServer has new SDK packages(Multi SDK).");\r
+               }\r
+       }\r
+\r
+       private void initConfigurationFile() {\r
+               copyMakeShortCutFile();\r
+               copyRemoveShortCutFile();\r
+\r
+               // Linux has several kinds such as Ubuntu, Fedora, etc. So, If\r
+               // installation needs super user's\r
+               // permission, sudo command depends on machine. Therefore,\r
+               // Installmanager gives a tsudo command\r
+               // which does not need to care of machine post install script for\r
+               // package.\r
+               if (Platform.isLinux()) {\r
+                       copyTizenSudoFile();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Delete temporary files related installmanager.\r
+        */\r
+       public static void deleteTempFile() {\r
+\r
+               File tmpDir = new File(PathUtil.getTempFileParent());\r
+               File[] tmpFiles = tmpDir.listFiles(new FilenameFilter() {\r
+                       @Override\r
+                       public boolean accept(File dir, String name) {\r
+                               boolean found = false;\r
+                               String[] prefix = { "makeshortcut", "removeshortcut",\r
+                                               "installmanager.repository", "Packages",\r
+                                               "tizen_installmanager", "checkJavaInstallation",\r
+                                               "install" };\r
+                               for (String pref : prefix) {\r
+                                       found = name.startsWith(pref);\r
+                                       if (found == true) {\r
+                                               return true;\r
+                                       }\r
+                               }\r
+                               return found;\r
+                       }\r
+               });\r
+\r
+               if (tmpFiles != null) {\r
+                       for (File f : tmpFiles) {\r
+                               if (!f.delete()) {\r
+                                       Log.err("Fail to delete file ==> " + f);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Copy make shortcut file from resource to temp directory.\r
+        */\r
+       private void copyMakeShortCutFile() {\r
+               try {\r
+                       if (Platform.isLinux()) {\r
+                               makeShortCutFile = PathUtil.getTempFileFromResource(\r
+                                               LINUX_MAKE_SHORTCUT_PATH, "makeshortcut", ".sh");\r
+                       } else if (Platform.isWindows()) {\r
+                               makeShortCutFile = PathUtil.getTempFileFromResource(\r
+                                               WINDOWS_MAKE_SHORTCUT_PATH, "makeshortcut", ".vbs");\r
+                       } else if (Platform.isMacOS()) {\r
+                               makeShortCutFile = PathUtil.getTempFileFromResource(\r
+                                               LINUX_MAKE_SHORTCUT_PATH, "makeshortcut", ".sh");\r
+                       } else {\r
+                               throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
+                       }\r
+\r
+                       if (makeShortCutFile.exists()) {\r
+                               makeShortCutFile.setExecutable(true);\r
+                       }\r
+               } catch (IOException e) {\r
+                       Log.err("Installer cannot make 'makeshortcut script' file.");\r
+                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_SHORTCUT);\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Copy remove shortcut file from resource to temp directory.\r
+        */\r
+       private void copyRemoveShortCutFile() {\r
+               try {\r
+                       if (Platform.isLinux()) {\r
+                               removeShortCutFile = PathUtil.getTempFileFromResource(\r
+                                               LINUX_REMOVE_SHORTCUT_PATH, "removeshortcut", ".sh");\r
+                       } else if (Platform.isWindows()) {\r
+                               removeShortCutFile = PathUtil.getTempFileFromResource(\r
+                                               WINDOWS_REMOVE_SHORTCUT_PATH, "removeshortcut", ".vbs");\r
+                       } else if (Platform.isMacOS()) {\r
+                               removeShortCutFile = PathUtil.getTempFileFromResource(\r
+                                               LINUX_REMOVE_SHORTCUT_PATH, "removeshortcut", ".sh");\r
+                       } else {\r
+                               throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
+                       }\r
+                       removeShortCutFile.setExecutable(true);\r
+               } catch (IOException e) {\r
+                       Log.err("Installer cannot make 'makeshortcut script' file.");\r
+                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_SHORTCUT);\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Copy remove shortcut file from resource to temp directory.\r
+        */\r
+       private void copyTizenSudoFile() {\r
+               try {\r
+                       tSudoFile = PathUtil.getTempFileFromResource(LINUX_TSUDO_PATH,\r
+                                       "tsudo", ".sh");\r
+                       tSudoFile.setExecutable(true);\r
+               } catch (IOException e) {\r
+                       Log.err("Installer cannot make 'tsudo.sh' file.");\r
+                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_TSUDO);\r
+               }\r
+       }\r
+\r
+       /**\r
+        * get make shortcut File instance.\r
+        * \r
+        * @return File instance of makeshortcut script.\r
+        */\r
+       public File getTSudo() {\r
+               return tSudoFile;\r
+       }\r
+\r
+       /**\r
+        * Get temporary file path.(makeshortcut script, Packages list, Installer\r
+        * log)\r
+        * \r
+        * @return temporary file path, if not exist makeshortcut file, return empty\r
+        *         string.\r
+        */\r
+       public String getTSudoPath() {\r
+               if (getTSudo() == null) {\r
+                       return "";\r
+               } else {\r
+                       return getTSudo().getAbsolutePath();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * get make shortcut File instance.\r
+        * \r
+        * @return File instance of makeshortcut script.\r
+        */\r
+       public File getMakeShortCut() {\r
+               return makeShortCutFile;\r
+       }\r
+\r
+       /**\r
+        * Get temporary file path.(makeshortcut script, Packages list, Installer\r
+        * log)\r
+        * \r
+        * @return temporary file path, if not exist makeshortcut file, return empty\r
+        *         string.\r
+        */\r
+       public String getMakeShortCutPath() {\r
+               if (getMakeShortCut() == null) {\r
+                       return "";\r
+               } else {\r
+                       return getMakeShortCut().getAbsolutePath();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Get temporary file path.(rmoveshortcut script, Packages list, Installer\r
+        * log)\r
+        * \r
+        * @return temporary file path, if not exist removeshortcut file, return\r
+        *         emptry string.\r
+        */\r
+       public String getRemoveShortCutPath() {\r
+               if (getRemoveShortCut() == null) {\r
+                       return "";\r
+               } else {\r
+                       return getRemoveShortCut().getAbsolutePath();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Get remove shortcut File instance.\r
+        * \r
+        * @return File instance of removeshortcut script.\r
+        */\r
+       public File getRemoveShortCut() {\r
+               return removeShortCutFile;\r
+       }\r
+\r
+       /**\r
+        * Get Config instance\r
+        * \r
+        * @return\r
+        */\r
+       public Config getConfig() {\r
+               return mConfig;\r
+       }\r
+\r
+       /**\r
+        * Get PackageManager instance.\r
+        * \r
+        * @return\r
+        */\r
+       public PackageManager getPackageManager() {\r
+               return packageManager;\r
+       }\r
+\r
+       /**\r
+        * Check old SDK is installed for compatibility.\r
+        */\r
+       private void checkOldSDK() {\r
+               Log.log("Check old SDK.");\r
+               if (Registry.getOldInstalledPath() != "") { // Old SDK is installed.\r
+                       if (Registry.getInstalledPath() != null\r
+                                       && !Registry.getInstalledPath().isEmpty()) {\r
+                               // Old SDK is installed but new SDK is also installed, so\r
+                               // environment does not need to\r
+                               // set new SDK environment.\r
+                               Log.log("Old SDK is installed but new SDK is also installed. => "\r
+                                               + Registry.getInstalledPath());\r
+                               return;\r
+                       } else {\r
+                               Log.log("Old SDK is installed. => "\r
+                                               + Registry.getOldInstalledPath());\r
+                               setCurrentSDKEnvironment(Registry.getOldInstalledPath());\r
+                       }\r
+               } else {\r
+                       return;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * If old SDK is installed and new SDK is not installed, installmanager set\r
+        * environment for new SDK running properly.\r
+        * \r
+        * @param targetPath\r
+        *            SDK installed path.\r
+        */\r
+       private void setCurrentSDKEnvironment(String targetPath) {\r
+               Log.log("Set new SDK environment from old SDK.");\r
+               Registry.sdkDataPath = Config.getConfigHome();\r
+\r
+               if (targetPath == null || targetPath.isEmpty()) {\r
+                       Log.err("Install path is invalid: " + targetPath\r
+                                       + ". This might be a bug of IM");\r
+                       throw new IMFatalException(ErrorCode.INVALID_INSTALL_PATH);\r
+               } else {\r
+                       Registry.exportInstallPath(targetPath);\r
+                       Registry.exportMultiInstallPath(targetPath, true);\r
+               }\r
+\r
+               // Make sdk.info file into target directory for compatibility.\r
+               Registry.saveSDKInfo(targetPath);\r
+               // Remove tizensdkpath file in 'tizen-sdk-data'.\r
+               // Registry.removeOldRegistry();\r
+       }\r
+\r
+       /**\r
+        * @param pkg\r
+        * @param filePath\r
+        * @return <code>true</code> if the package is already downloaded to the\r
+        *         file path\r
+        */\r
+       private boolean existInCacheFolder(Package pkg, String filePath,\r
+                       IIMProgressMonitor monitor) {\r
+               File file = new File(filePath);\r
+\r
+               if (!file.exists()) {\r
+                       return false;\r
+               }\r
+\r
+               if (monitor != null) {\r
+                       monitor.workedDownloadProgress("Validate the " + pkg.getPackageName(), 0);\r
+               }\r
+\r
+               if (Options.doPackageValidation) {\r
+                       if (Checksum.getSHA256(filePath) != null) {\r
+                               return checkFileChecksum(pkg, Checksum.getSHA256(filePath));\r
+                       } else {\r
+                               return false;\r
+                       }\r
+               } else {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       private boolean checkPackageSize(Package pkg, long size) {\r
+               if (pkg.getPackageSize() == size) {\r
+                       return true;\r
+               }\r
+               return false;\r
+       }\r
+\r
+       private boolean checkFileChecksum(Package pkg, MessageDigest mDigest) {\r
+\r
+               if (pkg.getSHA256() == null || pkg.getSHA256().isEmpty()) {\r
+                       return false;\r
+               }\r
+\r
+               if (mDigest.getAlgorithm().equals(Checksum.SHA_256_TYPE)) {\r
+                       return (pkg.getSHA256().equalsIgnoreCase(Checksum\r
+                                       .messageDigestToString(mDigest)));\r
+               } else {\r
+                       // TODO there's no checksum field in package.\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Packages Installation management. Download and install packages.\r
+        * \r
+        * @param packagesToInstall\r
+        * @param targetDir\r
+        * @param monitor\r
+        * @return\r
+        * @throws IMExitException\r
+        */\r
+       public boolean install(PackageSet installablePackages,\r
+                       final String targetDir, InstallProgressMonitor monitor)\r
+                       throws IMExitException, IMNetworkException {\r
+               Log.log("InstallManager.install() installable packages : "\r
+                               + installablePackages);\r
+\r
+               // performance measurement\r
+               Performance.sdkPackageSize = packageManager\r
+                               .getTotalSizeOfInstallablePackages(installablePackages, true);\r
+\r
+               if (installablePackages == null || targetDir == null\r
+                               || targetDir.isEmpty()) {\r
+                       Log.err("packaegs => " + installablePackages + ", targetDir => "\r
+                                       + targetDir);\r
+                       return false;\r
+               }\r
+\r
+               mConfig.setTargetDir(targetDir);\r
+               mConfig.setSdkDatatDir(Registry.sdkDataPath);\r
+\r
+               if (monitor != null) {\r
+                       monitor.workedRefresh();\r
+                       monitor.beginTask(installablePackages.size(),\r
+                                       getTotalDownloadSize(installablePackages),\r
+                                       getTotalInstallSize(installablePackages));\r
+               }\r
+\r
+               // make start menu\r
+               // if you cannot get installmanager from repository, install from local.\r
+               if (!packageManager\r
+                               .existsPackage(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME)) {\r
+                       Log.log("Cannot find install-manager from repository.");\r
+\r
+                       if (installInstallManagerFromLocal(targetDir)) {\r
+                               makeShortcutMenu();\r
+                       } else {\r
+                               Log.err("Cannot install install-manager from local directory.");\r
+                       }\r
+               }\r
+\r
+               // wait if cancel confirm dialog is showing. wait until user press\r
+               // button(cancel or not).\r
+               // TODO :\r
+               if (monitor != null) {\r
+                       while (monitor.checkCancelAndDisableCancelButton() == false) {\r
+                               if (monitor.isCanceled()) {\r
+                                       throw new IMInstallCancelException();\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // remove missing packages in repository.\r
+               removeMissingPackages(monitor);\r
+\r
+               for (Package pkg : installablePackages) {\r
+                       if (!install2(pkg, targetDir, monitor)) {\r
+                               return false;\r
+                       }\r
+               }\r
+\r
+               // download complete.\r
+               if (monitor != null) {\r
+                       monitor.workedDownloadProgress("Download complete", 0);\r
+               }\r
+\r
+               // install thread is running yet.\r
+               try {\r
+                       installThread.join();\r
+               } catch (InterruptedException e) {\r
+                       Log.ExceptionLog(e);\r
+                       Log.err("");\r
+               }\r
+\r
+               // install complete\r
+               if (monitor != null) {\r
+                       monitor.workedInstallProgress("Installation complete", 0);\r
+               }\r
+\r
+               // save config file\r
+               mConfig.saveConfig();\r
+\r
+               // save sdk version.\r
+               saveSDKVersion();\r
+\r
+               // Delete installed packages\r
+               if (Options.doRemovePackages) {\r
+                       removePackagesDir();\r
+               }\r
+\r
+               if (Config.status == Config.Status.INSTALL) {\r
+                       Registry.exportMultiInstallPath(targetDir, true);\r
+               }\r
+\r
+               // show reboot message in linux platform.\r
+               if (Platform.isLinux() || Platform.isMacOS()) {\r
+                       ErrorController.setInfoCode(InfoCode.RESTART_THE_COMPUTER);\r
+               }\r
+\r
+               Performance.setInstallationEndTime();\r
+               return true;\r
+       }\r
+\r
+       private long getTotalDownloadSize(PackageSet pkgSet) {\r
+               if (pkgSet == null) {\r
+                       return -1;\r
+               }\r
+\r
+               long totalSize = 0;\r
+               for (Package pkg : pkgSet) {\r
+                       totalSize += pkg.getPackageSize();\r
+               }\r
+\r
+               return totalSize;\r
+       }\r
+\r
+       private long getTotalInstallSize(PackageSet pkgSet) {\r
+               if (pkgSet == null) {\r
+                       return -1;\r
+               }\r
+\r
+               long totalSize = 0;\r
+               for (Package pkg : pkgSet) {\r
+                       totalSize += pkg.getUncompressedPackageSize();\r
+               }\r
+\r
+               return totalSize;\r
+       }\r
+\r
+       private boolean install2(final Package pkg, final String targetDir,\r
+                       final InstallProgressMonitor monitor) throws IMExitException,\r
+                       IMNetworkException {\r
+               Log.log("Install package => " + pkg.getPackageName());\r
+               Log.log("Target directory => " + targetDir);\r
+\r
+               boolean result = false;\r
+\r
+               if (Options.doTest && Performance.getDownloadStartTime() == null) {\r
+                       Performance.setDownloadStartTime();\r
+               }\r
+\r
+               // download package from repository.\r
+               result = downloadPackage(pkg, monitor);\r
+\r
+               if (Options.doTest) {\r
+                       Performance.setDownloadEndTime();\r
+               }\r
+\r
+               if (result) {\r
+                       installBuffer.push(pkg);\r
+\r
+                       if (Options.doTest\r
+                                       && Performance.getInstallationStartTime() == null) {\r
+                               Performance.setInstallationStartTime();\r
+                       }\r
+\r
+                       if (installThread == null || !installThread.isAlive()) {\r
+                               installThread = new Thread() {\r
+                                       public void run() {\r
+                                               Package p = null;\r
+                                               while ((p = installBuffer.pollLast()) != null) {\r
+                                                       if (!installPackage(p, targetDir, monitor)) {\r
+                                                               return;\r
+                                                       }\r
+                                                       \r
+                                                       if (installBuffer.size() <= 0) {\r
+                                                               if (monitor != null ) {\r
+                                                                       monitor.workedInstallProgress("Waiting for download", 0);\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               };\r
+\r
+                               installThread.start();\r
+                       }\r
+\r
+                       if (Options.doTest) {\r
+                               Performance.setInstallationEndTime();\r
+                       }\r
+\r
+                       if (!ErrorController.checkInstallationSuccess()) {\r
+                               return false;\r
+                       }\r
+               } else {\r
+                       Log.log("Installation failed. => " + pkg.getPackageName());\r
+                       return false;\r
+               }\r
+\r
+               return result;\r
+       }\r
+\r
+       public boolean downloadPackages(PackageSet packageSet,\r
+                       InstallProgressMonitor monitor) throws IMNetworkException {\r
+               if (packageSet == null) {\r
+                       return false;\r
+               }\r
+\r
+               for (Package pkg : packageSet) {\r
+                       if (!downloadPackage(pkg, monitor)) {\r
+                               return false;\r
+                       }\r
+               }\r
+               return true;\r
+       }\r
+\r
+       private boolean downloadPackage(Package pkg, InstallProgressMonitor monitor)\r
+                       throws IMNetworkException {\r
+               Log.log("Download package => " + pkg);\r
+\r
+               // check the parameter\r
+               if (pkg == null) {\r
+                       Log.err("Cannot find package.");\r
+                       return false;\r
+               }\r
+\r
+               // check the option.\r
+               if (Options.doInstallNoUI) {\r
+                       System.out.println(pkg.getPackageName() + " is downloading...");\r
+               }\r
+\r
+               // check the cancel button\r
+               if (monitor != null) {\r
+                       if (monitor.isCanceled()) {\r
+                               Log.log("download canceled");\r
+                               throw new IMInstallCancelException();\r
+                       } else {\r
+                               monitor.workedDownloadProgress(pkg.getPackageName(), 1);\r
+                       }\r
+               }\r
+\r
+               URL downloadFileURL = pkg.getURL();\r
+               String downloadTargetPath = getDownloadTargetPath(pkg);\r
+\r
+               // check the package in cache folder\r
+               if (existInCacheFolder(pkg, downloadTargetPath, monitor)) {\r
+                       Log.log("Found the package in cache");\r
+                       \r
+                       if (monitor != null) {\r
+                               monitor.workedDownloadSize(pkg.getPackageSize());\r
+                       }\r
+                       \r
+                       return true;\r
+               }\r
+\r
+               // download package from repository\r
+               long size = mDownloader.download(downloadFileURL, downloadTargetPath,\r
+                               monitor);\r
+\r
+               if (size >= 0) {\r
+                       if (Options.onlyDownload) {\r
+                               System.out.println("Download success. => " + pkg);\r
+                       }\r
+                       Log.log("finish download => " + pkg);\r
+               } else { // fail\r
+                       Log.err("download failed => " + downloadFileURL);\r
+\r
+                       PathUtil.remove(downloadTargetPath);\r
+\r
+                       String errMsg = "";\r
+                       if (monitor.isCanceled()) {\r
+                               errMsg = ErrorController.getErrorMessage();\r
+                       } else {\r
+                               errMsg = "Fail to get '" + pkg.getPackageName() + "'." + "\n("\r
+                                               + ErrorController.getErrorMessage() + ")";\r
+                       }\r
+                       throw new IMFatalException(errMsg);\r
+               }\r
+\r
+               // package validation\r
+               if (Options.doPackageValidation) {\r
+                       Log.log("Validate package");\r
+                       if (!checkPackageSize(pkg, size)) {\r
+                               Log.err("The expected size of package => "\r
+                                               + pkg.getPackageSize());\r
+                               Log.err("Package size error. downloaded size => " + size);\r
+\r
+                               PathUtil.remove(downloadTargetPath);\r
+\r
+                               throw new IMFatalException(ErrorCode.PACKAGE_WRONG_SIZE);\r
+                       }\r
+\r
+                       // TODO :\r
+                       if (!checkFileChecksum(pkg, mDownloader.getFileChecksum())) {\r
+                               Log.err("The expected checksum of package => "\r
+                                               + pkg.getSHA256());\r
+                               Log.err("Package checksum error downloaded checksum => "\r
+                                               + mDownloader.getFileChecksum());\r
+\r
+                               PathUtil.remove(downloadTargetPath);\r
+\r
+                               throw new IMFatalException(ErrorCode.PACKAGE_WRONG_CHECKSUM);\r
+                       }\r
+               }\r
+\r
+               return true;\r
+       }\r
+\r
+       private boolean installPackage(Package pkg, String targetDir,\r
+                       InstallProgressMonitor monitor) {\r
+               // save target directory\r
+               initializeTargetDir(targetDir);\r
+\r
+               // remove packages to update.\r
+               if (packageManager.isReInstall() || packageManager.isUpdatable(pkg)) {\r
+                       if (monitor != null) {\r
+                               monitor.workedInstallProgress("Remove the previous version",  0);\r
+                       }\r
+                       removePackage(pkg, null);\r
+               }\r
+\r
+               // remove conflict packages\r
+               PackageSet pkgSet = packageManager.getConflictPackages(pkg);\r
+               if (pkgSet.size() > 0) {\r
+                       if (monitor != null) {\r
+                               monitor.workedInstallProgress("Remove the conflict packages", 0);\r
+                       }\r
+                       removePackages(pkgSet, null);\r
+               }\r
+\r
+               if (Options.doInstallNoUI) {\r
+                       System.out.println(pkg.getPackageName() + " is installing...");\r
+               }\r
+\r
+               Installer installer = new Installer();\r
+               boolean bResult = installer.install(pkg, targetDir, monitor);\r
+\r
+               if (bResult) {// save installed package list\r
+                       packageManager.addPackageToInstalledPackages(pkg);\r
+                       packageManager.saveInstalledList();\r
+               } else {\r
+                       Log.log("Installation failed => " + pkg);\r
+\r
+                       ErrorController.setError(ErrorCode.INSTALLATION_FAIL);\r
+                       ErrorController.setInstallationSuccess(false);\r
+               }\r
+\r
+               return bResult;\r
+       }\r
+\r
+       private String getDownloadTargetPath(Package pkg) {\r
+               String repository = pkg.getBaseURL().toString();\r
+\r
+               String encodeRepository = null;\r
+               try {\r
+                       encodeRepository = URLEncoder.encode(repository, "UTF-8");\r
+               } catch (UnsupportedEncodingException e) {\r
+                       Log.ExceptionLog(e);\r
+                       return encodeRepository;\r
+               }\r
+\r
+               return PathUtil.get(mConfig.getDownloadDirPath(), encodeRepository,\r
+                               pkg.getFileName());\r
+       }\r
+\r
+       private boolean installInstallManagerFromLocal(String sdkPath) {\r
+               Log.log("Install install-manager from local. => " + sdkPath);\r
+               String targetDir = PathUtil.get(sdkPath,\r
+                               InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME);\r
+\r
+               File targetDirFile = new File(targetDir);\r
+\r
+               if (!targetDirFile.exists()) {\r
+                       targetDirFile.mkdirs();\r
+               }\r
+\r
+               try {\r
+                       if (Platform.isLinux()) {\r
+                               installInstallManagerFromLocalInLinux(targetDir);\r
+                       } else if (Platform.isWindows()) {\r
+                               installInstallManagerFromLocalInWindows(targetDir);\r
+                       } else if (Platform.isMacOS()) {\r
+                               installInstallManagerFromLocalInMac(targetDir);\r
+                       } else {\r
+                               throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
+                       }\r
+\r
+                       File toInstallManagerImage = new File(PathUtil.get(\r
+                                       Registry.getInstalledPath(),\r
+                                       InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME,\r
+                                       InstallManagerConstants.INSTALLMANAGER_SHORTCUT_IMAGE_NAME));\r
+                       PathUtil.writeFileFromInputStream(\r
+                                       PathUtil.getResourceAsStream(InstallManagerConstants.INSTALLMANAGER_SHORTCUT_IMAGE_PATH),\r
+                                       toInstallManagerImage);\r
+\r
+                       File toDesktopFile = new File(PathUtil.get(\r
+                                       Registry.getInstalledPath(),\r
+                                       InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME,\r
+                                       InstallManagerConstants.DESKTOP_SHORTCUT_IMAGE_NAME));\r
+                       PathUtil.writeFileFromInputStream(\r
+                                       PathUtil.getResourceAsStream(InstallManagerConstants.DESKTOP_SHORTCUT_IMAGE_PATH),\r
+                                       toDesktopFile);\r
+\r
+               } catch (IOException e) {\r
+                       Log.ExceptionLog(e);\r
+                       return false;\r
+               }\r
+\r
+               // execute install script\r
+               File installScript = getInstallScript();\r
+               if (installScript != null && installScript.exists()) {\r
+                       installScript.setExecutable(true);\r
+\r
+                       Installer installer = new Installer();\r
+                       try {\r
+                               installer.executeScript(installScript);\r
+                               return true;\r
+                       } catch (IMShellCommandFail e) {\r
+                               Log.ExceptionLog(e);\r
+                       }\r
+               }\r
+               return false;\r
+       }\r
+\r
+       private void installInstallManagerFromLocalInLinux(String targetDir) {\r
+               try {\r
+                       // copy excutable file to target directory\r
+                       PathUtil.copy(PathUtil.get(Options.executablePath,\r
+                                       InstallManagerConstants.INSTALLMANAGER_BINARY_NAME),\r
+                                       targetDir);\r
+\r
+                       // copy library file to target directory\r
+                       PathUtil.copy(PathUtil.get(PathUtil.getCurrentDir(),\r
+                                       InstallManagerConstants.INSTALLMANAGER_JAR_FILE_NAME),\r
+                                       targetDir);\r
+               } catch (IOException e) {\r
+                       Log.ExceptionLog(e);\r
+               }\r
+       }\r
+\r
+       private void installInstallManagerFromLocalInWindows(String targetDir) {\r
+               installInstallManagerFromLocalInLinux(targetDir);\r
+       }\r
+\r
+       private void installInstallManagerFromLocalInMac(String targetDir) {\r
+               String parentDir = PathUtil.getParentDirectory(\r
+                               PathUtil.getCurrentDir(), 4);\r
+\r
+               String imExecutableAppDirPath = PathUtil\r
+                               .get(parentDir,\r
+                                               InstallManagerConstants.INSTALLMANAGER_EXECUTALBE_DIR_NAME_FOR_MAC);\r
+               String command = "cp -rf " + imExecutableAppDirPath + " " + targetDir;\r
+\r
+               try {\r
+                       ShellUtil.execute(command);\r
+               } catch (IMShellCommandFail e) {\r
+                       Log.ExceptionLog(e);\r
+                       Log.err(command);\r
+                       throw new IMFatalException(\r
+                                       ErrorCode.CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY);\r
+               }\r
+\r
+               String imExecutableBinaryPath = PathUtil\r
+                               .get(parentDir,\r
+                                               InstallManagerConstants.INSTALLMANAGER_EXECUTALBE_FILE_NAME_FOR_LINUX);\r
+               command = "cp -rf " + imExecutableBinaryPath + " " + targetDir;\r
+\r
+               try {\r
+                       ShellUtil.execute(command);\r
+               } catch (IMShellCommandFail e) {\r
+                       Log.ExceptionLog(e);\r
+                       return;\r
+               }\r
+\r
+               String imJarFilePath = PathUtil.get(parentDir,\r
+                               InstallManagerConstants.INSTALLMANAGER_JAR_FILE_NAME);\r
+               command = "cp -rf " + imJarFilePath + " " + targetDir;\r
+\r
+               try {\r
+                       ShellUtil.execute(command);\r
+               } catch (IMShellCommandFail e) {\r
+                       Log.ExceptionLog(e);\r
+                       return;\r
+               }\r
+       }\r
+\r
+       private void removeMissingPackages(IIMProgressMonitor monitor) {\r
+               PackageSet missingPackages = packageManager\r
+                               .getMissingPackagesFromRepository();\r
+               Log.log("Remove missing packages => " + missingPackages);\r
+\r
+               if (monitor != null) {\r
+                       monitor.workedDownloadProgress("Remove missing packages", 0);\r
+               }\r
+\r
+               for (Package pkg : missingPackages) {\r
+                       if (!removePackage(pkg, monitor)) {\r
+                               Log.err("Cannot remove missing package");\r
+                               throw new IMFatalException(\r
+                                               ErrorCode.CANNOT_REMOVE_MISSING_PACKAGE);\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Initializes target directory\r
+        * \r
+        * @param targetDir\r
+        *            path to SDK target directory\r
+        */\r
+       public void initializeTargetDir(String targetDir) {\r
+               Log.log("Initialize target dir. " + targetDir);\r
+               // Make target directory\r
+               File targetDirFile = new File(targetDir);\r
+               if (!targetDirFile.exists()) {\r
+                       if (!targetDirFile.mkdirs()) {\r
+                               Log.err("Fail to create file ==> " + targetDirFile);\r
+                       }\r
+               }\r
+\r
+               // Keep target path in system\r
+               Registry.exportInstallPath(targetDir);\r
+\r
+               // Keep target path for later use\r
+               mConfig.setTargetDir(targetDir);\r
+               mConfig.setSdkDatatDir(Registry.sdkDataPath);\r
+\r
+               // Make .info directory\r
+               if (!mConfig.makeInfoDirectory()) {\r
+                       Log.err(Config.CONFIG_HOME_PATH + " cannot create.");\r
+                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_CONFIG_FILE);\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Save installed SDK version.\r
+        */\r
+       public void saveSDKVersion() {\r
+               Registry.saveInstallVersion(mConfig.getConfigFile()\r
+                               .getInstallManagerVersion());\r
+       }\r
+\r
+       /**\r
+        * Make tizen menu and installmanager shortcut.\r
+        */\r
+       private void makeShortcutMenu() {\r
+               Log.log("InstallManager make shortcut menu.");\r
+\r
+               // execute install script.\r
+               File installScript = getInstallScript();\r
+               if (installScript != null) {\r
+                       installScript.setExecutable(true);\r
+\r
+                       Installer installer = new Installer();\r
+                       try {\r
+                               installer.executeScript(installScript);\r
+                       } catch (IMShellCommandFail e) {\r
+                               // TODO\r
+                               Log.ExceptionLog(e);\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Get install script from resource according to each platform.\r
+        * \r
+        * @return\r
+        */\r
+       private File getInstallScript() {\r
+               try {\r
+                       if (Platform.isLinux()) {\r
+                               return PathUtil.getTempFileFromResource(\r
+                                               LINUX_INSTALL_MANAGER_INSTALL_SCRIPT, "im_install",\r
+                                               ".sh");\r
+                       } else if (Platform.isWindows()) {\r
+                               return PathUtil.getTempFileFromResource(\r
+                                               WINDOWS_INSTALL_MANAGER_INSTALL_SCRIPT, "im_install",\r
+                                               ".vbs");\r
+                       } else if (Platform.isMacOS()) {\r
+                               return null;\r
+                       } else {\r
+                               throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
+                       }\r
+               } catch (IOException e) {\r
+                       Log.err("Cannot execute InstallManager's install script.");\r
+                       Log.ExceptionLog(e);\r
+                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_SHORTCUT);\r
+               }\r
+       }\r
+\r
+       private void removeInstallManager() {\r
+               Log.log("InstallManager.removeInstallManager");\r
+\r
+               String installManagerDirectory = PathUtil.get(\r
+                               Registry.getInstalledPath(),\r
+                               InstallManagerConstants.INSTALLMANAGER_DIRECTORY_NAME);\r
+               PathUtil.remove(installManagerDirectory);\r
+\r
+               if (Registry.getInstalledPath().isEmpty()) {\r
+                       return;\r
+               }\r
+       }\r
+\r
+       private void removeShortcutMenu() {\r
+               File removeScript = getRemoveScript();\r
+\r
+               if (removeScript == null) {\r
+                       return;\r
+               }\r
+\r
+               removeScript.setExecutable(true);\r
+\r
+               Installer installer = new Installer();\r
+               try {\r
+                       installer.executeScript(removeScript);\r
+               } catch (IMShellCommandFail e) {\r
+                       Log.err("Cannot execute InstallManager's remove script.");\r
+                       Log.ExceptionLog(e);\r
+               }\r
+       }\r
+\r
+       private File getRemoveScript() {\r
+               try {\r
+                       if (Platform.isLinux()) {\r
+                               return PathUtil\r
+                                               .getTempFileFromResource(\r
+                                                               LINUX_INSTALL_MANAGER_REMOVE_SCRIPT,\r
+                                                               "im_remove", ".sh");\r
+                       } else if (Platform.isWindows()) {\r
+                               return PathUtil.getTempFileFromResource(\r
+                                               WINDOWS_INSTALL_MANAGER_REMOVE_SCRIPT, "im_remove",\r
+                                               ".vbs");\r
+                       } else if (Platform.isMacOS()) {\r
+                               return null;\r
+                       } else {\r
+                               throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
+                       }\r
+               } catch (IOException e) {\r
+                       // TODO Auto-generated catch block\r
+                       Log.err("Cannot get InstallManager's remove script.");\r
+                       Log.ExceptionLog(e);\r
+                       return null;\r
+               }\r
+       }\r
+\r
+       /*\r
+        * private void copyInstallManagerToTargetDirectoryForMac() {\r
+        * Log.log("Copy InstallManager to target in MAC platform");\r
+        * \r
+        * //get '.app' directory String fromPath =\r
+        * PathUtil.getParentDirectory(PathUtil.getCurrentDir(), 3); if (fromPath ==\r
+        * null) { Log.err("Cannot get parent directory => " +\r
+        * PathUtil.getCurrentDir()); return; }\r
+        * \r
+        * File fromFile = new File(fromPath);\r
+        * \r
+        * if (Registry.getInstalledPath() == null ||\r
+        * Registry.getInstalledPath().equals("")) {\r
+        * Log.err("Cannot find target dir"); return; }\r
+        * \r
+        * File toFile = getInstalledAppPath(); if (!toFile.exists()) { if\r
+        * (!toFile.mkdirs()) { Log.err("Fail to create file ==> " + toFile); } }\r
+        * \r
+        * if (fromFile.getAbsolutePath().equals(toFile.getAbsolutePath())) {\r
+        * return; }\r
+        * \r
+        * try { PathUtil.copy(fromFile, toFile); } catch (IOException e) {\r
+        * Log.ExceptionLog(e); return; }\r
+        * \r
+        * // copy InstallManager script to {target dir}/install-manager/ File\r
+        * installManagerScript = new File(PathUtil.get(Registry.getInstalledPath(),\r
+        * Config.INSTALL_MANAGER_DIRECTORY, Config.INSTALL_MANAGER_APP_JAVA,\r
+        * Config.EXECUTE_FILE_NAME_OF_INSTALL_MANAGER )); File targetDir = new\r
+        * File(PathUtil.get(Registry.getInstalledPath(),\r
+        * Config.INSTALL_MANAGER_DIRECTORY));\r
+        * \r
+        * try { PathUtil.copy(installManagerScript, targetDir); } catch\r
+        * (IOException e) { Log.ExceptionLog(e); return; }\r
+        * \r
+        * //remove binary directory in target directory String removableBinaryPath\r
+        * = PathUtil.get(toFile.getAbsolutePath() , "Contents" , "Resources" ,\r
+        * "Java" , "binary");\r
+        * \r
+        * PathUtil.remove(removableBinaryPath); }\r
+        * \r
+        * private File getInstalledAppPath() { String appPath =\r
+        * Registry.getInstalledPath() + File.separator +\r
+        * Config.INSTALL_MANAGER_DIRECTORY + File.separator +\r
+        * Config.INSTALL_MANAGER_APP;\r
+        * \r
+        * return new File(appPath); }\r
+        */\r
+\r
+       /**\r
+        * Remove trash packages which are used during installation using SDK image.\r
+        */\r
+       private void cleanPackageDir() {\r
+               // remove binary directory. TODO remove INSTALL_MANAGER_TEMP_DIRECTORY\r
+               if (PathUtil.remove(PathUtil.get(Config.INSTALL_MANAGER_TEMP_DIRECTORY,\r
+                               Config.INSTALL_MANAGER_DOWNLOAD_DIRECTORY_NAME,\r
+                               Config.INSTALL_MANAGER_IMAGE_DOWNLOAD_DIRECTORY_NAME))) {\r
+                       Log.log("Success to remove trash SDK image package binaries.");\r
+               } else {\r
+                       Log.err("Fail to remove trash SDK image package binaries.");\r
+               }\r
+       }\r
+\r
+       public void removePackagesDir() {\r
+               // remove binary directory. TODO remove INSTALL_MANAGER_TEMP_DIRECTORY\r
+               if (PathUtil.remove(PathUtil.get(Config.INSTALL_MANAGER_TEMP_DIRECTORY,\r
+                               Config.INSTALL_MANAGER_DOWNLOAD_DIRECTORY_NAME))) {\r
+                       Log.log("Success to remove downloaded package binaries.");\r
+               } else {\r
+                       Log.err("Fail to remove downloaded package binaries.");\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Package uninstallation management\r
+        * \r
+        * @param pkg\r
+        * @param monitor\r
+        * @return\r
+        */\r
+       public boolean removePackage(Package pkg, IIMProgressMonitor monitor) {\r
+               Log.log("InstallManager package remove start  => " + pkg);\r
+\r
+               if (pkg == null) {\r
+                       return false;\r
+               }\r
+\r
+               if (Options.doRemoveNoUI || Options.doInstallNoUI) {\r
+                       System.out.println(pkg.getPackageName() + " is uninstalling...");\r
+               }\r
+\r
+               Installer installer = new Installer();\r
+\r
+               boolean bResult = installer.uninstall(pkg, monitor);\r
+\r
+               // Remove packages in installed package list without result.\r
+               // We don't know that failed packages are working well.\r
+               packageManager.exceptPackageFromInstalledPackages(pkg);\r
+               packageManager.saveInstalledList();\r
+\r
+               Log.log(pkg + " remove end => " + bResult);\r
+               return bResult;\r
+       }\r
+\r
+       /**\r
+        * Packages uninstallation management\r
+        * \r
+        * @param pkg\r
+        * @param monitor\r
+        * @return\r
+        */\r
+       public boolean removePackages(PackageSet metasToRemove,\r
+                       IIMProgressMonitor monitor) {\r
+               Log.log("InstallManager Packages remove Start => " + metasToRemove);\r
+\r
+               if (metasToRemove == null) {\r
+                       return false;\r
+               }\r
+\r
+               PackageSet pkgsToRemove = packageManager\r
+                               .getToRemovePackagesInRemove(metasToRemove);\r
+\r
+               Log.log("Remove packages: " + pkgsToRemove);\r
+\r
+               if (monitor != null) {\r
+                       monitor.beginTask("Uninstalling...", pkgsToRemove.size() + 1);\r
+               }\r
+\r
+               int i = 0;\r
+               for (Package pkg : pkgsToRemove) {\r
+                       if (monitor != null) {\r
+                               monitor.workedDownloadProgress(pkg.getPackageName(), 1);\r
+                               monitor.worked(++i);\r
+                       }\r
+\r
+                       if (removePackage(pkg, monitor)) {\r
+                               continue;\r
+                       } else {\r
+                               Log.log("Remove fail but make progress=> " + pkg);\r
+                       }\r
+               }\r
+\r
+               // if you remove all packages, delete targetDirectory and config File.\r
+               if (!packageManager.existInstalledMetaPackages()) {\r
+                       Log.log("Installed meta packages do not exist");\r
+                       if (monitor != null) {\r
+                               monitor.workedDownloadProgress("Remove target directory...", 0);\r
+                               monitor.worked(pkgsToRemove.size());\r
+                       }\r
+\r
+                       if (packageManager.existInstalledPackages()) {\r
+                               Log.log("Installed meta packages do not exist, but some packages exist.");\r
+                               removeAll(monitor);\r
+                       } else {\r
+                               // not exist to remove\r
+                               removeSDK(monitor);\r
+                       }\r
+               }\r
+\r
+               Log.log("InstallManager packages remove success. return => " + true);\r
+               return true;\r
+       }\r
+\r
+       /**\r
+        * Remove all of packages.\r
+        * \r
+        * @param monitor\r
+        */\r
+       public void removeAll(IIMProgressMonitor monitor) {\r
+               Log.log("InstallManager.removeAll()");\r
+\r
+               removeAllPackages(monitor);\r
+               removeSDK(monitor);\r
+       }\r
+\r
+       private void removeAllPackages(IIMProgressMonitor monitor) {\r
+               Log.log("Remove all packages.");\r
+\r
+               if (monitor != null) {\r
+                       monitor.workedTitle(REMOVE_ALL_PACKAGES);\r
+               }\r
+\r
+               PackageSet removablePackages = packageManager.getInstalledPackages();\r
+\r
+               for (Package pkg : removablePackages) {\r
+                       if (!removePackage(pkg, monitor)) {\r
+                               Log.err("InstallManager.removeAll remove fail => " + pkg);\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Remove All of TizenSDK files.\r
+        */\r
+       public void removeSDK(IIMProgressMonitor monitor) {\r
+               Log.log("InstallManager removeSDK start");\r
+\r
+               if (monitor != null) {\r
+                       monitor.workedTitle(REMOVE_ALL_SDK_FILES);\r
+               }\r
+\r
+               removeInstallManager();\r
+               removeShortcutMenu();\r
+               removeChangeLog();\r
+               removeInfoDirectory();\r
+               checkTargetDirAndRemove();\r
+               // Registry.removeRegistry();\r
+               if (Config.isSupportMultiSDK()) {\r
+                       Registry.removeMultiSDKInfo(Config.getSelectedSDKPath());\r
+               } else {\r
+                       Registry.removeMultiSDKInfo(Registry.getInstalledPath());\r
+               }\r
+\r
+               // do not remove config home because it has log files\r
+               Log.log("InstallManager removeSDK end");\r
+       }\r
+\r
+       private void checkTargetDirAndRemove() {\r
+               File targetDir = new File(Registry.getInstalledPath());\r
+               if (canRemoveTargetDir(targetDir)) {\r
+                       removeTargetDirectory();\r
+               } else {\r
+                       Log.err("Cannot delete target directory => "\r
+                                       + targetDir.getAbsolutePath());\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Check status that target directory can remove or not.\r
+        * \r
+        * @param targetDir\r
+        * @return\r
+        */\r
+       private boolean canRemoveTargetDir(File targetDir) {\r
+               if (targetDir.exists()) {\r
+                       File[] fileList = targetDir.listFiles();\r
+                       if ((fileList == null || fileList.length <= 0)\r
+                                       || (fileList.length == 1 && fileList[0].getName().equals(\r
+                                                       Config.OLD_INSTALL_MANAGER_DIRECTORY))) {\r
+                               return true;\r
+                       } else {\r
+                               ArrayList<String> fileNames = new ArrayList<String>();\r
+                               for (File file : fileList) {\r
+                                       fileNames.add(file.getName());\r
+                               }\r
+                               Log.err("The SDK directory is not empty => " + fileNames);\r
+                               return false;\r
+                       }\r
+               } else {\r
+                       Log.err("The SDK direcotry is already removed");\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       private void removeChangeLog() {\r
+               File releaseNoteFile = new File(\r
+                               PathUtil.getFromInstalledPath(Config.RELEASE_NOTE));\r
+\r
+               if (releaseNoteFile.exists()) {\r
+                       PathUtil.remove(releaseNoteFile);\r
+               }\r
+       }\r
+\r
+       private void removeInfoDirectory() {\r
+               // remove info directory in $HOME/tizen-sdk-data\r
+               File infoDirFile = new File(\r
+                               PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY));\r
+               if (infoDirFile.exists()) {\r
+                       PathUtil.remove(infoDirFile);\r
+               }\r
+\r
+               // remove info directory in target directory\r
+               File targetInfoFile = new File(\r
+                               PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY));\r
+\r
+               if (targetInfoFile.exists()) {\r
+                       PathUtil.remove(targetInfoFile);\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Remove target directory.\r
+        */\r
+       public void removeTargetDirectory() {\r
+               Log.log("InstallManager remove target directory start");\r
+\r
+               if (Platform.CURRENT_PLATFORM == Platform.LINUX_32\r
+                               || Platform.CURRENT_PLATFORM == Platform.LINUX_64\r
+                               || Platform.CURRENT_PLATFORM == Platform.MACOS_64) {\r
+                       PathUtil.remove(Registry.getInstalledPath());\r
+               } else if (Platform.CURRENT_PLATFORM == Platform.WINDOWS_32\r
+                               || Platform.CURRENT_PLATFORM == Platform.WINDOWS_64) {\r
+                       if (!WindowsProgramController.removeRunningDir(Registry\r
+                                       .getInstalledPath())) {\r
+                               Log.err("Cannot remove target directory");\r
+                       }\r
+               } else {\r
+                       throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
+               }\r
+\r
+               Log.log("InstallManager remove target directory end");\r
+       }\r
+\r
+       /**\r
+        * Singleton and global downloader shared and used by every components in IM\r
+        * \r
+        * @return singleton downloader object\r
+        */\r
+       public static Downloader getDownloader() {\r
+               return InstallManager.mDownloader;\r
+       }\r
+}\r
index 87d9b6f..0344f50 100644 (file)
-/*
- *  InstallManager
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: 
- * Wooyoung Cho <wooyoung1.cho@samsung.com>
- * Shihyun Kim <shihyun.kim@samsung.com>
- * Taeyoung Son <taeyoung2.son@samsung.com>
- * Yongsung kim <yongsung1.kim@samsung.com>
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-package org.tizen.installmanager.core;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Stack;
-
-import org.tizen.installmanager.lib.ErrorController;
-import org.tizen.installmanager.lib.ErrorController.InfoCode;
-import org.tizen.installmanager.lib.IIMProgressMonitor;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.lib.LoggerShellParser;
-import org.tizen.installmanager.lib.Platform;
-import org.tizen.installmanager.lib.Registry;
-import org.tizen.installmanager.lib.SDKPackageFormat;
-import org.tizen.installmanager.lib.ErrorController.ErrorCode;
-import org.tizen.installmanager.pkg.model.Package;
-import org.tizen.installmanager.util.IMShellCommandFail;
-import org.tizen.installmanager.util.PathUtil;
-import org.tizen.installmanager.util.ShellUtil;
-
-/**
- * This class manages lowlevel install/uninstall operations
- * 
- * @author Shihyun Kim <shihyun.kim@samsung.com>
- */
-public class Installer {
-       /**
-        * Install a package to target directory.
-        * 
-        * @param pack
-        *            Package to be installed.
-        * @param targetDir
-        *            Target directory to install.
-        * @param monitor
-        *            If you want to express in UI, implement IIMProgressMonitor and
-        *            set this parametor. if not, set <code>null</code>.
-        * @return <code>true</code>, if installation is success.
-        */
-       public boolean install(Package pack, String targetDir,
-                       IIMProgressMonitor monitor) {
-               Log.log("**** installer install start => " + pack + ", target => " + targetDir);
-
-               // unzip in temp dir
-               String tempDir = PathUtil.get(targetDir, Config.TEMP_DIRECTORY);
-
-               // Clear temp dir before unzip package.
-               File tmpDir = new File(tempDir);
-               
-               if (tmpDir.exists()) {
-                       if (!tmpDir.delete()) {
-                               Log.err("Fail to delete " + tmpDir);
-                       }
-               }
-
-               long unZipSize = unZipPackage(pack, tempDir, monitor);
-
-               if (unZipSize <= 0) {
-                       Log.err("Unzip failed. => " + pack);
-                       PathUtil.remove(tempDir);
-                       throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);
-               }
-               if (!checkUnzipSize(pack, unZipSize)) {
-                       Log.err("Unzip size error. => " + pack);
-                       PathUtil.remove(tempDir);
-                       throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);
-               }
-
-               if (!moveToTargetDirectoryFromTempDirectory(tempDir, targetDir)) {
-                       PathUtil.remove(tempDir);
-                       Log.err("Moving temp to target failed. Remove temp and cancel installing.");
-                       throw new IMFatalException(
-                                       ErrorCode.CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY);
-               }
-
-               List<File> missingFiles = findMissingFiles(pack);
-               if (missingFiles.size() > 0) {
-                       Log.err("Some files are not moved properly: " + missingFiles);
-//                     throw new IMFatalException(ErrorCode.FIND_MISSING_FILES);
-               } else {
-                       Log.log("All files moved properly.");
-               }
-
-               if (!executeInstallScript(pack, monitor, tempDir)) {
-                       Log.err("Fail to execute install script.");
-                       throw new IMFatalException(ErrorController.getMessage(ErrorCode.INSTALL_SCRIPT_FATAL_ERROR)
-                                       + " (" + pack + " package)");
-               }
-
-               if (!moveRemoveScript(tempDir, pack)) {
-                       return false;
-               }
-               
-//             if (!moveInstallScript(tempDir, pack)) {
-//                     return false;
-//             }
-               
-               PathUtil.remove(tempDir);
-               return true;
-       }
-       
-       private boolean moveRemoveScript(String tempDir, Package pack) {
-               // move removeScript file to special Directory
-               File removeScriptFrom = new File(tempDir + File.separator
-                               + pack.getRemoveScript());
-
-               if ((pack.getRemoveScript() != null)
-                               && !(pack.getRemoveScript().equals(""))
-                               && (removeScriptFrom.exists())) {
-                       File removeScriptTo = new File(getRemoveScriptLocalPath(pack));
-                       if (!createRemoveScriptDir(removeScriptTo)) {
-                               Log.err("Cannot create remove script directory in Info directory => "
-                                               + pack.getPackageName());
-                               return false;
-                       } else {
-                               if (removeScriptTo.exists()) {
-                                       if (!removeScriptTo.delete()) {
-                                               Log.err("Fail to delete file ==> " + removeScriptTo);
-                                       }
-                               }
-                               if (!PathUtil.moveFile(removeScriptFrom, removeScriptTo)) {
-                                       Log.err("Cannot move removeScript to targetDir => "
-                                                       + pack.getPackageName());
-                                       return false;
-                               }
-                       }
-               }
-               return true;
-       }
-       
-//     private boolean moveInstallScript(String tempDir, Package pack) {
-//             // move removeScript file to special Directory
-//             File installScriptFrom = new File(tempDir + File.separator
-//                             + pack.getInstallScript());
-//
-//             if ((pack.getInstallScript() != null)
-//                             && !(pack.getInstallScript().equals(""))
-//                             && (installScriptFrom.exists())) {
-//                     File installScriptTo = new File(getInstallScriptLocalPath(pack));
-//                     if (!createInstallScriptDir(installScriptTo)) {
-//                             Log.err("Cannot create install script directory in Info directory => "
-//                                             + pack.getPackageName());
-//                             return false;
-//                     } else {
-//                             if (installScriptTo.exists()) {
-//                                     if (!installScriptTo.delete()) {
-//                                             Log.err("Fail to delete file ==> " + installScriptTo);
-//                                     }
-//                             }
-//                             if (!PathUtil.moveFile(installScriptFrom, installScriptTo)) {
-//                                     Log.err("Cannot move install Script to targetDir => "
-//                                                     + pack.getPackageName());
-//                                     return false;
-//                             }
-//                     }
-//             }
-//             return true;
-//     }
-
-       /**
-        * @param pack
-        * @return list of files which are not moved normally
-        */
-       private List<File> findMissingFiles(Package pack) {
-               LinkedList<File> missingFiles = new LinkedList<File>();
-               File listFile = new File(getInstalledFileListPath(pack));
-               InputStream is = null;
-               BufferedReader in = null;
-               try {
-                       is = new FileInputStream(listFile);
-                       in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
-                       String line;
-                       while ((line = in.readLine()) != null) {
-                               File tmp = new File(PathUtil.getFromInstalledPath(line));
-                               if (!tmp.exists()) {
-                                       if (Platform.isWindows()) {
-                                               missingFiles.add(tmp);
-                                       } else if (Platform.isLinux() || Platform.isMacOS()) {
-                                               // check if it is broken link
-                                               try {
-                                                       int exitCode = ShellUtil.execute("ls " + tmp, null);
-                                                       if (exitCode == 0) {
-                                                               Log.log("broken link " + tmp
-                                                                               + " but no problem");
-                                                       } else {
-                                                               Log.err(tmp + " not exist.");
-                                                               missingFiles.add(tmp);
-                                                       }
-                                               } catch (IMShellCommandFail e) {
-                                                       Log.err("Failed to check file exists");
-                                                       Log.ExceptionLog(e);
-                                               }
-                                       } else {
-                                               throw new IMFatalException(
-                                                               ErrorCode.UNSUPPORTED_PLATFORM);
-                                       }
-                               }
-                       }
-               } catch (IOException e) {
-                       Log.err("Installer.findMissingFiles() Cannot check file list: "
-                                       + listFile.getAbsolutePath());
-                       throw new IMFatalException(
-                                       ErrorCode.CANNOT_CHECK_INSTLLED_FILE_LIST);
-               } finally {
-                       if (in != null) {
-                               try {
-                                       in.close();
-                               } catch (IOException e) {
-                                       Log.ExceptionLog(e);
-                               }
-                       }
-                       
-                       if (is != null) {
-                               try {
-                                       is.close();
-                               } catch (IOException e) {
-                                       Log.ExceptionLog(e);
-                               }
-                       }
-               }
-               return missingFiles;
-       }
-
-       /**
-        * Set script running process' environment variables.
-        * 
-        * @return Environment variables map
-        */
-       private Map<String, String> setEnvironmentVariable() {
-               HashMap<String, String> env = new HashMap<String, String>();
-
-               env.put("INSTALLED_PATH", Registry.getInstalledPath());
-               env.put("SDK_DATA_PATH", Registry.sdkDataPath);
-               env.put("USER_DATA_PATH", Registry.sdkDataPath);
-               env.put("MAKESHORTCUT_PATH", InstallManager.getInstance().getMakeShortCutPath());
-               env.put("REMOVE_SHORTCUT", InstallManager.getInstance().getRemoveShortCutPath());
-               env.put("TSUDO", InstallManager.getInstance().getTSudoPath());
-               
-               if (Options.doInstallNoUI || Options.doRemoveNoUI){
-                       env.put("INSTALLMANAGER_UI", "CLI");
-               } else {
-                       env.put("INSTALLMANAGER_UI", "GUI");
-               }
-               
-               if (Options.interactive) {
-                       env.put("INTERACTIVE", "true");
-               } else {
-                       env.put("INTERACTIVE", "false");
-                       env.put("SUPASS", Options.suPass);
-               }
-               
-               return env;
-       }
-
-       private long unZipPackage(Package pkg, String tempDir,
-                       IIMProgressMonitor monitor) {
-               String filePath = PathUtil.get(Config.getInstance().getDownloadPkgPath(), pkg.getFileName());
-
-               File pkgFile = new File(filePath);
-               if (!pkgFile.exists()) {
-                       Log.err(filePath + " doesn't exist");
-                       throw new IMFatalException(ErrorCode.CANNOT_FIND_FILE_IN_LOCAL);
-               }
-
-               SDKPackageFormat format = SDKPackageFormat.createSDKPackageFormat();
-
-               // Each packages are saved installed list to file
-               String installedFileListPath = getInstalledFileListPath(pkg);
-
-               format.setFileOutput(installedFileListPath);
-
-               return format.unZip(filePath, tempDir, monitor);
-       }
-
-       private String getRemoveScriptLocalPath(Package pkg) {
-               return PathUtil.get(
-                               PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),
-                               pkg.getPackageName(), pkg.getRemoveScript());
-       }
-
-       private String getInstalledFileListPath(Package pkg) {
-               return PathUtil.get(
-                               PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),
-                               pkg.getPackageName(), (pkg.getPackageName() + ".list"));
-       }
-
-       private boolean moveToTargetDirectoryFromTempDirectory(String tempDir,
-                       String targetDir) {
-               Log.log("Move temp to target");
-               File fromFile = new File(tempDir + File.separator
-                               + Config.DATA_DIRECTORY);
-               if (!fromFile.exists()) {
-                       Log.err("Data directory is not exist in package.");
-                       return true;
-               }
-               File toFile = new File(targetDir);
-
-               File[] fromList = fromFile.listFiles();
-
-               if (fromList == null) {
-                       return false;
-               }
-
-               for (int i = 0; i < fromList.length; i++) {
-                       boolean ret = false;
-                       if (Platform.isLinux()) {
-                               ret = PathUtil.copyHardLink(fromList[i], toFile);
-                       } else if (Platform.isWindows()) {
-                               ret = PathUtil.move(fromList[i],
-                                               new File(toFile, fromList[i].getName()));
-                       } else if (Platform.isMacOS()) {
-                               ret = PathUtil.copyHardLink(fromList[i], toFile);
-                       } else {
-                               throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
-                       }
-                       if (!ret) {
-                               return false;
-                       }
-               }
-               return true;
-       }
-
-       /**
-        * Uninstalls the given package
-        * 
-        * @param pkg
-        *            package to be uninstalled
-        * @param monitor
-        * @return true if success. false if fatal error. delete failure is checked
-        *         and sets error status in ErrorController but still returns true.
-        *         if file to be deleted doesn't exist, it's not considered error.
-        */
-       public boolean uninstall(Package pkg, IIMProgressMonitor monitor) {
-               Log.log("Installer uninstall start");
-               int resultRemoveScript = executeRemoveScript(pkg, monitor);
-
-               if (resultRemoveScript == 0) {
-                       Log.log("Execute remove script success.");
-               } else if (resultRemoveScript == 1) {
-                       Log.err("Execute remove script fail.");
-               } else if (resultRemoveScript == 2) {
-                       Log.log("This package does not need a remove script.");
-               }
-
-               File installedFileList = new File(getInstalledFileListPath(pkg));
-
-               if (!installedFileList.exists()) {
-                       ErrorController.setError(ErrorCode.CONFIG_CANNOT_FIND_INSTALLED_FILE_LIST);
-                       return false;
-               }
-
-               BufferedReader reader = null;
-               try {
-                       reader = new BufferedReader(new FileReader(installedFileList));
-
-                       String line = null;
-                       Stack<File> dirStack = new Stack<File>();
-                       while ((line = reader.readLine()) != null) {
-                               File deleteFile = new File(PathUtil.getFromInstalledPath(line));
-
-                               if (deleteFile.isDirectory()) {
-                                       File[] listFiles = deleteFile.listFiles();
-
-                                       if (listFiles == null || listFiles.length <= 0) {
-                                               deleteIfExists(deleteFile);
-                                       } else {
-                                               dirStack.push(deleteFile);
-                                       }
-                               } else {
-                                       deleteIfExists(deleteFile);
-                               }
-                       }
-
-                       while (!dirStack.isEmpty()) {
-                               File deleteDir = dirStack.pop();
-                               File[] listFiles = deleteDir.listFiles();
-
-                               if (listFiles == null || listFiles.length <= 0) {
-                                       deleteIfExists(deleteDir);
-                               }
-                       }
-
-               } catch (FileNotFoundException e) {
-                       Log.err("File not found => " + installedFileList.getAbsolutePath());
-                       return false;
-               } catch (IOException e) {
-                       Log.err("IO Exception => " + installedFileList.getAbsolutePath());
-                       return false;
-               } catch (Throwable e) {
-                       Log.ExceptionLog(e);
-                       return false;
-               } finally {
-                       try {
-                               if (reader != null) {
-                                       reader.close();
-                                       deleteIfExists(installedFileList);
-                               }
-                       } catch (IOException ioe) {
-                               Log.err("Close fileoutput fail.");
-                       }
-               }
-
-               return true;
-       }
-
-       /**
-        * Delete the <code>file</code>
-        * 
-        * @param file
-        */
-       private void deleteIfExists(File file) {
-               if (!file.delete()) {
-                       Log.err("Delete fail -> " + file.getAbsolutePath());
-               }
-       }
-
-       private boolean checkUnzipSize(Package pack, long size) {
-               // TODO : impl. not supported
-               return true;
-       }
-
-       private boolean createRemoveScriptDir(File removeScript) {
-               File parentDir = removeScript.getParentFile();
-
-               if (!parentDir.exists()) {
-                       return parentDir.mkdirs();
-               } else {
-                       return true;
-               }
-       }
-       
-       private boolean executeInstallScript(Package pack,
-                       IIMProgressMonitor monitor, String tempDir) {
-               if (pack.getInstallScript() != null
-                               && !pack.getInstallScript().equals("")) {
-                       String command = PathUtil.get(tempDir, pack.getInstallScript());
-                       File scriptFile = new File(command);
-
-                       if (scriptFile.exists()) {
-                               Log.log("Execute install script");
-
-                               if (monitor != null) {
-                                       monitor.workedSubTitle(scriptFile.getName());
-                               }
-                               try {
-                                       return executeScript(scriptFile);
-                               } catch (IMShellCommandFail e) {
-                                       Log.ExceptionLog(e);
-                                       throw new IMFatalException(ErrorController.getMessage(ErrorCode.INSTALL_SCRIPT_FATAL_ERROR)
-                                                       + " (" + pack + " package)");
-                               }
-                       } else {
-                               Log.log(pack.getPackageName() + " does not have install script");
-                       }
-               }
-               return true;
-       }
-
-       private int executeRemoveScript(Package pkg, IIMProgressMonitor monitor) {
-               Log.log("executeRemoveScript => " + pkg.getRemoveScript());
-
-               // execute remove script
-               String script = PathUtil.get(getRemoveScriptLocalPath(pkg));
-               File scriptFile = new File(script);
-
-               if (scriptFile.exists()) {
-
-                       if (monitor != null) {
-                               monitor.workedSubTitle(scriptFile.getName());
-                       }
-
-                       try {
-                               if (executeScript(scriptFile)) {
-                                       return 0; // succeed to execute remove script.
-                               } else {
-                                       return 1; // fail to execute remove script.
-                               }
-                       } catch (IMShellCommandFail e) {
-                               Log.ExceptionLog(e);
-                               throw new IMFatalException(ErrorController.getMessage(ErrorCode.REMOVE_SCRIPT_FATAL_ERROR)
-                                               + " (" + pkg + " package)");
-                       }
-               }
-               return 2; // package does not need remove script.
-       }
-
-       /**
-        * Executes the file with default environment variables
-        * 
-        * @param scriptFile
-        * @return <code>true</code> if success
-        * @throws IMShellCommandFail
-        */
-       public boolean executeScript(File scriptFile) throws IMShellCommandFail {
-               scriptFile.setExecutable(true);
-               Map<String, String> env = setEnvironmentVariable();
-
-               String command = ShellUtil.addInterpreter(scriptFile.getAbsolutePath());
-
-               String current = PathUtil.getCurrentDir();
-               Log.log("Current working directory. => " + current);
-               int exitCode = ShellUtil.execute(command, env, new File(current),
-                               new LoggerShellParser());
-
-               // check exit code
-               if (exitCode == 0) {
-                       return true;
-               } else if (exitCode == 1 || exitCode == 2) {
-                       Log.err("Exit code => " + Integer.toString(exitCode));
-                       return false;
-               } else if (exitCode == 99) {
-                       ErrorController.setInfoCode(InfoCode.RESTART_THE_COMPUTER);
-                       Log.log("Set restart message.");
-                       return true;
-               } else {
-                       Log.err("Installer.executeScript() install script error => "
-                                       + scriptFile.getAbsolutePath());
-                       Log.err("Exit code => " + Integer.toString(exitCode));
-                       throw new IMFatalException(ErrorController.getMessage(ErrorCode.SCRIPT_FATAL_ERROR)
-                                       + " (" + scriptFile.getParentFile().getName() + " package)");
-               }
-       }
-}
+/*\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.core;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
+import java.io.FileReader;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.InputStreamReader;\r
+import java.util.HashMap;\r
+import java.util.LinkedList;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Stack;\r
+\r
+import org.tizen.installmanager.lib.ErrorController;\r
+import org.tizen.installmanager.lib.ErrorController.InfoCode;\r
+import org.tizen.installmanager.lib.IIMProgressMonitor;\r
+import org.tizen.installmanager.lib.Log;\r
+import org.tizen.installmanager.lib.LoggerShellParser;\r
+import org.tizen.installmanager.lib.Platform;\r
+import org.tizen.installmanager.lib.Registry;\r
+import org.tizen.installmanager.lib.SDKPackageFormat;\r
+import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
+import org.tizen.installmanager.pkg.model.Package;\r
+import org.tizen.installmanager.util.IMShellCommandFail;\r
+import org.tizen.installmanager.util.PathUtil;\r
+import org.tizen.installmanager.util.ShellUtil;\r
+\r
+/**\r
+ * This class manages lowlevel install/uninstall operations\r
+ * \r
+ * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+ */\r
+public class Installer {\r
+       /**\r
+        * Install a package to target directory.\r
+        * \r
+        * @param pack\r
+        *            Package to be installed.\r
+        * @param targetDir\r
+        *            Target directory to install.\r
+        * @param monitor\r
+        *            If you want to express in UI, implement IIMProgressMonitor and\r
+        *            set this parametor. if not, set <code>null</code>.\r
+        * @return <code>true</code>, if installation is success.\r
+        */\r
+       public boolean install(Package pack, String targetDir,\r
+                       IIMProgressMonitor monitor) {\r
+               Log.log("**** installer install start => " + pack + ", target => " + targetDir);\r
+\r
+               if (monitor != null) {\r
+                       monitor.workedInstallProgress(pack.getPackageName(), 1);\r
+               }\r
+               \r
+               // unzip in temp dir\r
+               String tempDir = PathUtil.get(targetDir, Config.TEMP_DIRECTORY);\r
+\r
+               // Clear temp dir before unzip package.\r
+               File tmpDir = new File(tempDir);\r
+               \r
+               if (tmpDir.exists()) {\r
+                       if (!tmpDir.delete()) {\r
+                               Log.err("Fail to delete " + tmpDir);\r
+                       }\r
+               }\r
+\r
+               long unZipSize = unZipPackage(pack, tempDir, monitor);\r
+\r
+               if (unZipSize <= 0) {\r
+                       Log.err("Unzip failed. => " + pack);\r
+                       PathUtil.remove(tempDir);\r
+                       throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);\r
+               }\r
+               if (!checkUnzipSize(pack, unZipSize)) {\r
+                       Log.err("Unzip size error. => " + pack);\r
+                       PathUtil.remove(tempDir);\r
+                       throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);\r
+               }\r
+\r
+               if (!moveToTargetDirectoryFromTempDirectory(tempDir, targetDir)) {\r
+                       PathUtil.remove(tempDir);\r
+                       Log.err("Moving temp to target failed. Remove temp and cancel installing.");\r
+                       throw new IMFatalException(\r
+                                       ErrorCode.CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY);\r
+               }\r
+\r
+               List<File> missingFiles = findMissingFiles(pack);\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
+                       PathUtil.remove(tempDir);\r
+                       throw new IMFatalException(ErrorController.getMessage(ErrorCode.INSTALL_SCRIPT_FATAL_ERROR)\r
+                                       + " (" + pack + " package)");\r
+               }\r
+\r
+               if (!moveRemoveScript(tempDir, pack)) {\r
+                       PathUtil.remove(tempDir);\r
+                       return false;\r
+               }\r
+               \r
+               PathUtil.remove(tempDir);\r
+               return true;\r
+       }\r
+       \r
+       private boolean moveRemoveScript(String tempDir, Package pack) {\r
+               // move removeScript file to special Directory\r
+               File removeScriptFrom = new File(tempDir + File.separator\r
+                               + pack.getRemoveScript());\r
+\r
+               if ((pack.getRemoveScript() != null)\r
+                               && !(pack.getRemoveScript().equals(""))\r
+                               && (removeScriptFrom.exists())) {\r
+                       File removeScriptTo = new File(getRemoveScriptLocalPath(pack));\r
+                       if (!createRemoveScriptDir(removeScriptTo)) {\r
+                               Log.err("Cannot create remove script directory in Info directory => "\r
+                                               + pack.getPackageName());\r
+                               return false;\r
+                       } else {\r
+                               if (removeScriptTo.exists()) {\r
+                                       if (!removeScriptTo.delete()) {\r
+                                               Log.err("Fail to delete file ==> " + removeScriptTo);\r
+                                       }\r
+                               }\r
+                               if (!PathUtil.moveFile(removeScriptFrom, removeScriptTo)) {\r
+                                       Log.err("Cannot move removeScript to targetDir => "\r
+                                                       + pack.getPackageName());\r
+                                       return false;\r
+                               }\r
+                       }\r
+               }\r
+               return true;\r
+       }\r
+       \r
+//     private boolean moveInstallScript(String tempDir, Package pack) {\r
+//             // move removeScript file to special Directory\r
+//             File installScriptFrom = new File(tempDir + File.separator\r
+//                             + pack.getInstallScript());\r
+//\r
+//             if ((pack.getInstallScript() != null)\r
+//                             && !(pack.getInstallScript().equals(""))\r
+//                             && (installScriptFrom.exists())) {\r
+//                     File installScriptTo = new File(getInstallScriptLocalPath(pack));\r
+//                     if (!createInstallScriptDir(installScriptTo)) {\r
+//                             Log.err("Cannot create install script directory in Info directory => "\r
+//                                             + pack.getPackageName());\r
+//                             return false;\r
+//                     } else {\r
+//                             if (installScriptTo.exists()) {\r
+//                                     if (!installScriptTo.delete()) {\r
+//                                             Log.err("Fail to delete file ==> " + installScriptTo);\r
+//                                     }\r
+//                             }\r
+//                             if (!PathUtil.moveFile(installScriptFrom, installScriptTo)) {\r
+//                                     Log.err("Cannot move install Script to targetDir => "\r
+//                                                     + pack.getPackageName());\r
+//                                     return false;\r
+//                             }\r
+//                     }\r
+//             }\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) {\r
+               LinkedList<File> missingFiles = new LinkedList<File>();\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
+        * \r
+        * @return Environment variables map\r
+        */\r
+       private Map<String, String> setEnvironmentVariable() {\r
+               HashMap<String, String> env = new HashMap<String, String>();\r
+\r
+               env.put("INSTALLED_PATH", Registry.getInstalledPath());\r
+               env.put("SDK_DATA_PATH", Registry.sdkDataPath);\r
+               env.put("USER_DATA_PATH", Registry.sdkDataPath);\r
+               env.put("MAKESHORTCUT_PATH", InstallManager.getInstance().getMakeShortCutPath());\r
+               env.put("REMOVE_SHORTCUT", InstallManager.getInstance().getRemoveShortCutPath());\r
+               env.put("TSUDO", InstallManager.getInstance().getTSudoPath());\r
+               \r
+               if (Options.doInstallNoUI || Options.doRemoveNoUI){\r
+                       env.put("INSTALLMANAGER_UI", "CLI");\r
+               } else {\r
+                       env.put("INSTALLMANAGER_UI", "GUI");\r
+               }\r
+               \r
+               if (Options.interactive) {\r
+                       env.put("INTERACTIVE", "true");\r
+               } else {\r
+                       env.put("INTERACTIVE", "false");\r
+                       env.put("SUPASS", Options.suPass);\r
+               }\r
+               \r
+               return env;\r
+       }\r
+\r
+       private long unZipPackage(Package pkg, String tempDir,\r
+                       IIMProgressMonitor monitor) {\r
+               String filePath = PathUtil.get(Config.getInstance().getDownloadPkgPath(), pkg.getFileName());\r
+\r
+               File pkgFile = new File(filePath);\r
+               if (!pkgFile.exists()) {\r
+                       Log.err(filePath + " doesn't exist");\r
+                       throw new IMFatalException(ErrorCode.CANNOT_FIND_FILE_IN_LOCAL);\r
+               }\r
+\r
+               SDKPackageFormat format = SDKPackageFormat.createSDKPackageFormat();\r
+\r
+               // Each packages are saved installed list to file\r
+               String installedFileListPath = getInstalledFileListPath(pkg);\r
+\r
+               format.setFileOutput(installedFileListPath);\r
+\r
+               return format.unZip(filePath, tempDir, monitor);\r
+       }\r
+\r
+       private String getRemoveScriptLocalPath(Package pkg) {\r
+               return PathUtil.get(\r
+                               PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),\r
+                               pkg.getPackageName(), pkg.getRemoveScript());\r
+       }\r
+\r
+       private String getInstalledFileListPath(Package pkg) {\r
+               return PathUtil.get(\r
+                               PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),\r
+                               pkg.getPackageName(), (pkg.getPackageName() + ".list"));\r
+       }\r
+\r
+       private boolean moveToTargetDirectoryFromTempDirectory(String tempDir,\r
+                       String targetDir) {\r
+               Log.log("Move temp to target");\r
+               File fromFile = new File(tempDir + File.separator\r
+                               + Config.DATA_DIRECTORY);\r
+               if (!fromFile.exists()) {\r
+                       Log.err("Data directory is not exist in package.");\r
+                       return true;\r
+               }\r
+               File toFile = new File(targetDir);\r
+\r
+               File[] fromList = fromFile.listFiles();\r
+\r
+               if (fromList == null) {\r
+                       return false;\r
+               }\r
+\r
+               for (int i = 0; i < fromList.length; i++) {\r
+                       boolean ret = false;\r
+                       if (Platform.isLinux()) {\r
+                               ret = PathUtil.copyHardLink(fromList[i], toFile);\r
+                       } else if (Platform.isWindows()) {\r
+                               ret = PathUtil.move(fromList[i],\r
+                                               new File(toFile, fromList[i].getName()));\r
+                       } else if (Platform.isMacOS()) {\r
+                               ret = PathUtil.copyHardLink(fromList[i], toFile);\r
+                       } else {\r
+                               throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
+                       }\r
+                       if (!ret) {\r
+                               return false;\r
+                       }\r
+               }\r
+               return true;\r
+       }\r
+\r
+       /**\r
+        * Uninstalls the given package\r
+        * \r
+        * @param pkg\r
+        *            package to be uninstalled\r
+        * @param monitor\r
+        * @return true if success. false if fatal error. delete failure is checked\r
+        *         and sets error status in ErrorController but still returns true.\r
+        *         if file to be deleted doesn't exist, it's not considered error.\r
+        */\r
+       public boolean uninstall(Package pkg, IIMProgressMonitor monitor) {\r
+               Log.log("Installer uninstall start");\r
+               \r
+               if (monitor != null) {\r
+                       monitor.workedInstallProgress("Remove the " + pkg.getPackageName(), 1);\r
+               }\r
+               \r
+               int resultRemoveScript = executeRemoveScript(pkg, monitor);\r
+\r
+               if (resultRemoveScript == 0) {\r
+                       Log.log("Execute remove script success.");\r
+               } else if (resultRemoveScript == 1) {\r
+                       Log.err("Execute remove script fail.");\r
+               } else if (resultRemoveScript == 2) {\r
+                       Log.log("This package does not need a remove script.");\r
+               }\r
+\r
+               File installedFileList = new File(getInstalledFileListPath(pkg));\r
+\r
+               if (!installedFileList.exists()) {\r
+                       ErrorController.setError(ErrorCode.CONFIG_CANNOT_FIND_INSTALLED_FILE_LIST);\r
+                       return false;\r
+               }\r
+\r
+               BufferedReader reader = null;\r
+               try {\r
+                       reader = new BufferedReader(new FileReader(installedFileList));\r
+\r
+                       String line = null;\r
+                       Stack<File> dirStack = new Stack<File>();\r
+                       while ((line = reader.readLine()) != null) {\r
+                               File deleteFile = new File(PathUtil.getFromInstalledPath(line));\r
+\r
+                               if (deleteFile.isDirectory()) {\r
+                                       File[] listFiles = deleteFile.listFiles();\r
+\r
+                                       if (listFiles == null || listFiles.length <= 0) {\r
+                                               deleteIfExists(deleteFile);\r
+                                       } else {\r
+                                               dirStack.push(deleteFile);\r
+                                       }\r
+                               } else {\r
+                                       deleteIfExists(deleteFile);\r
+                               }\r
+                       }\r
+\r
+                       while (!dirStack.isEmpty()) {\r
+                               File deleteDir = dirStack.pop();\r
+                               File[] listFiles = deleteDir.listFiles();\r
+\r
+                               if (listFiles == null || listFiles.length <= 0) {\r
+                                       deleteIfExists(deleteDir);\r
+                               }\r
+                       }\r
+\r
+               } catch (FileNotFoundException e) {\r
+                       Log.err("File not found => " + installedFileList.getAbsolutePath());\r
+                       return false;\r
+               } catch (IOException e) {\r
+                       Log.err("IO Exception => " + installedFileList.getAbsolutePath());\r
+                       return false;\r
+               } catch (Throwable e) {\r
+                       Log.ExceptionLog(e);\r
+                       return false;\r
+               } finally {\r
+                       try {\r
+                               if (reader != null) {\r
+                                       reader.close();\r
+                                       deleteIfExists(installedFileList);\r
+                               }\r
+                       } catch (IOException ioe) {\r
+                               Log.err("Close fileoutput fail.");\r
+                       }\r
+               }\r
+\r
+               return true;\r
+       }\r
+\r
+       /**\r
+        * Delete the <code>file</code>\r
+        * \r
+        * @param file\r
+        */\r
+       private void deleteIfExists(File file) {\r
+               if (!file.delete()) {\r
+                       Log.err("Delete fail -> " + file.getAbsolutePath());\r
+               }\r
+       }\r
+\r
+       private boolean checkUnzipSize(Package pack, long size) {\r
+               // TODO : impl. not supported\r
+               return true;\r
+       }\r
+\r
+       private boolean createRemoveScriptDir(File removeScript) {\r
+               File parentDir = removeScript.getParentFile();\r
+\r
+               if (!parentDir.exists()) {\r
+                       return parentDir.mkdirs();\r
+               } else {\r
+                       return true;\r
+               }\r
+       }\r
+       \r
+       private boolean executeInstallScript(Package pack,\r
+                       IIMProgressMonitor monitor, String tempDir) {\r
+               if (pack.getInstallScript() != null\r
+                               && !pack.getInstallScript().equals("")) {\r
+                       String command = PathUtil.get(tempDir, pack.getInstallScript());\r
+                       File scriptFile = new File(command);\r
+\r
+                       if (scriptFile.exists()) {\r
+                               Log.log("Execute " + pack.getPackageName() + " install script");\r
+\r
+                               if (monitor != null) {\r
+                                       monitor.workedInstallProgress("Execute the " + pack.getPackageName() + " install script", 0);\r
+                               }\r
+                               try {\r
+                                       return executeScript(scriptFile);\r
+                               } catch (IMShellCommandFail e) {\r
+                                       Log.ExceptionLog(e);\r
+                                       throw new IMFatalException(ErrorController.getMessage(ErrorCode.INSTALL_SCRIPT_FATAL_ERROR)\r
+                                                       + " (" + pack + " package)");\r
+                               }\r
+                       } else {\r
+                               Log.log(pack.getPackageName() + " does not have install script");\r
+                       }\r
+               }\r
+               return true;\r
+       }\r
+\r
+       private int executeRemoveScript(Package pkg, IIMProgressMonitor monitor) {\r
+               Log.log("executeRemoveScript => " + pkg.getRemoveScript());\r
+\r
+               // execute remove script\r
+               String script = PathUtil.get(getRemoveScriptLocalPath(pkg));\r
+               File scriptFile = new File(script);\r
+\r
+               if (scriptFile.exists()) {\r
+\r
+                       if (monitor != null) {\r
+                               monitor.workedInstallProgress("Excute the " + pkg.getPackageName() + " remove script", 0);\r
+                       }\r
+\r
+                       try {\r
+                               if (executeScript(scriptFile)) {\r
+                                       return 0; // succeed to execute remove script.\r
+                               } else {\r
+                                       return 1; // fail to execute remove script.\r
+                               }\r
+                       } catch (IMShellCommandFail e) {\r
+                               Log.ExceptionLog(e);\r
+                               throw new IMFatalException(ErrorController.getMessage(ErrorCode.REMOVE_SCRIPT_FATAL_ERROR)\r
+                                               + " (" + pkg + " package)");\r
+                       }\r
+               }\r
+               return 2; // package does not need remove script.\r
+       }\r
+\r
+       /**\r
+        * Executes the file with default environment variables\r
+        * \r
+        * @param scriptFile\r
+        * @return <code>true</code> if success\r
+        * @throws IMShellCommandFail\r
+        */\r
+       public boolean executeScript(File scriptFile) throws IMShellCommandFail {\r
+               scriptFile.setExecutable(true);\r
+               Map<String, String> env = setEnvironmentVariable();\r
+\r
+               String command = ShellUtil.addInterpreter(scriptFile.getAbsolutePath());\r
+\r
+               String current = PathUtil.getCurrentDir();\r
+               Log.log("Current working directory. => " + current);\r
+               int exitCode = ShellUtil.execute(command, env, new File(current),\r
+                               new LoggerShellParser());\r
+\r
+               // check exit code\r
+               if (exitCode == 0) {\r
+                       return true;\r
+               } else if (exitCode == 1 || exitCode == 2) {\r
+                       Log.err("Exit code => " + Integer.toString(exitCode));\r
+                       return false;\r
+               } else if (exitCode == 99) {\r
+                       ErrorController.setInfoCode(InfoCode.RESTART_THE_COMPUTER);\r
+                       Log.log("Set restart message.");\r
+                       return true;\r
+               } else {\r
+                       Log.err("Installer.executeScript() install script error => "\r
+                                       + scriptFile.getAbsolutePath());\r
+                       Log.err("Exit code => " + Integer.toString(exitCode));\r
+                       throw new IMFatalException(ErrorController.getMessage(ErrorCode.SCRIPT_FATAL_ERROR)\r
+                                       + " (" + scriptFile.getParentFile().getName() + " package)");\r
+               }\r
+       }\r
+}\r
index b9d3bb1..82c2482 100644 (file)
-/*
-*  InstallManager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: 
-* Wooyoung Cho <wooyoung1.cho@samsung.com>
-* Shihyun Kim <shihyun.kim@samsung.com>
-* Taeyoung Son <taeyoung2.son@samsung.com>
-* Yongsung kim <yongsung1.kim@samsung.com>
-* 
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/ 
-
-package org.tizen.installmanager.core;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import org.tizen.installmanager.core.Config.ServerType;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.lib.Platform;
-import org.tizen.installmanager.lib.ErrorController.ErrorCode;
-
-/**
- * This class represents options from command line arguments.
- * @author Wooyoung Cho <wooyoung1.cho@samsung.com>
- *
- */
-public class Options {
-       /**
-        * Do sanity checks including file size and checksum 
-        */
-       public static boolean doPackageValidation = true;
-       
-       /**
-        * Do download package file.
-        */
-       public static boolean onlyDownload = false;
-       
-       /**
-        * Do resume downloading.
-        */
-       public static boolean doResumeDownloading = true;
-       
-       /**
-        * Use system proxy
-        */
-       public static boolean useAutoProxy = true;
-       
-       /**
-        * Do remove temporary installmanager that exist in /tmp/tizensdk
-        */
-       public static boolean doRemoveTempTizenSDK = true;
-       
-       /**
-        * Conf file provided by user
-        */
-       public static String userConfPath = null;
-       
-       /**
-        * update installmanager.
-        * If <code>doUpdateInstallManager</code> is false, do not update installmanager binary.
-        */
-       public static boolean doUpdateInstallManager = true;
-       /**
-        * Do replace repository. 
-        * If <code>doRepository</code> is true, change repository address to <code>repo</code> variable.  
-        */
-       public static boolean doReplaceRepository = false;
-       
-       /**
-        * Do remove packages after installation
-        */
-       public static boolean doRemovePackages = true;
-       
-       /**
-        * Do remove old sdk.
-        * If installer cannot update sdk, <code>doRemoveOldSDK</code> is true.
-        */
-       public static boolean doRemoveOldSDK = false;
-       /**
-        * Just check installer is available for update.
-        */
-       public static boolean checkPackageUpdate = false;
-       
-       /**
-        * Prints dependency graph of packages
-        */
-       public static boolean printDepGraph = false;
-       
-       /**
-        * start installmanager test
-        */     
-       public static boolean doTest = false;
-       
-       /**
-        * Use Snapshot file.
-        */
-       public static boolean snapshot = false;
-       
-       /**
-     * Do auto install or uninstall without GUI
-     */
-       public static boolean doInstallNoUI = false;
-       public static boolean doRemoveNoUI = false;
-       public static boolean doUpdateNoUI = false;
-       public static boolean doShowDistListNoUI = false;
-       public static boolean doShowPackageListNoUI = false;
-       public static boolean doShowSDKInstallStatus = false;
-       public static boolean doShowHelp = false;
-       
-       public static String repository = null;
-       public static String imageFilePath = null;
-       public static String snapshotPath = null;
-       public static ServerType serverType = null;
-       public static String distribution = null;
-       public static String targetDir = null;
-       public static String sdkDataPath = null;
-       
-       public static boolean isNetwork = true;
-       
-       public static List<String> packages = new ArrayList<String>();
-       public static List<String> skipPackages = new ArrayList<String>();
-       
-       public static boolean isAgreeLicense = false;
-       
-       /**
-        * Use only download for making SDK image.
-        */
-       public static String boundary = "public"; // all, public, partner
-       public static String platForm = null;
-       public static int platFormBit = 0;
-       
-       /**
-        * See all snapshots
-        */
-       public static boolean allSnapshots = false;
-       
-       /**
-        * Support Partner SDK
-        */
-       public static boolean partnerSdk = false;
-       public static String purposeOfInstalling = "public";
-       
-       /**
-        * Display InstallManager Version
-        */
-       public static boolean showVersion = false;
-       
-       /**
-        * User-provided proxy server
-        */
-       public static String proxy = null;
-       
-       /**
-        * Logging all system information
-        */
-       public static boolean propertyLogging = false;
-       
-       /**
-        * Non-interactive(continuous installation).
-        */
-       public static boolean interactive = true;
-       public static String suPass = ""; 
-       
-       public static String[] args;
-       
-       public static String executablePath = null;
-       
-       /**
-        * Parses command line arguments and sets corresponding options. 
-        * @param args command line arguments
-        */
-       public static void loadCmdArgs(String[] args) {
-               Options.args = args;
-               Iterator<String> iter = Arrays.asList(args).iterator();
-               
-               while (iter.hasNext()) {
-                       String arg = iter.next();
-                       Log.log(arg+" option is specified");
-
-                       if (arg.equals("-noPackageValidation")) {
-                               doPackageValidation = false;
-                       } else if (arg.equals("-path")) {
-                               if (iter.hasNext()) {
-                                       executablePath = iter.next();
-                                       Log.log("executable path : " + executablePath);
-                               }
-                       } else if (arg.equals(OptionConstant.OPTION_TEST)) {
-                               doTest = true;
-                       } else if (arg.equals("-install")) {
-                               if (iter.hasNext()) {
-                                       doInstallNoUI = true;
-                                       workCliOptions(args);
-                               } else {
-                                       Log.err("-install option must have some arguments.");
-                                       System.out.println("-install option must have some arguements" +
-                                                       " such as specific meta packages");
-                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);
-                               }
-
-                               if (!validateArgs()) {
-                                       Log.err("repository : " + repository + ", distribution : "
-                                                       + distribution + ", packages : " + packages);
-                                       System.out.println("-install option must have some arguements"
-                                                                       + " you can see usage using '-help'");
-                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);
-                               }
-                               break;
-                       } else if (arg.equals("-remove")) {
-                               if (iter.hasNext()) {
-                                       doRemoveNoUI = true;
-                                       workCliOptions(args);
-                               } else {
-                                       Log.err("-remove option must have some arguments.");
-                                       System.out.println("-remove option must have some arguements" +
-                                                       " such as specific meta packages or 'all'");
-                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);
-                               }
-                               break;
-                       } else if (arg.equalsIgnoreCase("-repoinfo")) {
-                               if (iter.hasNext()) {
-                                       doShowDistListNoUI = true;
-                                       serverType = ServerType.SNAPSHOT;
-                                       workCliOptions(args);
-                               } else {
-                                       Log.err("-info option must have some arguments.");
-                                       System.out.println("-remove option must have some arguements" +
-                                                       " such as repository address.");
-                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);
-                               }
-                               break;
-                       } else if (arg.equalsIgnoreCase("-packageinfo")) {
-                               if (iter.hasNext()) {
-                                       doShowPackageListNoUI = true;
-                                       serverType = ServerType.SNAPSHOT;
-                                       workCliOptions(args);
-                               } else {
-                                       Log.err("-packages option must have some arguments.");
-                                       System.out.println("-remove option must have some arguements" +
-                                                       " such as repository address and distribution.");
-                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);
-                               }
-                               break;
-                       } else if (arg.equalsIgnoreCase("-status")) {
-                               doShowSDKInstallStatus = true;
-                               break;
-                       } else if (arg.equalsIgnoreCase("-help")) {
-                               doShowHelp = true;
-                               break;
-                       } else if (arg.equals("-noRemovePackages")) {
-                               doRemovePackages = false;
-                       } else if (arg.equals("-skipUpdate")) {
-                               doUpdateInstallManager = false;
-                       } else if (arg.equals("-checkPackageUpdate")) {
-                               checkPackageUpdate = true;
-                       } else if (arg.equals("-printDepGraph")) {
-                               printDepGraph = true;
-                       } else if (arg.equals("-proxy")) {
-                               if(iter.hasNext()) {
-                                       proxy = iter.next();
-                                       Log.log("User-provided proxy: "+proxy);
-                               } else {
-                                       Log.err("-proxy requires proxy description");
-                                       throw new IMFatalException(ErrorCode.PROXY_NOT_PROVIDED);
-                               }
-                       } else if (arg.equals("-snapShot")) {
-                               if(iter.hasNext()) {
-                                       snapshot = true;
-                                       snapshotPath = iter.next();
-                                       Log.log("User-provided repository: " + repository);
-                               } else {
-                                       Log.err("-snapShot requires repository description");
-                                       throw new IMFatalException(ErrorCode.USESNAPSHOT_REPOSITORY_NOT_PROVIDED);
-                               }
-                       } else if (arg.equals("-allSnapshots")) {
-                               allSnapshots = true;
-                               Log.log("Using '-allSnapshots' option, all snapshots are displaying.");
-                       } else if (arg.equals("-onlyDownload")) {
-                               if(iter.hasNext()) {
-                                       onlyDownload = true;
-                                       boundary = iter.next();
-                                       platForm = iter.next().toLowerCase();
-                                       platFormBit = Integer.parseInt(iter.next());
-                                       Log.log("Only download boundary : "+ boundary);
-                               } else {
-                                       Log.err("-onlyDownload requires packageList description");
-                                       throw new IMFatalException(ErrorCode.REPOSITORY_NOT_PROVIDED);
-                               }
-                               onlyDownload = true;
-                       } else if (arg.equals("-noResumeDownloading")) {
-                               doResumeDownloading = false;
-                               Log.log("Using '-noResumeDownloading' option, do not resume downloading");
-                       } else if (arg.equals("-noUseAutoProxy")) {
-                               useAutoProxy = false;
-                               Log.log("Using '-noUseAutoProxy' option, do not use system proxy.");
-                       } else if (arg.equals("-version")) {
-                               showVersion = true;
-                               Log.log("Using '-version' option, display InstallManager version on console.");
-                       } else if (arg.equals("-noRemoveTempTizenSDK")) {
-                               doRemoveTempTizenSDK = false;
-                       } else if (arg.equals("-repository")) {
-                               if(iter.hasNext()) {
-                                       doReplaceRepository = true;
-                                       repository = iter.next();
-                                       Log.log("replace repository : "+repository);
-                               } else {
-                                       Log.err("-replaceRepository requires repository description");
-                                       throw new IMFatalException(ErrorCode.REPOSITORY_NOT_PROVIDED);
-                               }
-                       } else if (arg.equals(OptionConstant.OPTION_DISTRIBUTION)) {
-                               if(iter.hasNext()) {
-                                       distribution = iter.next();
-                                       Log.log("replace distribution : "+distribution);
-                               } else {
-                                       Log.err("-distribution requires distribution description");
-                                       throw new IMFatalException(OptionConstant.MSG_DISTRIBUTION_NOT_PROVIDED);
-                               }
-                       } else if (arg.equals("-removeOldSDK")) {
-                               doRemoveOldSDK = true;
-                       } else if (arg.equals("-property")) {
-                               propertyLogging = true;
-                       } else {
-                               Log.err("InstallManager do not support '" + arg + "' option");
-                               throw new IMFatalException(ErrorCode.WRONG_OPTION);
-                       }
-               }
-       }
-
-       /**
-        * Get options.
-        * @return
-        */
-       public static String getArgsStr() {
-               String argsStr = "";
-               for(String arg : args) {
-                       argsStr = argsStr + " " + arg;
-               }
-               return argsStr;
-       }
-       
-       private static boolean validateArgs() {
-               if (isNetwork) {
-                       if (Options.repository != null && Options.distribution != null && !Options.packages.isEmpty()) {
-                               return true;
-                       } else {
-                               return false;
-                       }
-               } else {
-                       if (Options.repository != null && !Options.packages.isEmpty()) {
-                               if (Platform.isWindows()) {
-                                       if (Options.repository.startsWith("file")) {
-                                               return true;
-                                       } else {
-                                               return false;
-                                       }
-                               } else {
-                                       return true;
-                               }
-                       } else if (Options.imageFilePath == null) {
-                               return false;
-                       } else {
-                               return true;
-                       }
-               }
-       }
-               
-       private static void workCliOptions(String[] args) {
-               ArrayList<String> argArray = new ArrayList<String>();
-
-               for (String t : args) {
-                       if (!t.equalsIgnoreCase("-install") && !t.equalsIgnoreCase("-remove")) {
-                               argArray.add(t);                                
-                       }
-               }
-               
-               Iterator<String> argIter = argArray.iterator();
-               while (argIter.hasNext()) {
-                       if (argIter.next().equalsIgnoreCase("-path")) {
-                               argIter.remove();
-                               argIter.next();
-                               argIter.remove();
-                       }
-               }
-               
-               // set repository
-               argIter = argArray.iterator();
-               while (argIter.hasNext()) {
-                       if (argIter.next().equalsIgnoreCase("-r")) {
-                               argIter.remove();
-                               repository = argIter.next();
-                               if (!repository.startsWith("http")) {
-                                       isNetwork = false;
-                                       serverType = ServerType.LOCAL;
-                                       exclusiveOptions("-d", argArray);
-                               } else {
-                                       serverType = ServerType.SNAPSHOT;
-                                       isNetwork = true;                                       
-                               }
-                               argIter.remove();
-                       }
-               }
-               
-               // set SDK image path
-               argIter = argArray.iterator();
-               while (argIter.hasNext()) {
-                       if (argIter.next().equalsIgnoreCase("-f")) {
-                               argIter.remove();
-                               imageFilePath = argIter.next();
-                               isNetwork = false;
-                               serverType = ServerType.LOCAL;
-                               argIter.remove();
-                               exclusiveOptions("-d", argArray);
-                       }
-               }
-               
-               // set target directory
-               argIter = argArray.iterator();
-               while (argIter.hasNext()) {
-                       if (argIter.next().equalsIgnoreCase("-l")) {
-                               argIter.remove();
-                               targetDir = argIter.next();
-                               argIter.remove();
-                       }
-               }
-               
-               // set license agreement
-               if (doInstallNoUI) {
-                       argIter = argArray.iterator();
-                       while (argIter.hasNext()) {
-                               if (argIter.next().equalsIgnoreCase("-accept_license")) {
-                                       argIter.remove();
-                                       isAgreeLicense = true;
-                               }
-                       }                       
-               }
-               
-               // set sdk data directory
-               argIter = argArray.iterator();
-               while (argIter.hasNext()) {
-                       if (argIter.next().equalsIgnoreCase("-w")) {
-                               argIter.remove();
-                               sdkDataPath = argIter.next();
-                               argIter.remove();
-                       }
-               }
-
-               // set distribution
-               argIter = argArray.iterator();
-               while (argIter.hasNext()) {
-                       if (argIter.next().equalsIgnoreCase("-d")) {
-                               argIter.remove();
-                               distribution = argIter.next();
-                               argIter.remove();
-                       }
-               }
-
-               // set packages
-               argIter = argArray.iterator();
-               while (argIter.hasNext()) {
-                       if (argIter.next().equalsIgnoreCase("-p")) {
-                               argIter.remove();
-                               while (argIter.hasNext()) {
-                                       String pkg = argIter.next();
-                                       if (!pkg.startsWith("-")) {
-                                               packages.add(pkg);
-                                               argIter.remove();
-                                       } else {
-                                               break;                                          
-                                       }
-                               }
-                       }
-               }
-               
-               // set skip packages
-               argIter = argArray.iterator();
-               while (argIter.hasNext()) {
-                       if (argIter.next().equalsIgnoreCase("-skip")) {
-                               argIter.remove();
-                               while (argIter.hasNext()) {
-                                       String pkg = argIter.next();
-                                       if (!pkg.startsWith("-")) {
-                                               skipPackages.add(pkg);
-                                               argIter.remove();
-                                       } else {
-                                               break;                                          
-                                       }
-                               }
-                       }
-               }
-               
-               // set proxy
-               argIter = argArray.iterator();
-               while (argIter.hasNext()) {
-                       if (argIter.next().equalsIgnoreCase("-x")) {
-                               argIter.remove();
-                               Options.proxy = argIter.next();
-                               Log.log("Use proxy setting => " + Options.proxy);
-                               argIter.remove();
-                       }
-               }
-               
-               // set test
-               argIter = argArray.iterator();
-               while (argIter.hasNext()) {
-                       if (argIter.next().equalsIgnoreCase("-test")) {
-                               argIter.remove();
-                               Options.doTest = true;
-                               Log.log("Set to test working performance.");
-                       }
-               }
-               
-               argIter = argArray.iterator();
-               while (argIter.hasNext()) {
-                       if (argIter.next().equalsIgnoreCase("-ni")) {
-                               argIter.remove();
-                               if (argIter.hasNext()) { // -ni option must have -passwd option.
-                                       if (Platform.isLinux()) {
-                                               argIter = argArray.iterator();
-                                               while (argIter.hasNext()) {
-                                                       if (argIter.next().equalsIgnoreCase("-passwd")) {
-                                                               argIter.remove();
-                                                               if (argIter.hasNext()) {
-                                                                       suPass = argIter.next();
-                                                                       interactive = false;
-                                                                       argIter.remove();
-                                                               } else { // -passwd option must have value.
-                                                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);
-                                                               }
-                                                       }
-                                               }
-                                               if (suPass == "") {
-                                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);
-                                               }
-                                       } else if (Platform.isWindows()) {
-                                               interactive = true;
-                                       } else if (Platform.isMacOS()) {
-                                               interactive = true;
-                                       } else {
-                                               throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
-                                       }
-                               } else {
-                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);
-                               }
-                       }
-               }
-       }
-       
-       private static void exclusiveOptions(String option, ArrayList<String> argArray) {
-               Iterator<String> argIter = argArray.iterator();
-               while (argIter.hasNext()) {
-                       if (argIter.next().equalsIgnoreCase(option)) {
-                               Log.err("[" + option + "] cannot be used.");
-                               System.out.println("[" + option + "] cannot be used with some options.");
-                               throw new IMFatalException("[" + option + "] cannot be used with some options.");
-                       }
-               }
-       }
-}
+/*\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.core;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
+import org.tizen.installmanager.core.Config.ServerType;\r
+import org.tizen.installmanager.lib.Log;\r
+import org.tizen.installmanager.lib.Platform;\r
+import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
+\r
+/**\r
+ * This class represents options from command line arguments.\r
+ * @author Wooyoung Cho <wooyoung1.cho@samsung.com>\r
+ *\r
+ */\r
+public class Options {\r
+       /**\r
+        * Do sanity checks including file size and checksum \r
+        */\r
+       public static boolean doPackageValidation = true;\r
+       \r
+       /**\r
+        * Do download package file.\r
+        */\r
+       public static boolean onlyDownload = false;\r
+       \r
+       /**\r
+        * Do resume downloading.\r
+        */\r
+       public static boolean doResumeDownloading = true;\r
+       \r
+       /**\r
+        * Use system proxy\r
+        */\r
+       public static boolean useAutoProxy = true;\r
+       \r
+       /**\r
+        * Do remove temporary installmanager that exist in /tmp/tizensdk\r
+        */\r
+       public static boolean doRemoveTempTizenSDK = true;\r
+       \r
+       /**\r
+        * Conf file provided by user\r
+        */\r
+       public static String userConfPath = null;\r
+       \r
+       /**\r
+        * update installmanager.\r
+        * If <code>doUpdateInstallManager</code> is false, do not update installmanager binary.\r
+        */\r
+       public static boolean doUpdateInstallManager = true;\r
+       /**\r
+        * Do replace repository. \r
+        * If <code>doRepository</code> is true, change repository address to <code>repo</code> variable.  \r
+        */\r
+       public static boolean doReplaceRepository = false;\r
+       \r
+       /**\r
+        * Do remove packages after installation\r
+        */\r
+       public static boolean doRemovePackages = true;\r
+       \r
+       /**\r
+        * Do remove old sdk.\r
+        * If installer cannot update sdk, <code>doRemoveOldSDK</code> is true.\r
+        */\r
+       public static boolean doRemoveOldSDK = false;\r
+       /**\r
+        * Just check installer is available for update.\r
+        */\r
+       public static boolean checkPackageUpdate = false;\r
+       \r
+       /**\r
+        * Prints dependency graph of packages\r
+        */\r
+       public static boolean printDepGraph = false;\r
+       \r
+       /**\r
+        * start installmanager test\r
+        */     \r
+       public static boolean doTest = false;\r
+       \r
+       /**\r
+        * Use Snapshot file.\r
+        */\r
+       public static boolean snapshot = false;\r
+       \r
+       /**\r
+     * Do auto install or uninstall without GUI\r
+     */\r
+       public static boolean doInstallNoUI = false;\r
+       public static boolean doRemoveNoUI = false;\r
+       public static boolean doUpdateNoUI = false;\r
+       public static boolean doShowDistListNoUI = false;\r
+       public static boolean doShowPackageListNoUI = false;\r
+       public static boolean doShowSDKInstallStatus = false;\r
+       public static boolean doShowHelp = false;\r
+       \r
+       public static String repository = null;\r
+       public static String imageFilePath = null;\r
+       public static String snapshotPath = null;\r
+       public static ServerType serverType = null;\r
+       public static String distribution = null;\r
+       public static String targetDir = null;\r
+       public static String sdkDataPath = null;\r
+       \r
+       public static boolean isNetwork = true;\r
+       \r
+       public static List<String> packages = new ArrayList<String>();\r
+       public static List<String> skipPackages = new ArrayList<String>();\r
+       \r
+       public static boolean isAgreeLicense = false;\r
+       \r
+       /**\r
+        * Use only download for making SDK image.\r
+        */\r
+       public static String boundary = "public"; // all, public, partner\r
+       public static String platForm = null;\r
+       public static int platFormBit = 0;\r
+       \r
+       /**\r
+        * See all snapshots\r
+        */\r
+       public static boolean allSnapshots = false;\r
+       \r
+       /**\r
+        * Support Partner SDK\r
+        */\r
+       public static boolean partnerSdk = false;\r
+       public static String purposeOfInstalling = "public";\r
+       \r
+       /**\r
+        * Display InstallManager Version\r
+        */\r
+       public static boolean showVersion = false;\r
+       \r
+       /**\r
+        * User-provided proxy server\r
+        */\r
+       public static String proxy = null;\r
+       \r
+       /**\r
+        * Logging all system information\r
+        */\r
+       public static boolean propertyLogging = false;\r
+       \r
+       /**\r
+        * Non-interactive(continuous installation).\r
+        */\r
+       public static boolean interactive = true;\r
+       public static String suPass = ""; \r
+       \r
+       public static String[] args;\r
+       \r
+       public static String executablePath = null;\r
+       \r
+       /**\r
+        * Parses command line arguments and sets corresponding options. \r
+        * @param args command line arguments\r
+        */\r
+       public static void loadCmdArgs(String[] args) {\r
+               Options.args = args;\r
+               Iterator<String> iter = Arrays.asList(args).iterator();\r
+               \r
+               while (iter.hasNext()) {\r
+                       String arg = iter.next();\r
+                       Log.log(arg+" option is specified");\r
+\r
+                       if (arg.equals("-noPackageValidation")) {\r
+                               doPackageValidation = false;\r
+                       } else if (arg.equals("-path")) {\r
+                               if (iter.hasNext()) {\r
+                                       executablePath = iter.next();\r
+                                       Log.log("executable path : " + executablePath);\r
+                               }\r
+                       } else if (arg.equals(OptionConstant.OPTION_TEST)) {\r
+                               doTest = true;\r
+                       } else if (arg.equals("-install")) {\r
+                               if (iter.hasNext()) {\r
+                                       doInstallNoUI = true;\r
+                                       workCliOptions(args);\r
+                               } else {\r
+                                       Log.err("-install option must have some arguments.");\r
+                                       System.out.println("-install option must have some arguements" +\r
+                                                       " such as specific meta packages");\r
+                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
+                               }\r
+\r
+                               if (!validateArgs()) {\r
+                                       Log.err("repository : " + repository + ", distribution : "\r
+                                                       + distribution + ", packages : " + packages);\r
+                                       System.out.println("-install option must have some arguements"\r
+                                                                       + " you can see usage using '-help'");\r
+                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
+                               }\r
+                               break;\r
+                       } else if (arg.equals("-remove")) {\r
+                               if (iter.hasNext()) {\r
+                                       doRemoveNoUI = true;\r
+                                       workCliOptions(args);\r
+                               } else {\r
+                                       Log.err("-remove option must have some arguments.");\r
+                                       System.out.println("-remove option must have some arguements" +\r
+                                                       " such as specific meta packages or 'all'");\r
+                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
+                               }\r
+                               break;\r
+                       } else if (arg.equalsIgnoreCase("-repoinfo")) {\r
+                               if (iter.hasNext()) {\r
+                                       doShowDistListNoUI = true;\r
+                                       serverType = ServerType.SNAPSHOT;\r
+                                       workCliOptions(args);\r
+                               } else {\r
+                                       Log.err("-info option must have some arguments.");\r
+                                       System.out.println("-remove option must have some arguements" +\r
+                                                       " such as repository address.");\r
+                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
+                               }\r
+                               break;\r
+                       } else if (arg.equalsIgnoreCase("-packageinfo")) {\r
+                               if (iter.hasNext()) {\r
+                                       doShowPackageListNoUI = true;\r
+                                       serverType = ServerType.SNAPSHOT;\r
+                                       workCliOptions(args);\r
+                               } else {\r
+                                       Log.err("-packages option must have some arguments.");\r
+                                       System.out.println("-remove option must have some arguements" +\r
+                                                       " such as repository address and distribution.");\r
+                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
+                               }\r
+                               break;\r
+                       } else if (arg.equalsIgnoreCase("-status")) {\r
+                               doShowSDKInstallStatus = true;\r
+                               break;\r
+                       } else if (arg.equalsIgnoreCase("-help")) {\r
+                               doShowHelp = true;\r
+                               break;\r
+                       } else if (arg.equals("-noRemovePackages")) {\r
+                               doRemovePackages = false;\r
+                       } else if (arg.equals("-skipUpdate")) {\r
+                               doUpdateInstallManager = false;\r
+                       } else if (arg.equals("-checkPackageUpdate")) {\r
+                               checkPackageUpdate = true;\r
+                       } else if (arg.equals("-printDepGraph")) {\r
+                               printDepGraph = true;\r
+                       } else if (arg.equals("-proxy")) {\r
+                               if(iter.hasNext()) {\r
+                                       proxy = iter.next();\r
+                                       Log.log("User-provided proxy: "+proxy);\r
+                               } else {\r
+                                       Log.err("-proxy requires proxy description");\r
+                                       throw new IMFatalException(ErrorCode.PROXY_NOT_PROVIDED);\r
+                               }\r
+                       } else if (arg.equals("-snapShot")) {\r
+                               if(iter.hasNext()) {\r
+                                       snapshot = true;\r
+                                       snapshotPath = iter.next();\r
+                                       Log.log("User-provided repository: " + repository);\r
+                               } else {\r
+                                       Log.err("-snapShot requires repository description");\r
+                                       throw new IMFatalException(ErrorCode.USESNAPSHOT_REPOSITORY_NOT_PROVIDED);\r
+                               }\r
+                       } else if (arg.equals("-allSnapshots")) {\r
+                               allSnapshots = true;\r
+                               Log.log("Using '-allSnapshots' option, all snapshots are displaying.");\r
+                       } else if (arg.equals("-onlyDownload")) {\r
+                               if(iter.hasNext()) {\r
+                                       onlyDownload = true;\r
+                                       boundary = iter.next();\r
+                                       platForm = iter.next().toLowerCase();\r
+                                       platFormBit = Integer.parseInt(iter.next());\r
+                                       Log.log("Only download boundary : "+ boundary);\r
+                               } else {\r
+                                       Log.err("-onlyDownload requires packageList description");\r
+                                       throw new IMFatalException(ErrorCode.REPOSITORY_NOT_PROVIDED);\r
+                               }\r
+                               onlyDownload = true;\r
+                       } else if (arg.equals("-noResumeDownloading")) {\r
+                               doResumeDownloading = false;\r
+                               Log.log("Using '-noResumeDownloading' option, do not resume downloading");\r
+                       } else if (arg.equals("-noUseAutoProxy")) {\r
+                               useAutoProxy = false;\r
+                               Log.log("Using '-noUseAutoProxy' option, do not use system proxy.");\r
+                       } else if (arg.equals("-version")) {\r
+                               showVersion = true;\r
+                               Log.log("Using '-version' option, display InstallManager version on console.");\r
+                       } else if (arg.equals("-noRemoveTempTizenSDK")) {\r
+                               doRemoveTempTizenSDK = false;\r
+                       } else if (arg.equals("-repository")) {\r
+                               if(iter.hasNext()) {\r
+                                       doReplaceRepository = true;\r
+                                       repository = iter.next();\r
+                                       Log.log("replace repository : "+repository);\r
+                               } else {\r
+                                       Log.err("-replaceRepository requires repository description");\r
+                                       throw new IMFatalException(ErrorCode.REPOSITORY_NOT_PROVIDED);\r
+                               }\r
+                       } else if (arg.equals(OptionConstant.OPTION_DISTRIBUTION)) {\r
+                               if(iter.hasNext()) {\r
+                                       distribution = iter.next();\r
+                                       Log.log("replace distribution : "+distribution);\r
+                               } else {\r
+                                       Log.err("-distribution requires distribution description");\r
+                                       throw new IMFatalException(OptionConstant.MSG_DISTRIBUTION_NOT_PROVIDED);\r
+                               }\r
+                       } else if (arg.equals("-removeOldSDK")) {\r
+                               doRemoveOldSDK = true;\r
+                       } else if (arg.equals("-property")) {\r
+                               propertyLogging = true;\r
+                       } else if (arg.equals("-skip")) {\r
+                               if (iter.hasNext()) {\r
+                                       String skipPackageName = iter.next(); \r
+                                       skipPackages.add(skipPackageName);\r
+                                       Log.log("Skip package => " + skipPackageName);\r
+                               } else {\r
+                                       Log.err("-skip requires package name");\r
+                                       throw new IMFatalException("-skip requires package name");\r
+                               }\r
+                       } else {\r
+                               Log.err("InstallManager do not support '" + arg + "' option");\r
+                               throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Get options.\r
+        * @return\r
+        */\r
+       public static String getArgsStr() {\r
+               String argsStr = "";\r
+               for(String arg : args) {\r
+                       argsStr = argsStr + " " + arg;\r
+               }\r
+               return argsStr;\r
+       }\r
+       \r
+       private static boolean validateArgs() {\r
+               if (isNetwork) {\r
+                       if (Options.repository != null && Options.distribution != null && !Options.packages.isEmpty()) {\r
+                               return true;\r
+                       } else {\r
+                               return false;\r
+                       }\r
+               } else {\r
+                       if (Options.repository != null && !Options.packages.isEmpty()) {\r
+                               if (Platform.isWindows()) {\r
+                                       if (Options.repository.startsWith("file")) {\r
+                                               return true;\r
+                                       } else {\r
+                                               return false;\r
+                                       }\r
+                               } else {\r
+                                       return true;\r
+                               }\r
+                       } else if (Options.imageFilePath == null) {\r
+                               return false;\r
+                       } else {\r
+                               return true;\r
+                       }\r
+               }\r
+       }\r
+               \r
+       private static void workCliOptions(String[] args) {\r
+               ArrayList<String> argArray = new ArrayList<String>();\r
+\r
+               for (String t : args) {\r
+                       if (!t.equalsIgnoreCase("-install") && !t.equalsIgnoreCase("-remove")) {\r
+                               argArray.add(t);                                \r
+                       }\r
+               }\r
+               \r
+               Iterator<String> argIter = argArray.iterator();\r
+               while (argIter.hasNext()) {\r
+                       if (argIter.next().equalsIgnoreCase("-path")) {\r
+                               argIter.remove();\r
+                               argIter.next();\r
+                               argIter.remove();\r
+                       }\r
+               }\r
+               \r
+               // set repository\r
+               argIter = argArray.iterator();\r
+               while (argIter.hasNext()) {\r
+                       if (argIter.next().equalsIgnoreCase("-r")) {\r
+                               argIter.remove();\r
+                               repository = argIter.next();\r
+                               if (!repository.startsWith("http")) {\r
+                                       isNetwork = false;\r
+                                       serverType = ServerType.LOCAL;\r
+                                       exclusiveOptions("-d", argArray);\r
+                               } else {\r
+                                       serverType = ServerType.SNAPSHOT;\r
+                                       isNetwork = true;                                       \r
+                               }\r
+                               argIter.remove();\r
+                       }\r
+               }\r
+               \r
+               // set SDK image path\r
+               argIter = argArray.iterator();\r
+               while (argIter.hasNext()) {\r
+                       if (argIter.next().equalsIgnoreCase("-f")) {\r
+                               argIter.remove();\r
+                               imageFilePath = argIter.next();\r
+                               isNetwork = false;\r
+                               serverType = ServerType.LOCAL;\r
+                               argIter.remove();\r
+                               exclusiveOptions("-d", argArray);\r
+                       }\r
+               }\r
+               \r
+               // set target directory\r
+               argIter = argArray.iterator();\r
+               while (argIter.hasNext()) {\r
+                       if (argIter.next().equalsIgnoreCase("-l")) {\r
+                               argIter.remove();\r
+                               targetDir = argIter.next();\r
+                               argIter.remove();\r
+                       }\r
+               }\r
+               \r
+               // set license agreement\r
+               if (doInstallNoUI) {\r
+                       argIter = argArray.iterator();\r
+                       while (argIter.hasNext()) {\r
+                               if (argIter.next().equalsIgnoreCase("-accept_license")) {\r
+                                       argIter.remove();\r
+                                       isAgreeLicense = true;\r
+                               }\r
+                       }                       \r
+               }\r
+               \r
+               // set sdk data directory\r
+               argIter = argArray.iterator();\r
+               while (argIter.hasNext()) {\r
+                       if (argIter.next().equalsIgnoreCase("-w")) {\r
+                               argIter.remove();\r
+                               sdkDataPath = argIter.next();\r
+                               argIter.remove();\r
+                       }\r
+               }\r
+\r
+               // set distribution\r
+               argIter = argArray.iterator();\r
+               while (argIter.hasNext()) {\r
+                       if (argIter.next().equalsIgnoreCase("-d")) {\r
+                               argIter.remove();\r
+                               distribution = argIter.next();\r
+                               argIter.remove();\r
+                       }\r
+               }\r
+\r
+               // set packages\r
+               argIter = argArray.iterator();\r
+               while (argIter.hasNext()) {\r
+                       if (argIter.next().equalsIgnoreCase("-p")) {\r
+                               argIter.remove();\r
+                               while (argIter.hasNext()) {\r
+                                       String pkg = argIter.next();\r
+                                       if (!pkg.startsWith("-")) {\r
+                                               packages.add(pkg);\r
+                                               argIter.remove();\r
+                                       } else {\r
+                                               break;                                          \r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               // set skip packages\r
+               argIter = argArray.iterator();\r
+               while (argIter.hasNext()) {\r
+                       if (argIter.next().equalsIgnoreCase("-skip")) {\r
+                               argIter.remove();\r
+                               while (argIter.hasNext()) {\r
+                                       String pkg = argIter.next();\r
+                                       if (!pkg.startsWith("-")) {\r
+                                               skipPackages.add(pkg);\r
+                                               argIter.remove();\r
+                                       } else {\r
+                                               break;                                          \r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               // set proxy\r
+               argIter = argArray.iterator();\r
+               while (argIter.hasNext()) {\r
+                       if (argIter.next().equalsIgnoreCase("-x")) {\r
+                               argIter.remove();\r
+                               Options.proxy = argIter.next();\r
+                               Log.log("Use proxy setting => " + Options.proxy);\r
+                               argIter.remove();\r
+                       }\r
+               }\r
+               \r
+               // set test\r
+               argIter = argArray.iterator();\r
+               while (argIter.hasNext()) {\r
+                       if (argIter.next().equalsIgnoreCase("-test")) {\r
+                               argIter.remove();\r
+                               Options.doTest = true;\r
+                               Log.log("Set to test working performance.");\r
+                       }\r
+               }\r
+               \r
+               argIter = argArray.iterator();\r
+               while (argIter.hasNext()) {\r
+                       if (argIter.next().equalsIgnoreCase("-ni")) {\r
+                               argIter.remove();\r
+                               if (argIter.hasNext()) { // -ni option must have -passwd option.\r
+                                       if (Platform.isLinux()) {\r
+                                               argIter = argArray.iterator();\r
+                                               while (argIter.hasNext()) {\r
+                                                       if (argIter.next().equalsIgnoreCase("-passwd")) {\r
+                                                               argIter.remove();\r
+                                                               if (argIter.hasNext()) {\r
+                                                                       suPass = argIter.next();\r
+                                                                       interactive = false;\r
+                                                                       argIter.remove();\r
+                                                               } else { // -passwd option must have value.\r
+                                                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                               if (suPass == "") {\r
+                                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
+                                               }\r
+                                       } else if (Platform.isWindows()) {\r
+                                               interactive = true;\r
+                                       } else if (Platform.isMacOS()) {\r
+                                               interactive = true;\r
+                                       } else {\r
+                                               throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
+                                       }\r
+                               } else {\r
+                                       throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       \r
+       private static void exclusiveOptions(String option, ArrayList<String> argArray) {\r
+               Iterator<String> argIter = argArray.iterator();\r
+               while (argIter.hasNext()) {\r
+                       if (argIter.next().equalsIgnoreCase(option)) {\r
+                               Log.err("[" + option + "] cannot be used.");\r
+                               System.out.println("[" + option + "] cannot be used with some options.");\r
+                               throw new IMFatalException("[" + option + "] cannot be used with some options.");\r
+                       }\r
+               }\r
+       }\r
+}\r
index 9e70f45..7100c95 100644 (file)
-package org.tizen.installmanager.core;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.util.PathUtil;
-
-public class Performance {
-       public static final String INSTALL_TEST_FILE_NAME = "installtime";
-       public static final String REMOVE_TEST_FILE_NAME = "removetime";
-       
-       //total time
-       private static Date imStartTime = null;
-       private static Date imEndTime = null;
-       
-       //initialize time
-       private static Date initializeStartTime = null;
-       private static Date initializeEndTime = null;
-       
-       //download time
-       private static Date downloadStartTime = null;
-       private static Date downloadEndTime = null;
-       
-       
-       //installation time
-       private static Date installationStartTime = null;
-       private static Date installationEndTime = null;
-       
-       //removal time
-       private static Date removalStartTime = null;
-       private static Date removalEndTime = null;
-       
-       //information
-       public static long sdkPackageSize = 0; 
-       
-       
-       public static void setIMStartTime() {
-               imStartTime = new Date();
-       }
-       
-       public static void setIMEndTime() {
-               imEndTime = new Date();
-       }
-       
-       public static void setInitializeStartTime() {
-               initializeStartTime = new Date();
-       }
-       
-       public static void setInitializeEndTime() {
-               initializeEndTime = new Date();
-       }
-       
-       public static void setDownloadStartTime() {
-               downloadStartTime = new Date();
-       }
-       
-       public static void setDownloadEndTime() {
-               downloadEndTime = new Date();
-       }
-       
-       public static void setInstallationStartTime() {
-               installationStartTime = new Date();
-       }
-       
-       public static void setInstallationEndTime() {
-               installationEndTime = new Date();
-       }
-       
-       public static void setRemovalStartTime() {
-               removalStartTime = new Date();
-       }
-       
-       public static void setRemovalEndTime() {
-               removalEndTime = new Date();
-       }
-       
-       public static void printToLogFile() {
-               Log.log("The installmanager start time : " + imStartTime);
-               Log.log("The installmanager end time : " + imEndTime);
-               Log.log("The installation start time : " + installationStartTime);
-               Log.log("The installation end time : " + installationEndTime);
-               
-               long progressSecond = getInstallationTime()/1000;
-               
-               if (progressSecond >= 0) {
-                       Log.log("The progress time of the installation : About " + progressSecond/60 + " minutes"
-                                       +"(" + progressSecond + " seconds)");
-               } else {
-                       Log.log("The progress time of the installation : Installation fail");
-               }
-       }
-       
-       public static void printTestResult() {
-               //get file name of test result
-               SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
-               String testFileName = formatter.format(imStartTime) + ".txt";
-               
-               String testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);
-               File testResultFile = new File(testResultFilePath);
-               
-               if (!testResultFile.getParentFile().exists()) {
-                       testResultFile.getParentFile().mkdirs();
-               }
-               
-               BufferedWriter out = null;
-               try {
-                       out = new BufferedWriter(new FileWriter(testResultFile));
-                       
-                       out.write("***  InstallManager performance test ***");
-                       out.newLine();
-                       out.write("Sdk package size\t: " + sdkPackageSize);
-                       out.newLine();
-                       out.write("The initialization time\t: " + getInitializeTime() + "sec");
-                       out.write("(" + getBitPerSecond(sdkPackageSize, getInitializeTime())+ "b/s)");
-                       out.newLine();
-                       out.write("The download time\t: " + getDownloadTime() + "sec");
-                       out.write("(" + getBitPerSecond(sdkPackageSize, getDownloadTime())+ "b/s)");
-                       out.newLine();
-                       out.write("The installation time\t: " + getInstallationTime() + "sec");
-                       out.write("(" + getBitPerSecond(sdkPackageSize, getInstallationTime())+ "b/s)");
-                       out.newLine();
-                       out.write("The removal time\t: " + getRemovalTime() + "sec");
-                       out.write("(" + getBitPerSecond(sdkPackageSize, getRemovalTime())+ "b/s)");
-                       out.newLine();
-                       out.write("The install-manager start time\t: " + imStartTime);
-                       out.newLine();
-                       out.write("The install-manager end time\t: " + imEndTime);
-                       out.newLine();
-                       out.newLine();
-                       
-                       long progressSecond = getTotalTime();
-                       
-                       if (progressSecond >= 0) {
-                               out.write("* Total time to install : About " + progressSecond/60 + " minutes"
-                                               +"(" + progressSecond + " seconds)");
-                               out.newLine();
-                       } else {
-                               out.write("* Total time to install : Installation fail");
-                               out.newLine();
-                       }
-                                                       
-               } catch (IOException e) {
-                       Log.ExceptionLog(e);
-               } finally {
-                       if (out != null) {
-                               try {
-                                       out.close();
-                               } catch (IOException e) {
-                                       Log.ExceptionLog(e);
-                               }
-                       }
-               }
-       }
-       
-       public static void printTestResultXmlFormat() {
-               //get file name of test result
-               SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
-               String testFileName = formatter.format(imStartTime) + ".xml";
-               
-               String testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);
-               File testResultFile = new File(testResultFilePath);
-               
-               if (!testResultFile.getParentFile().exists()) {
-                       testResultFile.getParentFile().mkdirs();
-               }
-               
-               BufferedWriter out = null;
-               try {
-                       out = new BufferedWriter(new FileWriter(testResultFile));
-                       out.write(getTestSuiteXml("InstallManager performance test", 4, getTotalTime()));
-                       out.newLine();
-                       out.write(getTestCaseXml("InitTest", "The initialization time", getInitializeTime()));
-                       out.newLine();
-                       out.write(getTestCaseXml("DownloadTest", "The download time", getDownloadTime()));
-                       out.newLine();
-                       out.write(getTestCaseXml("InstallTest", "The installation time", getInstallationTime()));
-                       out.newLine();
-                       out.write(getTestCaseXml("RemoveTest", "The removal time", getRemovalTime()));
-                       out.newLine();
-                       out.write("</testsuite>");
-               } catch (IOException e) {
-                       Log.ExceptionLog(e);
-               } finally {
-                       if (out != null) {
-                               try {
-                                       out.close();
-                               } catch (IOException e) {
-                                       Log.ExceptionLog(e);
-                               }
-                       }
-               }
-       }
-       
-       public static void printTestResultXmlFormat2() {
-               if (installationStartTime != null) {
-                       printInstallTestResultXmlFormat();
-               } else {
-                       printRemoveTestResultXmlFormat();
-               }
-       }
-       
-       public static void printInstallTestResultXmlFormat() {
-               //get file name of test result
-               SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
-               String testFileName = INSTALL_TEST_FILE_NAME + "_" + formatter.format(imStartTime) + ".xml";
-               
-               String testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);
-               File testResultFile = new File(testResultFilePath);
-               
-               if (!testResultFile.getParentFile().exists()) {
-                       testResultFile.getParentFile().mkdirs();
-               }
-               
-               BufferedWriter out = null;
-               try {
-                       out = new BufferedWriter(new FileWriter(testResultFile));
-                       out.write(getTestSuiteXml("InstallManager performance test", 3, getTotalTime()));
-                       out.newLine();
-                       out.write(getTestCaseXml("InitTest", "The initialization time", getInitializeTime()));
-                       out.newLine();
-                       out.write(getTestCaseXml("DownloadTest", "The download time", getDownloadTime()));
-                       out.newLine();
-                       out.write(getTestCaseXml("InstallTest", "The installation time", getInstallationTime()));
-                       out.newLine();
-                       out.write("</testsuite>");
-               } catch (IOException e) {
-                       Log.ExceptionLog(e);
-               } finally {
-                       if (out != null) {
-                               try {
-                                       out.close();
-                               } catch (IOException e) {
-                                       Log.ExceptionLog(e);
-                               }
-                       }
-               }
-       }
-       
-       public static void printRemoveTestResultXmlFormat() {
-               //get file name of test result
-               SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
-               String testFileName = REMOVE_TEST_FILE_NAME + "_" + formatter.format(imStartTime) + ".xml";
-               
-               String testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);
-               File testResultFile = new File(testResultFilePath);
-               
-               if (!testResultFile.getParentFile().exists()) {
-                       testResultFile.getParentFile().mkdirs();
-               }
-               
-               BufferedWriter out = null;
-               try {
-                       out = new BufferedWriter(new FileWriter(testResultFile));
-                       out.write(getTestSuiteXml("InstallManager performance test", 1, getTotalTime()));
-                       out.newLine();
-                       out.write(getTestCaseXml("RemoveTest", "The removal time", getRemovalTime()));
-                       out.newLine();
-                       out.write("</testsuite>");
-               } catch (IOException e) {
-                       Log.ExceptionLog(e);
-               } finally {
-                       if (out != null) {
-                               try {
-                                       out.close();
-                               } catch (IOException e) {
-                                       Log.ExceptionLog(e);
-                               }
-                       }
-               }
-       }
-       
-       private static String getTestSuiteXml(String testName, int testNum, long time) {
-               return "<testsuite errors=\"\" failures=\"\" name=\"" + testName + "\" skips=\"\" tests=\"" + testNum +"\" time=\""+ time +"\">";
-       }
-       
-       private static String getTestCaseXml(String testClass, String testName, long time) {
-               return "<testcase classname=\"" + testClass + "\" name=\"" + testName + "\" time=\"" + time +"\"/>";
-       }
-       
-       private static long getInitializeTime() {
-               if (initializeStartTime == null || initializeEndTime == null) {
-                       return 0;
-               }
-               
-               long interval = (initializeEndTime.getTime() - initializeStartTime.getTime())/1000;
-               return interval;
-       }
-       
-       private static long getDownloadTime() {
-               if (downloadStartTime == null || downloadEndTime == null) {
-                       return 0;
-               }
-               
-               long interval = (downloadEndTime.getTime() - downloadStartTime.getTime())/1000;
-               return interval;
-       }
-       
-       private static long getTotalTime() {
-               if (imStartTime == null || imEndTime == null) {
-                       return 0;
-               }
-               
-               long interval = (imEndTime.getTime() - imStartTime.getTime())/1000;
-               return interval;
-       }
-       
-       private static long getInstallationTime() {
-               if (installationStartTime == null || installationEndTime == null) {
-                       return 0;
-               }
-               
-               long interval = (installationEndTime.getTime() - installationStartTime.getTime())/1000;
-               return interval;
-       }
-       
-       private static long getRemovalTime() {
-               if (removalStartTime == null || removalEndTime == null) {
-                       return 0;
-               }
-               
-               long interval = (removalEndTime.getTime() - removalStartTime.getTime())/1000;
-               return interval;
-       }
-       
-       private static long getBitPerSecond(long size, long seconds) {
-               if (seconds == 0) {
-                       return 0;
-               } else {
-                       return size/seconds;
-               }
-       }
-}
+package org.tizen.installmanager.core;\r
+\r
+import java.io.BufferedWriter;\r
+import java.io.File;\r
+import java.io.FileWriter;\r
+import java.io.IOException;\r
+import java.text.SimpleDateFormat;\r
+import java.util.Date;\r
+\r
+import org.tizen.installmanager.lib.Log;\r
+import org.tizen.installmanager.util.PathUtil;\r
+\r
+public class Performance {\r
+       public static final String INSTALL_TEST_FILE_NAME = "installtime";\r
+       public static final String REMOVE_TEST_FILE_NAME = "removetime";\r
+       \r
+       //total time\r
+       private static Date imStartTime = null;\r
+       private static Date imEndTime = null;\r
+       \r
+       //initialize time\r
+       private static Date initializeStartTime = null;\r
+       private static Date initializeEndTime = null;\r
+       \r
+       //download time\r
+       private static Date downloadStartTime = null;\r
+       private static Date downloadEndTime = null;\r
+       \r
+       \r
+       //installation time\r
+       private static Date installationStartTime = null;\r
+       private static Date installationEndTime = null;\r
+       \r
+       //removal time\r
+       private static Date removalStartTime = null;\r
+       private static Date removalEndTime = null;\r
+       \r
+       //information\r
+       public static long sdkPackageSize = 0; \r
+       \r
+       \r
+       public static void setIMStartTime() {\r
+               imStartTime = new Date();\r
+       }\r
+       \r
+       public static void setIMEndTime() {\r
+               imEndTime = new Date();\r
+       }\r
+       \r
+       public static void setInitializeStartTime() {\r
+               initializeStartTime = new Date();\r
+       }\r
+       \r
+       public static void setInitializeEndTime() {\r
+               initializeEndTime = new Date();\r
+       }\r
+       \r
+       public static void setDownloadStartTime() {\r
+               downloadStartTime = new Date();\r
+       }\r
+       \r
+       public static Date getDownloadStartTime() {\r
+               return downloadStartTime;\r
+       }\r
+       \r
+       public static void setDownloadEndTime() {\r
+               downloadEndTime = new Date();\r
+       }\r
+       \r
+       public static void setInstallationStartTime() {\r
+               installationStartTime = new Date();\r
+       }\r
+       \r
+       public static Date getInstallationStartTime() {\r
+               return installationStartTime;\r
+       }\r
+       \r
+       public static void setInstallationEndTime() {\r
+               installationEndTime = new Date();\r
+       }\r
+       \r
+       public static void setRemovalStartTime() {\r
+               removalStartTime = new Date();\r
+       }\r
+       \r
+       public static void setRemovalEndTime() {\r
+               removalEndTime = new Date();\r
+       }\r
+       \r
+       public static void printToLogFile() {\r
+               Log.log("The installmanager start time : " + imStartTime);\r
+               Log.log("The installmanager end time : " + imEndTime);\r
+               Log.log("The installation start time : " + installationStartTime);\r
+               Log.log("The installation end time : " + installationEndTime);\r
+               \r
+               long progressSecond = getInstallationTime()/1000;\r
+               \r
+               if (progressSecond >= 0) {\r
+                       Log.log("The progress time of the installation : About " + progressSecond/60 + " minutes"\r
+                                       +"(" + progressSecond + " seconds)");\r
+               } else {\r
+                       Log.log("The progress time of the installation : Installation fail");\r
+               }\r
+       }\r
+       \r
+       public static void printTestResult() {\r
+               //get file name of test result\r
+               SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");\r
+               String testFileName = formatter.format(imStartTime) + ".txt";\r
+               \r
+               String testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);\r
+               File testResultFile = new File(testResultFilePath);\r
+               \r
+               if (!testResultFile.getParentFile().exists()) {\r
+                       testResultFile.getParentFile().mkdirs();\r
+               }\r
+               \r
+               BufferedWriter out = null;\r
+               try {\r
+                       out = new BufferedWriter(new FileWriter(testResultFile));\r
+                       \r
+                       out.write("***  InstallManager performance test ***");\r
+                       out.newLine();\r
+                       out.write("Sdk package size\t: " + sdkPackageSize);\r
+                       out.newLine();\r
+                       out.write("The initialization time\t: " + getInitializeTime() + "sec");\r
+                       out.write("(" + getBitPerSecond(sdkPackageSize, getInitializeTime())+ "b/s)");\r
+                       out.newLine();\r
+                       out.write("The download time\t: " + getDownloadTime() + "sec");\r
+                       out.write("(" + getBitPerSecond(sdkPackageSize, getDownloadTime())+ "b/s)");\r
+                       out.newLine();\r
+                       out.write("The installation time\t: " + getInstallationTime() + "sec");\r
+                       out.write("(" + getBitPerSecond(sdkPackageSize, getInstallationTime())+ "b/s)");\r
+                       out.newLine();\r
+                       out.write("The removal time\t: " + getRemovalTime() + "sec");\r
+                       out.write("(" + getBitPerSecond(sdkPackageSize, getRemovalTime())+ "b/s)");\r
+                       out.newLine();\r
+                       out.write("The install-manager start time\t: " + imStartTime);\r
+                       out.newLine();\r
+                       out.write("The install-manager end time\t: " + imEndTime);\r
+                       out.newLine();\r
+                       out.newLine();\r
+                       \r
+                       long progressSecond = getTotalTime();\r
+                       \r
+                       if (progressSecond >= 0) {\r
+                               out.write("* Total time to install : About " + progressSecond/60 + " minutes"\r
+                                               +"(" + progressSecond + " seconds)");\r
+                               out.newLine();\r
+                       } else {\r
+                               out.write("* Total time to install : Installation fail");\r
+                               out.newLine();\r
+                       }\r
+                                                       \r
+               } catch (IOException e) {\r
+                       Log.ExceptionLog(e);\r
+               } finally {\r
+                       if (out != null) {\r
+                               try {\r
+                                       out.close();\r
+                               } catch (IOException e) {\r
+                                       Log.ExceptionLog(e);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       \r
+       public static void printTestResultXmlFormat() {\r
+               //get file name of test result\r
+               SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");\r
+               String testFileName = formatter.format(imStartTime) + ".xml";\r
+               \r
+               String testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);\r
+               File testResultFile = new File(testResultFilePath);\r
+               \r
+               if (!testResultFile.getParentFile().exists()) {\r
+                       testResultFile.getParentFile().mkdirs();\r
+               }\r
+               \r
+               BufferedWriter out = null;\r
+               try {\r
+                       out = new BufferedWriter(new FileWriter(testResultFile));\r
+                       out.write(getTestSuiteXml("InstallManager performance test", 4, getTotalTime()));\r
+                       out.newLine();\r
+                       out.write(getTestCaseXml("InitTest", "The initialization time", getInitializeTime()));\r
+                       out.newLine();\r
+                       out.write(getTestCaseXml("DownloadTest", "The download time", getDownloadTime()));\r
+                       out.newLine();\r
+                       out.write(getTestCaseXml("InstallTest", "The installation time", getInstallationTime()));\r
+                       out.newLine();\r
+                       out.write(getTestCaseXml("RemoveTest", "The removal time", getRemovalTime()));\r
+                       out.newLine();\r
+                       out.write("</testsuite>");\r
+               } catch (IOException e) {\r
+                       Log.ExceptionLog(e);\r
+               } finally {\r
+                       if (out != null) {\r
+                               try {\r
+                                       out.close();\r
+                               } catch (IOException e) {\r
+                                       Log.ExceptionLog(e);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       \r
+       public static void printTestResultXmlFormat2() {\r
+               if (installationStartTime != null) {\r
+                       printInstallTestResultXmlFormat();\r
+               } else {\r
+                       printRemoveTestResultXmlFormat();\r
+               }\r
+       }\r
+       \r
+       public static void printInstallTestResultXmlFormat() {\r
+               //get file name of test result\r
+               SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");\r
+               String testFileName = INSTALL_TEST_FILE_NAME + "_" + formatter.format(imStartTime) + ".xml";\r
+               \r
+               String testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);\r
+               File testResultFile = new File(testResultFilePath);\r
+               \r
+               if (!testResultFile.getParentFile().exists()) {\r
+                       testResultFile.getParentFile().mkdirs();\r
+               }\r
+               \r
+               BufferedWriter out = null;\r
+               try {\r
+                       out = new BufferedWriter(new FileWriter(testResultFile));\r
+                       out.write(getTestSuiteXml("InstallManager performance test", 3, getTotalTime()));\r
+                       out.newLine();\r
+                       out.write(getTestCaseXml("InitTest", "The initialization time", getInitializeTime()));\r
+                       out.newLine();\r
+                       out.write(getTestCaseXml("DownloadTest", "The download time", getDownloadTime()));\r
+                       out.newLine();\r
+                       out.write(getTestCaseXml("InstallTest", "The installation time", getInstallationTime()));\r
+                       out.newLine();\r
+                       out.write("</testsuite>");\r
+               } catch (IOException e) {\r
+                       Log.ExceptionLog(e);\r
+               } finally {\r
+                       if (out != null) {\r
+                               try {\r
+                                       out.close();\r
+                               } catch (IOException e) {\r
+                                       Log.ExceptionLog(e);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       \r
+       public static void printRemoveTestResultXmlFormat() {\r
+               //get file name of test result\r
+               SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");\r
+               String testFileName = REMOVE_TEST_FILE_NAME + "_" + formatter.format(imStartTime) + ".xml";\r
+               \r
+               String testResultFilePath = PathUtil.get(InstallManagerConstants.getInstallManagerTestResultPath(), testFileName);\r
+               File testResultFile = new File(testResultFilePath);\r
+               \r
+               if (!testResultFile.getParentFile().exists()) {\r
+                       testResultFile.getParentFile().mkdirs();\r
+               }\r
+               \r
+               BufferedWriter out = null;\r
+               try {\r
+                       out = new BufferedWriter(new FileWriter(testResultFile));\r
+                       out.write(getTestSuiteXml("InstallManager performance test", 1, getTotalTime()));\r
+                       out.newLine();\r
+                       out.write(getTestCaseXml("RemoveTest", "The removal time", getRemovalTime()));\r
+                       out.newLine();\r
+                       out.write("</testsuite>");\r
+               } catch (IOException e) {\r
+                       Log.ExceptionLog(e);\r
+               } finally {\r
+                       if (out != null) {\r
+                               try {\r
+                                       out.close();\r
+                               } catch (IOException e) {\r
+                                       Log.ExceptionLog(e);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       \r
+       private static String getTestSuiteXml(String testName, int testNum, long time) {\r
+               return "<testsuite errors=\"\" failures=\"\" name=\"" + testName + "\" skips=\"\" tests=\"" + testNum +"\" time=\""+ time +"\">";\r
+       }\r
+       \r
+       private static String getTestCaseXml(String testClass, String testName, long time) {\r
+               return "<testcase classname=\"" + testClass + "\" name=\"" + testName + "\" time=\"" + time +"\"/>";\r
+       }\r
+       \r
+       private static long getInitializeTime() {\r
+               if (initializeStartTime == null || initializeEndTime == null) {\r
+                       return 0;\r
+               }\r
+               \r
+               long interval = (initializeEndTime.getTime() - initializeStartTime.getTime())/1000;\r
+               return interval;\r
+       }\r
+       \r
+       private static long getDownloadTime() {\r
+               if (downloadStartTime == null || downloadEndTime == null) {\r
+                       return 0;\r
+               }\r
+               \r
+               long interval = (downloadEndTime.getTime() - downloadStartTime.getTime())/1000;\r
+               return interval;\r
+       }\r
+       \r
+       private static long getTotalTime() {\r
+               if (imStartTime == null || imEndTime == null) {\r
+                       return 0;\r
+               }\r
+               \r
+               long interval = (imEndTime.getTime() - imStartTime.getTime())/1000;\r
+               return interval;\r
+       }\r
+       \r
+       private static long getInstallationTime() {\r
+               if (installationStartTime == null || installationEndTime == null) {\r
+                       return 0;\r
+               }\r
+               \r
+               long interval = (installationEndTime.getTime() - installationStartTime.getTime())/1000;\r
+               return interval;\r
+       }\r
+       \r
+       private static long getRemovalTime() {\r
+               if (removalStartTime == null || removalEndTime == null) {\r
+                       return 0;\r
+               }\r
+               \r
+               long interval = (removalEndTime.getTime() - removalStartTime.getTime())/1000;\r
+               return interval;\r
+       }\r
+       \r
+       private static long getBitPerSecond(long size, long seconds) {\r
+               if (seconds == 0) {\r
+                       return 0;\r
+               } else {\r
+                       return size/seconds;\r
+               }\r
+       }\r
+}\r
index b97d790..ef15eba 100644 (file)
-/*
-*  InstallManager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact:
-* Wooyoung Cho <wooyoung1.cho@samsung.com>
-* Shihyun Kim <shihyun.kim@samsung.com>
-* Taeyoung Son <taeyoung2.son@samsung.com>
-* Yongsung kim <yongsung1.kim@samsung.com>
-*
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
-
-package org.tizen.installmanager.lib;
-
-import org.tizen.installmanager.core.Config;
-
-/**
- * This class manages error codes and states
- *
- * @author Shihyun Kim <shihyun.kim@samsung.com>
- */
-public class ErrorController {
-       /**
-        * Define case of error
-        *
-        * @author Shihyun Kim <shihyun.kim@samsung.com>
-        *
-        */
-       public enum ErrorCode {
-               CANNOT_FIND_CONFIG_FILE("The installmanager.conf file not found."),
-               CANNOT_FIND_FILE_IN_REPOSITROY("Cannot find file in repository."),
-               CANNOT_CREATE_DOWNLOAD_FILE("Download file cannot be created."),
-               CANNOT_CHECK_INSTLLED_FILE_LIST("Installed file list cannot be checked."),
-               CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY("File cannot be moved to the target directory."),
-               CANNOT_CONNECT_TO_PROXY_SERVER("Proxy server connection fails."),
-               WRONG_PACKAGE_URL("Package URLs are invalid."),
-               CANCEL("Download canceled."),
-               UNKNOWN_ERROR("Unknown error."),
-               UNKNOWN_PACKAGE_EXTENSION("Package extension not supported."),
-               INVALID_PACKAGE_VERSION("Invalid package version."),
-               CANNOT_FIND_PACKAGE_VERSION("Package version not found."),
-               CANNOT_FIND_INSTALLABLE_OR_REMOVABLE_PACKAGES("Install or uninstall packages not found. Network connection may have failed."),
-               CANNOT_FIND_FILE_IN_LOCAL("Local file not found."),
-               CANNOT_SAVE_CONFIG("Configuration file cannot be saved."),
-               CANNOT_CREATE_SHORTCUT("Shortcut creation is failed."),
-               CANNOT_CREATE_TSUDO("tsudo creation is failed."),
-               CANNOT_CREATE_INSTALL_LIST("Install list creation failed."),
-               CANNOT_CREATE_CONFIG_FILE("Configuration directory or file creation failed."),
-               CANNOT_FIND_USER_CONFIG_FILE("User configuration file creation failed."),
-               CANNOT_REGISTER_TARGET_DIR("Target directory registration failed."),
-               CANNOT_PARSING_TEXT("Configuration file parsing failed."),
-               CANNOT_SAVE_PROPERTY_FILE("The installmanager.conf or Package file cannot be saved."),
-               CANNOT_UNPACK_PACKAGE("The package zip file unpackaging failed."),
-               CANNOT_CREATE_RESOURCE("Resource file creation failed."),
-               CANNOT_FIND_PACKAGE("Required packages not found. The package server may be invalid."),
-               CANNOT_REMOVE_PACKAGE("Package removal failed."),
-               CANNOT_REMOVE_MISSING_PACKAGE("Missing package cannot be removed."),
-               FIND_MISSING_FILES("Some files are not installed properly."),
-               CANNOT_ACCESS_FILE("File access failed."),
-               CANNOT_REMOVE_OLDSDK("Old SDK removal failed."),
-               COPY_FILE_IS_FAIL("Copying the file to the target directory failed."),
-               OLD_TIZEN_SDK_EXISTS("Old Tizen SDK is installed. Remove the old SDK and run the Tizen SDK Install Manager again."),
-               UNSUPPORTED_PLATFORM("Platform not supported."),
-               REMOVE_SCRIPT_NOT_EXISTS("Removal script not found."),
-               REMOVE_SCRIPT_FATAL_ERROR("Fatal error occurred while executing remove script."),
-               INSTALLATION_FAIL("Installation failed."),
-               INSTALL_CANCELED("Installation canceled."),
-               INSTALLED_VERSION_IS_HIGH("Installation progress failed due to high installed package version."),
-               CANNOT_CREATE_FILE("File creation failed."),
-               THREAD_INTERRUPTED("Thread execution interrupted."),
-               CIRCULAR_PACKAGE_DEPENDENCY("Circular package dependency detected."),
-               
-               //Configuration file error
-               CONFIG_CANNOT_PARSING_PACKAGE_LIST("Package list cannot be read. Check the repository or proxy server."),
-               CONFIG_CANNOT_FIND_PACKAGE_LIST_FILE_IN_REPOSITORY("Cannot get the package information. " +
-                               "\nPlease check your repository or SDK image file."),
-               CONFIG_CANNOT_REMOVE_CONFLICT_PACKAGES("Conflict package removal failed."),
-               CONFIG_CANNOT_REMOVE_UPDATABLE_PACKAGES("Updatable package removal failed."),
-               CONFIG_CANNOT_READ_SERVER_TYPE("Server type cannot be read. Check the server type in the installmanager.conf file."),
-               CONFIG_CANNOT_FIND_INSTALLED_FILE_LIST("Installation file list not found."),
-               
-               //Package error
-               CANNOT_FIND_REPOSITORY("Cannot find repository. Please check your repository."),
-               PACKAGE_WRONG_SIZE("Package size incorrect."),
-               PACKAGE_WRONG_CHECKSUM("Package file checksum error."),
-               PACKAGE_NOT_EXIST_TO_INSTALL_OR_UNINSTALL("Install or uninstall package not found."),
-               INSTALL_SCRIPT_NOT_EXISTS("Install script files not found."),
-               INSTALL_SCRIPT_FATAL_ERROR("Fatal error occurred while executing install script."),
-               SCRIPT_FATAL_ERROR("Fatal error occurred while executing post script."),
-               
-               // Network error
-               INTERNET_CONNECTION_ERROR("Server connection failed. Check the network status or set InstallManager settings."),
-               SERVER_CONNECTION_TIME_OUT("Server connection timed out."),
-               PROXY_NOT_PROVIDED("Proxy setting missing. Use the '-proxy <proxy-address>:<port>' option."),
-               PROXY_SERVER_IS_WRONG("Proxy server connection failed. Check the proxy server."),
-               PROXY_CONNECT_ERROR("Proxy server connection failed. Check the proxy server."),
-               URL_SECURITY_EXCEPTION("Proxy server URL security error."),
-               UNKNOWN_HOST_EXCEPTION("Fail to resolve host name."),
-               URL_PORT_IS_WRONG("Incorrect port number."),
-               NO_ROUTE_TO_HOST("Server not found. Check the URL."),
-               NOT_LOGGED_IN("Login failed."),
-               NOT_SUPPORT_HTTPS_PROTOCOL("HTTPS not supported."),
-               
-               //Network download error
-               NETWORK_DOWNLOADED_FILE_INCORRECTLY("The downloaded file is invalid."),
-               
-               //proxy
-               PROXY_CANNOT_FIND_SETTING("Cannot find proxy settings."),
-               PROXY_AUTHENTICATION_IS_WRONG("Your authentication is wrong, please enter your correct ID and password."),
-               
-               //Http Socket error message
-               HTTP_ERROR_MESSAGE_403("403 Forbidden is returned by http protocol. " +
-                               "The server can be reached, but the server declined to allow access to the page."),
-               HTTP_ERROR_MESSAGE_401("Server requires authentication."),
-               HTTP_ERROR_MESSAGE_407("Proxy requires Authentication "),
-               HTTP_ERROR_MESSAGE_416("Requested range not satisfiable."),
-               
-               //option
-               WRONG_OPTION("Incorrect option. Check it."),
-               USESNAPSHOT_REPOSITORY_NOT_PROVIDED("Repository setting is missing. Use the '-snapShot <repository>' option."),
-               REPOSITORY_NOT_PROVIDED("Repository setting is missing. Use the '-repository <repository>' option."),
-               PACKAGES_NOT_PROVIDED("Repository setting is missing. Use the '-proxy <repository>' option."),
-               CANNOT_FIND_INSTALLMANAGER_EXECUTABLE_PATH("Cannot find installmanager executable path."),
-               
-               //etc
-               CANNOT_REMOVE_TARGET_DIR("Target directory removal failed."),
-               INSTALLATION_STOP("Required packages for the META package not installed."),
-               UNINSTALLATION_FAIL("Uninstallation failed."),
-               FILE_NOT_FOUND("File not found."),
-               FILE_DO_NOT_HAVE_PERMISSION("Do not have permission for the file."),
-               REMOVE_OLD_SDK_OK("Old SDK uninstallation completed. Restart Install Manager."),
-               INVALID_INSTALL_PATH("Invalid installation path."),
-               DOWNLOAD_AND_EXIT("Packages downloaded successfully. Exit Install Manager."),
-               CANNOT_DOWNLOAD_FILE("File download failed."),
-               CANNOT_FIND_JAVA("\'JAVA\' not found. Check the java installation."),
-               UNKOWN_ERROR("Unknown error."),
-               NO_ERROR("Install Manager error. Send the log file to the Tizen SDK team."),
-               ERROR_TEMP("Information retrieval from the default SDK package server failed.\n In Advanced Configuration, select the package server and distribution."),
-               
-               SNAPSHOT_PATH_IS_NULL("Snapshot path missing."),
-               FAIL_TO_EXTRACT_SDK_IMAGE_FILE("SDK image file extraction failed."),
-               
-               //Using add extra repository dialog
-               SPACE_IN_REPOSITORY_NAME("Name cannot contain spaces."),
-               NOTHING_TO_REPOSITORY_NAME("Name must be more than 1 character long."),
-               HANGUL_IN_REPOSITORY_NAME("Repository name must be in English."),
-               WRONG_PACKAGE_SERVER("Package list files not found. Check the package list files on the package server."),
-               WRONG_PACKAGE_LIST_FORMAT("Mandatory field missing in the package list file."),
-               WRONG_URL_FORMAT_HTTP("URL must begin with 'http://'."),
-               WRONG_URL_FORMAT("Incorrect URL format. Enter the URL in the correct format."),
-               CANNOT_CONNECT_URL_ADDRESS("Connection to the URL failed. Enter the correct URL."),
-               PACKAGE_NOT_IN_EXTENSION_SERVER("Package file not found on the package server."),
-               DUPLICATED_EXTENSION_REPOSITORY("Extension repository URL already exists.\nEnter a different extension repository URL."),
-               DUPLICATED_BUILT_IN_EXTENSION_REPOSITORY("Built-in extension repository URL already exists.\nEnter a different extension repository URL."),
-               DUPLICATED_EXTENSION_REPOSITORY_NAME("Extension repository name already exists.\nEnter a different extension repository name."),
-               DUPLICATED_BUILT_IN_EXTENSION_REPOSITORY_NAME("Built-in extension repository name already exists.\nEnter a different extension repository name.");
-               
-               private String errorMessage = "";
-
-               ErrorCode(String arg) {
-                       errorMessage = arg;
-               }
-
-               public String getErrorMessage() {
-                       return errorMessage;
-               }
-               
-               public void setErrorMessage(String msg) {
-                       errorMessage = msg;
-               }
-               
-               public boolean existErrorMessage() {
-                       if (errorMessage.isEmpty()) {
-                               return false;
-                       } else {
-                               return true;
-                       }
-               }
-               
-       }
-       
-       public enum InfoCode {
-               CANNOT_KILL_PROCESS("Cannot kill the proecss."),
-               RESTART_THE_COMPUTER("Some Tizen SDK components may not work yet.\nPlease restart your computer before using Tizen SDK.");
-               
-               private String infoMessage = "";
-
-               InfoCode(String arg) {
-                       infoMessage = arg;
-               }
-
-               public String getInfoMessage() {
-                       return infoMessage;
-               }
-       }
-       
-       static public boolean isInstallManagerUpdatable = false;
-
-
-       static private ErrorCode mErrorCode = ErrorCode.NO_ERROR;
-       static private boolean mInstallationStatus = true;
-       static private String errorMsg = "";
-       static private InfoCode infoCode = null;
-
-       private static int exitCode = Config.EXITCODE_NORMAL;
-
-       /**
-        * Set error code.
-        * @param errorCode
-        */
-       static public void setError(ErrorCode errorCode) {
-               mErrorCode = errorCode;
-       }
-
-       /**
-        * 
-        * @return Latest error message.
-        */
-       static public String getErrorMessage() {
-               if (mErrorCode != null) {                       
-                       return mErrorCode.getErrorMessage();
-               } else {
-                       return errorMsg;
-               }
-       }
-       
-       static public void setErrorMessage(String msg) {
-               mErrorCode = null; 
-               errorMsg = msg;
-       }
-
-       /** 
-        * @return Latest error code.
-        */
-       static public ErrorCode getErrorCode() {
-               return mErrorCode;
-       }
-       
-       /**
-        * Get information message
-        * @return
-        */
-       static public String getInfoMessage() {
-               return infoCode.getInfoMessage();
-       }
-       
-       /**
-        * Set information message
-        * @param msg
-        */
-       static public void setInfoCode(InfoCode info) {
-               infoCode = info;
-       }
-       
-       static public boolean existInfoMessage() {
-               if (infoCode == null) {
-                       return false;
-               } else {
-                       return true;
-               }
-       }
-
-       /**
-        * Set status of installation.
-        * @param status
-        */
-       static public void setInstallationSuccess(boolean status) {
-               Log.log("Set installation success: "+status);
-               if (status == true) {
-                       mErrorCode = null;
-               }
-               mInstallationStatus = status;
-       }
-
-       /**
-        * Get status of installation.
-        * @return
-        */
-       static public boolean checkInstallationSuccess() {
-               return mInstallationStatus;
-       }
-
-       /**
-        * Get error message of e
-        * @param e
-        * @return
-        */
-       public static String getMessage(ErrorCode e) {
-               return e.getErrorMessage();
-       }
-
-       /**
-        * Sets exit code to be used on exit
-        * @param exitCode
-        */
-       public static void setExitCode(int exitCode) {
-               ErrorController.exitCode = exitCode;
-       }
-
-       /**
-        * Gets exit code to be used on exit
-        */
-       public static int getExitCode() {
-               return ErrorController.exitCode;
-       }
-}
+/*\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;\r
+\r
+import org.tizen.installmanager.core.Config;\r
+\r
+/**\r
+ * This class manages error codes and states\r
+ *\r
+ * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+ */\r
+public class ErrorController {\r
+       /**\r
+        * Define case of error\r
+        *\r
+        * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+        *\r
+        */\r
+       public enum ErrorCode {\r
+               CANNOT_FIND_CONFIG_FILE("The installmanager.conf file not found."),\r
+               CANNOT_FIND_FILE_IN_REPOSITROY("Cannot find file in repository."),\r
+               CANNOT_CREATE_DOWNLOAD_FILE("Download file cannot be created."),\r
+               CANNOT_CHECK_INSTLLED_FILE_LIST("Installed file list cannot be checked."),\r
+               CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY("File cannot be moved to the target directory."),\r
+               CANNOT_CONNECT_TO_PROXY_SERVER("Proxy server connection fails."),\r
+               WRONG_PACKAGE_URL("Package URLs are invalid."),\r
+               CANCEL("Download canceled."),\r
+               UNKNOWN_ERROR("Unknown error."),\r
+               UNKNOWN_PACKAGE_EXTENSION("Package extension not supported."),\r
+               INVALID_PACKAGE_VERSION("Invalid package version."),\r
+               CANNOT_FIND_PACKAGE_VERSION("Package version not found."),\r
+               CANNOT_FIND_INSTALLABLE_OR_REMOVABLE_PACKAGES("Install or uninstall packages not found. Network connection may have failed."),\r
+               CANNOT_FIND_FILE_IN_LOCAL("Local file not found."),\r
+               CANNOT_SAVE_CONFIG("Configuration file cannot be saved."),\r
+               CANNOT_CREATE_SHORTCUT("Shortcut creation is failed."),\r
+               CANNOT_CREATE_TSUDO("tsudo creation is failed."),\r
+               CANNOT_CREATE_INSTALL_LIST("Install list creation failed."),\r
+               CANNOT_CREATE_CONFIG_FILE("Configuration directory or file creation failed."),\r
+               CANNOT_FIND_USER_CONFIG_FILE("User configuration file creation failed."),\r
+               CANNOT_REGISTER_TARGET_DIR("Target directory registration failed."),\r
+               CANNOT_PARSING_TEXT("Configuration file parsing failed."),\r
+               CANNOT_SAVE_PROPERTY_FILE("The installmanager.conf or Package file cannot be saved."),\r
+               CANNOT_UNPACK_PACKAGE("The package zip file unpackaging failed."),\r
+               CANNOT_CREATE_RESOURCE("Resource file creation failed."),\r
+               CANNOT_FIND_PACKAGE("Required packages not found. The package server may be invalid."),\r
+               CANNOT_REMOVE_PACKAGE("Package removal failed."),\r
+               CANNOT_REMOVE_MISSING_PACKAGE("Missing package cannot be removed."),\r
+               FIND_MISSING_FILES("Some files are not installed properly."),\r
+               CANNOT_ACCESS_FILE("File access failed."),\r
+               CANNOT_REMOVE_OLDSDK("Old SDK removal failed."),\r
+               COPY_FILE_IS_FAIL("Copying the file to the target directory failed."),\r
+               OLD_TIZEN_SDK_EXISTS("Old Tizen SDK is installed. Remove the old SDK and run the Tizen SDK Install Manager again."),\r
+               UNSUPPORTED_PLATFORM("Platform not supported."),\r
+               REMOVE_SCRIPT_NOT_EXISTS("Removal script not found."),\r
+               REMOVE_SCRIPT_FATAL_ERROR("Fatal error occurred while executing remove script."),\r
+               INSTALLATION_FAIL("Installation failed."),\r
+               INSTALL_CANCELED("Installation canceled."),\r
+               INSTALLED_VERSION_IS_HIGH("Installation progress failed due to high installed package version."),\r
+               CANNOT_CREATE_FILE("File creation failed."),\r
+               THREAD_INTERRUPTED("Thread execution interrupted."),\r
+               CIRCULAR_PACKAGE_DEPENDENCY("Circular package dependency detected."),\r
+               \r
+               //Configuration file error\r
+               CONFIG_CANNOT_PARSING_PACKAGE_LIST("Package list cannot be read. Check the repository or proxy server."),\r
+               CONFIG_CANNOT_FIND_PACKAGE_LIST_FILE_IN_REPOSITORY("Cannot get the package information. " +\r
+                               "\nPlease check your repository or SDK image file."),\r
+               CONFIG_CANNOT_REMOVE_CONFLICT_PACKAGES("Conflict package removal failed."),\r
+               CONFIG_CANNOT_REMOVE_UPDATABLE_PACKAGES("Updatable package removal failed."),\r
+               CONFIG_CANNOT_READ_SERVER_TYPE("Server type cannot be read. Check the server type in the installmanager.conf file."),\r
+               CONFIG_CANNOT_FIND_INSTALLED_FILE_LIST("Installation file list not found."),\r
+               \r
+               //Package error\r
+               CANNOT_FIND_REPOSITORY("Cannot find repository. Please check your repository."),\r
+               PACKAGE_WRONG_SIZE("Package size incorrect."),\r
+               PACKAGE_WRONG_CHECKSUM("Package file checksum error."),\r
+               PACKAGE_NOT_EXIST_TO_INSTALL_OR_UNINSTALL("Install or uninstall package not found."),\r
+               INSTALL_SCRIPT_NOT_EXISTS("Install script files not found."),\r
+               INSTALL_SCRIPT_FATAL_ERROR("Fatal error occurred while executing install script."),\r
+               SCRIPT_FATAL_ERROR("Fatal error occurred while executing post script."),\r
+               \r
+               // Network error\r
+               INTERNET_CONNECTION_ERROR("Server connection failed. Check the network status or set InstallManager settings."),\r
+               SERVER_CONNECTION_TIME_OUT("Server connection timed out."),\r
+               PROXY_NOT_PROVIDED("Proxy setting missing. Use the '-proxy <proxy-address>:<port>' option."),\r
+               PROXY_SERVER_IS_WRONG("Proxy server connection failed. Check the proxy server."),\r
+               PROXY_CONNECT_ERROR("Proxy server connection failed. Check the proxy server."),\r
+               URL_SECURITY_EXCEPTION("Proxy server URL security error."),\r
+               UNKNOWN_HOST_EXCEPTION("Fail to resolve host name."),\r
+               URL_PORT_IS_WRONG("Incorrect port number."),\r
+               NO_ROUTE_TO_HOST("Server not found. Check the URL."),\r
+               NOT_LOGGED_IN("Login failed."),\r
+               NOT_SUPPORT_HTTPS_PROTOCOL("HTTPS not supported."),\r
+               \r
+               //Network download error\r
+               NETWORK_DOWNLOADED_FILE_INCORRECTLY("The downloaded file is invalid."),\r
+               \r
+               //proxy\r
+               PROXY_CANNOT_FIND_SETTING("Cannot find proxy settings."),\r
+               PROXY_AUTHENTICATION_IS_WRONG("Your authentication is wrong, please enter your correct ID and password."),\r
+               \r
+               //Http Socket error message\r
+               HTTP_ERROR_MESSAGE_403("403 Forbidden is returned by http protocol. " +\r
+                               "The server can be reached, but the server declined to allow access to the page."),\r
+               HTTP_ERROR_MESSAGE_401("Server requires authentication."),\r
+               HTTP_ERROR_MESSAGE_407("Proxy requires Authentication "),\r
+               HTTP_ERROR_MESSAGE_416("Requested range not satisfiable."),\r
+               \r
+               //option\r
+               WRONG_OPTION("Incorrect option. Check it."),\r
+               USESNAPSHOT_REPOSITORY_NOT_PROVIDED("Repository setting is missing. Use the '-snapShot <repository>' option."),\r
+               REPOSITORY_NOT_PROVIDED("Repository setting is missing. Use the '-repository <repository>' option."),\r
+               PACKAGES_NOT_PROVIDED("Repository setting is missing. Use the '-proxy <repository>' option."),\r
+               CANNOT_FIND_INSTALLMANAGER_EXECUTABLE_PATH("Cannot find installmanager executable path."),\r
+               \r
+               //etc\r
+               CANNOT_REMOVE_TARGET_DIR("Target directory removal failed."),\r
+               INSTALLATION_STOP("Required packages for the META package not installed."),\r
+               UNINSTALLATION_FAIL("Uninstallation failed."),\r
+               FILE_NOT_FOUND("File not found."),\r
+               FILE_DO_NOT_HAVE_PERMISSION("Do not have permission for the file."),\r
+               REMOVE_OLD_SDK_OK("Old SDK uninstallation completed. Restart Install Manager."),\r
+               INVALID_INSTALL_PATH("Invalid installation path."),\r
+               DOWNLOAD_AND_EXIT("Packages downloaded successfully. Exit Install Manager."),\r
+               CANNOT_DOWNLOAD_FILE("File download failed."),\r
+               CANNOT_FIND_JAVA("\'JAVA\' not found. Check the java installation."),\r
+               UNKOWN_ERROR("Unknown error."),\r
+               NO_ERROR("Install Manager error. Send the log file to the Tizen SDK team."),\r
+               ERROR_TEMP("Information retrieval from the default SDK package server failed.\n In Advanced Configuration, select the package server and distribution."),\r
+               \r
+               SNAPSHOT_PATH_IS_NULL("Snapshot path missing."),\r
+               FAIL_TO_EXTRACT_SDK_IMAGE_FILE("SDK image file extraction failed."),\r
+               \r
+               //Using add extra repository dialog\r
+               SPACE_IN_REPOSITORY_NAME("Name cannot contain spaces."),\r
+               NOTHING_TO_REPOSITORY_NAME("Name must be more than 1 character long."),\r
+               HANGUL_IN_REPOSITORY_NAME("Repository name must be in English."),\r
+               WRONG_PACKAGE_SERVER("Package list files not found. Check the package list files on the package server."),\r
+               WRONG_PACKAGE_LIST_FORMAT("Mandatory field missing in the package list file."),\r
+               WRONG_URL_FORMAT_HTTP("URL must begin with 'http://'."),\r
+               WRONG_URL_FORMAT("Incorrect URL format. Enter the URL in the correct format."),\r
+               CANNOT_CONNECT_URL_ADDRESS("Connection to the URL failed. Enter the correct URL."),\r
+               PACKAGE_NOT_IN_EXTENSION_SERVER("Package file not found on the package server."),\r
+               DUPLICATED_EXTENSION_REPOSITORY("Extension repository URL already exists.\nEnter a different extension repository URL."),\r
+               DUPLICATED_BUILT_IN_EXTENSION_REPOSITORY("Built-in extension repository URL already exists.\nEnter a different extension repository URL."),\r
+               DUPLICATED_EXTENSION_REPOSITORY_NAME("Extension repository name already exists.\nEnter a different extension repository name."),\r
+               DUPLICATED_BUILT_IN_EXTENSION_REPOSITORY_NAME("Built-in extension repository name already exists.\nEnter a different extension repository name.");\r
+               \r
+               private String errorMessage = "";\r
+\r
+               ErrorCode(String arg) {\r
+                       errorMessage = arg;\r
+               }\r
+\r
+               public String getErrorMessage() {\r
+                       return errorMessage;\r
+               }\r
+               \r
+               public void setErrorMessage(String msg) {\r
+                       errorMessage = msg;\r
+               }\r
+               \r
+               public boolean existErrorMessage() {\r
+                       if (errorMessage.isEmpty()) {\r
+                               return false;\r
+                       } else {\r
+                               return true;\r
+                       }\r
+               }\r
+               \r
+       }\r
+       \r
+       public enum InfoCode {\r
+               CANNOT_KILL_PROCESS("Cannot kill the proecss."),\r
+               RESTART_THE_COMPUTER("Some Tizen SDK components may not work yet.\nPlease restart your computer before using Tizen SDK.");\r
+               \r
+               private String infoMessage = "";\r
+\r
+               InfoCode(String arg) {\r
+                       infoMessage = arg;\r
+               }\r
+\r
+               public String getInfoMessage() {\r
+                       return infoMessage;\r
+               }\r
+       }\r
+       \r
+       static public boolean isInstallManagerUpdatable = false;\r
+\r
+\r
+       static private ErrorCode mErrorCode = ErrorCode.NO_ERROR;\r
+       static private boolean mInstallationStatus = true;\r
+       static private String errorMsg = "";\r
+       static private InfoCode infoCode = null;\r
+\r
+       private static int exitCode = Config.EXITCODE_NORMAL;\r
+\r
+       /**\r
+        * Set error code.\r
+        * @param errorCode\r
+        */\r
+       static public void setError(ErrorCode errorCode) {\r
+               mInstallationStatus = false;\r
+               mErrorCode = errorCode;\r
+       }\r
+\r
+       /**\r
+        * \r
+        * @return Latest error message.\r
+        */\r
+       static public String getErrorMessage() {\r
+               if (mErrorCode != null) {                       \r
+                       return mErrorCode.getErrorMessage();\r
+               } else {\r
+                       return errorMsg;\r
+               }\r
+       }\r
+       \r
+       static public void setErrorMessage(String msg) {\r
+               mInstallationStatus = false;\r
+               mErrorCode = null; \r
+               errorMsg = msg;\r
+       }\r
+\r
+       /** \r
+        * @return Latest error code.\r
+        */\r
+       static public ErrorCode getErrorCode() {\r
+               return mErrorCode;\r
+       }\r
+       \r
+       /**\r
+        * Get information message\r
+        * @return\r
+        */\r
+       static public String getInfoMessage() {\r
+               return infoCode.getInfoMessage();\r
+       }\r
+       \r
+       /**\r
+        * Set information message\r
+        * @param msg\r
+        */\r
+       static public void setInfoCode(InfoCode info) {\r
+               infoCode = info;\r
+       }\r
+       \r
+       static public boolean existInfoMessage() {\r
+               if (infoCode == null) {\r
+                       return false;\r
+               } else {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Set status of installation.\r
+        * @param status\r
+        */\r
+       static public void setInstallationSuccess(boolean status) {\r
+               Log.log("Set installation success: "+status);\r
+               if (status == true) {\r
+                       mErrorCode = null;\r
+               }\r
+               mInstallationStatus = status;\r
+       }\r
+\r
+       /**\r
+        * Get status of installation.\r
+        * @return\r
+        */\r
+       static public boolean checkInstallationSuccess() {\r
+               return mInstallationStatus;\r
+       }\r
+\r
+       /**\r
+        * Get error message of e\r
+        * @param e\r
+        * @return\r
+        */\r
+       public static String getMessage(ErrorCode e) {\r
+               return e.getErrorMessage();\r
+       }\r
+\r
+       /**\r
+        * Sets exit code to be used on exit\r
+        * @param exitCode\r
+        */\r
+       public static void setExitCode(int exitCode) {\r
+               ErrorController.exitCode = exitCode;\r
+       }\r
+\r
+       /**\r
+        * Gets exit code to be used on exit\r
+        */\r
+       public static int getExitCode() {\r
+               return ErrorController.exitCode;\r
+       }\r
+}\r
index b5a9f6f..da4148c 100644 (file)
@@ -1,97 +1,69 @@
-/*
-*  InstallManager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: 
-* Wooyoung Cho <wooyoung1.cho@samsung.com>
-* Shihyun Kim <shihyun.kim@samsung.com>
-* Taeyoung Son <taeyoung2.son@samsung.com>
-* Yongsung kim <yongsung1.kim@samsung.com>
-* 
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/ 
-
-package org.tizen.installmanager.lib;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-/**
- * If you want to express in UI, implement this interface and exchange information from this.
- * 
- * @author Shihyun Kim <shihyun.kim@samsung.com>
- *
- */
-public interface IIMProgressMonitor extends IProgressMonitor{
-       
-       /**
-        * Display title of progress bar.
-        * @param title
-        */
-       public void workedTitle(String title);
-       
-       /**
-        * Display title of progress bar.
-        * @param title
-        */
-       public void workedChecksum(String title);
-       
-       /**
-        * Display subtitle of progress bar.
-        */
-       public void workedSubTitle(String subTitle);
-       
-       /**
-        * Display download size to UI.
-        * @param size
-        */
-       public void workedDownload(long size);
-       /**
-        * Display checksum size to UI.
-        * @param size
-        */
-       public void workedChecksum(final long size);
-       
-       /**
-        * Refresh worked size.
-        */
-       public void workedRefresh();
-       /**
-        * Set start time to download.
-        * It can be used remaining time or download speed.
-        * @param startTime
-        */
-       public void setDownloadStartTime(long startTime);
-       /**
-        * Display progressbar to UI.
-        * @param percent
-        */
-    public void workedProgressbar(int percent);
-    public void setError(int errorCode);
-
-    /**
-     * Set progress package name to title.
-     * @param title
-     */
-       void workedProcess(String title);
-
-       /**
-        * Set file name to download.
-        * @param title
-        */
-       void workedDownload(String title);
-}
+/*\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;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+\r
+/**\r
+ * If you want to express in UI, implement this interface and exchange information from this.\r
+ * \r
+ * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+ *\r
+ */\r
+public interface IIMProgressMonitor extends IProgressMonitor{\r
+       \r
+       /**\r
+        * Display title of progress bar.\r
+        * @param title\r
+        */\r
+       public void workedTitle(String title);\r
+\r
+       /**\r
+        * Display download progress.\r
+        * @param fileName\r
+        * @param progressNumber\r
+        */\r
+       public void workedDownloadProgress(String fileName, int progressNumber);\r
+       public void workedDownloadSize(long size);\r
+       \r
+       /**\r
+        * Display install progress.\r
+        * @param fileName\r
+        * @param progressNumber\r
+        */\r
+       public void workedInstallProgress(String fileName, int progressNumber);\r
+       void workedInstallSize(long size);\r
+       \r
+       /**\r
+        * Refresh worked size.\r
+        */\r
+       public void workedRefresh();\r
+\r
+    public void setError(int errorCode);\r
+}\r
index 62e707c..62eb494 100644 (file)
-/*
-*  InstallManager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: 
-* Wooyoung Cho <wooyoung1.cho@samsung.com>
-* Shihyun Kim <shihyun.kim@samsung.com>
-* Taeyoung Son <taeyoung2.son@samsung.com>
-* Yongsung kim <yongsung1.kim@samsung.com>
-* 
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/ 
-
-package org.tizen.installmanager.lib.linux;
-
-import java.io.File;
-
-import org.tizen.installmanager.core.IMFatalException;
-import org.tizen.installmanager.lib.IIMProgressMonitor;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.lib.SDKPackageFormat;
-import org.tizen.installmanager.lib.ErrorController.ErrorCode;
-import org.tizen.installmanager.util.IMShellCommandFail;
-import org.tizen.installmanager.util.PathUtil;
-import org.tizen.installmanager.util.ShellUtil;
-
-
-/**
- * Manages to unpack package of tizen sdk for linux.
- * @author Shihyun Kim <shihyun.kim@samsung.com>
- *
- */
-public class LinuxSDKPackageFormat extends SDKPackageFormat{
-       private PackageType checkExtension;
-    
-    @Override
-    public long unZip(File fileFullPath, File targetDir, IIMProgressMonitor monitor) {
-        Log.log("Unpack "+fileFullPath+" to "+targetDir);
-        
-        checkExtension = getPackageType(fileFullPath.getAbsolutePath());
-        
-        if (!fileFullPath.exists()) {
-               Log.err("Package file is not exsisting");
-               return ERROR;
-        } else if (checkExtension == PackageType.ELSE) {
-               Log.err("Package extension is not '.zip' or '.tar.gz'");
-               return ERROR;
-        }
-        
-        if (targetDir == null || !targetDir.isAbsolute()) {
-               return ERROR;
-        }
-
-        if (!targetDir.exists()) {
-               if (targetDir.mkdirs()) {
-                       Log.log("Success to create directory ==> " + targetDir);
-               } else {
-                       Log.err("Fail to create directory ==> " + targetDir);
-               }
-        }
-
-        int exitValue;
-        
-       try {
-               if (checkExtension == PackageType.ZIP) {
-                       exitValue = sendCommand( "unzip -o "+ fileFullPath.getAbsolutePath() + " -d " + targetDir.getAbsolutePath(),
-                                       fileFullPath.getAbsolutePath(), PackageType.ZIP, monitor);
-                       unzipReturnValue(exitValue);
-               } else if (checkExtension == PackageType.TAR_GZ) {
-                       exitValue = sendCommand( "tar xvf "+ fileFullPath.getAbsolutePath() + " -C " + targetDir.getAbsolutePath(),
-                                       fileFullPath.getAbsolutePath(), PackageType.TAR_GZ, monitor);
-                       tarReturnValue(exitValue);
-               } else {
-                       throw new IMFatalException(ErrorCode.UNKNOWN_PACKAGE_EXTENSION);
-               }
-               } catch (IMShellCommandFail e) {
-                       return ERROR;
-               }
-       
-       if (monitor != null) {
-               monitor.workedSubTitle("");
-       }
-
-        return SUCCESS;
-    }
-    
-    private int sendCommand(String command, String path, PackageType type, IIMProgressMonitor monitor) throws IMShellCommandFail {
-       LinuxShellInstalledListParser parser = null;
-       String fileName = PathUtil.getFileName(path);
-       
-       if (mFileOutput != null) {
-               parser = new LinuxShellInstalledListParser(fileName, type);
-               parser.setFileOutputStream(mFileOutput);
-               parser.setProgress(monitor);
-       }
-       
-       int exitValue = ShellUtil.execute(command, null, null, parser);
-       
-       return exitValue;
-    }
-    
-    /**
-     * extract tar error case.
-     * @param exitValue
-     * @return
-     * @throws IMShellCommandFail
-     */
-       private static boolean tarReturnValue(int exitValue) throws IMShellCommandFail {
-               if (exitValue == 0) {
-                       return true;
-               } else {
-                       throw new IMShellCommandFail();
-               }
-       }
-    
-    /**
-     * extract zip error case.
-     * @param exitValue
-     * @return
-     * @throws IMShellCommandFail
-     */
-       private static boolean unzipReturnValue(int exitValue) throws IMShellCommandFail {
-               switch(exitValue) {
-               case 0:
-                       return true;
-               case 1:
-                       Log.err("one or more warning errors were encountered, but processing completed  successfully  anyway." +
-                                       "This  includes  zipfiles  where one or more files was skipped due to unsupported compression " +
-                                       "method or encryption with an unknown password.");
-                       throw new IMShellCommandFail();
-               case 2:
-                       Log.err("a generic error in the zipfile format was detected.  Processing may have completed" +
-                                       "successfully anyway; some broken zipfiles created by other archivers have simple work-arounds.");
-                       throw new IMShellCommandFail();
-               case 3:
-                       Log.err("a severe error in the zipfile format was detected.  Processing probably failed immediately.");
-                       throw new IMShellCommandFail();
-               case 4:
-                       Log.err("unzip was unable to allocate memory for one or more buffers during program initialization.");
-                       throw new IMShellCommandFail();
-               case 5:
-                       Log.err("unzip was unable to allocate memory or unable to obtain a tty to read the decryption password(s).");
-                       throw new IMShellCommandFail();
-               case 6:
-                       Log.err("unzip was unable to allocate memory during decompression to disk.");
-                       throw new IMShellCommandFail();
-               case 7:
-                       Log.err("unzip was unable to allocate memory during in-memory decompression.");
-                       throw new IMShellCommandFail();
-               case 8:
-                       Log.err("[currently not used]");
-                       throw new IMShellCommandFail();
-               case 9:
-                       Log.err("the specified zipfiles were not found.");
-                       throw new IMShellCommandFail();
-               case 10:
-                       Log.err("invalid options were specified on the command line.");
-                       throw new IMShellCommandFail();
-               case 11:
-                       Log.err("no matching files were found.");
-                       throw new IMShellCommandFail();
-               case 50:
-                       Log.err("the disk is (or was) full during extraction.");
-                       throw new IMShellCommandFail();
-               case 51:
-                       Log.err("the end of the ZIP archive was encountered prematurely.");
-                       throw new IMShellCommandFail();
-               case 80:
-                       Log.err("the user aborted unzip prematurely with control-C (or similar)");
-                       throw new IMShellCommandFail();
-               case 81:
-                       Log.err("testing or extraction of one or more files failed due to unsupported compression methods  or unsupported decryption.");
-                       throw new IMShellCommandFail();
-               case 82:
-                       Log.err("no  files  were  found due to bad decryption password(s).  (If even one file is successfully" +
-                     "processed, however, the exit status is 1.)");
-                       throw new IMShellCommandFail();
-               default:
-                       Log.err("Unknown exit value");
-                       throw new IMFatalException("Unknown exit value after unzip");
-               }
-       }
-}
+/*\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.PathUtil;\r
+import org.tizen.installmanager.util.ShellUtil;\r
+\r
+\r
+/**\r
+ * Manages to unpack package of tizen sdk for linux.\r
+ * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+ *\r
+ */\r
+public class LinuxSDKPackageFormat extends SDKPackageFormat{\r
+       private PackageType checkExtension;\r
+    \r
+    @Override\r
+    public long unZip(File fileFullPath, File targetDir, 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;\r
+        \r
+       try {\r
+               if (checkExtension == PackageType.ZIP) {\r
+                       exitValue = sendCommand( "unzip -o "+ fileFullPath.getAbsolutePath() + " -d " + targetDir.getAbsolutePath(),\r
+                                       fileFullPath.getAbsolutePath(), PackageType.ZIP, monitor);\r
+                       unzipReturnValue(exitValue);\r
+               } else if (checkExtension == PackageType.TAR_GZ) {\r
+                       exitValue = sendCommand( "tar xvf "+ fileFullPath.getAbsolutePath() + " -C " + targetDir.getAbsolutePath(),\r
+                                       fileFullPath.getAbsolutePath(), PackageType.TAR_GZ, monitor);\r
+                       tarReturnValue(exitValue);\r
+               } else {\r
+                       throw new IMFatalException(ErrorCode.UNKNOWN_PACKAGE_EXTENSION);\r
+               }\r
+               } catch (IMShellCommandFail e) {\r
+                       return ERROR;\r
+               }\r
+       \r
+       if (monitor != null) {\r
+               monitor.workedDownloadProgress("", 0);\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
+       String fileName = PathUtil.getFileName(path);\r
+       \r
+       if (mFileOutput != null) {\r
+               parser = new LinuxShellInstalledListParser(fileName, 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
+     * @param exitValue\r
+     * @return\r
+     * @throws IMShellCommandFail\r
+     */\r
+       private static boolean tarReturnValue(int exitValue) 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
+     * @param exitValue\r
+     * @return\r
+     * @throws IMShellCommandFail\r
+     */\r
+       private static boolean unzipReturnValue(int exitValue) 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 7140c7a..56d5caa 100644 (file)
-/*
-*  InstallManager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: 
-* Wooyoung Cho <wooyoung1.cho@samsung.com>
-* Shihyun Kim <shihyun.kim@samsung.com>
-* Taeyoung Son <taeyoung2.son@samsung.com>
-* Yongsung kim <yongsung1.kim@samsung.com>
-* 
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/ 
-
-package org.tizen.installmanager.lib.linux;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import org.tizen.installmanager.core.Config;
-import org.tizen.installmanager.core.IMFatalException;
-import org.tizen.installmanager.lib.IIMProgressMonitor;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.lib.Platform;
-import org.tizen.installmanager.lib.ShellParser;
-import org.tizen.installmanager.lib.ErrorController.ErrorCode;
-import org.tizen.installmanager.lib.SDKPackageFormat.PackageType;
-import org.tizen.installmanager.util.PathUtil;
-
-
-/**
- * Parsing standard out message and save installed file list.
- * @author Shihyun Kim <shihyun.kim@samsung.com>
- *
- */
-public class LinuxShellInstalledListParser extends ShellParser {
-       
-
-       IIMProgressMonitor mMonitor = null;
-       FileOutputStream mFileOut = null;
-       
-       public static final String FILE_PATH_SEPARATOR = ":";
-       private String fileName;
-       private PackageType extension;
-       
-       LinuxShellInstalledListParser(String name, PackageType type) {
-               fileName = name;
-               extension = type;
-       }
-
-       @Override
-       public void parseStdOut(InputStream input) {
-               // TODO Auto-generated method stub
-
-               BufferedReader br = null;
-               try {
-            InputStreamReader isr = new InputStreamReader(input, Platform.CURRENT_CHARSET);
-            br = new BufferedReader(isr);
-            
-            setMonitorFile();
-            
-            String line;
-            while ( (line = br.readLine()) != null) {
-                print(line);
-            }
-            
-            closeFileOutputStream();
-        } catch (IOException ioe) {
-               Log.err("Cannot parse shell input stream.");
-        }finally{
-               if (br != null) {
-                               try {                                   
-                                       br.close();
-                               } catch (IOException e) {
-                                       // TODO Auto-generated catch block
-                                       Log.err("LinuxShellInstalledListParser fail to close fileoutput");
-                               } 
-                       }
-        }
-       }
-       
-       private void setMonitorFile() {
-       if (mMonitor != null) {
-               mMonitor.workedSubTitle(fileName);
-       }               
-       }
-       
-       private void print(String line) {
-               printToProgressBar(line);
-       printToFile(line);
-    }
-    
-    private void printToProgressBar(String line) {     
-       if (mMonitor != null) {
-               String name = PathUtil.getFileName(line);
-               
-               mMonitor.workedSubTitle(name);
-       }
-    }
-    
-    private void printToFile(String line) {
-       if (mFileOut == null) {
-               return;
-       }
-       
-       String filePath = "";
-       if (extension == PackageType.ZIP) {
-               filePath = getFilePathFromValue(line);                  
-       } else if (extension == PackageType.TAR_GZ) {
-               filePath = PathUtil.getFromInstalledPath(Config.TEMP_DIRECTORY, line);
-       }
-
-       try {                   
-               String dataDir = PathUtil.getFromInstalledPath(Config.TEMP_DIRECTORY, Config.DATA_DIRECTORY); 
-               if (filePath.length() <= dataDir.length() || filePath.indexOf(dataDir) < 0) {
-                       return;
-               }
-               
-               int index = dataDir.length() + 1;
-
-               filePath = filePath.substring(index).trim();  
-               if (!filePath.equals("")) {
-                       filePath = filePath + "\n";
-                       mFileOut.write(filePath.getBytes());
-               }
-               } catch (IOException e) {
-                       // TODO Auto-generated catch block
-                       Log.err("File write failure(" + filePath + ")");
-                       Log.err(e.getMessage());
-                       throw new IMFatalException("File write failure(" + filePath + ")");
-               }
-    }
-    
-    private String getFilePathFromValue(String line) {
-       String value = getValue(line);
-       
-       if (value.length() <= 0) {
-               return "";
-       }
-       
-       String seperator = "";
-       if (isCreatingFile(line)) {
-               return value.trim();
-       } else if (isLinkingFile(line)) {
-               seperator = "->";
-       } else {
-               seperator = "[";
-       }
-       
-       int index = value.lastIndexOf(seperator);
-       
-       if (index < 0) {
-               return value.trim();
-       }
-       
-       return value.substring(0, index).trim();
-    }
-    
-    private String getKey(String line) {
-       int index = line.indexOf(FILE_PATH_SEPARATOR);
-       
-       if (index < 0 ){
-               return "";
-       }
-       
-       return line.substring(0, index).trim();
-    }
-    
-    private String getValue(String line) {     
-       int index = line.indexOf(FILE_PATH_SEPARATOR);
-       
-       if (index < 0 ){
-               return "";
-       }
-       
-       return line.substring(index+1).trim();
-    }
-    
-    /**
-     * set file output for saving installed list
-     * @param path
-     */
-    public void setFileOutputStream(String path) {
-       setFileOutputStream(new File(path));
-    }
-    
-    /**
-     * set file output for saving installed list
-     * @param filePath
-     */
-    public void setFileOutputStream(File filePath) {
-       File parentFile = filePath.getParentFile();
-       
-       if (!parentFile.exists()) {
-               if (parentFile.mkdirs()) {
-                       Log.log("Success to create directory ==> " + parentFile);
-               } else {
-                       Log.err("Fail to create directory ==> " + parentFile);
-               }
-       }
-       
-       if (filePath.exists()) {
-               if (filePath.delete()) {
-                       Log.log("Success to delete directory ==> " + filePath);
-               } else {
-                       Log.err("Fail to delete directory ==> " + filePath);
-               }
-       }
-       
-       
-               try {
-                       filePath.createNewFile();
-               } catch (IOException e) {
-                       Log.err("Cannot create install list => " + filePath.getAbsolutePath());
-                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_INSTALL_LIST);
-               }
-       
-       try {
-                       mFileOut = new FileOutputStream(filePath);
-               } catch (FileNotFoundException e) {
-                       Log.err("Cannot create install list => " + filePath.getAbsolutePath());
-                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_INSTALL_LIST);
-               }
-    }
-       
-    /**
-     * set file output for saving installed list
-     * @param fOut
-     */
-       public void setFileOutputStream(FileOutputStream fOut) {
-               mFileOut = fOut;
-       }
-       
-       /**
-        * close FileOutput instance.
-        */
-       public void closeFileOutputStream() {
-               if(mFileOut != null) {
-                       try {
-                               mFileOut.close();
-                               mFileOut = null;
-                       } catch (IOException e) {
-                               // TODO Auto-generated catch block
-                               Log.err("LinuxShellInstalledListParser fail to close fileoutput.");
-                       }
-               }
-       }
-       
-       /**
-        * If you set this, you can get file name to UI.
-        * @param monitor
-        */
-       public void setProgress(IIMProgressMonitor monitor) {
-               mMonitor = monitor;
-       }
-       
-       private boolean isLinkingFile(String line) {
-               String key = getKey(line);
-               
-               return key.equals("linking");
-       }
-       
-       private boolean isCreatingFile(String line) {
-               String key = getKey(line);
-               
-               return key.equals("creating");
-       }
-       
-}
+/*\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.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileNotFoundException;\r
+import java.io.FileOutputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.InputStreamReader;\r
+\r
+import org.tizen.installmanager.core.Config;\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.Platform;\r
+import org.tizen.installmanager.lib.ShellParser;\r
+import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
+import org.tizen.installmanager.lib.SDKPackageFormat.PackageType;\r
+import org.tizen.installmanager.util.PathUtil;\r
+\r
+\r
+/**\r
+ * Parsing standard out message and save installed file list.\r
+ * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+ *\r
+ */\r
+public class LinuxShellInstalledListParser extends ShellParser {\r
+       \r
+\r
+       IIMProgressMonitor mMonitor = null;\r
+       FileOutputStream mFileOut = null;\r
+       \r
+       public static final String FILE_PATH_SEPARATOR = ":";\r
+       private String fileName;\r
+       private PackageType extension;\r
+       \r
+       LinuxShellInstalledListParser(String name, PackageType type) {\r
+               fileName = name;\r
+               extension = type;\r
+       }\r
+\r
+       @Override\r
+       public void parseStdOut(InputStream input) {\r
+               // TODO Auto-generated method stub\r
+\r
+               BufferedReader br = null;\r
+               try {\r
+            InputStreamReader isr = new InputStreamReader(input, Platform.CURRENT_CHARSET);\r
+            br = new BufferedReader(isr);\r
+            \r
+            setMonitorFile();\r
+            \r
+            String line;\r
+            while ( (line = br.readLine()) != null) {\r
+                print(line);\r
+            }\r
+            \r
+            closeFileOutputStream();\r
+        } catch (IOException ioe) {\r
+               Log.err("Cannot parse shell input stream.");\r
+        }finally{\r
+               if (br != null) {\r
+                               try {                                   \r
+                                       br.close();\r
+                               } catch (IOException e) {\r
+                                       // TODO Auto-generated catch block\r
+                                       Log.err("LinuxShellInstalledListParser fail to close fileoutput");\r
+                               } \r
+                       }\r
+        }\r
+       }\r
+       \r
+       private void setMonitorFile() {\r
+       if (mMonitor != null) {\r
+               mMonitor.workedInstallProgress(fileName, 0);\r
+       }               \r
+       }\r
+       \r
+       private void print(String line) {\r
+               printToProgressBar(line);\r
+       printToFile(line);\r
+    }\r
+    \r
+    private void printToProgressBar(String line) {     \r
+       if (mMonitor != null) {\r
+               String name = PathUtil.getFileName(line);\r
+               \r
+               mMonitor.workedInstallProgress(name, 0);\r
+       }\r
+    }\r
+    \r
+    private void printToFile(String line) {\r
+       if (mFileOut == null) {\r
+               return;\r
+       }\r
+       \r
+       String filePath = "";\r
+       if (extension == PackageType.ZIP) {\r
+               filePath = getFilePathFromValue(line);                  \r
+       } else if (extension == PackageType.TAR_GZ) {\r
+               filePath = PathUtil.getFromInstalledPath(Config.TEMP_DIRECTORY, line);\r
+       }\r
+\r
+       try {                   \r
+               String dataDir = PathUtil.getFromInstalledPath(Config.TEMP_DIRECTORY, Config.DATA_DIRECTORY); \r
+               if (filePath.length() <= dataDir.length() || filePath.indexOf(dataDir) < 0) {\r
+                       return;\r
+               }\r
+               \r
+               int index = dataDir.length() + 1;\r
+\r
+               filePath = filePath.substring(index).trim();  \r
+               if (!filePath.equals("")) {\r
+                       filePath = filePath + "\n";\r
+                       mFileOut.write(filePath.getBytes());\r
+               }\r
+               } catch (IOException e) {\r
+                       // TODO Auto-generated catch block\r
+                       Log.err("File write failure(" + filePath + ")");\r
+                       Log.err(e.getMessage());\r
+                       throw new IMFatalException("File write failure(" + filePath + ")");\r
+               }\r
+    }\r
+    \r
+    private String getFilePathFromValue(String line) {\r
+       String value = getValue(line);\r
+       \r
+       if (value.length() <= 0) {\r
+               return "";\r
+       }\r
+       \r
+       String seperator = "";\r
+       if (isCreatingFile(line)) {\r
+               return value.trim();\r
+       } else if (isLinkingFile(line)) {\r
+               seperator = "->";\r
+       } else {\r
+               seperator = "[";\r
+       }\r
+       \r
+       int index = value.lastIndexOf(seperator);\r
+       \r
+       if (index < 0) {\r
+               return value.trim();\r
+       }\r
+       \r
+       return value.substring(0, index).trim();\r
+    }\r
+    \r
+    private String getKey(String line) {\r
+       int index = line.indexOf(FILE_PATH_SEPARATOR);\r
+       \r
+       if (index < 0 ){\r
+               return "";\r
+       }\r
+       \r
+       return line.substring(0, index).trim();\r
+    }\r
+    \r
+    private String getValue(String line) {     \r
+       int index = line.indexOf(FILE_PATH_SEPARATOR);\r
+       \r
+       if (index < 0 ){\r
+               return "";\r
+       }\r
+       \r
+       return line.substring(index+1).trim();\r
+    }\r
+    \r
+    /**\r
+     * set file output for saving installed list\r
+     * @param path\r
+     */\r
+    public void setFileOutputStream(String path) {\r
+       setFileOutputStream(new File(path));\r
+    }\r
+    \r
+    /**\r
+     * set file output for saving installed list\r
+     * @param filePath\r
+     */\r
+    public void setFileOutputStream(File filePath) {\r
+       File parentFile = filePath.getParentFile();\r
+       \r
+       if (!parentFile.exists()) {\r
+               if (parentFile.mkdirs()) {\r
+                       Log.log("Success to create directory ==> " + parentFile);\r
+               } else {\r
+                       Log.err("Fail to create directory ==> " + parentFile);\r
+               }\r
+       }\r
+       \r
+       if (filePath.exists()) {\r
+               if (filePath.delete()) {\r
+                       Log.log("Success to delete directory ==> " + filePath);\r
+               } else {\r
+                       Log.err("Fail to delete directory ==> " + filePath);\r
+               }\r
+       }\r
+       \r
+       \r
+               try {\r
+                       filePath.createNewFile();\r
+               } catch (IOException e) {\r
+                       Log.err("Cannot create install list => " + filePath.getAbsolutePath());\r
+                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_INSTALL_LIST);\r
+               }\r
+       \r
+       try {\r
+                       mFileOut = new FileOutputStream(filePath);\r
+               } catch (FileNotFoundException e) {\r
+                       Log.err("Cannot create install list => " + filePath.getAbsolutePath());\r
+                       throw new IMFatalException(ErrorCode.CANNOT_CREATE_INSTALL_LIST);\r
+               }\r
+    }\r
+       \r
+    /**\r
+     * set file output for saving installed list\r
+     * @param fOut\r
+     */\r
+       public void setFileOutputStream(FileOutputStream fOut) {\r
+               mFileOut = fOut;\r
+       }\r
+       \r
+       /**\r
+        * close FileOutput instance.\r
+        */\r
+       public void closeFileOutputStream() {\r
+               if(mFileOut != null) {\r
+                       try {\r
+                               mFileOut.close();\r
+                               mFileOut = null;\r
+                       } catch (IOException e) {\r
+                               // TODO Auto-generated catch block\r
+                               Log.err("LinuxShellInstalledListParser fail to close fileoutput.");\r
+                       }\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * If you set this, you can get file name to UI.\r
+        * @param monitor\r
+        */\r
+       public void setProgress(IIMProgressMonitor monitor) {\r
+               mMonitor = monitor;\r
+       }\r
+       \r
+       private boolean isLinkingFile(String line) {\r
+               String key = getKey(line);\r
+               \r
+               return key.equals("linking");\r
+       }\r
+       \r
+       private boolean isCreatingFile(String line) {\r
+               String key = getKey(line);\r
+               \r
+               return key.equals("creating");\r
+       }\r
+       \r
+}\r
index 8efb885..fd4025a 100644 (file)
-/*
-*  InstallManager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: 
-* Wooyoung Cho <wooyoung1.cho@samsung.com>
-* Shihyun Kim <shihyun.kim@samsung.com>
-* Taeyoung Son <taeyoung2.son@samsung.com>
-* Yongsung kim <yongsung1.kim@samsung.com>
-* 
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/ 
-
-package org.tizen.installmanager.lib.win;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-import org.tizen.installmanager.core.IMFatalException;
-import org.tizen.installmanager.lib.ErrorController;
-import org.tizen.installmanager.lib.IIMProgressMonitor;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.lib.SDKPackageFormat;
-import org.tizen.installmanager.lib.ErrorController.ErrorCode;
-import org.tizen.installmanager.util.PathUtil;
-
-
-/**
- * Manages to unpack package of tizen sdk for windows.
- * @author Shihyun Kim <shihyun.kim@samsung.com>
- *
- */
-public class WindowsSDKPackageFormat extends SDKPackageFormat{
-
-    final static int BUF_SIZE = 65536;
-    
-    private static final String DATA_DIRECTORY = "data/";
-    
-    @Override 
-    public long unZip(File fileFullPath, File targetDir, IIMProgressMonitor monitor) {
-        Log.log("Unzip "+fileFullPath+" to "+targetDir);
-        
-        PackageType checkExtension = getPackageType(fileFullPath.getAbsolutePath());
-        
-        if (!fileFullPath.exists()) {
-               Log.err("Package file is not exsisting");
-               return ERROR;
-        } else if (checkExtension != PackageType.ZIP) {
-               Log.err("Package extension is not '.zip'");
-               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);
-                       }
-               }
-
-               long ret = unZipPackage(fileFullPath, targetDir, monitor);
-        
-        closeFileOutput(); 
-        return ret;
-    }
-    
-       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) {
-                               if (monitor != null) {
-                                       String fileName = PathUtil.getFileName(zipEntry.getName());
-                                       monitor.workedSubTitle(fileName);
-                               }
-
-                               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);
-                                       } 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);
-                                       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 void writeFileList(String filePath) {
-       if (filePath == null || filePath.equals("")) {
-               return;
-       }
-       
-       filePath = removeDataDirectory(filePath);
-       if (filePath == null || filePath.equals("")) {
-               return;
-       }
-       
-       if (mFileOutput == null) {
-               return;
-       }
-       
-       try {
-                       mFileOutput.write((filePath + "\n").getBytes());
-               } catch (IOException e) {
-                       Log.ExceptionLog(e);
-                       Log.err("Fail to unpack " + filePath);
-            throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);
-               }
-    }
-    
-    private String removeDataDirectory(String filePath) {
-       if (filePath == null || filePath.equals("")) {
-               return "";
-       }
-       
-       if (!filePath.startsWith(DATA_DIRECTORY)) {
-               return "";
-       }
-       
-       filePath = filePath.substring(DATA_DIRECTORY.length());
-       return filePath;
-    }
-}
+/*\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.win;\r
+\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileOutputStream;\r
+import java.io.IOException;\r
+import java.util.zip.ZipEntry;\r
+import java.util.zip.ZipInputStream;\r
+\r
+import org.tizen.installmanager.core.IMFatalException;\r
+import org.tizen.installmanager.lib.ErrorController;\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
+\r
+\r
+/**\r
+ * Manages to unpack package of tizen sdk for windows.\r
+ * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+ *\r
+ */\r
+public class WindowsSDKPackageFormat extends SDKPackageFormat{\r
+\r
+    final static int BUF_SIZE = 65536;\r
+    \r
+    private static final String DATA_DIRECTORY = "data/";\r
+    \r
+    @Override \r
+    public long unZip(File fileFullPath, File targetDir, IIMProgressMonitor monitor) {\r
+        Log.log("Unzip "+fileFullPath+" to "+targetDir);\r
+        \r
+        PackageType 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.ZIP) {\r
+               Log.err("Package extension is not '.zip'");\r
+               return ERROR;\r
+        }\r
+        Log.log(fileFullPath + " exists.");\r
+               \r
+               if (targetDir == null || !targetDir.isAbsolute()) {\r
+                       return ERROR;\r
+               }\r
+               \r
+               Log.log(targetDir + " is not null and absolute.");\r
+               \r
+               if (!targetDir.exists()) {\r
+                       Log.log(targetDir + " does not exist. InstallManager will make target directory.");\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
+               long ret = unZipPackage(fileFullPath, targetDir, monitor);\r
+        \r
+        closeFileOutput(); \r
+        return ret;\r
+    }\r
+    \r
+       private long unZipPackage(File fileFullPath, File targetDir, IIMProgressMonitor monitor) {\r
+               ZipInputStream zipInStream = null;\r
+               FileOutputStream zipOutput = null;\r
+               ZipEntry zipEntry = null;\r
+\r
+               try {\r
+                       zipInStream = new ZipInputStream(new FileInputStream(fileFullPath));\r
+                       zipEntry = zipInStream.getNextEntry();\r
+\r
+                       long totalUnZipSize = 0;\r
+                       while (zipEntry != null) {\r
+                               String targetPath = targetDir.getAbsolutePath() + File.separator + zipEntry.getName();\r
+\r
+                               // make directory\r
+                               File targetFile = new File(targetPath);\r
+                               if (targetFile.exists() && targetFile.isDirectory()) {\r
+                                       writeFileList(zipEntry.getName());\r
+                                       zipEntry = zipInStream.getNextEntry();\r
+                                       continue;\r
+                               }\r
+\r
+                               File parentFile = targetFile.getParentFile();\r
+                               if (!parentFile.exists()) {\r
+                                       if (parentFile.mkdirs()) {\r
+                                               Log.log("Success to create parent directory ==> " + parentFile);\r
+                                       } else {\r
+                                               Log.err("Fail to create parent directory ==> " + parentFile);\r
+                                       }\r
+                               }\r
+\r
+                               if (targetPath.endsWith("/")) {// zipEntry.isDirectory\r
+                                       File target = new File(targetPath);\r
+                                       if (target.mkdir()) {\r
+                                               Log.log("Success to create target directory ==> " + target);\r
+                                       } else {\r
+                                               Log.err("Fail to create target directory ==> " + target);\r
+                                       }\r
+                                       zipInStream.closeEntry();\r
+                                       writeFileList(zipEntry.getName());\r
+                                       zipEntry = zipInStream.getNextEntry();\r
+                                       continue;\r
+                               }\r
+\r
+                               zipOutput = new FileOutputStream(targetPath);\r
+\r
+                               byte[] zipBuf = new byte[BUF_SIZE];\r
+                               int readByte = 0;\r
+\r
+                               while ((readByte = zipInStream.read(zipBuf)) >= 0) {\r
+                                       zipOutput.write(zipBuf, 0, readByte);\r
+                                       \r
+                                       if (monitor != null) {\r
+                                               monitor.workedInstallSize(readByte);\r
+                                       }\r
+                                       totalUnZipSize += readByte;\r
+                               }\r
+\r
+                               writeFileList(zipEntry.getName());\r
+\r
+                               if (zipOutput != null) {\r
+                                       zipOutput.close();\r
+                               }\r
+\r
+                               if (zipEntry != null) {\r
+                                       zipInStream.closeEntry();\r
+                               }\r
+                               zipEntry = zipInStream.getNextEntry();\r
+                       }\r
+\r
+                       return totalUnZipSize;\r
+               } catch (IOException e) {\r
+                       Log.ExceptionLog(e);\r
+                       if (zipEntry != null) {\r
+                               Log.err("Fail to unpack " + zipEntry.getName());\r
+                       }\r
+                       \r
+                       return ERROR;\r
+               } catch (Throwable e) {\r
+                       Log.ExceptionLog(e);\r
+                       return ERROR;\r
+               } finally {\r
+                       try {\r
+                               if (zipOutput != null) {\r
+                                       zipOutput.flush();\r
+                                       zipOutput.close();\r
+                               }\r
+                       } catch (IOException e) {\r
+                               if (zipEntry != null) {\r
+                                       Log.err("Fail to close output stream : "\r
+                                               + zipEntry.getName());\r
+                               } else {\r
+                                       Log.ExceptionLog(e);\r
+                               }\r
+                       }\r
+\r
+                       try {\r
+                               if (zipInStream != null) {\r
+                                       zipInStream.closeEntry();\r
+                               }\r
+                       } catch (IOException e) {\r
+                               if (zipEntry != null) {\r
+                                       Log.err("Fail to close output stream : "\r
+                                               + zipEntry.getName());\r
+                               } else {\r
+                                       Log.ExceptionLog(e);\r
+                               }\r
+                       }\r
+                       \r
+                       if (zipInStream != null) {\r
+                               try {\r
+                                       zipInStream.close();\r
+                               } catch (IOException e) {\r
+                                       Log.ExceptionLog(e);\r
+                               }\r
+                       }\r
+\r
+                       try {\r
+                               if (mFileOutput != null) {\r
+                                       mFileOutput.close();\r
+                               }\r
+                       } catch (IOException e) {\r
+                               if (zipEntry != null) {\r
+                                       Log.err("Fail to close output stream : "\r
+                                               + zipEntry.getName());\r
+                               } else {\r
+                                       Log.ExceptionLog(e);\r
+                               }\r
+                       }\r
+\r
+                       closeFileOutput();\r
+               }\r
+       }\r
+    \r
+    private void writeFileList(String filePath) {\r
+       if (filePath == null || filePath.equals("")) {\r
+               return;\r
+       }\r
+       \r
+       filePath = removeDataDirectory(filePath);\r
+       if (filePath == null || filePath.equals("")) {\r
+               return;\r
+       }\r
+       \r
+       if (mFileOutput == null) {\r
+               return;\r
+       }\r
+       \r
+       try {\r
+                       mFileOutput.write((filePath + "\n").getBytes());\r
+               } catch (IOException e) {\r
+                       Log.ExceptionLog(e);\r
+                       Log.err("Fail to unpack " + filePath);\r
+            throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);\r
+               }\r
+    }\r
+    \r
+    private String removeDataDirectory(String filePath) {\r
+       if (filePath == null || filePath.equals("")) {\r
+               return "";\r
+       }\r
+       \r
+       if (!filePath.startsWith(DATA_DIRECTORY)) {\r
+               return "";\r
+       }\r
+       \r
+       filePath = filePath.substring(DATA_DIRECTORY.length());\r
+       return filePath;\r
+    }\r
+}\r
index 0650f09..64cf177 100644 (file)
-/*
-*  InstallManager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: 
-* Wooyoung Cho <wooyoung1.cho@samsung.com>
-* Shihyun Kim <shihyun.kim@samsung.com>
-* Taeyoung Son <taeyoung2.son@samsung.com>
-* Yongsung kim <yongsung1.kim@samsung.com>
-* 
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/ 
-
-package org.tizen.installmanager.pkg.lib;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Stack;
-
-import org.tizen.installmanager.core.Config;
-import org.tizen.installmanager.core.Config.ServerType;
-import org.tizen.installmanager.core.DistributionController;
-import org.tizen.installmanager.core.IMExitException;
-import org.tizen.installmanager.core.IMFatalException;
-import org.tizen.installmanager.core.InstallManager;
-import org.tizen.installmanager.core.Options;
-import org.tizen.installmanager.core.SDKExtensionInfo;
-import org.tizen.installmanager.lib.Downloader;
-import org.tizen.installmanager.lib.ErrorController;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.lib.Registry;
-import org.tizen.installmanager.lib.ErrorController.ErrorCode;
-import org.tizen.installmanager.lib.Platform;
-import org.tizen.installmanager.lib.exception.IMNetworkConnectException;
-import org.tizen.installmanager.lib.exception.IMNetworkDownloadException;
-import org.tizen.installmanager.pkg.lib.darwin.DarwinPackageManager;
-import org.tizen.installmanager.pkg.lib.linux.LinuxPackageManager;
-import org.tizen.installmanager.pkg.lib.win.WindowsPackageManager;
-import org.tizen.installmanager.pkg.model.IMPackageNotFound;
-import org.tizen.installmanager.pkg.model.Package;
-import org.tizen.installmanager.pkg.model.PackageSet;
-import org.tizen.installmanager.pkg.model.Properties;
-import org.tizen.installmanager.pkg.model.Property;
-import org.tizen.installmanager.pkg.model.PropertySection;
-import org.tizen.installmanager.pkg.model.Snapshot;
-import org.tizen.installmanager.pkg.model.Version;
-import org.tizen.installmanager.util.PathUtil;
-
-
-/**
- * Package Manager
- * <p>
- * This class provides various methods for managing packages.
- * Most of the methods handle packages symbolically. Namely, they are identified by its package name not the object if not specially mentioned.
- * <p>
- * Some methods are carefully designed to preserve the order of packages because the order of packages is important sometimes. 
- * See the details in the documentation of each methods.
- * 
- * @author Shihyun Kim <shihyun.kim@samsung.com>
- *
- */
-public abstract class PackageManager {
-       /**
-        * Packages that are already installed in the system.
-        */
-       private PackageSet installedPackages;
-       /**
-        * packages that are available in the repositories(package servers).
-        */
-       private PackageSet repoPackages;
-       /**
-        * packages that combines <code>installedPackages</code> and <code>repoPackages</code>. 
-        * This includes only the latest package from the several versions of a package.
-        * This is used as the universe set(base set) of packages available.
-        */
-       private PackageSet recentPackages;
-       
-       /**
-        * Packages from extension package server.111
-        */
-       private PackageSet extensionPackages = new PackageSet();
-       
-       private static PackageManager pm = null;
-       
-       //repository that installed.
-       private static String installedRepository = null;
-       private String currentRepository = null;
-       
-       public boolean isInstallInstallManager = false;
-       
-       public enum State {
-               INSTALL,
-               UNINSTALL;
-       }
-       
-       /**
-        * It is a position where can installmanager get the package list file 
-        */
-       private enum Style {
-               NETWORK,
-               IMAGE,
-               EXTRA;
-       }
-       
-       //abstract method
-       /**
-        * Get package list file name.
-        * @return
-        */
-       abstract public String getPackageListFileName();
-       
-       /**
-        * Creates and initializes Package Manager instance.
-        * This combines installed packages and packages from the repositories.
-        * 
-        * @param installed a file in which installed packages are specified. This can be <code>null</code> if no packages are installed.
-        * @param repoPackagesUrls a collection of URLs of repositories(package servers). This cannot be <code>null</code>.
-        * @throws IOException if temporary file cannot created
-        */
-       protected PackageManager(File installed, Collection<String> repoPackagesUrls) throws IOException {
-               setInstalledPackageList(installed);
-               loadRepositoryPackageList(repoPackagesUrls);
-               getRecentPackages();
-               
-               if (repoPackagesUrls.size() > 0) {
-                       setRepository(repoPackagesUrls.iterator().next());
-               }
-       }
-       
-       private void setRepository(String repository) {
-               if (installedRepository == null) {
-                       installedRepository = repository;
-               }
-               
-               currentRepository = repository;
-               return;
-       }
-       
-       /**
-        * set repository url to each package.(reposistory url plus package name is complete url.)
-        * @param repoPackagesUrls
-        * @throws IOException
-        */
-       public void loadRepositoryPackageList(Collection<String> repoPackagesUrls) throws IOException {
-               HashMap<String,List<PropertySection>> r2sMap = null;
-               ServerType serverType = Config.getInstance().getConfigFile().getServerType();
-               
-               if (serverType == ServerType.LOCAL) { // Using SDK Image
-                       r2sMap = getRepositoryAndPackageList(repoPackagesUrls, Style.IMAGE);
-               } else {
-                       r2sMap = getRepositoryAndPackageList(repoPackagesUrls, Style.NETWORK);                  
-               }
-               setRepoPackages(r2sMap);
-               
-               //Add EXTRAS for extention packages
-               addExtraMetaPackage();
-       }
-       
-       /**
-        * set repository url to each package.(reposistory url plus package name is complete url.)
-        * @param repoPackagesUrls Packgae server list.
-        * @throws IOException
-        */
-       public void loadExtensionPackages() throws IOException {
-               HashMap<String,List<PropertySection>> repoToSectionsMap = 
-                               getRepositoryAndPackageList(SDKExtensionInfo.getInstance().getExtensionRepositories().keySet(),
-                                               Style.EXTRA);
-               
-               //Update extension packages.
-               if (repoToSectionsMap != null/*adall && !repoToSectionsMap.isEmpty()*/) {
-                       setExtensionPackages(repoToSectionsMap);
-                       setExtensionPackagesToRecentPackages();
-               } else {
-                       return;
-               }
-       }
-       
-       private HashMap<String,List<PropertySection>> getRepositoryAndPackageList
-               (Collection<String> repoPackagesUrls, Style style) throws IOException {
-               PropertyParser parser = new PropertyParser();
-               HashMap<String,List<PropertySection>> r2sMap = new HashMap<String,List<PropertySection>>();
-               
-               if(repoPackagesUrls != null) {
-                       for(String repo : repoPackagesUrls) {                           
-                               URL packageListURL = getPackageListPath(repo, style);
-                               File packageListFile = null;
-                               
-                               if (style != Style.EXTRA) { // Snapshot, Image case
-                                       packageListFile = downloadPackageListFile(packageListURL);
-                                       if(packageListFile != null) {
-                                               r2sMap.put(repo, parser.readFromFile(packageListFile));
-                                       }
-                               } else { // Extra extension case
-                                       // Get package list file from cache.
-                                       URL extraPackageListURL = getPackageListPath(SDKExtensionInfo.getInstance().getExtraPackageListPath(repo), style);
-                                       packageListFile = downloadPackageListFile(extraPackageListURL);
-                                       if (packageListFile != null) { // If cache does not exist, install manager get it from remote repository.
-                                               r2sMap.put(repo, parser.readFromFile(packageListFile));
-                                       } else {
-                                               // InstallManager can get package list file from remote repository.
-                                               packageListFile = downloadPackageListFile(packageListURL);
-                                               if (packageListFile != null) {
-                                                       r2sMap.put(repo, parser.readFromFile(packageListFile));
-                                               }
-                                       }
-                               }
-                       }
-               } else {
-                       Log.log("Cannot find repository. This is local installer.");
-               }
-               
-               return r2sMap;
-       }
-       
-       private File downloadPackageListFile(URL packageListURL) throws IOException {
-               if (packageListURL == null) {
-                       return null;
-               }
-               Downloader dl = InstallManager.getDownloader();
-               File tmp = null;
-               
-               if (Options.onlyDownload) {
-                       tmp = new File(PathUtil.getFromCurrDir(getPackageListFileName()));
-               } else {
-                       tmp = File.createTempFile("Packages", ".list");
-                       tmp.deleteOnExit();
-               }
-               
-               long size = 0;
-               try {
-                       size = dl.download(packageListURL, tmp.getAbsolutePath(), null);
-               } catch (IMNetworkConnectException e) {
-                       Log.ExceptionLog(e);
-                       return null;
-               } catch (IMNetworkDownloadException e) {
-                       Log.ExceptionLog(e);
-                       return null;
-               }
-               
-               if (size > 0) {
-                       return tmp;
-               } else {
-                       return null;
-               }
-       }
-       
-       private void setExtensionPackages(HashMap<String,List<PropertySection>> repoToSectionsMap) {
-               extensionPackages = new PackageSet();
-               boolean result = setPackages(extensionPackages, repoToSectionsMap, true);
-               if (!result) {
-                       Log.err("Cannot set extension packages.");
-               }
-       }
-       
-       private void addExtraMetaPackage() {
-               if (repoPackages == null) {
-                       repoPackages = new PackageSet();
-               } else {
-                       if (repoPackages.hasPackageByName("EXTRAS")) {
-                               return;
-                       }
-               }
-               
-               Properties props = new Properties();
-               
-               props.add(new Property(Package.FIELD_PACKAGE, "EXTRAS"));
-               props.add(new Property(Package.FIELD_LABEL, "Extras"));
-               props.add(new Property(Package.FIELD_ATTRIBUTE, "root"));
-               props.add(new Property(Package.FIELD_PACKAGE_SIZE, "0"));
-               props.add(new Property(Package.FIELD_UNCOMPRESSED_SIZE, "0"));
-               
-               Package extraPackage = new Package(props);
-               repoPackages.add(extraPackage);
-       }
-       
-       /**
-        * Get packages from extension package server.
-        * @return set of packages
-        */
-       public PackageSet getExtensionPackages() {
-               return extensionPackages;
-       }
-       
-       public PackageSet getInstalledExtensionPackages() {
-               PackageSet extensionPackages = new PackageSet();
-               PackageSet pkgs = this.getInstalledPackages();
-               
-               
-               for (Package pkg : pkgs) {
-                       if (pkg.isExtensionPackage()) {
-                               extensionPackages.add(pkg);
-                       }
-               }
-               
-               return extensionPackages;
-       }
-       
-       /**
-        * Set installed packages.
-        * @param installedPackageListPath
-        */
-       public void setInstalledPackageList(File installedPackageListPath) {
-               List<PropertySection> sectionsInstalled = null;
-               PropertyParser parser = new PropertyParser();
-               
-               if(installedPackageListPath != null) {
-                       sectionsInstalled = parser.readFromFile(installedPackageListPath);
-               } else {
-                       sectionsInstalled= new LinkedList<PropertySection>();
-               }
-               
-               if (sectionsInstalled != null) {
-                       setInstalledPackageList(sectionsInstalled);                     
-               }
-       }
-       
-       /**
-        * Set installed packages
-        * @param sections
-        */
-       private void setInstalledPackageList(List<PropertySection> sections) {
-               installedPackages = new PackageSet();
-               
-               for(PropertySection sect : sections) {
-                       installedPackages.add(new Package(sect.getProperties()));
-               }
-       }
-       
-       public void installedPackagesFree() {
-               installedPackages = null;
-       }
-       
-       /**
-        * Get package list file path from url.
-        * @param url
-        * @return Full url path
-        */
-       private URL getPackageListPath(String url, Style style) {
-               if (url == null || url.isEmpty()) {
-                       return null;
-               } else {
-                       String packageListURL = "";
-
-                       if (style == Style.NETWORK) {
-                               String snapshotPath = Config.getInstance().getSnapshotPath();
-                               
-                               if (snapshotPath == null || snapshotPath.isEmpty() || snapshotPath.equalsIgnoreCase("null")) {
-                                       String distribution = Config.getInstance().getConfigFile().getDistribution();
-                                       
-                                       Snapshot latestSnapshot = DistributionController.getInstance().getLatestSnapshot(distribution);
-                                       if (latestSnapshot == null) {
-                                               return null;
-                                       } else {
-                                               snapshotPath = DistributionController.getInstance().getLatestSnapshot(distribution).getPath();
-                                       }
-                               }
-                               
-                               packageListURL = PathUtil.addURLPath(url,
-                                                   snapshotPath, 
-                                                   getPackageListFileName());
-                       } else {
-                               packageListURL = PathUtil.addURLPath(url, getPackageListFileName());
-                       }
-                       
-                       try {
-                               return new URL(packageListURL);
-                       } catch (MalformedURLException e) {
-                               Log.ExceptionLog(e);
-                               return null;
-                       }
-               }
-       }
-       
-       
-       
-       /**
-        * @return installed packages
-        */
-       public PackageSet getInstalledPackages() {
-               return (PackageSet) installedPackages.clone();
-       }
-       
-       /**
-        * Set packages of repository
-        * @param sections
-        */
-       protected void setRepoPackages( Map<String,List<PropertySection>> repoToSectionsMap) {
-               repoPackages = new PackageSet();
-               boolean result = setPackages(repoPackages, repoToSectionsMap, false);
-               if (!result) {
-                       Log.err("Cannot find repository. Please check your repository.");
-                       ErrorController.setError(ErrorCode.CANNOT_FIND_REPOSITORY);
-               }
-       }
-       
-       /**
-        * Set packages to <code>destPackages</code>
-        * @param destPackages It is set of packages.
-        * @param repoToSectionsMap It is added to <code>destPackages</code>
-        */
-       private boolean setPackages(PackageSet destPackages, Map<String,List<PropertySection>> repoToSectionsMap, boolean isExtensionPackage) {
-               if (destPackages == null) {
-                       destPackages = new PackageSet();
-               }
-               
-               if (repoToSectionsMap == null || repoToSectionsMap.isEmpty()) {
-                       return false;
-               }
-               
-               for(String repoBaseUrl : repoToSectionsMap.keySet()) {
-                       for(PropertySection sect : repoToSectionsMap.get(repoBaseUrl)) {
-                                       Package pkg = new Package(sect.getProperties(), repoBaseUrl);
-                                       Log.log("Check valid package version. => " + pkg);
-                                       pkg.getVersion(); // Vaild version check.
-                                       if (isExtensionPackage) {
-                                               if (pkg.getAttribute().equalsIgnoreCase("extra")) {
-                                                       pkg.setExtensionServer(repoBaseUrl);
-                                                       destPackages.add(pkg);
-                                               }
-                                       } else {
-                                               destPackages.add(pkg);
-
-                                       }
-                       }
-               }
-               
-               return true;
-       }
-       
-       /**
-        * @return packages of repository
-        */
-       public PackageSet getRepoPackages() {
-               return repoPackages;
-       }
-       
-       /**
-        * Set repository packages.
-        * @param packageSet
-        */
-       public void setRepoPackages(PackageSet packageSet) {
-               repoPackages = packageSet;
-       }
-       
-       /**
-        * @return root meta packages of repository
-        */
-       public PackageSet getRootMetaPackagesOfRepository() {
-               PackageSet clone = (PackageSet) repoPackages.clone();
-               
-               // Repository packages should not have extension packages.
-               for (Package pkg : repoPackages) {
-                       if (pkg.isExtensionPackage()) {
-                               clone.remove(pkg);
-                       }
-               }
-               
-               repoPackages = clone;
-               
-               return rootMeta(repoPackages);
-       }
-       
-       /**
-        * Get install meta packages from repository.
-        * @return
-        */
-       public PackageSet getInstallMetaPackagesOfRepository() {
-               return installMeta(repoPackages);
-       }
-       
-       /**
-        * Get root meta package from extension package server()
-        */
-       public PackageSet getRootMetaPackagesOfExtensionServer() {
-               return rootMeta(extensionPackages);
-       }
-       
-       /**
-        * @return recent packages. This includes the latest packages among all packages from currently 
-        *              installed packages and packages of repository if a package has several versions.
-        */
-       public PackageSet getRecentPackages() {
-               if(recentPackages == null) {
-                       recentPackages = new PackageSet();
-                       for(Package ip : installedPackages) {
-                               if(repoPackages != null && repoPackages.contains(ip)) {
-                                       Package rp = repoPackages.getPackage(ip);
-                                       Log.log("Repo packages : " + repoPackages);
-                                       if(ip.getVersion().compareTo(rp.getVersion()) > 0) {
-                                               recentPackages.add(ip);
-                                       } else {
-                                               recentPackages.add(rp);
-                                       }
-                               } else if (extensionPackages != null && extensionPackages.contains(ip)) {
-                                       Package ep = extensionPackages.getPackage(ip);
-                                       if(ip.getVersion().compareTo(ep.getVersion()) > 0) {
-                                               recentPackages.add(ip);
-                                       } else {
-                                               recentPackages.add(ep);
-                                       }
-                               } else {
-                                       recentPackages.add(ip);
-                               }
-                       }
-                       
-                       if (repoPackages != null) {
-                               for(Package rp : repoPackages) {
-                                       if(!recentPackages.contains(rp)) {
-                                               recentPackages.add(rp);
-                                       }
-                               }
-                       }
-               }
-               return recentPackages;
-       }
-       
-       private void setExtensionPackagesToRecentPackages() {
-               if (recentPackages == null) {
-                       recentPackages = new PackageSet();
-               }
-               
-               for(Package ip : installedPackages) {
-                       if (extensionPackages != null && extensionPackages.contains(ip)) {
-                               Package ep = extensionPackages.getPackage(ip);
-                               if(ip.getVersion().compareTo(ep.getVersion()) > 0) {
-                                       recentPackages.add(ip);
-                               } else {
-                                       recentPackages.add(ep);
-                               }
-                       } else {
-                               recentPackages.add(ip);
-                       }
-               }
-       }
-       
-       
-       
-       // Methods for update process
-       /**
-        * except package from installed package list. 
-        * @param pkg
-        * @return
-        */
-       public boolean exceptPackageFromInstalledPackages(Package pkg) {
-               return installedPackages.remove(pkg);
-       }
-       
-       /**
-        * Add package to installed package list.
-        * @param pkg
-        * @return
-        */
-       public boolean addPackageToInstalledPackages(Package pkg) {
-               installedPackages.remove(pkg);
-               return installedPackages.add(pkg);
-       }
-       
-       /**
-        * @return updatable packages among installed packages
-        */
-       public PackageSet getUpdatableInstalledPackages() {
-               PackageSet updatables = new PackageSet();
-               for(Package ip : installedPackages) {
-                       if(repoPackages.contains(ip)) {
-                               Package rp = repoPackages.getPackage(ip);
-                               if(rp.getVersion().compareTo(ip.getVersion()) != 0) {
-                                       updatables.add(ip);
-                               }
-                       }
-               }
-               return updatables;
-       }
-       
-       /**
-        * if pkg is updatable, return true. else return false.
-        * @param pkg
-        * @return
-        */
-       public boolean isUpdatable(Package pkg) {
-               if (pkg == null) {
-                       return false;
-               }
-               
-               PackageSet updatables = getUpdatableInstalledPackages();
-               if (updatables.contains(pkg)) {
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-       
-       /**
-        * If package set of repository is empty, return true;
-        * @return
-        */
-       public boolean isRepoPackagesEmpty() {
-               if (repoPackages == null || repoPackages.isEmpty()) {
-                       return true;
-               } else if (repoPackages.size() == 1) {
-                       if (repoPackages.getPackageByName("EXTRAS") != null) {
-                               return true;
-                       } else {
-                               return false;
-                       }
-               } else {
-                       return false;
-               }
-       }
-       
-       /**
-        * If pkg is installed, return true. else return false
-        * @param pkg
-        * @return
-        */
-       public boolean isInstalledVersion(Package pkg) {
-               Package installedPackage = installedPackages.getPackage(pkg);
-               if (installedPackage == null) {
-                       return false;
-               } else {
-                       Version installedVersion = installedPackage.getVersion();
-                       if (installedVersion.compareTo(pkg.getVersion()) == 0) {
-                               return true;
-                       } else {
-                               return false;
-                       }                       
-               }
-       }
-       
-       public PackageSet getRecentMetaPackages() {
-               PackageSet recentPackages = union(repoPackages, installedPackages);
-               return rootMeta(recentPackages);
-       }
-       
-       /**
-        * @return meta packages among installed packages
-        */
-       public PackageSet getInstalledMetaPackages() {
-               return meta(installedPackages);
-       }
-       
-       public List<String> getInstalledMetaNames() {
-               ArrayList<String> installedMetaNames = new ArrayList<String>();
-               
-               for (Package meta : getInstalledMetaPackages()) {
-                       installedMetaNames.add(meta.getPackageName());
-               }
-               
-               return installedMetaNames;
-       }
-       
-       public List<String> getInstalledPkgNames() {
-               ArrayList<String> installedPkgNames = new ArrayList<String>();
-               
-               for (Package pkg : getInstalledPackages()) {
-                       installedPkgNames.add(pkg.getPackageName());
-               }
-               
-               return installedPkgNames;
-       }
-       
-       /**
-        * @return meta packages among all recent packages
-        */
-       public PackageSet getAllMetaPackages() {
-               PackageSet allMeta = new PackageSet();
-               
-               PackageSet recentMeta = meta(recentPackages);
-               PackageSet extensionMeta = meta(extensionPackages);
-               
-               allMeta.addAll(recentMeta);
-               allMeta.addAll(extensionMeta);
-               
-               return allMeta;
-       }
-       
-       public PackageSet getLeafMetaPackages() {
-               PackageSet allMetas = meta(recentPackages);
-               
-               PackageSet leafMetas = new PackageSet();
-               for (Package meta : allMetas) {
-                       //if (depends size <= 0) is leaf
-                       if (meta.getDependentPackageNames().size() <= 0) {
-                               leafMetas.add(meta);
-                       } else {
-                               if (!isChildrenAllMeta(meta)) {
-                                       leafMetas.add(meta);
-                               }
-                       }
-               }
-               
-               return leafMetas;
-       }
-       
-       public PackageSet getInstalledLeafMetaPackages() {
-               PackageSet allMetas = meta(installedPackages);
-               
-               PackageSet leafMetas = new PackageSet();
-               for (Package meta : allMetas) {
-                       //if (depends size <= 0) is leaf
-                       if (meta.getDependentPackageNames().size() <= 0) {
-                               leafMetas.add(meta);
-                       } else {
-                               if (!isChildrenAllMeta(meta)) {
-                                       leafMetas.add(meta);
-                               }
-                       }
-               }
-               
-               return leafMetas;
-       }
-       
-       private boolean hasMetaPackagesInChildren(Package pkg) {
-               PackageSet dependPackages = getDependsPackages(pkg);
-               
-               if (dependPackages == null) {
-                       return true;
-               } else {
-                       for (Package dPackage : dependPackages) {
-                               if (dPackage.isMeta()) {
-                                       return true;
-                               }
-                       }
-                       return false;
-               }
-       }
-       private boolean isChildrenAllMeta(Package pkg) {                
-               PackageSet dependPackages = getDependsPackages(pkg);
-               
-               if (dependPackages == null) {
-                       return true;
-               } else {
-                       for (Package dPackage : dependPackages) {
-                               if (!dPackage.isMeta()) {
-                                       return false;
-                               }
-                       }
-                       return true;
-               }
-       }
-       
-       private PackageSet getDependsPackages(Package pkg) {
-               PackageSet dependPackages = new PackageSet();
-               if (pkg == null) {
-                       return dependPackages;
-               }
-               
-               Collection<String> depends = pkg.getDependentPackageNames();
-               
-               try {
-                       dependPackages = recentPackages.getPackagesByNames(depends);
-               } catch (IMPackageNotFound e) {
-                       Log.ExceptionLog(e);
-               }
-               return dependPackages;
-       }
-       
-       /**
-        * @return partner meta packages among all meta packages.
-        */
-       public PackageSet getPartnerMetaPackages() {
-               PackageSet allMetas = meta(recentPackages);
-               
-               PackageSet partnerMeta = new PackageSet();
-               for (Package meta : allMetas) {
-                       if (meta.isPartnerMeta()) {
-                               partnerMeta.add(meta);
-                       }
-               }
-               
-               return partnerMeta;
-       }
-       
-       /**
-        * @return public meta packages among all meta packages.
-        */
-       public PackageSet getPublicMetaPackages() {
-               PackageSet allMetas = meta(recentPackages);
-               
-               PackageSet publicMeta = new PackageSet();
-               for (Package meta : allMetas) {
-                       if (meta.isPublicMeta()) {
-                               publicMeta.add(meta);
-                       }
-               }
-               
-               return publicMeta;
-       }
-       
-       /**
-        * Get dependency packages of installable package.
-        * @param pkgs installable packages.
-        * @return
-        */
-       public PackageSet getDependsPackagesFromRepository(PackageSet pkgs) {
-               return dep(pkgs, State.INSTALL);
-       }
-       
-       /**
-        * @return meta packages that have no updates considering its dependents
-        */
-       public PackageSet getNotUpdatableMetaPackages() {
-               PackageSet noup = new PackageSet();
-               for(Package m : getAllMetaPackages()) {
-                       if(!isMetaUpdatable(m)) {
-                               noup.add(m);
-                       }
-               }
-               return noup;
-       }
-       
-       public PackageSet getNotInstallableAndNotUpdatablePackages() {
-               PackageSet notPkg = new PackageSet();
-               
-               for (Package m :getAllMetaPackages()) {
-                       if (isMetaRemovable(m) && !isMetaUpdatable(m)) {
-                               notPkg.add(m);
-                       }
-               }
-               
-               return notPkg;
-       }
-       
-       /**
-        * @return meta packages thar are updatable among installed packages
-        */
-       public PackageSet getUpdatableMetaPackages() {
-               PackageSet allMetas = getAllMetaPackages();
-               PackageSet notUpdatableMetas = getNotUpdatableMetaPackages(); 
-               return diff(allMetas, notUpdatableMetas);
-       }
-       
-       public PackageSet getUpdatableInstalledMetaPackages() {
-               PackageSet installedMeta = getInstalledMetaPackages();
-               PackageSet updatableMeta = getUpdatableMetaPackages();
-               return intersect(installedMeta, updatableMeta);
-       }
-
-       /**
-        * @param selectedMetas
-        * @return packages that will be installed after update/install resulted from the selected meta packages
-        */     
-       public PackageSet getResultPackagesAfterUpdate(PackageSet selectedMetas) {
-               PackageSet deps = dep(selectedMetas, State.INSTALL);
-               PackageSet conflicts = conflictPackages(selectedMetas);
-               PackageSet remainedFromConflicts = diff(installedPackages, conflicts);
-               return union(deps, remainedFromConflicts);
-       }
-       
-       /**
-        * Get updatable packages in update process except new packages.
-        * @param packageSet
-        * @return
-        */
-       public PackageSet getUpdatablePackagesInUpdate(PackageSet packageSet) {
-               PackageSet result = dep(packageSet, State.INSTALL);
-               PackageSet up = getUpdatableInstalledPackages();
-               return intersect(result, up);
-       }
-       
-       /**
-        * Get removable packages in snapshot process except new packages.
-        * @param selectedMetas
-        * @return
-        */
-       public PackageSet getRemovablePackagesInSnapshot(PackageSet selectedMetas) {
-               PackageSet result = dep(selectedMetas, State.UNINSTALL);
-               PackageSet pkgSet = getdifferentVersionFromInstalledPackages(result);
-               
-               return pkgSet;
-       }
-       
-       /**
-        * check version between sourcePackages and installedPackages, and return different version packages.
-        * @param pkgs 
-        * @return Different version packages among installed packages
-        */
-       public PackageSet getdifferentVersionFromInstalledPackages(PackageSet pkgs) {
-               PackageSet depPkgs = dep(pkgs, State.INSTALL);
-               PackageSet otherVersionPackages = new PackageSet();
-               for(Package ip : installedPackages) {
-                       if(depPkgs.contains(ip)) {
-                               Package rp = depPkgs.getPackage(ip);
-                               if(rp.getVersion().compareTo(ip.getVersion()) != 0) {
-                                       otherVersionPackages.add(ip);
-                               }
-                       }
-               }
-               
-               return otherVersionPackages;
-       }
-       
-       /**
-        * @param selectedMetas
-        * @return packages to newly install in update process by the selected meta packages
-        */
-       public PackageSet getInstallablePackages(PackageSet selectedMetas) {
-               PackageSet installablePackages = null;
-               if (isReInstallable()) {
-                       installablePackages = dep(selectedMetas, State.INSTALL);
-               } else if (Config.isSupportMultiSDK()) {
-                       if (Config.status == Config.Status.INSTALL) {
-                               installablePackages = dep(selectedMetas, State.INSTALL);                                
-                       } else if (Config.status == Config.Status.UPDATE) {
-                               PackageSet result = getResultPackagesAfterUpdate(selectedMetas);
-                               installablePackages = diffPackageWithVersion(result, installedPackages);
-                       }
-               } else {
-                       PackageSet result = getResultPackagesAfterUpdate(selectedMetas);
-                       installablePackages = diffPackageWithVersion(result, installedPackages);
-               }
-               
-               return installablePackages;
-       }
-       
-       /**
-        * @param selectedMetas
-        * @return packages to update in update process by the selected meta packages
-        */
-       public PackageSet getToUpdatePackagesInUpdate(PackageSet selectedMetas) {
-               PackageSet result = getResultPackagesAfterUpdate(selectedMetas);
-               PackageSet up = getUpdatableInstalledPackages();
-               return intersect(result, up);
-       }
-
-
-       /**
-        * Get conflict packages that installed.
-        * @param packageSet
-        * @return packages to remove in update process by conflicts with the selected meta packages 
-        */
-       public PackageSet getConflictPackagesInUpdate(PackageSet packageSet) {          
-               return intersect(installedPackages, getConflictPackages(packageSet));
-       }
-       
-       /**
-        * Get conflict packages that contain reverse depends packages. 
-        * @param packageSet
-        * @return
-        */
-       public PackageSet getConflictPackages(PackageSet packageSet) {
-               PackageSet conflicts = conflictPackages(packageSet);
-               
-               conflicts.addAll(reverseDep(conflicts));
-               return intersect(getConflictMetaPackages(), conflicts);
-       }
-       
-       /**
-        * Get conflict packages that contain reverse depends packages. 
-        * @param packageSet
-        * @return
-        */
-       public PackageSet getConflictPackages(Package pkg) {
-               PackageSet conflicts = conflictPackages(pkg);
-               
-               conflicts.addAll(reverseDep(conflicts));
-               return intersect(getConflictMetaPackages(), conflicts);
-       }
-       
-       private PackageSet getConflictMetaPackages() {          
-               PackageSet leafMetas = new PackageSet();
-               for (Package meta : recentPackages) {
-                       //if (depends size <= 0) is leaf
-                       if (meta.getDependentPackageNames().size() <= 0) {
-                               leafMetas.add(meta);
-                       } else {
-                               if (!hasMetaPackagesInChildren(meta)) {
-                                       leafMetas.add(meta);
-                               }
-                       }
-               }
-               
-               return leafMetas;
-       }
-       
-       // Methods for remove process
-       
-       /**
-        * @return packages that can be removed
-        */
-       public PackageSet getRemovableMetaPackages() {
-               return getInstalledMetaPackages();
-       }
-       
-       public PackageSet getInstallableMetaPackagesInSnapshot() {
-               PackageSet repoMetas = meta(repoPackages);
-               
-               PackageSet installableMeta = new PackageSet();
-               for (Package metaPackage : repoMetas) {
-                       if (isMetaInstallable(metaPackage)) {
-                               installableMeta.add(metaPackage);
-                       }
-               }
-               
-               return installableMeta;
-       }
-       
-       /**
-        * Get remove packages by selected metas.
-        * @param selectedMetas
-        * @return packages to remove in remove process
-        */
-       public PackageSet getToRemovePackagesInRemove(PackageSet selectedMetas) {
-               if (Options.doRemoveNoUI) {
-                       // When installmanager removes specific packages, it should consider package dependency.
-                       // For example, 'sdb' package depends on 'tizen-web-cli' and 'tizen-native-cli'.
-                       // In this case, when installmanager removes 'tizen-web-cli' package, 'sdb' package should
-                       // not be removed because of 'tizen-native-cli'.
-                       
-                       // Get candidate packages to remove. 
-                       PackageSet depMetas = getDependMetas(selectedMetas, State.UNINSTALL);
-                       PackageSet dep = dep(depMetas, State.UNINSTALL);
-                       PackageSet mayRemove = intersect(installedPackages, dep);
-                       
-                       // Get packages to remain.
-                       PackageSet remainMetas = diff(getInstalledLeafMetaPackages(), depMetas);
-                       PackageSet remainPackages = dep(remainMetas, State.UNINSTALL);
-                       
-                       // Get packages to remove.
-                       PackageSet toRemove = diff(mayRemove, remainPackages);
-                       return reverseSet(toRemove);                    
-               } else {
-                       // InstallManager removes whole SDK.
-                       PackageSet dep = dep(selectedMetas, State.UNINSTALL);
-                       return reverseSet(dep);
-               }
-       }
-       
-       /**
-        * @param selectedMetas
-        * @return packages that will be remained after remove resulted from the selected meta packages
-        */
-       public PackageSet getResultPackagesAfterRemove(PackageSet selectedMetas) {
-               return diff(getInstalledMetaPackages(), selectedMetas);
-       }
-       
-       // set handling methods
-       
-       /**
-        * @param pset
-        * @return meta packages in the package set
-        */
-       private PackageSet meta(PackageSet pset) {
-               PackageSet metas = new PackageSet();
-               
-               if (pset == null) {
-                       return metas;
-               }
-               
-               for(Package p : pset) {
-                       if(p.isMeta()) {
-                               metas.add(p);
-                       }
-               }
-               return metas;
-       }
-       
-       /**
-        * @param pset
-        * @return meta packages in the package set
-        */
-       private PackageSet rootMeta(PackageSet pset) {
-               PackageSet metas = new PackageSet();
-               for(Package p : pset) {
-                       if (!Options.doTest) {
-                               if(p.isRootMeta() || p.isExtraMeta() || p.isPublicMeta()) {
-                                       metas.add(p);
-                               }
-                       } else {
-                               if(p.isRootMeta() || p.isExtraMeta() || p.isPublicMeta() || p.isTestMeta()) {
-                                       metas.add(p);
-                               }
-                       }
-               }
-               return metas;
-       }
-       
-       /**
-        * @param pset
-        * @return meta packages in the package set
-        */
-       private PackageSet installMeta(PackageSet pset) {
-               PackageSet metas = new PackageSet();
-               for(Package p : pset) {
-                       if(p.isInstallMeta()) {
-                               metas.add(p);
-                       }
-               }
-               return metas;
-       }
-       
-       /**
-        * Get dependency package list from p.
-        * @param p a package
-        * @return all the packages that the given package depends on directly or indirectly
-        */
-       private PackageSet dep(Package p, State state) {
-               // depth first traverse on dependency graph
-               PackageSet dep = new PackageSet();
-               Stack<Package> pkgStack = new Stack<Package>();
-               pkgStack.push(p);
-               while(!pkgStack.isEmpty()) {
-                       Package pkg = pkgStack.pop();
-                               
-                       if(!dep.contains(pkg)) {
-                               dep.add(pkg);
-                               PackageSet depPackageSet = new PackageSet();
-                               try {
-                                       if (state == State.INSTALL) {
-                                               if (repoPackages.contains(pkg)) {
-                                                       depPackageSet = repoPackages.getPackagesByNames(pkg.getDependentPackageNames());
-                                               } else if (extensionPackages.contains(pkg)) {
-                                                       depPackageSet = extensionPackages.getPackagesByNames(pkg.getDependentPackageNames());
-                                               }
-                                       } else if (state == State.UNINSTALL){
-                                               depPackageSet = installedPackages.getPackagesByNames(pkg.getDependentPackageNames());
-                                       } else {
-                                               Log.err("State class have two state(INSTALL/UNINSTALL) ");
-                                               throw new IMFatalException(ErrorCode.UNKOWN_ERROR); 
-                                       }
-                               } catch (IMPackageNotFound e) {
-                                       Log.err("Finding dependents: "+p+": Package does not exist: " + e.getPackageName()+ " or "+ pkg.getDependentPackageNames());
-                                       throw new IMFatalException(ErrorCode.CANNOT_FIND_PACKAGE);
-                               }
-
-                               for(Package depPkg : depPackageSet) {
-                                       if(p.equals(depPkg)) {
-                                               Log.err("Circular dependency found: "+p);
-                                               throw new IMFatalException(ErrorCode.CIRCULAR_PACKAGE_DEPENDENCY);
-                                       }
-                                       pkgStack.push(depPkg);
-                               }
-                       } else {
-                               // already visited.
-                               addDependsSet(dep, pkg);
-                       }
-               }
-               
-               return reverseSet(dep);
-       }
-       
-       private PackageSet reverseDep(PackageSet packages) {
-               PackageSet reversePackages = new PackageSet();
-               
-               for (Package pkg : packages) {
-                       reversePackages.addAll(reverseDep(pkg));
-               }
-               
-               return reversePackages;
-       }
-       
-       /**
-        * Need reverse depends when remove.
-        * @param p
-        * @return
-        */
-       private PackageSet reverseDep(Package p) {
-               // depth first traverse on dependency graph
-               PackageSet reverseDep = new PackageSet();
-               Stack<Package> pkgStack = new Stack<Package>();
-               pkgStack.push(p);
-               while(!pkgStack.isEmpty()) {
-                       Package pkg = pkgStack.pop();
-                               
-                       if(!reverseDep.contains(pkg)) {
-                               reverseDep.add(pkg);
-                               
-                               for (Package recentPkg : recentPackages) {
-                                       Collection<String> dependsList = recentPkg.getDependentPackageNames();
-                                       for (String pkgName :  dependsList) {
-                                               if (pkgName.equals(pkg.getPackageName())) {
-                                                       pkgStack.push(recentPkg);
-                                                       break;
-                                               }
-                                       }
-                                       
-                               }
-                       } else {
-                               // already visited
-                               addDependsSet(reverseDep, pkg);
-                       }
-               }
-               
-               return reverseDep;
-       }
-       
-       /**
-        * Remove saved package and save package at the end of set.
-        * @param dependsSet
-        * @param pkg
-        */
-       private void addDependsSet(PackageSet dependsSet, Package pkg) {
-               if (dependsSet.contains(pkg)) {
-                       dependsSet.remove(pkg);
-               }
-               
-               dependsSet.add(pkg);
-       }
-       
-       /**
-        * reverse package list.
-        * @param pkgSet
-        * @return
-        */
-       public PackageSet reverseSet(PackageSet pkgSet) {
-               if (pkgSet == null) {
-                       return null;
-               }
-               
-               Stack<Package> stack = new Stack<Package>();
-               for (Package pkg : pkgSet) {
-                       stack.push(pkg);
-               }
-               
-               PackageSet reverseSet = new PackageSet();
-               
-               while(!stack.isEmpty()) {
-                       reverseSet.add(stack.pop());
-               }
-               
-               return reverseSet;
-       }
-       
-       /**
-        * @param pset package set
-        * @return all the packages that the given packages depends on directly or indirectly
-        */
-       private PackageSet dep(PackageSet pset, State state) {
-               PackageSet dep = new PackageSet();
-               for(Package p : pset) {
-                       dep.addAll(dep(p, state));
-               }
-               return dep;
-       }
-       
-       /**
-        * Get conflict package list from p.
-        * @param p
-        * @return packages that conflict with the given package directly or indirectly
-        */
-       public PackageSet conflictPackages(Package p) {
-               PackageSet conflicts = new PackageSet();
-               PackageSet dep = dep(p, State.INSTALL);
-               for(Package pkg : dep) {
-                       Collection<String> conflictPackageNames = pkg.getConflictPackageNames();
-                       for(String conflictPackageName : conflictPackageNames) {
-                               if(installedPackages.hasPackageByName(conflictPackageName)) {
-                                       Package conflictPackage = installedPackages.getPackageByName(conflictPackageName);
-                                       conflicts.addAll(reverseDep(conflictPackage));
-                               } else if (repoPackages.hasPackageByName(conflictPackageName)) {
-                                       Package conflictPackage = repoPackages.getPackageByName(conflictPackageName);
-                                       conflicts.addAll(reverseDep(conflictPackage));
-                               }
-                       }
-               }
-               return conflicts;
-       }
-       
-       /**
-        * Get conflict package list.
-        * @param pset
-        * @return packages that conflict with the given packages directly or indirectly 
-        */
-       public PackageSet conflictPackages(PackageSet pset) {
-               PackageSet conflicts = new PackageSet();
-               for(Package p : pset) {
-                       conflicts.addAll(conflictPackages(p));
-               }
-               return conflicts;
-       }
-       
-       /**
-        * Adds packages of pset2 to packages of pset1.
-        * @param pset1
-        * @param pset2
-        * @return new package set has the union of pset1 and pset2.
-        */
-       private PackageSet union(PackageSet pset1, PackageSet pset2) {
-               PackageSet union = (PackageSet) pset1.clone();
-               union.addAll(pset2);
-               return union;
-       }
-       
-       /**
-        * Removes packages of pset2 from packages of pset1.
-        * @param pset1
-        * @param pset2
-        * @return new package set that represents (pset1 - pset2). 
-        */
-       public PackageSet diff(PackageSet pset1, PackageSet pset2) {
-               PackageSet diff = new PackageSet();
-               for(Package p : pset1) {
-                       if(!pset2.contains(p)) {
-                               diff.add(p);
-                       }
-               }
-               return diff;
-       }
-       
-       private PackageSet diffPackageWithVersion(PackageSet pset1, PackageSet pset2) {
-               PackageSet diff = new PackageSet();
-               for(Package p : pset1) {
-                       Package pkg = pset2.getPackage(p);
-                       
-                       if (pkg == null) {
-                               diff.add(p);
-                       } else {
-                               if (Version.compareTo(p.getVersion(), pkg.getVersion()) != 0) {
-                                       diff.add(p);
-                               }
-                       }
-               }
-               return diff;
-       }
-       
-       /**
-        * 
-        * @param pset1
-        * @param pset2
-        * @return new set of intersection of pset1 and pset2. It has the order of pset1.
-        */
-       private PackageSet intersect(PackageSet pset1, PackageSet pset2) {
-               PackageSet pset = new PackageSet();
-               for(Package p : pset1) {
-                       if(pset2.contains(p)) {
-                               pset.add(p);
-                       }
-               }
-               return pset;
-       }
-       
-       private PackageSet getDependMetas(PackageSet packageSet, State state) {
-               PackageSet depMetas = new PackageSet();
-               PackageSet depPkgs = dep(packageSet, state);
-               for (Package p : depPkgs) {
-                       if (p.isMeta()) {
-                               depMetas.add(p);
-                       }
-               }
-               
-               return depMetas;
-       }
-       
-       /**
-        * @param m meta package to be checked updatable
-        * @return <code>true</code> if the meta package is updatable. 
-        *              ie. the meta package is installed and one of its dependents is already installed and is updatable.
-        */
-       public boolean isMetaUpdatable(Package m) {             
-               // if one of the meta package's dependents is installed and updatable, the meta package is updatable.
-               PackageSet dep = dep(m, State.INSTALL);
-
-               for(Package p : dep) {
-                       
-                       if(installedPackages.contains(p)) {
-                               Package ip = installedPackages.getPackage(p);
-                               if (ip == null) {
-                                       continue;
-                               }
-                               
-                               Package rp = null;
-                               if (repoPackages != null && repoPackages.hasPackage(p)) {
-                                       rp = repoPackages.getPackage(p);
-                               } else if (extensionPackages != null && extensionPackages.hasPackage(p)) {
-                                       rp = extensionPackages.getPackage(p);
-                               }
-                               
-                               // checks p is updatable
-                               if(rp != null && rp.getVersion().compareTo(ip.getVersion()) != 0) {
-                                       return true;
-                               }
-                       }
-               }
-               return false;
-       }
-       
-
-       
-       /**
-        * @param m meta package to be checked removable
-        * @return <code>true</code> if the meta package is removable 
-        *              ie. the meta package is installed and one of its dependents is already installed and is removable.
-        */
-       private boolean isMetaRemovable(Package m) {
-               // if the meta package is not installed, it's never updatable
-               if(installedPackages.contains(m)) {
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-       
-       /**
-        * check new installation or upgrade or downgrade.
-        * @param meta meta package to be checked installable.
-        * @return <code>true</code> if the meta package is updatable. 
-        *              ie. the meta package is installed and one of its dependents is already installed and is updatable.
-        */
-       private boolean isMetaInstallable(Package meta) {                               
-               // if one of the meta package's dependents is installed and updatable, the meta package is updatable.
-               PackageSet dep = dep(meta, State.INSTALL);
-               
-               for(Package p : dep) {
-                       //Do not check meta package. It is only used by install-type or category.
-                       if (p.isMeta()) {
-                               continue;
-                       }
-                       
-                       if(installedPackages.contains(p)) {
-                               Package ip = installedPackages.getPackage(p);
-                               if (ip == null) {
-                                       continue;
-                               }
-                               
-                               Package rp = repoPackages.getPackage(p); // rp always exists if ip exists
-                               
-                               // checks p is updatable
-                               if(rp.getVersion().compareTo(ip.getVersion()) != 0) {
-                                       return true;
-                               }
-                       } else {
-                               return true;
-                       }
-               }
-               return false;
-       }
-       
-       // utility methods
-       /**
-        * Get installed package.
-        * @param pkg
-        * @return If not exist package in installed package list, return empty string.
-        */
-       public Package getInstalledPackageByName(String pkgName) {
-               Package retPkg = installedPackages.getPackageByName(pkgName);
-               
-               return retPkg;
-       }
-       
-       /**
-        * Get installed packages by package name.
-        * @param pkgName name of packages
-        * @return If not exist package in installed package list, return empty string.
-        */
-       public PackageSet getInstalledPackagesByName(List<String> pkgNames) {
-               PackageSet installedPackages = new PackageSet();
-               for (String pkg : pkgNames) {
-                       Package retPkg = getInstalledPackageByName(pkg);
-                       
-                       if (retPkg != null) {
-                               installedPackages.add(retPkg);
-                       }
-               }
-               
-               return installedPackages;
-       }
-       
-       /**
-        * Get Package instance from package name.
-        * @param pkgName
-        * @return
-        */
-       public Package getPackageByName(String pkgName) {
-               PackageSet packageList = repoPackages;
-               packageList.addAll(extensionPackages);
-               
-               if (packageList.hasPackageByName(pkgName)) {
-                       return packageList.getPackageByName(pkgName);
-               } else {
-                       return null;
-               }
-       }
-       
-       public boolean existsPackage(String packageName) {
-               if (getPackageByName(packageName) != null) {
-                       return true;
-               } else if (getInstalledPackageByName(packageName) != null) {
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-       
-       public void removePackageFromPackageManager(String pkgName) {
-               PackageSet clone = (PackageSet) repoPackages.clone();
-               Package pkg = clone.getPackageByName(pkgName);
-               
-               if (clone.hasPackage(pkg)) {
-                       clone.remove(pkg);
-               }
-               
-               repoPackages = clone;
-       }
-       /**
-        * @param packageNames
-        * @return packages collected by the given package names
-        */
-       public PackageSet getPackagesByNames(Collection<String> packageNames) {
-               PackageSet pset = new PackageSet();
-               for(String name : packageNames) {
-                       if(repoPackages.hasPackageByName(name)) {
-                               Package pkg = repoPackages.getPackageByName(name);
-                               pset.add(pkg);
-                       } else if (extensionPackages.hasPackageByName(name)) {
-                               Package pkg = extensionPackages.getPackageByName(name);
-                               pset.add(pkg);
-                       } else {
-                               throw new IMFatalException(ErrorCode.CANNOT_FIND_FILE_IN_REPOSITROY);
-                       }
-               }
-               return pset;
-       }
-       
-       public PackageSet getMandatoryPackages() {
-               PackageSet pSet = new PackageSet();
-               
-               for (Package pkg : repoPackages) {
-                       if (pkg.isMandatory()) {
-                               pSet.add(pkg);
-                       }
-               }
-               
-               return pSet;
-       }
-       
-       public PackageSet getUpdatableMandatoryPackages() {
-               PackageSet pSet = new PackageSet();
-               
-               for (Package mPkg : getMandatoryPackages()) {
-                       if (!installedPackages.contains(mPkg)) {
-                               pSet.add(mPkg);
-                       } else if(isUpdatable(mPkg)) {
-                               pSet.add(mPkg);
-                       } else {
-                               continue;
-                       }
-               }
-               
-               return pSet;
-       }
-       
-       /**
-        * Check installed meta packages
-        * @return if installed package exists, return true. if not return false.
-        */
-       public boolean existInstalledMetaPackages() {
-               if (getInstalledMetaPackages().size() <= 0) {
-                       return false;
-               } else {
-                       return true;
-               }
-       }
-       
-       /**
-        * Check installable meta packages
-        * @return if installable meta package exists, return true. if not return false.
-        */
-       public boolean existInstallableMetaPackages() {
-               if (getInstalledMetaPackages().size() <= 0) {
-                       return false;
-               } else {
-                       return true;
-               }
-       }
-       
-       /**
-        * Check installed packages.
-        * @return if installed package exists, return true. if not return false.
-        */
-       public boolean existInstalledPackages() {
-               if (installedPackages.size() <= 0) {
-                       return false;
-               } else {
-                       return true;
-               }
-       }
-       
-       /**
-        * Check installable or updatable packages.
-        * @return if installable package exists, return true. if not return false.
-        */
-       public boolean existInstallablePackages() {
-               for(Package p : repoPackages) {
-                       if(installedPackages.contains(p)) {
-                               Package ip = installedPackages.getPackage(p);
-                               if (ip == null) {
-                                       continue;
-                               }
-                               
-                               Package rp = recentPackages.getPackage(p); // rp always exists if ip exists
-                               // checks p is updatable
-                               if(rp.getVersion().compareTo(ip.getVersion()) > 0) {
-                                       return true;
-                               }
-                       }
-               }
-               return false;
-       }
-       
-       /**
-        * get total size to remove. 
-        * @param pkg
-        * @return
-        */
-       public long getTotalSizeOfRemovablePackages(Package pkg) {
-               PackageSet pkgs = new PackageSet();
-               
-               pkgs.add(pkg);
-               PackageSet depPkgSet = getToRemovePackagesInRemove(pkgs);
-               
-               return getTotalSize(depPkgSet, true);
-       }
-       
-       /**
-        * get total size to install. 
-        * @param pkg
-        * @param isUncompressed Uncompressed is true, not false.
-        * @return
-        */
-       public long getTotalSizeOfInstallablePackages(PackageSet pkgs, boolean isUncompressed) {
-               PackageSet depPkgSet = getInstallablePackages(pkgs);
-               
-               return getTotalSize(depPkgSet, isUncompressed);
-       }
-       
-       /**
-        * get total size to remove. 
-        * @param pkg
-        * @return
-        */
-       public long getTotalSizeOfRemovablePackages(PackageSet pkgs) {
-               PackageSet depPkgSet = getRemovablePackagesInSnapshot(pkgs);
-               
-               return getTotalSize(depPkgSet, true);
-       }
-
-       /**
-        * Get uncompressed packages size or compressed(zipped) packages size.
-        * @param pkgs Packages set which can be calculated total size.
-        * @param isUncompressed Uncompressed is true, not false.
-        * @return
-        */
-       private long getTotalSize(PackageSet pkgs, boolean isUncompressed) {
-               long totalSize = 0;
-               for (Package depPkg : pkgs) {
-                       if (isUncompressed) {
-                               totalSize += depPkg.getUncompressedPackageSize();                               
-                       } else {
-                               totalSize += depPkg.getPackageSize();                           
-                       }
-               }
-               
-               return totalSize;
-       }
-       
-       /**
-        * @return <code>true</code> if installed and repository packages are empty.
-        */
-       public boolean isEmpty() {
-               
-               if (installedPackages.size() <= 0 && repoPackages.size() <= 0) {
-                       return true;
-               }
-               
-               return false;
-       }
-       
-       /**
-        * Get Installable packages.
-        * @return packages that can be newly installable.
-        */
-       public PackageSet getInstallableMetaPackages() {
-               return diff(getAllMetaPackages(), getInstalledMetaPackages());
-       }
-
-       /**
-        * @return packages that can be newly installable or updatable. 
-        */
-       public PackageSet getInstallableOrUpdatableMetaPackages() {
-               PackageSet installableMetaPackages = new PackageSet();
-               PackageSet allMetaPackages = getAllMetaPackages();
-               
-               for (Package metaPackage : allMetaPackages) {
-                       if (isMetaInstallable(metaPackage)) {
-                               installableMetaPackages.add(metaPackage);
-                       }
-               }
-               
-               return installableMetaPackages;
-       }
-       
-       
-       /**
-        * Check missing packages from repository's package list.   
-        * @return packages that is missing in repository's package list.
-        */
-       public PackageSet getMissingPackagesFromRepository() {
-               PackageSet missingPackages = new PackageSet();
-               
-               if (!repoPackages.isEmpty()) {
-                       missingPackages = diff(installedPackages, repoPackages);
-                       missingPackages = diff(missingPackages, extensionPackages);
-               }
-               
-               return missingPackages;
-       }
-       
-       /**
-        * save packages to installedpackage.list
-        * @param filePath
-        */
-       public void saveInstalledList(String filePath) {
-       if (filePath == null) {
-               return;
-       }
-        PropertyParser parser = new PropertyParser();
-        List<PropertySection> pSections = saveProperySectionsFromPackages(installedPackages);
-        parser.writeToFile(pSections, filePath);
-    }
-       
-       /**
-        * save information of packages.
-        * @param packages 
-        * @return
-        */
-       public List<PropertySection> saveProperySectionsFromPackages(PackageSet packages) {
-       List<PropertySection> pSections = new ArrayList<PropertySection>();
-       PropertySection pSection = null;
-       Properties properties = null;
-       
-       for (Package pkg : packages) {
-               properties = (Properties)pkg.getProperties();
-               pSection = new PropertySection();
-               pSection.setProperties(properties);
-               pSections.add(pSection);
-       }
-       
-       return pSections;
-    }
-       
-       /**
-        * Check the repository change.
-        * @return
-        */
-       public boolean isRepositoryChanged() {          
-               if (installedRepository == null || !currentRepository.equalsIgnoreCase(installedRepository)) {
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-       
-       /**
-        * Check to need re-installation.
-        * If there has been a change distribution or repository or SDK image, force to re-install.
-        * @return If it needs to re-install, return true. otherwise return false.
-        */
-       public boolean isReInstallable() {
-               if (isInstallInstallManager) {
-                       return  false;
-               } else if (Config.fromWhere == Config.ConfDialog.LOCAL_IMAGE) {
-                       return true;
-               } else  if (isRepositoryChanged()) {
-                       return true;
-               } else {
-                       if (DistributionController.getInstance().isDistributionChanged()) {
-                               return true;
-                       } else {
-                               return false;
-                       }
-               }
-       }
-       
-       /**
-        * Prints dependency graph of packages in dot format to stdout.
-        * @throws IMExitException 
-        */
-       public void printDepGraph() {
-               StringBuffer buf = new StringBuffer();
-               
-               buf.append("digraph G {\n");
-               
-               for(Package p : recentPackages) {
-                       PackageSet dep = dep(p, State.INSTALL);
-                       
-                       for(Package d : dep) {
-                               if(!d.equals(p)) {
-                                       buf.append("\""+p+"\" -> \"" + d + "\";\n");
-                               }
-                       }
-               }
-               
-               buf.append("}\n");
-               System.out.println(buf);
-       }
-       
-       public static void dispose() {
-               if (pm != null) {
-                       pm = null;
-               }
-       }
-
-       /**
-        * Get PackageManager singleton instance.
-        * @param installed
-        * @param repoPackagesUrls
-        * @return
-        * @throws IOException
-        */
-       public static PackageManager getInstance(File installed, Collection<String> repoPackagesUrls) throws IOException {
-               if (Options.platForm == null) {
-                       if (Config.isSupportMultiSDK) {
-                               if (Registry.targetPath != "") {
-                                       pm = null;
-                                       if (Platform.isLinux()) {
-                                               pm = new LinuxPackageManager(installed, repoPackagesUrls);
-                                       } else if (Platform.isWindows()) {
-                                               pm = new WindowsPackageManager(installed, repoPackagesUrls);
-                                       } else if (Platform.isMacOS()) {
-                                               pm = new DarwinPackageManager(installed, repoPackagesUrls);
-                                       } else {
-                                               return null;
-                                       }                               
-                               } else {
-                                       if (pm == null) {
-                                               if (Platform.isLinux()) {
-                                                       pm = new LinuxPackageManager(installed, repoPackagesUrls);
-                                               } else if (Platform.isWindows()) {
-                                                       pm = new WindowsPackageManager(installed, repoPackagesUrls);
-                                               } else if (Platform.isMacOS()) {
-                                                       pm = new DarwinPackageManager(installed, repoPackagesUrls);
-                                               } else {
-                                                       return null;
-                                               }
-                                       }       
-                               }
-                       } else {
-                               if (pm == null) {
-                                       if (Platform.isLinux()) {
-                                               pm = new LinuxPackageManager(installed, repoPackagesUrls);
-                                       } else if (Platform.isWindows()) {
-                                               pm = new WindowsPackageManager(installed, repoPackagesUrls);
-                                       } else if (Platform.isMacOS()) {
-                                               pm = new DarwinPackageManager(installed, repoPackagesUrls);
-                                       } else {
-                                               return null;
-                                       }
-                               }                               
-                       }
-               } else {
-                       if (pm == null) {
-                               if (Options.platForm.equalsIgnoreCase("ubuntu")) {
-                                       pm = new LinuxPackageManager(installed, repoPackagesUrls);
-                               } else if (Options.platForm.equalsIgnoreCase("windows")) {
-                                       pm = new WindowsPackageManager(installed, repoPackagesUrls);
-                               } else if (Options.platForm.equalsIgnoreCase("macos")) {
-                                       pm = new DarwinPackageManager(installed, repoPackagesUrls);
-                               } else {
-                                       return null;
-                               }
-                       }
-               }
-               return pm;
-       }
-       
-       public static PackageManager getInstance() {
-               return pm;
-       }
-       
-       public SDKExtensionInfo getSdkExtensionInfo() {
-               return SDKExtensionInfo.getInstance();
-       }
-}
+/*\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.pkg.lib;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.net.MalformedURLException;\r
+import java.net.URL;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.HashMap;\r
+import java.util.LinkedList;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Stack;\r
+\r
+import org.tizen.installmanager.core.Config;\r
+import org.tizen.installmanager.core.Config.ServerType;\r
+import org.tizen.installmanager.core.DistributionController;\r
+import org.tizen.installmanager.core.IMExitException;\r
+import org.tizen.installmanager.core.IMFatalException;\r
+import org.tizen.installmanager.core.InstallManager;\r
+import org.tizen.installmanager.core.Options;\r
+import org.tizen.installmanager.core.SDKExtensionInfo;\r
+import org.tizen.installmanager.lib.Downloader;\r
+import org.tizen.installmanager.lib.ErrorController;\r
+import org.tizen.installmanager.lib.Log;\r
+import org.tizen.installmanager.lib.Registry;\r
+import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
+import org.tizen.installmanager.lib.Platform;\r
+import org.tizen.installmanager.lib.exception.IMNetworkConnectException;\r
+import org.tizen.installmanager.lib.exception.IMNetworkDownloadException;\r
+import org.tizen.installmanager.pkg.lib.darwin.DarwinPackageManager;\r
+import org.tizen.installmanager.pkg.lib.linux.LinuxPackageManager;\r
+import org.tizen.installmanager.pkg.lib.win.WindowsPackageManager;\r
+import org.tizen.installmanager.pkg.model.IMPackageNotFound;\r
+import org.tizen.installmanager.pkg.model.Package;\r
+import org.tizen.installmanager.pkg.model.PackageSet;\r
+import org.tizen.installmanager.pkg.model.Properties;\r
+import org.tizen.installmanager.pkg.model.Property;\r
+import org.tizen.installmanager.pkg.model.PropertySection;\r
+import org.tizen.installmanager.pkg.model.Snapshot;\r
+import org.tizen.installmanager.pkg.model.Version;\r
+import org.tizen.installmanager.util.PathUtil;\r
+\r
+\r
+/**\r
+ * Package Manager\r
+ * <p>\r
+ * This class provides various methods for managing packages.\r
+ * Most of the methods handle packages symbolically. Namely, they are identified by its package name not the object if not specially mentioned.\r
+ * <p>\r
+ * Some methods are carefully designed to preserve the order of packages because the order of packages is important sometimes. \r
+ * See the details in the documentation of each methods.\r
+ * \r
+ * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+ *\r
+ */\r
+public abstract class PackageManager {\r
+       /**\r
+        * Packages that are already installed in the system.\r
+        */\r
+       private PackageSet installedPackages;\r
+       /**\r
+        * packages that are available in the repositories(package servers).\r
+        */\r
+       private PackageSet repoPackages;\r
+       /**\r
+        * packages that combines <code>installedPackages</code> and <code>repoPackages</code>. \r
+        * This includes only the latest package from the several versions of a package.\r
+        * This is used as the universe set(base set) of packages available.\r
+        */\r
+       private PackageSet recentPackages;\r
+       \r
+       /**\r
+        * Packages from extension package server.111\r
+        */\r
+       private PackageSet extensionPackages = new PackageSet();\r
+       \r
+       private static PackageManager pm = null;\r
+       \r
+       //repository that installed.\r
+       private static String installedRepository = null;\r
+       private String currentRepository = null;\r
+       \r
+       public boolean isInstallInstallManager = false;\r
+       \r
+       public enum State {\r
+               INSTALL,\r
+               UNINSTALL;\r
+       }\r
+       \r
+       /**\r
+        * It is a position where can installmanager get the package list file \r
+        */\r
+       private enum Style {\r
+               NETWORK,\r
+               IMAGE,\r
+               EXTRA;\r
+       }\r
+       \r
+       //abstract method\r
+       /**\r
+        * Get package list file name.\r
+        * @return\r
+        */\r
+       abstract public String getPackageListFileName();\r
+       \r
+       /**\r
+        * Creates and initializes Package Manager instance.\r
+        * This combines installed packages and packages from the repositories.\r
+        * \r
+        * @param installed a file in which installed packages are specified. This can be <code>null</code> if no packages are installed.\r
+        * @param repoPackagesUrls a collection of URLs of repositories(package servers). This cannot be <code>null</code>.\r
+        * @throws IOException if temporary file cannot created\r
+        */\r
+       protected PackageManager(File installed, Collection<String> repoPackagesUrls) throws IOException {\r
+               setInstalledPackageList(installed);\r
+               loadRepositoryPackageList(repoPackagesUrls);\r
+               getRecentPackages();\r
+               \r
+               if (repoPackagesUrls.size() > 0) {\r
+                       setRepository(repoPackagesUrls.iterator().next());\r
+               }\r
+       }\r
+       \r
+       private void setRepository(String repository) {\r
+               if (installedRepository == null) {\r
+                       installedRepository = repository;\r
+               }\r
+               \r
+               currentRepository = repository;\r
+               return;\r
+       }\r
+       \r
+       /**\r
+        * set repository url to each package.(reposistory url plus package name is complete url.)\r
+        * @param repoPackagesUrls\r
+        * @throws IOException\r
+        */\r
+       public void loadRepositoryPackageList(Collection<String> repoPackagesUrls) throws IOException {\r
+               HashMap<String,List<PropertySection>> r2sMap = null;\r
+               ServerType serverType = Config.getInstance().getConfigFile().getServerType();\r
+               \r
+               if (serverType == ServerType.LOCAL) { // Using SDK Image\r
+                       r2sMap = getRepositoryAndPackageList(repoPackagesUrls, Style.IMAGE);\r
+               } else {\r
+                       r2sMap = getRepositoryAndPackageList(repoPackagesUrls, Style.NETWORK);                  \r
+               }\r
+               setRepoPackages(r2sMap);\r
+               \r
+               //Add EXTRAS for extention packages\r
+               addExtraMetaPackage();\r
+       }\r
+       \r
+       /**\r
+        * set repository url to each package.(reposistory url plus package name is complete url.)\r
+        * @param repoPackagesUrls Packgae server list.\r
+        * @throws IOException\r
+        */\r
+       public void loadExtensionPackages() throws IOException {\r
+               HashMap<String,List<PropertySection>> repoToSectionsMap = \r
+                               getRepositoryAndPackageList(SDKExtensionInfo.getInstance().getExtensionRepositories().keySet(),\r
+                                               Style.EXTRA);\r
+               \r
+               //Update extension packages.\r
+               if (repoToSectionsMap != null/*adall && !repoToSectionsMap.isEmpty()*/) {\r
+                       setExtensionPackages(repoToSectionsMap);\r
+                       setExtensionPackagesToRecentPackages();\r
+               } else {\r
+                       return;\r
+               }\r
+       }\r
+       \r
+       private HashMap<String,List<PropertySection>> getRepositoryAndPackageList\r
+               (Collection<String> repoPackagesUrls, Style style) throws IOException {\r
+               PropertyParser parser = new PropertyParser();\r
+               HashMap<String,List<PropertySection>> r2sMap = new HashMap<String,List<PropertySection>>();\r
+               \r
+               if(repoPackagesUrls != null) {\r
+                       for(String repo : repoPackagesUrls) {                           \r
+                               URL packageListURL = getPackageListPath(repo, style);\r
+                               File packageListFile = null;\r
+                               \r
+                               if (style != Style.EXTRA) { // Snapshot, Image case\r
+                                       packageListFile = downloadPackageListFile(packageListURL);\r
+                                       if(packageListFile != null) {\r
+                                               r2sMap.put(repo, parser.readFromFile(packageListFile));\r
+                                       }\r
+                               } else { // Extra extension case\r
+                                       // Get package list file from cache.\r
+                                       URL extraPackageListURL = getPackageListPath(SDKExtensionInfo.getInstance().getExtraPackageListPath(repo), style);\r
+                                       packageListFile = downloadPackageListFile(extraPackageListURL);\r
+                                       if (packageListFile != null) { // If cache does not exist, install manager get it from remote repository.\r
+                                               r2sMap.put(repo, parser.readFromFile(packageListFile));\r
+                                       } else {\r
+                                               // InstallManager can get package list file from remote repository.\r
+                                               packageListFile = downloadPackageListFile(packageListURL);\r
+                                               if (packageListFile != null) {\r
+                                                       r2sMap.put(repo, parser.readFromFile(packageListFile));\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               } else {\r
+                       Log.log("Cannot find repository. This is local installer.");\r
+               }\r
+               \r
+               return r2sMap;\r
+       }\r
+       \r
+       private File downloadPackageListFile(URL packageListURL) throws IOException {\r
+               if (packageListURL == null) {\r
+                       return null;\r
+               }\r
+               Downloader dl = InstallManager.getDownloader();\r
+               File tmp = null;\r
+               \r
+               if (Options.onlyDownload) {\r
+                       tmp = new File(PathUtil.getFromCurrDir(getPackageListFileName()));\r
+               } else {\r
+                       tmp = File.createTempFile("Packages", ".list");\r
+                       tmp.deleteOnExit();\r
+               }\r
+               \r
+               long size = 0;\r
+               try {\r
+                       size = dl.download(packageListURL, tmp.getAbsolutePath(), null);\r
+               } catch (IMNetworkConnectException e) {\r
+                       Log.ExceptionLog(e);\r
+                       return null;\r
+               } catch (IMNetworkDownloadException e) {\r
+                       Log.ExceptionLog(e);\r
+                       return null;\r
+               }\r
+               \r
+               if (size > 0) {\r
+                       return tmp;\r
+               } else {\r
+                       return null;\r
+               }\r
+       }\r
+       \r
+       private void setExtensionPackages(HashMap<String,List<PropertySection>> repoToSectionsMap) {\r
+               extensionPackages = new PackageSet();\r
+               boolean result = setPackages(extensionPackages, repoToSectionsMap, true);\r
+               if (!result) {\r
+                       Log.err("Cannot set extension packages.");\r
+               }\r
+       }\r
+       \r
+       private void addExtraMetaPackage() {\r
+               if (repoPackages == null) {\r
+                       repoPackages = new PackageSet();\r
+               } else {\r
+                       if (repoPackages.hasPackageByName("EXTRAS")) {\r
+                               return;\r
+                       }\r
+               }\r
+               \r
+               Properties props = new Properties();\r
+               \r
+               props.add(new Property(Package.FIELD_PACKAGE, "EXTRAS"));\r
+               props.add(new Property(Package.FIELD_LABEL, "Extras"));\r
+               props.add(new Property(Package.FIELD_ATTRIBUTE, "root"));\r
+               props.add(new Property(Package.FIELD_PACKAGE_SIZE, "0"));\r
+               props.add(new Property(Package.FIELD_UNCOMPRESSED_SIZE, "0"));\r
+               \r
+               Package extraPackage = new Package(props);\r
+               repoPackages.add(extraPackage);\r
+       }\r
+       \r
+       /**\r
+        * Get packages from extension package server.\r
+        * @return set of packages\r
+        */\r
+       public PackageSet getExtensionPackages() {\r
+               return extensionPackages;\r
+       }\r
+       \r
+       public PackageSet getInstalledExtensionPackages() {\r
+               PackageSet extensionPackages = new PackageSet();\r
+               PackageSet pkgs = this.getInstalledPackages();\r
+               \r
+               \r
+               for (Package pkg : pkgs) {\r
+                       if (pkg.isExtensionPackage()) {\r
+                               extensionPackages.add(pkg);\r
+                       }\r
+               }\r
+               \r
+               return extensionPackages;\r
+       }\r
+       \r
+       /**\r
+        * Set installed packages.\r
+        * @param installedPackageListPath\r
+        */\r
+       public void setInstalledPackageList(File installedPackageListPath) {\r
+               List<PropertySection> sectionsInstalled = null;\r
+               PropertyParser parser = new PropertyParser();\r
+               \r
+               if(installedPackageListPath != null) {\r
+                       sectionsInstalled = parser.readFromFile(installedPackageListPath);\r
+               } else {\r
+                       sectionsInstalled= new LinkedList<PropertySection>();\r
+               }\r
+               \r
+               if (sectionsInstalled != null) {\r
+                       setInstalledPackageList(sectionsInstalled);                     \r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Set installed packages\r
+        * @param sections\r
+        */\r
+       private void setInstalledPackageList(List<PropertySection> sections) {\r
+               installedPackages = new PackageSet();\r
+               \r
+               for(PropertySection sect : sections) {\r
+                       installedPackages.add(new Package(sect.getProperties()));\r
+               }\r
+       }\r
+       \r
+       public void installedPackagesFree() {\r
+               installedPackages = null;\r
+       }\r
+       \r
+       /**\r
+        * Get package list file path from url.\r
+        * @param url\r
+        * @return Full url path\r
+        */\r
+       private URL getPackageListPath(String url, Style style) {\r
+               if (url == null || url.isEmpty()) {\r
+                       return null;\r
+               } else {\r
+                       String packageListURL = "";\r
+\r
+                       if (style == Style.NETWORK) {\r
+                               String snapshotPath = Config.getInstance().getSnapshotPath();\r
+                               \r
+                               if (snapshotPath == null || snapshotPath.isEmpty() || snapshotPath.equalsIgnoreCase("null")) {\r
+                                       String distribution = Config.getInstance().getConfigFile().getDistribution();\r
+                                       \r
+                                       Snapshot latestSnapshot = DistributionController.getInstance().getLatestSnapshot(distribution);\r
+                                       if (latestSnapshot == null) {\r
+                                               return null;\r
+                                       } else {\r
+                                               snapshotPath = DistributionController.getInstance().getLatestSnapshot(distribution).getPath();\r
+                                       }\r
+                               }\r
+                               \r
+                               packageListURL = PathUtil.addURLPath(url,\r
+                                                   snapshotPath, \r
+                                                   getPackageListFileName());\r
+                       } else {\r
+                               packageListURL = PathUtil.addURLPath(url, getPackageListFileName());\r
+                       }\r
+                       \r
+                       try {\r
+                               return new URL(packageListURL);\r
+                       } catch (MalformedURLException e) {\r
+                               Log.ExceptionLog(e);\r
+                               return null;\r
+                       }\r
+               }\r
+       }\r
+       \r
+       \r
+       \r
+       /**\r
+        * @return installed packages\r
+        */\r
+       public PackageSet getInstalledPackages() {\r
+               return (PackageSet) installedPackages.clone();\r
+       }\r
+       \r
+       /**\r
+        * Set packages of repository\r
+        * @param sections\r
+        */\r
+       protected void setRepoPackages( Map<String,List<PropertySection>> repoToSectionsMap) {\r
+               repoPackages = new PackageSet();\r
+               boolean result = setPackages(repoPackages, repoToSectionsMap, false);\r
+               if (!result) {\r
+                       Log.err("Cannot find repository. Please check your repository.");\r
+                       ErrorController.setError(ErrorCode.CANNOT_FIND_REPOSITORY);\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Set packages to <code>destPackages</code>\r
+        * @param destPackages It is set of packages.\r
+        * @param repoToSectionsMap It is added to <code>destPackages</code>\r
+        */\r
+       private boolean setPackages(PackageSet destPackages, Map<String,List<PropertySection>> repoToSectionsMap, boolean isExtensionPackage) {\r
+               if (destPackages == null) {\r
+                       destPackages = new PackageSet();\r
+               }\r
+               \r
+               if (repoToSectionsMap == null || repoToSectionsMap.isEmpty()) {\r
+                       return false;\r
+               }\r
+               \r
+               for(String repoBaseUrl : repoToSectionsMap.keySet()) {\r
+                       for(PropertySection sect : repoToSectionsMap.get(repoBaseUrl)) {\r
+                                       Package pkg = new Package(sect.getProperties(), repoBaseUrl);\r
+                                       Log.log("Check valid package version. => " + pkg);\r
+                                       pkg.getVersion(); // Vaild version check.\r
+                                       if (isExtensionPackage) {\r
+                                               if (pkg.getAttribute().equalsIgnoreCase("extra")) {\r
+                                                       pkg.setExtensionServer(repoBaseUrl);\r
+                                                       destPackages.add(pkg);\r
+                                               }\r
+                                       } else {\r
+                                               destPackages.add(pkg);\r
+\r
+                                       }\r
+                       }\r
+               }\r
+               return true;\r
+       }\r
+       \r
+       /**\r
+        * @return packages of repository\r
+        */\r
+       public PackageSet getRepoPackages() {\r
+               return repoPackages;\r
+       }\r
+       \r
+       /**\r
+        * Set repository packages.\r
+        * @param packageSet\r
+        */\r
+       public void setRepoPackages(PackageSet packageSet) {\r
+               repoPackages = packageSet;\r
+       }\r
+       \r
+       /**\r
+        * @return root meta packages of repository\r
+        */\r
+       public PackageSet getRootMetaPackagesOfRepository() {\r
+               PackageSet clone = (PackageSet) repoPackages.clone();\r
+               \r
+               // Repository packages should not have extension packages.\r
+               for (Package pkg : repoPackages) {\r
+                       if (pkg.isExtensionPackage()) {\r
+                               clone.remove(pkg);\r
+                       }\r
+               }\r
+               \r
+               repoPackages = clone;\r
+               \r
+               return rootMeta(repoPackages);\r
+       }\r
+       \r
+       /**\r
+        * Get install meta packages from repository.\r
+        * @return\r
+        */\r
+       public PackageSet getInstallMetaPackagesOfRepository() {\r
+               return installMeta(repoPackages);\r
+       }\r
+       \r
+       /**\r
+        * Get root meta package from extension package server()\r
+        */\r
+       public PackageSet getRootMetaPackagesOfExtensionServer() {\r
+               return rootMeta(extensionPackages);\r
+       }\r
+       \r
+       /**\r
+        * @return recent packages. This includes the latest packages among all packages from currently \r
+        *              installed packages and packages of repository if a package has several versions.\r
+        */\r
+       public PackageSet getRecentPackages() {\r
+               if(recentPackages == null) {\r
+                       recentPackages = new PackageSet();\r
+                       for(Package ip : installedPackages) {\r
+                               if(repoPackages != null && repoPackages.contains(ip)) {\r
+                                       Package rp = repoPackages.getPackage(ip);\r
+                                       Log.log("Repo packages : " + repoPackages);\r
+                                       if(ip.getVersion().compareTo(rp.getVersion()) > 0) {\r
+                                               recentPackages.add(ip);\r
+                                       } else {\r
+                                               recentPackages.add(rp);\r
+                                       }\r
+                               } else if (extensionPackages != null && extensionPackages.contains(ip)) {\r
+                                       Package ep = extensionPackages.getPackage(ip);\r
+                                       if(ip.getVersion().compareTo(ep.getVersion()) > 0) {\r
+                                               recentPackages.add(ip);\r
+                                       } else {\r
+                                               recentPackages.add(ep);\r
+                                       }\r
+                               } else {\r
+                                       recentPackages.add(ip);\r
+                               }\r
+                       }\r
+                       \r
+                       if (repoPackages != null) {\r
+                               for(Package rp : repoPackages) {\r
+                                       if(!recentPackages.contains(rp)) {\r
+                                               recentPackages.add(rp);\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               return recentPackages;\r
+       }\r
+       \r
+       private void setExtensionPackagesToRecentPackages() {\r
+               if (recentPackages == null) {\r
+                       recentPackages = new PackageSet();\r
+               }\r
+               \r
+               for(Package ip : installedPackages) {\r
+                       if (extensionPackages != null && extensionPackages.contains(ip)) {\r
+                               Package ep = extensionPackages.getPackage(ip);\r
+                               if(ip.getVersion().compareTo(ep.getVersion()) > 0) {\r
+                                       recentPackages.add(ip);\r
+                               } else {\r
+                                       recentPackages.add(ep);\r
+                               }\r
+                       } else {\r
+                               recentPackages.add(ip);\r
+                       }\r
+               }\r
+       }\r
+       \r
+       \r
+       \r
+       // Methods for update process\r
+       /**\r
+        * except package from installed package list. \r
+        * @param pkg\r
+        * @return\r
+        */\r
+       public boolean exceptPackageFromInstalledPackages(Package pkg) {\r
+               return installedPackages.remove(pkg);\r
+       }\r
+       \r
+       /**\r
+        * Add package to installed package list.\r
+        * @param pkg\r
+        * @return\r
+        */\r
+       public boolean addPackageToInstalledPackages(Package pkg) {\r
+               installedPackages.remove(pkg);\r
+               return installedPackages.add(pkg);\r
+       }\r
+       \r
+       /**\r
+        * @return updatable packages among installed packages\r
+        */\r
+       public PackageSet getUpdatableInstalledPackages() {\r
+               PackageSet updatables = new PackageSet();\r
+               for(Package ip : installedPackages) {\r
+                       if(repoPackages.contains(ip)) {\r
+                               Package rp = repoPackages.getPackage(ip);\r
+                               if(rp.getVersion().compareTo(ip.getVersion()) != 0) {\r
+                                       updatables.add(ip);\r
+                               }\r
+                       }\r
+               }\r
+               return updatables;\r
+       }\r
+       \r
+       /**\r
+        * if pkg is updatable, return true. else return false.\r
+        * @param pkg\r
+        * @return\r
+        */\r
+       public boolean isUpdatable(Package pkg) {\r
+               if (pkg == null) {\r
+                       return false;\r
+               }\r
+               \r
+               PackageSet updatables = getUpdatableInstalledPackages();\r
+               if (updatables.contains(pkg)) {\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * If package set of repository is empty, return true;\r
+        * @return\r
+        */\r
+       public boolean isRepoPackagesEmpty() {\r
+               if (repoPackages == null || repoPackages.isEmpty()) {\r
+                       return true;\r
+               } else if (repoPackages.size() == 1) {\r
+                       if (repoPackages.getPackageByName("EXTRAS") != null) {\r
+                               return true;\r
+                       } else {\r
+                               return false;\r
+                       }\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * If pkg is installed, return true. else return false\r
+        * @param pkg\r
+        * @return\r
+        */\r
+       public boolean isInstalledVersion(Package pkg) {\r
+               Package installedPackage = installedPackages.getPackage(pkg);\r
+               if (installedPackage == null) {\r
+                       return false;\r
+               } else {\r
+                       Version installedVersion = installedPackage.getVersion();\r
+                       if (installedVersion.compareTo(pkg.getVersion()) == 0) {\r
+                               return true;\r
+                       } else {\r
+                               return false;\r
+                       }                       \r
+               }\r
+       }\r
+       \r
+       public PackageSet getRecentMetaPackages() {\r
+               PackageSet recentPackages = union(repoPackages, installedPackages);\r
+               return rootMeta(recentPackages);\r
+       }\r
+       \r
+       /**\r
+        * @return meta packages among installed packages\r
+        */\r
+       public PackageSet getInstalledMetaPackages() {\r
+               return meta(installedPackages);\r
+       }\r
+       \r
+       public List<String> getInstalledMetaNames() {\r
+               ArrayList<String> installedMetaNames = new ArrayList<String>();\r
+               \r
+               for (Package meta : getInstalledMetaPackages()) {\r
+                       installedMetaNames.add(meta.getPackageName());\r
+               }\r
+               \r
+               return installedMetaNames;\r
+       }\r
+       \r
+       public List<String> getInstalledPkgNames() {\r
+               ArrayList<String> installedPkgNames = new ArrayList<String>();\r
+               \r
+               for (Package pkg : getInstalledPackages()) {\r
+                       installedPkgNames.add(pkg.getPackageName());\r
+               }\r
+               \r
+               return installedPkgNames;\r
+       }\r
+       \r
+       /**\r
+        * @return meta packages among all recent packages\r
+        */\r
+       public PackageSet getAllMetaPackages() {\r
+               PackageSet allMeta = new PackageSet();\r
+               \r
+               PackageSet recentMeta = meta(recentPackages);\r
+               PackageSet extensionMeta = meta(extensionPackages);\r
+               \r
+               allMeta.addAll(recentMeta);\r
+               allMeta.addAll(extensionMeta);\r
+               \r
+               return allMeta;\r
+       }\r
+       \r
+       public PackageSet getLeafMetaPackages() {\r
+               PackageSet allMetas = meta(recentPackages);\r
+               \r
+               PackageSet leafMetas = new PackageSet();\r
+               for (Package meta : allMetas) {\r
+                       //if (depends size <= 0) is leaf\r
+                       if (meta.getDependentPackageNames().size() <= 0) {\r
+                               leafMetas.add(meta);\r
+                       } else {\r
+                               if (!isChildrenAllMeta(meta)) {\r
+                                       leafMetas.add(meta);\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               return leafMetas;\r
+       }\r
+       \r
+       public PackageSet getInstalledLeafMetaPackages() {\r
+               PackageSet allMetas = meta(installedPackages);\r
+               \r
+               PackageSet leafMetas = new PackageSet();\r
+               for (Package meta : allMetas) {\r
+                       //if (depends size <= 0) is leaf\r
+                       if (meta.getDependentPackageNames().size() <= 0) {\r
+                               leafMetas.add(meta);\r
+                       } else {\r
+                               if (!isChildrenAllMeta(meta)) {\r
+                                       leafMetas.add(meta);\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               return leafMetas;\r
+       }\r
+       \r
+       private boolean hasMetaPackagesInChildren(Package pkg) {\r
+               PackageSet dependPackages = getDependsPackages(pkg);\r
+               \r
+               if (dependPackages == null) {\r
+                       return true;\r
+               } else {\r
+                       for (Package dPackage : dependPackages) {\r
+                               if (dPackage.isMeta()) {\r
+                                       return true;\r
+                               }\r
+                       }\r
+                       return false;\r
+               }\r
+       }\r
+       private boolean isChildrenAllMeta(Package pkg) {                \r
+               PackageSet dependPackages = getDependsPackages(pkg);\r
+               \r
+               if (dependPackages == null) {\r
+                       return true;\r
+               } else {\r
+                       for (Package dPackage : dependPackages) {\r
+                               if (!dPackage.isMeta()) {\r
+                                       return false;\r
+                               }\r
+                       }\r
+                       return true;\r
+               }\r
+       }\r
+       \r
+       private PackageSet getDependsPackages(Package pkg) {\r
+               PackageSet dependPackages = new PackageSet();\r
+               if (pkg == null) {\r
+                       return dependPackages;\r
+               }\r
+               \r
+               Collection<String> depends = pkg.getDependentPackageNames();\r
+               \r
+               try {\r
+                       dependPackages = recentPackages.getPackagesByNames(depends);\r
+               } catch (IMPackageNotFound e) {\r
+                       Log.ExceptionLog(e);\r
+               }\r
+               return dependPackages;\r
+       }\r
+       \r
+       /**\r
+        * @return partner meta packages among all meta packages.\r
+        */\r
+       public PackageSet getPartnerMetaPackages() {\r
+               PackageSet allMetas = meta(recentPackages);\r
+               \r
+               PackageSet partnerMeta = new PackageSet();\r
+               for (Package meta : allMetas) {\r
+                       if (meta.isPartnerMeta()) {\r
+                               partnerMeta.add(meta);\r
+                       }\r
+               }\r
+               \r
+               return partnerMeta;\r
+       }\r
+       \r
+       /**\r
+        * @return public meta packages among all meta packages.\r
+        */\r
+       public PackageSet getPublicMetaPackages() {\r
+               PackageSet allMetas = meta(recentPackages);\r
+               \r
+               PackageSet publicMeta = new PackageSet();\r
+               for (Package meta : allMetas) {\r
+                       if (meta.isPublicMeta()) {\r
+                               publicMeta.add(meta);\r
+                       }\r
+               }\r
+               \r
+               return publicMeta;\r
+       }\r
+       \r
+       /**\r
+        * Get dependency packages of installable package.\r
+        * @param pkgs installable packages.\r
+        * @return\r
+        */\r
+       public PackageSet getDependsPackagesFromRepository(PackageSet pkgs) {\r
+               return dep(pkgs, State.INSTALL);\r
+       }\r
+       \r
+       /**\r
+        * @return meta packages that have no updates considering its dependents\r
+        */\r
+       public PackageSet getNotUpdatableMetaPackages() {\r
+               PackageSet noup = new PackageSet();\r
+               for(Package m : getAllMetaPackages()) {\r
+                       if(!isMetaUpdatable(m)) {\r
+                               noup.add(m);\r
+                       }\r
+               }\r
+               return noup;\r
+       }\r
+       \r
+       public PackageSet getNotInstallableAndNotUpdatablePackages() {\r
+               PackageSet notPkg = new PackageSet();\r
+               \r
+               for (Package m :getAllMetaPackages()) {\r
+                       if (isMetaRemovable(m) && !isMetaUpdatable(m)) {\r
+                               notPkg.add(m);\r
+                       }\r
+               }\r
+               \r
+               return notPkg;\r
+       }\r
+       \r
+       /**\r
+        * @return meta packages thar are updatable among installed packages\r
+        */\r
+       public PackageSet getUpdatableMetaPackages() {\r
+               PackageSet allMetas = getAllMetaPackages();\r
+               PackageSet notUpdatableMetas = getNotUpdatableMetaPackages(); \r
+               return diff(allMetas, notUpdatableMetas);\r
+       }\r
+       \r
+       public PackageSet getUpdatableInstalledMetaPackages() {\r
+               PackageSet installedMeta = getInstalledMetaPackages();\r
+               PackageSet updatableMeta = getUpdatableMetaPackages();\r
+               return intersect(installedMeta, updatableMeta);\r
+       }\r
+\r
+       /**\r
+        * @param selectedMetas\r
+        * @return packages that will be installed after update/install resulted from the selected meta packages\r
+        */     \r
+       public PackageSet getResultPackagesAfterUpdate(PackageSet selectedMetas) {\r
+               PackageSet deps = dep(selectedMetas, State.INSTALL);\r
+               PackageSet conflicts = conflictPackages(selectedMetas);\r
+               PackageSet remainedFromConflicts = diff(installedPackages, conflicts);\r
+               return union(deps, remainedFromConflicts);\r
+       }\r
+       \r
+       /**\r
+        * Get updatable packages in update process except new packages.\r
+        * @param packageSet\r
+        * @return\r
+        */\r
+       public PackageSet getUpdatablePackagesInUpdate(PackageSet packageSet) {\r
+               PackageSet result = dep(packageSet, State.INSTALL);\r
+               PackageSet up = getUpdatableInstalledPackages();\r
+               return intersect(result, up);\r
+       }\r
+       \r
+       /**\r
+        * Get removable packages in snapshot process except new packages.\r
+        * @param selectedMetas\r
+        * @return\r
+        */\r
+       public PackageSet getRemovablePackagesInSnapshot(PackageSet selectedMetas) {\r
+               PackageSet result = dep(selectedMetas, State.UNINSTALL);\r
+               PackageSet pkgSet = getdifferentVersionFromInstalledPackages(result);\r
+               \r
+               return pkgSet;\r
+       }\r
+       \r
+       /**\r
+        * check version between sourcePackages and installedPackages, and return different version packages.\r
+        * @param pkgs \r
+        * @return Different version packages among installed packages\r
+        */\r
+       public PackageSet getdifferentVersionFromInstalledPackages(PackageSet pkgs) {\r
+               PackageSet depPkgs = dep(pkgs, State.INSTALL);\r
+               PackageSet otherVersionPackages = new PackageSet();\r
+               for(Package ip : installedPackages) {\r
+                       if(depPkgs.contains(ip)) {\r
+                               Package rp = depPkgs.getPackage(ip);\r
+                               if(rp.getVersion().compareTo(ip.getVersion()) != 0) {\r
+                                       otherVersionPackages.add(ip);\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               return otherVersionPackages;\r
+       }\r
+       \r
+       /**\r
+        * @param selectedMetas\r
+        * @return packages to newly install in update process by the selected meta packages\r
+        */\r
+       public PackageSet getInstallablePackages(PackageSet selectedMetas) {\r
+               PackageSet installablePackages = null;\r
+               if (isReInstall()) {\r
+                       installablePackages = dep(selectedMetas, State.INSTALL);\r
+               } else if (Config.isSupportMultiSDK()) {\r
+                       if (Config.status == Config.Status.INSTALL) {\r
+                               installablePackages = dep(selectedMetas, State.INSTALL);                                \r
+                       } else if (Config.status == Config.Status.UPDATE) {\r
+                               PackageSet result = getResultPackagesAfterUpdate(selectedMetas);\r
+                               installablePackages = diffPackageWithVersion(result, installedPackages);\r
+                       }\r
+               } else {\r
+                       PackageSet result = getResultPackagesAfterUpdate(selectedMetas);\r
+                       installablePackages = diffPackageWithVersion(result, installedPackages);\r
+               }\r
+               \r
+               return installablePackages;\r
+       }\r
+       \r
+       /**\r
+        * @param selectedMetas\r
+        * @return packages to update in update process by the selected meta packages\r
+        */\r
+       public PackageSet getToUpdatePackagesInUpdate(PackageSet selectedMetas) {\r
+               PackageSet result = getResultPackagesAfterUpdate(selectedMetas);\r
+               PackageSet up = getUpdatableInstalledPackages();\r
+               return intersect(result, up);\r
+       }\r
+\r
+\r
+       /**\r
+        * Get conflict packages that installed.\r
+        * @param packageSet\r
+        * @return packages to remove in update process by conflicts with the selected meta packages \r
+        */\r
+       public PackageSet getConflictPackagesInUpdate(PackageSet packageSet) {          \r
+               return intersect(installedPackages, getConflictPackages(packageSet));\r
+       }\r
+       \r
+       /**\r
+        * Get conflict packages that contain reverse depends packages. \r
+        * @param packageSet\r
+        * @return\r
+        */\r
+       public PackageSet getConflictPackages(PackageSet packageSet) {\r
+               PackageSet conflicts = conflictPackages(packageSet);\r
+               \r
+               conflicts.addAll(reverseDep(conflicts));\r
+               return intersect(getConflictMetaPackages(), conflicts);\r
+       }\r
+       \r
+       /**\r
+        * Get conflict packages that contain reverse depends packages. \r
+        * @param packageSet\r
+        * @return\r
+        */\r
+       public PackageSet getConflictPackages(Package pkg) {\r
+               PackageSet conflicts = conflictPackages(pkg);\r
+               \r
+               conflicts.addAll(reverseDep(conflicts));\r
+               return intersect(getConflictMetaPackages(), conflicts);\r
+       }\r
+       \r
+       private PackageSet getConflictMetaPackages() {          \r
+               PackageSet leafMetas = new PackageSet();\r
+               for (Package meta : recentPackages) {\r
+                       //if (depends size <= 0) is leaf\r
+                       if (meta.getDependentPackageNames().size() <= 0) {\r
+                               leafMetas.add(meta);\r
+                       } else {\r
+                               if (!hasMetaPackagesInChildren(meta)) {\r
+                                       leafMetas.add(meta);\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               return leafMetas;\r
+       }\r
+       \r
+       // Methods for remove process\r
+       \r
+       /**\r
+        * @return packages that can be removed\r
+        */\r
+       public PackageSet getRemovableMetaPackages() {\r
+               return getInstalledMetaPackages();\r
+       }\r
+       \r
+       public PackageSet getInstallableMetaPackagesInSnapshot() {\r
+               PackageSet repoMetas = meta(repoPackages);\r
+               \r
+               PackageSet installableMeta = new PackageSet();\r
+               for (Package metaPackage : repoMetas) {\r
+                       if (isMetaInstallable(metaPackage)) {\r
+                               installableMeta.add(metaPackage);\r
+                       }\r
+               }\r
+               \r
+               return installableMeta;\r
+       }\r
+       \r
+       /**\r
+        * Get remove packages by selected metas.\r
+        * @param selectedMetas\r
+        * @return packages to remove in remove process\r
+        */\r
+       public PackageSet getToRemovePackagesInRemove(PackageSet selectedMetas) {\r
+               if (Options.doRemoveNoUI) {\r
+                       // When installmanager removes specific packages, it should consider package dependency.\r
+                       // For example, 'sdb' package depends on 'tizen-web-cli' and 'tizen-native-cli'.\r
+                       // In this case, when installmanager removes 'tizen-web-cli' package, 'sdb' package should\r
+                       // not be removed because of 'tizen-native-cli'.\r
+                       \r
+                       // Get candidate packages to remove. \r
+                       PackageSet depMetas = getDependMetas(selectedMetas, State.UNINSTALL);\r
+                       PackageSet dep = dep(depMetas, State.UNINSTALL);\r
+                       PackageSet mayRemove = intersect(installedPackages, dep);\r
+                       \r
+                       // Get packages to remain.\r
+                       PackageSet remainMetas = diff(getInstalledLeafMetaPackages(), depMetas);\r
+                       PackageSet remainPackages = dep(remainMetas, State.UNINSTALL);\r
+                       \r
+                       // Get packages to remove.\r
+                       PackageSet toRemove = diff(mayRemove, remainPackages);\r
+                       return reverseSet(toRemove);                    \r
+               } else {\r
+                       // InstallManager removes whole SDK.\r
+                       PackageSet dep = dep(selectedMetas, State.UNINSTALL);\r
+                       return reverseSet(dep);\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * @param selectedMetas\r
+        * @return packages that will be remained after remove resulted from the selected meta packages\r
+        */\r
+       public PackageSet getResultPackagesAfterRemove(PackageSet selectedMetas) {\r
+               return diff(getInstalledMetaPackages(), selectedMetas);\r
+       }\r
+       \r
+       // set handling methods\r
+       \r
+       /**\r
+        * @param pset\r
+        * @return meta packages in the package set\r
+        */\r
+       private PackageSet meta(PackageSet pset) {\r
+               PackageSet metas = new PackageSet();\r
+               \r
+               if (pset == null) {\r
+                       return metas;\r
+               }\r
+               \r
+               for(Package p : pset) {\r
+                       if(p.isMeta()) {\r
+                               metas.add(p);\r
+                       }\r
+               }\r
+               return metas;\r
+       }\r
+       \r
+       /**\r
+        * @param pset\r
+        * @return meta packages in the package set\r
+        */\r
+       private PackageSet rootMeta(PackageSet pset) {\r
+               PackageSet metas = new PackageSet();\r
+               for(Package p : pset) {\r
+                       if (!Options.doTest) {\r
+                               if(p.isRootMeta() || p.isExtraMeta() || p.isPublicMeta()) {\r
+                                       metas.add(p);\r
+                               }\r
+                       } else {\r
+                               if(p.isRootMeta() || p.isExtraMeta() || p.isPublicMeta() || p.isTestMeta()) {\r
+                                       metas.add(p);\r
+                               }\r
+                       }\r
+               }\r
+               return metas;\r
+       }\r
+       \r
+       /**\r
+        * @param pset\r
+        * @return meta packages in the package set\r
+        */\r
+       private PackageSet installMeta(PackageSet pset) {\r
+               PackageSet metas = new PackageSet();\r
+               for(Package p : pset) {\r
+                       if(p.isInstallMeta()) {\r
+                               metas.add(p);\r
+                       }\r
+               }\r
+               return metas;\r
+       }\r
+       \r
+       /**\r
+        * Get dependency package list from p.\r
+        * @param p a package\r
+        * @return all the packages that the given package depends on directly or indirectly\r
+        */\r
+       private PackageSet dep(Package p, State state) {\r
+               // depth first traverse on dependency graph\r
+               PackageSet dep = new PackageSet();\r
+               Stack<Package> pkgStack = new Stack<Package>();\r
+               pkgStack.push(p);\r
+               while(!pkgStack.isEmpty()) {\r
+                       Package pkg = pkgStack.pop();\r
+                               \r
+                       if(!dep.contains(pkg)) {\r
+                               dep.add(pkg);\r
+                               PackageSet depPackageSet = new PackageSet();\r
+                               try {\r
+                                       if (state == State.INSTALL) {\r
+                                               if (repoPackages.contains(pkg)) {\r
+                                                       depPackageSet = repoPackages.getPackagesByNames(pkg.getDependentPackageNames());\r
+                                               } else if (extensionPackages.contains(pkg)) {\r
+                                                       depPackageSet = extensionPackages.getPackagesByNames(pkg.getDependentPackageNames());\r
+                                               }\r
+                                       } else if (state == State.UNINSTALL){\r
+                                               depPackageSet = installedPackages.getPackagesByNames(pkg.getDependentPackageNames());\r
+                                       } else {\r
+                                               Log.err("State class have two state(INSTALL/UNINSTALL) ");\r
+                                               throw new IMFatalException(ErrorCode.UNKOWN_ERROR); \r
+                                       }\r
+                               } catch (IMPackageNotFound e) {\r
+                                       Log.err("Finding dependents: "+p+": Package does not exist: " + e.getPackageName()+ " or "+ pkg.getDependentPackageNames());\r
+                                       throw new IMFatalException(ErrorCode.CANNOT_FIND_PACKAGE);\r
+                               }\r
+\r
+                               for(Package depPkg : depPackageSet) {\r
+                                       if(p.equals(depPkg)) {\r
+                                               Log.err("Circular dependency found: "+p);\r
+                                               throw new IMFatalException(ErrorCode.CIRCULAR_PACKAGE_DEPENDENCY);\r
+                                       }\r
+                                       pkgStack.push(depPkg);\r
+                               }\r
+                       } else {\r
+                               // already visited.\r
+                               addDependsSet(dep, pkg);\r
+                       }\r
+               }\r
+               \r
+               return reverseSet(dep);\r
+       }\r
+       \r
+       private PackageSet reverseDep(PackageSet packages) {\r
+               PackageSet reversePackages = new PackageSet();\r
+               \r
+               for (Package pkg : packages) {\r
+                       reversePackages.addAll(reverseDep(pkg));\r
+               }\r
+               \r
+               return reversePackages;\r
+       }\r
+       \r
+       /**\r
+        * Need reverse depends when remove.\r
+        * @param p\r
+        * @return\r
+        */\r
+       private PackageSet reverseDep(Package p) {\r
+               // depth first traverse on dependency graph\r
+               PackageSet reverseDep = new PackageSet();\r
+               Stack<Package> pkgStack = new Stack<Package>();\r
+               pkgStack.push(p);\r
+               while(!pkgStack.isEmpty()) {\r
+                       Package pkg = pkgStack.pop();\r
+                               \r
+                       if(!reverseDep.contains(pkg)) {\r
+                               reverseDep.add(pkg);\r
+                               \r
+                               for (Package recentPkg : recentPackages) {\r
+                                       Collection<String> dependsList = recentPkg.getDependentPackageNames();\r
+                                       for (String pkgName :  dependsList) {\r
+                                               if (pkgName.equals(pkg.getPackageName())) {\r
+                                                       pkgStack.push(recentPkg);\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                                       \r
+                               }\r
+                       } else {\r
+                               // already visited\r
+                               addDependsSet(reverseDep, pkg);\r
+                       }\r
+               }\r
+               \r
+               return reverseDep;\r
+       }\r
+       \r
+       /**\r
+        * Remove saved package and save package at the end of set.\r
+        * @param dependsSet\r
+        * @param pkg\r
+        */\r
+       private void addDependsSet(PackageSet dependsSet, Package pkg) {\r
+               if (dependsSet.contains(pkg)) {\r
+                       dependsSet.remove(pkg);\r
+               }\r
+               \r
+               dependsSet.add(pkg);\r
+       }\r
+       \r
+       /**\r
+        * reverse package list.\r
+        * @param pkgSet\r
+        * @return\r
+        */\r
+       public PackageSet reverseSet(PackageSet pkgSet) {\r
+               if (pkgSet == null) {\r
+                       return null;\r
+               }\r
+               \r
+               Stack<Package> stack = new Stack<Package>();\r
+               for (Package pkg : pkgSet) {\r
+                       stack.push(pkg);\r
+               }\r
+               \r
+               PackageSet reverseSet = new PackageSet();\r
+               \r
+               while(!stack.isEmpty()) {\r
+                       reverseSet.add(stack.pop());\r
+               }\r
+               \r
+               return reverseSet;\r
+       }\r
+       \r
+       /**\r
+        * @param pset package set\r
+        * @return all the packages that the given packages depends on directly or indirectly\r
+        */\r
+       private PackageSet dep(PackageSet pset, State state) {\r
+               PackageSet dep = new PackageSet();\r
+               for(Package p : pset) {\r
+                       dep.addAll(dep(p, state));\r
+               }\r
+               return dep;\r
+       }\r
+       \r
+       /**\r
+        * Get conflict package list from p.\r
+        * @param p\r
+        * @return packages that conflict with the given package directly or indirectly\r
+        */\r
+       public PackageSet conflictPackages(Package p) {\r
+               PackageSet conflicts = new PackageSet();\r
+               PackageSet dep = dep(p, State.INSTALL);\r
+               for(Package pkg : dep) {\r
+                       Collection<String> conflictPackageNames = pkg.getConflictPackageNames();\r
+                       for(String conflictPackageName : conflictPackageNames) {\r
+                               if(installedPackages.hasPackageByName(conflictPackageName)) {\r
+                                       Package conflictPackage = installedPackages.getPackageByName(conflictPackageName);\r
+                                       conflicts.addAll(reverseDep(conflictPackage));\r
+                               } else if (repoPackages.hasPackageByName(conflictPackageName)) {\r
+                                       Package conflictPackage = repoPackages.getPackageByName(conflictPackageName);\r
+                                       conflicts.addAll(reverseDep(conflictPackage));\r
+                               }\r
+                       }\r
+               }\r
+               return conflicts;\r
+       }\r
+       \r
+       /**\r
+        * Get conflict package list.\r
+        * @param pset\r
+        * @return packages that conflict with the given packages directly or indirectly \r
+        */\r
+       public PackageSet conflictPackages(PackageSet pset) {\r
+               PackageSet conflicts = new PackageSet();\r
+               for(Package p : pset) {\r
+                       conflicts.addAll(conflictPackages(p));\r
+               }\r
+               return conflicts;\r
+       }\r
+       \r
+       /**\r
+        * Adds packages of pset2 to packages of pset1.\r
+        * @param pset1\r
+        * @param pset2\r
+        * @return new package set has the union of pset1 and pset2.\r
+        */\r
+       private PackageSet union(PackageSet pset1, PackageSet pset2) {\r
+               PackageSet union = (PackageSet) pset1.clone();\r
+               union.addAll(pset2);\r
+               return union;\r
+       }\r
+       \r
+       /**\r
+        * Removes packages of pset2 from packages of pset1.\r
+        * @param pset1\r
+        * @param pset2\r
+        * @return new package set that represents (pset1 - pset2). \r
+        */\r
+       public PackageSet diff(PackageSet pset1, PackageSet pset2) {\r
+               PackageSet diff = new PackageSet();\r
+               for(Package p : pset1) {\r
+                       if(!pset2.contains(p)) {\r
+                               diff.add(p);\r
+                       }\r
+               }\r
+               return diff;\r
+       }\r
+       \r
+       private PackageSet diffPackageWithVersion(PackageSet pset1, PackageSet pset2) {\r
+               PackageSet diff = new PackageSet();\r
+               for(Package p : pset1) {\r
+                       Package pkg = pset2.getPackage(p);\r
+                       \r
+                       if (pkg == null) {\r
+                               diff.add(p);\r
+                       } else {\r
+                               if (Version.compareTo(p.getVersion(), pkg.getVersion()) != 0) {\r
+                                       diff.add(p);\r
+                               }\r
+                       }\r
+               }\r
+               return diff;\r
+       }\r
+       \r
+       /**\r
+        * \r
+        * @param pset1\r
+        * @param pset2\r
+        * @return new set of intersection of pset1 and pset2. It has the order of pset1.\r
+        */\r
+       private PackageSet intersect(PackageSet pset1, PackageSet pset2) {\r
+               PackageSet pset = new PackageSet();\r
+               for(Package p : pset1) {\r
+                       if(pset2.contains(p)) {\r
+                               pset.add(p);\r
+                       }\r
+               }\r
+               return pset;\r
+       }\r
+       \r
+       private PackageSet getDependMetas(PackageSet packageSet, State state) {\r
+               PackageSet depMetas = new PackageSet();\r
+               PackageSet depPkgs = dep(packageSet, state);\r
+               for (Package p : depPkgs) {\r
+                       if (p.isMeta()) {\r
+                               depMetas.add(p);\r
+                       }\r
+               }\r
+               \r
+               return depMetas;\r
+       }\r
+       \r
+       /**\r
+        * @param m meta package to be checked updatable\r
+        * @return <code>true</code> if the meta package is updatable. \r
+        *              ie. the meta package is installed and one of its dependents is already installed and is updatable.\r
+        */\r
+       public boolean isMetaUpdatable(Package m) {             \r
+               // if one of the meta package's dependents is installed and updatable, the meta package is updatable.\r
+               PackageSet dep = dep(m, State.INSTALL);\r
+\r
+               for(Package p : dep) {\r
+                       \r
+                       if(installedPackages.contains(p)) {\r
+                               Package ip = installedPackages.getPackage(p);\r
+                               if (ip == null) {\r
+                                       continue;\r
+                               }\r
+                               \r
+                               Package rp = null;\r
+                               if (repoPackages != null && repoPackages.hasPackage(p)) {\r
+                                       rp = repoPackages.getPackage(p);\r
+                               } else if (extensionPackages != null && extensionPackages.hasPackage(p)) {\r
+                                       rp = extensionPackages.getPackage(p);\r
+                               }\r
+                               \r
+                               // checks p is updatable\r
+                               if(rp != null && rp.getVersion().compareTo(ip.getVersion()) != 0) {\r
+                                       return true;\r
+                               }\r
+                       }\r
+               }\r
+               return false;\r
+       }\r
+       \r
+\r
+       \r
+       /**\r
+        * @param m meta package to be checked removable\r
+        * @return <code>true</code> if the meta package is removable \r
+        *              ie. the meta package is installed and one of its dependents is already installed and is removable.\r
+        */\r
+       private boolean isMetaRemovable(Package m) {\r
+               // if the meta package is not installed, it's never updatable\r
+               if(installedPackages.contains(m)) {\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * check new installation or upgrade or downgrade.\r
+        * @param meta meta package to be checked installable.\r
+        * @return <code>true</code> if the meta package is updatable. \r
+        *              ie. the meta package is installed and one of its dependents is already installed and is updatable.\r
+        */\r
+       private boolean isMetaInstallable(Package meta) {                               \r
+               // if one of the meta package's dependents is installed and updatable, the meta package is updatable.\r
+               PackageSet dep = dep(meta, State.INSTALL);\r
+               \r
+               for(Package p : dep) {\r
+                       //Do not check meta package. It is only used by install-type or category.\r
+                       if (p.isMeta()) {\r
+                               continue;\r
+                       }\r
+                       \r
+                       if(installedPackages.contains(p)) {\r
+                               Package ip = installedPackages.getPackage(p);\r
+                               if (ip == null) {\r
+                                       continue;\r
+                               }\r
+                               \r
+                               Package rp = repoPackages.getPackage(p); // rp always exists if ip exists\r
+                               \r
+                               // checks p is updatable\r
+                               if(rp.getVersion().compareTo(ip.getVersion()) != 0) {\r
+                                       return true;\r
+                               }\r
+                       } else {\r
+                               return true;\r
+                       }\r
+               }\r
+               return false;\r
+       }\r
+       \r
+       // utility methods\r
+       /**\r
+        * Get installed package.\r
+        * @param pkg\r
+        * @return If not exist package in installed package list, return empty string.\r
+        */\r
+       public Package getInstalledPackageByName(String pkgName) {\r
+               Package retPkg = installedPackages.getPackageByName(pkgName);\r
+               \r
+               return retPkg;\r
+       }\r
+       \r
+       /**\r
+        * Get installed packages by package name.\r
+        * @param pkgName name of packages\r
+        * @return If not exist package in installed package list, return empty string.\r
+        */\r
+       public PackageSet getInstalledPackagesByName(List<String> pkgNames) {\r
+               PackageSet installedPackages = new PackageSet();\r
+               for (String pkg : pkgNames) {\r
+                       Package retPkg = getInstalledPackageByName(pkg);\r
+                       \r
+                       if (retPkg != null) {\r
+                               installedPackages.add(retPkg);\r
+                       }\r
+               }\r
+               \r
+               return installedPackages;\r
+       }\r
+       \r
+       /**\r
+        * Get Package instance from package name.\r
+        * @param pkgName\r
+        * @return\r
+        */\r
+       public Package getPackageByName(String pkgName) {\r
+               PackageSet packageList = repoPackages;\r
+               packageList.addAll(extensionPackages);\r
+               \r
+               if (packageList.hasPackageByName(pkgName)) {\r
+                       return packageList.getPackageByName(pkgName);\r
+               } else {\r
+                       return null;\r
+               }\r
+       }\r
+       \r
+       public boolean existsPackage(String packageName) {\r
+               if (getPackageByName(packageName) != null) {\r
+                       return true;\r
+               } else if (getInstalledPackageByName(packageName) != null) {\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       public void removePackageFromPackageManager(String pkgName) {\r
+               PackageSet clone = (PackageSet) repoPackages.clone();\r
+               Package pkg = clone.getPackageByName(pkgName);\r
+               \r
+               if (clone.hasPackage(pkg)) {\r
+                       clone.remove(pkg);\r
+               }\r
+               \r
+               repoPackages = clone;\r
+       }\r
+       /**\r
+        * @param packageNames\r
+        * @return packages collected by the given package names\r
+        */\r
+       public PackageSet getPackagesByNames(Collection<String> packageNames) {\r
+               PackageSet pset = new PackageSet();\r
+               for(String name : packageNames) {\r
+                       if(repoPackages.hasPackageByName(name)) {\r
+                               Package pkg = repoPackages.getPackageByName(name);\r
+                               pset.add(pkg);\r
+                       } else if (extensionPackages.hasPackageByName(name)) {\r
+                               Package pkg = extensionPackages.getPackageByName(name);\r
+                               pset.add(pkg);\r
+                       } else {\r
+                               throw new IMFatalException(ErrorCode.CANNOT_FIND_FILE_IN_REPOSITROY);\r
+                       }\r
+               }\r
+               return pset;\r
+       }\r
+       \r
+       public PackageSet getMandatoryPackages() {\r
+               PackageSet pSet = new PackageSet();\r
+               \r
+               for (Package pkg : repoPackages) {\r
+                       if (pkg.isMandatory()) {\r
+                               pSet.add(pkg);\r
+                       }\r
+               }\r
+               \r
+               return pSet;\r
+       }\r
+       \r
+       public PackageSet getUpdatableMandatoryPackages() {\r
+               PackageSet pSet = new PackageSet();\r
+               \r
+               for (Package mPkg : getMandatoryPackages()) {\r
+                       if (!installedPackages.contains(mPkg)) {\r
+                               pSet.add(mPkg);\r
+                       } else if(isUpdatable(mPkg)) {\r
+                               pSet.add(mPkg);\r
+                       } else {\r
+                               continue;\r
+                       }\r
+               }\r
+               \r
+               return pSet;\r
+       }\r
+       \r
+       /**\r
+        * Check installed meta packages\r
+        * @return if installed package exists, return true. if not return false.\r
+        */\r
+       public boolean existInstalledMetaPackages() {\r
+               if (getInstalledMetaPackages().size() <= 0) {\r
+                       return false;\r
+               } else {\r
+                       return true;\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Check installable meta packages\r
+        * @return if installable meta package exists, return true. if not return false.\r
+        */\r
+       public boolean existInstallableMetaPackages() {\r
+               if (getInstalledMetaPackages().size() <= 0) {\r
+                       return false;\r
+               } else {\r
+                       return true;\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Check installed packages.\r
+        * @return if installed package exists, return true. if not return false.\r
+        */\r
+       public boolean existInstalledPackages() {\r
+               if (installedPackages.size() <= 0) {\r
+                       return false;\r
+               } else {\r
+                       return true;\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Check installable or updatable packages.\r
+        * @return if installable package exists, return true. if not return false.\r
+        */\r
+       public boolean existInstallablePackages() {\r
+               for(Package p : repoPackages) {\r
+                       if(installedPackages.contains(p)) {\r
+                               Package ip = installedPackages.getPackage(p);\r
+                               if (ip == null) {\r
+                                       continue;\r
+                               }\r
+                               \r
+                               Package rp = recentPackages.getPackage(p); // rp always exists if ip exists\r
+                               // checks p is updatable\r
+                               if(rp.getVersion().compareTo(ip.getVersion()) > 0) {\r
+                                       return true;\r
+                               }\r
+                       }\r
+               }\r
+               return false;\r
+       }\r
+       \r
+       /**\r
+        * get total size to remove. \r
+        * @param pkg\r
+        * @return\r
+        */\r
+       public long getTotalSizeOfRemovablePackages(Package pkg) {\r
+               PackageSet pkgs = new PackageSet();\r
+               \r
+               pkgs.add(pkg);\r
+               PackageSet depPkgSet = getToRemovePackagesInRemove(pkgs);\r
+               \r
+               return getTotalSize(depPkgSet, true);\r
+       }\r
+       \r
+       /**\r
+        * get total size to install. \r
+        * @param pkg\r
+        * @param isUncompressed Uncompressed is true, not false.\r
+        * @return\r
+        */\r
+       public long getTotalSizeOfInstallablePackages(PackageSet pkgs, boolean isUncompressed) {\r
+               PackageSet depPkgSet = getInstallablePackages(pkgs);\r
+               \r
+               return getTotalSize(depPkgSet, isUncompressed);\r
+       }\r
+       \r
+       /**\r
+        * get total size to remove. \r
+        * @param pkg\r
+        * @return\r
+        */\r
+       public long getTotalSizeOfRemovablePackages(PackageSet pkgs) {\r
+               PackageSet depPkgSet = getRemovablePackagesInSnapshot(pkgs);\r
+               \r
+               return getTotalSize(depPkgSet, true);\r
+       }\r
+\r
+       /**\r
+        * Get uncompressed packages size or compressed(zipped) packages size.\r
+        * @param pkgs Packages set which can be calculated total size.\r
+        * @param isUncompressed Uncompressed is true, not false.\r
+        * @return\r
+        */\r
+       private long getTotalSize(PackageSet pkgs, boolean isUncompressed) {\r
+               long totalSize = 0;\r
+               for (Package depPkg : pkgs) {\r
+                       if (isUncompressed) {\r
+                               totalSize += depPkg.getUncompressedPackageSize();                               \r
+                       } else {\r
+                               totalSize += depPkg.getPackageSize();                           \r
+                       }\r
+               }\r
+               \r
+               return totalSize;\r
+       }\r
+       \r
+       /**\r
+        * @return <code>true</code> if installed and repository packages are empty.\r
+        */\r
+       public boolean isEmpty() {\r
+               \r
+               if (installedPackages.size() <= 0 && repoPackages.size() <= 0) {\r
+                       return true;\r
+               }\r
+               \r
+               return false;\r
+       }\r
+       \r
+       /**\r
+        * Get Installable packages.\r
+        * @return packages that can be newly installable.\r
+        */\r
+       public PackageSet getInstallableMetaPackages() {\r
+               return diff(getAllMetaPackages(), getInstalledMetaPackages());\r
+       }\r
+\r
+       /**\r
+        * @return packages that can be newly installable or updatable. \r
+        */\r
+       public PackageSet getInstallableOrUpdatableMetaPackages() {\r
+               PackageSet installableMetaPackages = new PackageSet();\r
+               PackageSet allMetaPackages = getAllMetaPackages();\r
+               \r
+               for (Package metaPackage : allMetaPackages) {\r
+                       if (isMetaInstallable(metaPackage)) {\r
+                               installableMetaPackages.add(metaPackage);\r
+                       }\r
+               }\r
+               \r
+               return installableMetaPackages;\r
+       }\r
+       \r
+       \r
+       /**\r
+        * Check missing packages from repository's package list.   \r
+        * @return packages that is missing in repository's package list.\r
+        */\r
+       public PackageSet getMissingPackagesFromRepository() {\r
+               PackageSet missingPackages = new PackageSet();\r
+               \r
+               if (!repoPackages.isEmpty()) {\r
+                       missingPackages = diff(installedPackages, repoPackages);\r
+                       missingPackages = diff(missingPackages, extensionPackages);\r
+               }\r
+               \r
+               return missingPackages;\r
+       }\r
+       \r
+       /**\r
+        * save packages to installedpackage.list\r
+        * @param filePath\r
+        */\r
+       public void saveInstalledList() {\r
+               String filePath = PathUtil.get(\r
+                               PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY),\r
+                               Config.INSTALLED_PACKAGE_LIST_FILE_NAME);\r
+               \r
+        PropertyParser parser = new PropertyParser();\r
+        List<PropertySection> pSections = saveProperySectionsFromPackages(installedPackages);\r
+        parser.writeToFile(pSections, filePath);\r
+    }\r
+       \r
+       /**\r
+        * save information of packages.\r
+        * @param packages \r
+        * @return\r
+        */\r
+       public List<PropertySection> saveProperySectionsFromPackages(PackageSet packages) {\r
+       List<PropertySection> pSections = new ArrayList<PropertySection>();\r
+       PropertySection pSection = null;\r
+       Properties properties = null;\r
+       \r
+       for (Package pkg : packages) {\r
+               properties = (Properties)pkg.getProperties();\r
+               pSection = new PropertySection();\r
+               pSection.setProperties(properties);\r
+               pSections.add(pSection);\r
+       }\r
+       \r
+       return pSections;\r
+    }\r
+       \r
+       /**\r
+        * Check the repository change.\r
+        * @return\r
+        */\r
+       public boolean isRepositoryChanged() {          \r
+               if (installedRepository == null || !currentRepository.equalsIgnoreCase(installedRepository)) {\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Check to need re-installation.\r
+        * If there has been a change distribution or repository or SDK image, force to re-install.\r
+        * @return If it needs to re-install, return true. otherwise return false.\r
+        */\r
+       public boolean isReInstall() {\r
+               if (isInstallInstallManager) {\r
+                       return  false;\r
+               } else if (Config.fromWhere == Config.ConfDialog.LOCAL_IMAGE) {\r
+                       return true;\r
+               } else  if (isRepositoryChanged()) {\r
+                       return true;\r
+               } else {\r
+                       if (DistributionController.getInstance().isDistributionChanged()) {\r
+                               return true;\r
+                       } else {\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+       \r
+       public boolean isConflict(PackageSet pkgsToInstall, Package pkg) {\r
+               return false;\r
+       }\r
+       \r
+       /**\r
+        * Prints dependency graph of packages in dot format to stdout.\r
+        * @throws IMExitException \r
+        */\r
+       public void printDepGraph() {\r
+               StringBuffer buf = new StringBuffer();\r
+               \r
+               buf.append("digraph G {\n");\r
+               \r
+               for(Package p : recentPackages) {\r
+                       PackageSet dep = dep(p, State.INSTALL);\r
+                       \r
+                       for(Package d : dep) {\r
+                               if(!d.equals(p)) {\r
+                                       buf.append("\""+p+"\" -> \"" + d + "\";\n");\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               buf.append("}\n");\r
+               System.out.println(buf);\r
+       }\r
+       \r
+       public static void dispose() {\r
+               if (pm != null) {\r
+                       pm = null;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Get PackageManager singleton instance.\r
+        * @param installed\r
+        * @param repoPackagesUrls\r
+        * @return\r
+        * @throws IOException\r
+        */\r
+       public static PackageManager getInstance(File installed, Collection<String> repoPackagesUrls) throws IOException {\r
+               if (Options.platForm == null) {\r
+                       if (Config.isSupportMultiSDK) {\r
+                               if (Registry.targetPath != "") {\r
+                                       pm = null;\r
+                                       if (Platform.isLinux()) {\r
+                                               pm = new LinuxPackageManager(installed, repoPackagesUrls);\r
+                                       } else if (Platform.isWindows()) {\r
+                                               pm = new WindowsPackageManager(installed, repoPackagesUrls);\r
+                                       } else if (Platform.isMacOS()) {\r
+                                               pm = new DarwinPackageManager(installed, repoPackagesUrls);\r
+                                       } else {\r
+                                               return null;\r
+                                       }                               \r
+                               } else {\r
+                                       if (pm == null) {\r
+                                               if (Platform.isLinux()) {\r
+                                                       pm = new LinuxPackageManager(installed, repoPackagesUrls);\r
+                                               } else if (Platform.isWindows()) {\r
+                                                       pm = new WindowsPackageManager(installed, repoPackagesUrls);\r
+                                               } else if (Platform.isMacOS()) {\r
+                                                       pm = new DarwinPackageManager(installed, repoPackagesUrls);\r
+                                               } else {\r
+                                                       return null;\r
+                                               }\r
+                                       }       \r
+                               }\r
+                       } else {\r
+                               if (pm == null) {\r
+                                       if (Platform.isLinux()) {\r
+                                               pm = new LinuxPackageManager(installed, repoPackagesUrls);\r
+                                       } else if (Platform.isWindows()) {\r
+                                               pm = new WindowsPackageManager(installed, repoPackagesUrls);\r
+                                       } else if (Platform.isMacOS()) {\r
+                                               pm = new DarwinPackageManager(installed, repoPackagesUrls);\r
+                                       } else {\r
+                                               return null;\r
+                                       }\r
+                               }                               \r
+                       }\r
+               } else {\r
+                       if (pm == null) {\r
+                               if (Options.platForm.equalsIgnoreCase("ubuntu")) {\r
+                                       pm = new LinuxPackageManager(installed, repoPackagesUrls);\r
+                               } else if (Options.platForm.equalsIgnoreCase("windows")) {\r
+                                       pm = new WindowsPackageManager(installed, repoPackagesUrls);\r
+                               } else if (Options.platForm.equalsIgnoreCase("macos")) {\r
+                                       pm = new DarwinPackageManager(installed, repoPackagesUrls);\r
+                               } else {\r
+                                       return null;\r
+                               }\r
+                       }\r
+               }\r
+               return pm;\r
+       }\r
+       \r
+       public static PackageManager getInstance() {\r
+               return pm;\r
+       }\r
+       \r
+       public SDKExtensionInfo getSdkExtensionInfo() {\r
+               return SDKExtensionInfo.getInstance();\r
+       }\r
+}\r
index 5d6a2b7..7b66304 100644 (file)
-/*
-*  InstallManager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: 
-* Wooyoung Cho <wooyoung1.cho@samsung.com>
-* Shihyun Kim <shihyun.kim@samsung.com>
-* Taeyoung Son <taeyoung2.son@samsung.com>
-* Yongsung kim <yongsung1.kim@samsung.com>
-* 
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
-
-package org.tizen.installmanager.pkg.model;
-
-import java.io.File;
-import java.util.List;
-
-import org.tizen.installmanager.core.Config;
-import org.tizen.installmanager.core.IMFatalException;
-import org.tizen.installmanager.lib.ErrorController;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.lib.Platform;
-import org.tizen.installmanager.lib.ErrorController.ErrorCode;
-import org.tizen.installmanager.pkg.lib.PropertyParser;
-import org.tizen.installmanager.util.PathUtil;
-
-/**
- * This class discribes installmanager.cfg file.
- * @author reuentar
- */
-public class InstConfig {
-       public static final String INSTALL_MANAGER_CONFIG = getInstConfigHome();
-       private String SUPPORT_MULTI_SDK_FILE = "installmanager.cfg";
-       //Field of Property
-       private static final String FIELD_MULTI_SDK = "Multi-sdk";
-       
-       //Set of property
-       private Properties mProperties;
-
-       
-       public InstConfig() {
-               mProperties = new Properties();
-               if (!loadConfigFile()) {
-                       Log.err("Fail to load installmanager.cfg file");
-               } else {
-                       Log.log("Success to load installmanager.cfg file");
-               }
-       }
-       
-       private static String getInstConfigHome() {
-               if (Platform.isLinux() || Platform.isMacOS()) {
-                       return PathUtil.getFromHome(Config.INSTALL_MANAGER_CONFIG_DIRECTORY);
-               } else if (Platform.isWindows()) {
-                       return PathUtil.getFromAppData(Config.INSTALL_MANAGER_CONFIG_DIRECTORY);
-               } else {
-                       throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
-               }
-       }
-       
-       /**
-        * Load config file from configFilePath.
-        * 
-        * @param configFilePath
-        * @return
-        */
-       private boolean loadConfigFile() {
-               List<PropertySection> propertySections = null;
-
-               File instManagerCfg = new File(PathUtil.get(INSTALL_MANAGER_CONFIG, SUPPORT_MULTI_SDK_FILE));
-               
-               if (!instManagerCfg.exists()) {
-                       return false;
-               }
-
-               PropertyParser parser = new PropertyParser();
-               propertySections = parser.readFromFile(instManagerCfg);
-
-               return loadFromProperties(propertySections);
-       }
-       
-       /**
-        * Read PropertySection and make ConfigFile instance
-        * 
-        * @param propertySections
-        * @return
-        */
-       public boolean loadFromProperties(List<PropertySection> propertySections) {
-               if ((propertySections == null) || (propertySections.size() == 0)) {
-                       Log.log("(propertySections == null) || (propertySections.size() == 0)");
-                       return false;
-               }
-
-               this.setProperties(propertySections.get(0).getProperties());
-               return true;
-       }
-       
-       /**
-        * Get properties instance from this class
-        * 
-        * @return
-        */
-       public Properties getProperties() {
-               return mProperties;
-       }
-       
-       /**
-        * Set Properties instance to this class.
-        * 
-        * @param properties
-        */
-       public void setProperties(Properties properties) {
-               this.mProperties = properties;
-       }
-       
-       public boolean isSupportMultiSDK() {
-               String value = getValue(FIELD_MULTI_SDK);
-               
-               if (value.equalsIgnoreCase("true")) {
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-       
-       /**
-        * @param key
-        * @return Get value from configuration key.
-        */
-       public String getValue(String key) {
-               Property property = getProperty(key);
-
-               if (property != null) {
-                       return property.getValue();
-               } else {
-                       return "";
-               }
-       }
-       
-       /**
-        * Get Property instance from configuration key.
-        * 
-        * @param key
-        * @return
-        */
-       private Property getProperty(String key) {
-               if (mProperties != null && key != null) {
-                       for (int i = 0; i < mProperties.size(); i++) {
-                               if (key.compareTo(mProperties.get(i).getName()) == 0) {
-                                       return mProperties.get(i);
-                               }
-                       }
-               }
-               return 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.pkg.model;\r
+\r
+import java.io.File;\r
+import java.util.List;\r
+\r
+import org.tizen.installmanager.core.Config;\r
+import org.tizen.installmanager.core.IMFatalException;\r
+import org.tizen.installmanager.lib.Log;\r
+import org.tizen.installmanager.lib.Platform;\r
+import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
+import org.tizen.installmanager.pkg.lib.PropertyParser;\r
+import org.tizen.installmanager.util.PathUtil;\r
+\r
+/**\r
+ * This class discribes installmanager.cfg file.\r
+ * @author reuentar\r
+ */\r
+public class InstConfig {\r
+       public static final String INSTALL_MANAGER_CONFIG = getInstConfigHome();\r
+       private String SUPPORT_MULTI_SDK_FILE = "installmanager.cfg";\r
+       //Field of Property\r
+       private static final String FIELD_MULTI_SDK = "Multi-sdk";\r
+       \r
+       //Set of property\r
+       private Properties mProperties;\r
+\r
+       \r
+       public InstConfig() {\r
+               mProperties = new Properties();\r
+               if (!loadConfigFile()) {\r
+                       Log.err("Fail to load installmanager.cfg file");\r
+               } else {\r
+                       Log.log("Success to load installmanager.cfg file");\r
+               }\r
+       }\r
+       \r
+       private static String getInstConfigHome() {\r
+               if (Platform.isLinux() || Platform.isMacOS()) {\r
+                       return PathUtil.getFromHome(Config.INSTALL_MANAGER_CONFIG_DIRECTORY);\r
+               } else if (Platform.isWindows()) {\r
+                       return PathUtil.getFromAppData(Config.INSTALL_MANAGER_CONFIG_DIRECTORY);\r
+               } else {\r
+                       throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Load config file from configFilePath.\r
+        * \r
+        * @param configFilePath\r
+        * @return\r
+        */\r
+       private boolean loadConfigFile() {\r
+               List<PropertySection> propertySections = null;\r
+\r
+               File instManagerCfg = new File(PathUtil.get(INSTALL_MANAGER_CONFIG, SUPPORT_MULTI_SDK_FILE));\r
+               \r
+               if (!instManagerCfg.exists()) {\r
+                       return false;\r
+               }\r
+\r
+               PropertyParser parser = new PropertyParser();\r
+               propertySections = parser.readFromFile(instManagerCfg);\r
+\r
+               return loadFromProperties(propertySections);\r
+       }\r
+       \r
+       /**\r
+        * Read PropertySection and make ConfigFile instance\r
+        * \r
+        * @param propertySections\r
+        * @return\r
+        */\r
+       public boolean loadFromProperties(List<PropertySection> propertySections) {\r
+               if ((propertySections == null) || (propertySections.size() == 0)) {\r
+                       Log.log("(propertySections == null) || (propertySections.size() == 0)");\r
+                       return false;\r
+               }\r
+\r
+               this.setProperties(propertySections.get(0).getProperties());\r
+               return true;\r
+       }\r
+       \r
+       /**\r
+        * Get properties instance from this class\r
+        * \r
+        * @return\r
+        */\r
+       public Properties getProperties() {\r
+               return mProperties;\r
+       }\r
+       \r
+       /**\r
+        * Set Properties instance to this class.\r
+        * \r
+        * @param properties\r
+        */\r
+       public void setProperties(Properties properties) {\r
+               this.mProperties = properties;\r
+       }\r
+       \r
+       public boolean isSupportMultiSDK() {\r
+               String value = getValue(FIELD_MULTI_SDK);\r
+               \r
+               if (value.equalsIgnoreCase("true")) {\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * @param key\r
+        * @return Get value from configuration key.\r
+        */\r
+       public String getValue(String key) {\r
+               Property property = getProperty(key);\r
+\r
+               if (property != null) {\r
+                       return property.getValue();\r
+               } else {\r
+                       return "";\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Get Property instance from configuration key.\r
+        * \r
+        * @param key\r
+        * @return\r
+        */\r
+       private Property getProperty(String key) {\r
+               if (mProperties != null && key != null) {\r
+                       for (int i = 0; i < mProperties.size(); i++) {\r
+                               if (key.compareTo(mProperties.get(i).getName()) == 0) {\r
+                                       return mProperties.get(i);\r
+                               }\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+}\r
index e71942e..c669d00 100644 (file)
-/*
-*  InstallManager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: 
-* Wooyoung Cho <wooyoung1.cho@samsung.com>
-* Shihyun Kim <shihyun.kim@samsung.com>
-* Taeyoung Son <taeyoung2.son@samsung.com>
-* Yongsung kim <yongsung1.kim@samsung.com>
-* 
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/ 
-
-package org.tizen.installmanager.pkg.model;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-
-import org.tizen.installmanager.core.Config;
-import org.tizen.installmanager.core.IMFatalException;
-import org.tizen.installmanager.core.Options;
-import org.tizen.installmanager.lib.ErrorController.ErrorCode;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.lib.Platform;
-
-/**
- * This class describes a package.
- * 
- * @author Wooyoung Cho <wooyoung1.cho@samsung.com>
- *
- */
-public class Package {
-       
-       // fields of package control
-       // mandatory
-       public static final String FIELD_PACKAGE                = "Package";
-       public static final String FIELD_VERSION                = "Version";
-       public static final String FIELD_LABEL = "Label";
-       public static final String FIELD_MAINTAINER     = "Maintainer";
-       public static final String FIELD_DESCRIPTION    = "Description";
-
-       // etc
-       public static final String FIELD_DEPENDS                = "Install-dependency"; // list of packages that this package depends on
-       public static final String FIELD_CONFLICTS              = "Conflicts";
-       public static final String FIELD_PACKAGE_SIZE   = "Size"; // size of zipped package
-       public static final String FIELD_UNCOMPRESSED_SIZE      = "Uncompressed-size"; // uncompressed size of package
-       
-       // fields of installed control
-       public static final String FIELD_ATTRIBUTE              = "Attribute";
-       
-       // fields of repository control
-       public static final String FIELD_SHA256         = "SHA256";
-       public static final String FIELD_FILE_PATH      = "Path"; // path from the base url
-       
-       // fields of ordering for UI
-       public static final String FIELD_ORDER = "C-Order";
-       
-       // field of Partner SDK
-       public static final String FIELD_PARTNER = "C-Partner";
-       
-       // fields of script
-       public static final String INSTALL_SCRIPT_LINUX = "install.sh";
-       public static final String REMOVE_SCRIPT_LINUX = "remove.sh";
-       public static final String INSTALL_SCRIPT_WINDOWS = "Install.bat";
-       public static final String REMOVE_SCRIPT_WINDOWS = "Remove.bat";
-       
-       // fields of ui control
-       public static final String FIELD_DEFAULT_CHECK = "Default";
-       
-       //field of extension server. this field is used by installed list.
-       public static final String FIELD_EXTENSION_SERVER = "Extension-server"; 
-       
-       // attribute value
-       private static final String ATTRIBUTE_ROOT_META = "root";
-       private static final String ATTRIBUTE_EXTRA_META = "extra";
-       private static final String ATTRIBUTE_INSTALL_META = "install";
-       private static final String ATTRIBUTE_TEST_META = "test";
-       private static final String ATTRIBUTE_MANDATORY = "mandatory";
-       private static final String ATTRIBUTE_PARTNER = "partner";
-       private static final String ATTRIBUTE_PUBLIC = "public";
-
-       //dependency information
-       private static final String START_OF_OS_DEPENDENCY = "[";
-       
-       private List<Property> mProperties;
-       private URL url; // url to the package zip file
-       
-       private static final int LOWEST_ORDER = 100;
-       
-       public Package(List<Property> properties) {
-               this.mProperties = properties;
-       }
-
-       /**
-        * Make url of package.
-        * @param properties package
-        * @param repoBaseUrl url before snapshot path.
-        */
-       public Package(Properties properties, String repoBaseUrl) {
-               this(properties);
-               try {
-                       if (Config.fromWhere == Config.ConfDialog.LOCAL_IMAGE) { // data from file dialog for local installing
-                               this.url = new URL(repoBaseUrl + "/" +  getValue(FIELD_FILE_PATH));
-                       } else { // data from snapshot and normal 'next' case
-                               this.url = new URL(repoBaseUrl + "/" +  getValue(FIELD_FILE_PATH));                             
-                       }
-               } catch (MalformedURLException e) {
-                       Log.err("Invalid package url: "+repoBaseUrl + "/" +  getValue(FIELD_FILE_PATH));
-                       throw new IMFatalException(ErrorCode.WRONG_PACKAGE_URL);
-               }
-       }
-       
-       public void setProperties(List<Property> properties) {
-               mProperties = properties;
-       }
-
-       /**
-        * @return version of this package. If package does not have version, set version to 0.0.0
-        */
-       public Version getVersion() {
-               String version = getValue(FIELD_VERSION);
-               if (version == null || version.isEmpty()) {
-                       List<Property> props = this.getProperties();
-                       for (Property p : props) {
-                               if (p.getName().equalsIgnoreCase(Package.FIELD_VERSION)) {
-                                       p.setValue("0.0.0");
-                               }
-                       }
-               }
-               return new Version(getValue(FIELD_VERSION));                            
-       }
-       
-       /**
-        * @return package name of this package
-        */
-       public String getPackageName() {
-               return getValue(FIELD_PACKAGE);
-       }
-       
-       /**
-        * @return name of package.
-        */
-       public String getLabel() {
-               return getValue(FIELD_LABEL);
-       }
-       
-       /**
-        * @return the size of zipped package file 
-        */
-       public Long getPackageSize() {
-               long result = 0;
-               try {
-                       result = Long.parseLong(getValue(FIELD_PACKAGE_SIZE));
-               } catch(NumberFormatException e) {
-                       Log.err(toString() + " size does not exist.");
-                       Log.ExceptionLog(e);
-               }
-               
-               return result;
-       }
-       
-       /**
-        * @return the real size of package file 
-        */
-       public Long getUncompressedPackageSize() {
-               long result = 0;
-               try {
-                       result = Long.parseLong(getValue(FIELD_UNCOMPRESSED_SIZE));
-               } catch(NumberFormatException e) {
-                       // All packages do not have 'Uncompressed-size' filed.
-                       // In this case, InstallManager use 'Size' field.
-                       result = Long.parseLong(getValue(FIELD_PACKAGE_SIZE)); 
-               }
-               
-               return result;
-       }
-       
-       /**
-        * @return Path of this package File from repository. 
-        */
-       public String getFileName() {
-               return getValue(FIELD_FILE_PATH);
-       }
-       
-       /**
-        * @return Description of this package.
-        */
-       public String getDescription() {
-               return getValue(FIELD_DESCRIPTION);
-       }
-       
-       /**
-        * @return SHA256 digest of this package file.
-        */
-       public String getSHA256() {
-               return getValue(FIELD_SHA256);
-       }
-       
-       /**
-        * @return URL to the package file in repository.
-        */
-       public URL getURL() {
-               return url;
-       }
-       
-       public String getPartner() {
-               return getValue(FIELD_PARTNER);
-       }
-       
-       /**
-        * @return Extension server of this package.
-        */
-       public String getExtensionServer() {
-               return getValue(FIELD_EXTENSION_SERVER);
-       }
-       
-       /**
-        * Set extension server to package information.
-        * @param extensionServer extension server of this packge
-        */
-       public void setExtensionServer(String extensionServer) {
-               Property property = getProperty(FIELD_EXTENSION_SERVER);
-
-               if (property != null) {
-                       property.setValue(extensionServer);
-               } else {
-                       property = new Property();
-                       property.setName(FIELD_EXTENSION_SERVER);
-                       property.setValue(extensionServer);
-
-                       mProperties.add(property);
-               }
-       }
-       /**
-        * Get package order for InstallManager displaying package tree.
-        * @return package order
-        */
-       public int getOrder() {
-               String order = getValue(FIELD_ORDER);
-               if (order.equals("")) {
-                       return LOWEST_ORDER;
-               } else {
-                       int nOrder = 0;
-                       try {
-                               nOrder = Integer.parseInt(order);
-                       } catch (NumberFormatException e) {
-                               Log.err("C-Order field value is not a integer format.");
-                               return 100;
-                       }
-                       return nOrder;                  
-               }
-       }
-       
-       /**
-        * @return Remove Script name of this package.
-        */
-       public String getRemoveScript() {
-               if (Platform.CURRENT_PLATFORM == Platform.LINUX_32
-                               || Platform.CURRENT_PLATFORM == Platform.LINUX_64
-                               || Platform.CURRENT_PLATFORM == Platform.MACOS_64
-                               || Platform.CURRENT_PLATFORM == Platform.MACOS_32) {
-                       return REMOVE_SCRIPT_LINUX;
-               } else if (Platform.CURRENT_PLATFORM == Platform.WINDOWS_32
-                               || Platform.CURRENT_PLATFORM == Platform.WINDOWS_64) {
-                       return REMOVE_SCRIPT_WINDOWS;
-               } else if (Platform.CURRENT_PLATFORM == Platform.MACOS_64) {
-                       return "";
-               }
-               return null;
-       }
-       
-       /**
-        * @return Install script name of this package.
-        */
-       public String getInstallScript() {
-               if (Platform.isUbuntu() || Platform.isMacOS()) {
-                       return INSTALL_SCRIPT_LINUX;
-               } else if (Platform.isWindows()) {
-                       return INSTALL_SCRIPT_WINDOWS;
-               }
-               
-               return null;
-       }
-       
-       /**
-        * @return List of Property instance.
-        */
-       public List<Property> getProperties() {
-               return mProperties;
-       }
-       
-       /**
-        * Get Property instance from key.
-        * 
-        * @param key
-        * @return
-        */
-       private Property getProperty(String key) {
-               if (mProperties != null && key != null) {
-                       for (int i = 0; i < mProperties.size(); i++) {
-                               if (key.compareTo(mProperties.get(i).getName()) == 0) {
-                                       return mProperties.get(i);
-                               }
-                       }
-               }
-               return null;
-       }
-
-       /**
-        * @param propertyName
-        * @return string value of the property name. empty string if there's no such property name
-        */
-       private String getValue(String propertyName) {
-               for(Property prop : mProperties) {
-                       if(prop.getName().equals(propertyName)) {
-                               return prop.getValue();
-                       }
-               }
-               return "";
-       }
-       
-       /**
-        * @return Attribute value.
-        */
-       public String getAttribute() {
-               return getValue(FIELD_ATTRIBUTE);
-       }
-
-       /**
-        * @return <code>true</code> if this package is a meta package.
-        */
-       public boolean isMeta() {
-               // onlyDownload option, in this case, do not need separate public meta package 
-               // to partner meta package because installmanager should download all meta packages.
-               if (Options.onlyDownload) {
-                       if (isRootMeta() || isInstallMeta() || isExtraMeta() ||
-                                       isPublicMeta() || isPartnerMeta() || isMandatory()) {
-                               return true;
-                       } else {
-                               return false;
-                       }
-               }
-               
-               if (Options.doTest) { // include test packages for SDK testing
-                       if (isRootMeta() || isInstallMeta() || isExtraMeta() || isMandatory() || isPublicMeta() || isTestMeta()) {
-                               return true;
-                       } else {
-                               return false;
-                       }
-               } else { // except test packages for normal SDK.
-                       if (isRootMeta() || isInstallMeta() || isExtraMeta() || isMandatory() || isPublicMeta()) {
-                               return true;
-                       } else {
-                               return false;
-                       }
-               }
-       }
-       
-       /**
-        * @return <code>true</code> if this package is a root meta package.
-        */
-       public boolean isRootMeta() {
-               String attributeValue = getAttribute().trim();
-               
-               if (attributeValue.equalsIgnoreCase(ATTRIBUTE_ROOT_META)) {
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-       
-       /**
-        * @return <code>true</code> if this package is a extra meta package.
-        */
-       public boolean isExtraMeta() {
-               String attributeValue = getAttribute().trim();
-               
-               if (attributeValue.equalsIgnoreCase(ATTRIBUTE_EXTRA_META)) {
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-       
-       /**
-        * Check to belong to partner sdk given package
-        * @return <code>true</code> if this package is a partner package.
-        */
-       public boolean isPartnerMeta() {
-               String attributeValue = getAttribute().trim();
-               
-               if (attributeValue.equalsIgnoreCase(ATTRIBUTE_PARTNER)) {
-                       return true;
-               } else {
-                       return false;
-               }               
-       }
-       
-       /**
-        * Check to belong to partner sdk given package
-        * @return <code>true</code> if this package is a partner package.
-        */
-       public boolean isPublicMeta() {
-               String attributeValue = getAttribute().trim();
-               
-               if (attributeValue.equalsIgnoreCase(ATTRIBUTE_PUBLIC)) {
-                       return true;
-               } else {
-                       return false;
-               }
-       }       
-       
-       /**
-        * @return <code>true</code> if this meta package is a install meta package.
-        */
-       public boolean isInstallMeta() {
-               String attributeValue = getAttribute().trim();
-               
-               if (attributeValue.equalsIgnoreCase(ATTRIBUTE_INSTALL_META)) {
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-       
-       /**
-        * @return <code>true</code> if this meta package is a install meta package.
-        */
-       public boolean isTestMeta() {
-               String attributeValue = getAttribute().trim();
-               
-               if (attributeValue.equalsIgnoreCase(ATTRIBUTE_TEST_META)) {
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-       
-       /**
-        * @return <code>true</code>, if this package is a mandatory package. This package must install.
-        */
-       public boolean isMandatory() {
-               String attributeValue = getAttribute().trim();
-               
-               if (attributeValue.equalsIgnoreCase(ATTRIBUTE_MANDATORY)) {
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-       
-       public boolean isExtensionPackage() {
-               String extensionServer = getExtensionServer();
-               
-               if (extensionServer == null || extensionServer.isEmpty()) {
-                       return false;
-               } else {
-                       return true;
-               }
-       }
-
-       /**
-        * @return package names that this package directly depends on
-        */
-       public Collection<String> getDependentPackageNames() {
-               HashSet<String> depends = new HashSet<String>();
-               String dependsStr = getValue(FIELD_DEPENDS);
-               String deps[] = dependsStr.split(",");
-               for(int i = 0; i < deps.length; i++) {
-                       String dep = removeOSInformationOfDepends(deps[i]);
-
-                       if(!dep.isEmpty()) {
-                               depends.add(dep);
-                       }
-               }
-               return depends;
-       }
-       
-       private String removeOSInformationOfDepends(String info) {      
-               //Log.log("Package.removeOSInformation (info => " + info + ")");
-               
-               if (info.contains(START_OF_OS_DEPENDENCY)) {
-                       int index = info.indexOf(START_OF_OS_DEPENDENCY);
-                       String pkgInfo = info.substring(0, index).trim();
-                       
-                       return pkgInfo;
-               } else {
-                       return info.trim();
-               }
-       }
-
-       /**
-        * @return package names that this package directly conflicts to
-        */
-       public Collection<String> getConflictPackageNames() {
-               HashSet<String> conflicts = new HashSet<String>();
-               String conflictsStr = getValue(FIELD_CONFLICTS);
-               String confs[] = conflictsStr.split(",");
-               for(int i = 0; i < confs.length; i++) {
-                       conflicts.add(confs[i].trim());
-               }
-               return conflicts;
-       }
-       
-       public String toString() {
-               return getPackageName();
-       }
-       
-       /**
-        * Checks equality symbolically only using their package names.
-        * @return <code>true</code> if they have the same package name.
-        */
-       public boolean equals(Object obj) {
-               if (obj instanceof Package) {
-                       Package pkg2 = (Package)obj;
-                       return this.getPackageName().equals(pkg2.getPackageName());
-               } else {
-                       return false;
-               }
-       }
-       
-       public int hashCode() {
-               return getPackageName().hashCode();
-       }
-}
+/*\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.pkg.model;\r
+\r
+import java.net.MalformedURLException;\r
+import java.net.URL;\r
+import java.util.Collection;\r
+import java.util.HashSet;\r
+import java.util.List;\r
+\r
+import org.tizen.installmanager.core.IMFatalException;\r
+import org.tizen.installmanager.core.Options;\r
+import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
+import org.tizen.installmanager.lib.Log;\r
+import org.tizen.installmanager.lib.Platform;\r
+import org.tizen.installmanager.util.PathUtil;\r
+\r
+/**\r
+ * This class describes a package.\r
+ * \r
+ * @author Wooyoung Cho <wooyoung1.cho@samsung.com>\r
+ *\r
+ */\r
+public class Package {\r
+       \r
+       // fields of package control\r
+       // mandatory\r
+       public static final String FIELD_PACKAGE                = "Package";\r
+       public static final String FIELD_VERSION                = "Version";\r
+       public static final String FIELD_LABEL = "Label";\r
+       public static final String FIELD_MAINTAINER     = "Maintainer";\r
+       public static final String FIELD_DESCRIPTION    = "Description";\r
+\r
+       // etc\r
+       public static final String FIELD_DEPENDS                = "Install-dependency"; // list of packages that this package depends on\r
+       public static final String FIELD_CONFLICTS              = "Conflicts";\r
+       public static final String FIELD_PACKAGE_SIZE   = "Size"; // size of zipped package\r
+       public static final String FIELD_UNCOMPRESSED_SIZE      = "Uncompressed-size"; // uncompressed size of package\r
+       \r
+       // fields of installed control\r
+       public static final String FIELD_ATTRIBUTE              = "Attribute";\r
+       \r
+       // fields of repository control\r
+       public static final String FIELD_SHA256         = "SHA256";\r
+       public static final String FIELD_FILE_PATH      = "Path"; // path from the base url\r
+       \r
+       // fields of ordering for UI\r
+       public static final String FIELD_ORDER = "C-Order";\r
+       \r
+       // field of Partner SDK\r
+       public static final String FIELD_PARTNER = "C-Partner";\r
+       \r
+       // fields of script\r
+       public static final String INSTALL_SCRIPT_LINUX = "install.sh";\r
+       public static final String REMOVE_SCRIPT_LINUX = "remove.sh";\r
+       public static final String INSTALL_SCRIPT_WINDOWS = "Install.bat";\r
+       public static final String REMOVE_SCRIPT_WINDOWS = "Remove.bat";\r
+       \r
+       // fields of ui control\r
+       public static final String FIELD_DEFAULT_CHECK = "Default";\r
+       \r
+       //field of extension server. this field is used by installed list.\r
+       public static final String FIELD_EXTENSION_SERVER = "Extension-server"; \r
+       \r
+       // attribute value\r
+       private static final String ATTRIBUTE_ROOT_META = "root";\r
+       private static final String ATTRIBUTE_EXTRA_META = "extra";\r
+       private static final String ATTRIBUTE_INSTALL_META = "install";\r
+       private static final String ATTRIBUTE_TEST_META = "test";\r
+       private static final String ATTRIBUTE_MANDATORY = "mandatory";\r
+       private static final String ATTRIBUTE_PARTNER = "partner";\r
+       private static final String ATTRIBUTE_PUBLIC = "public";\r
+\r
+       //dependency information\r
+       private static final String START_OF_OS_DEPENDENCY = "[";\r
+       \r
+       private List<Property> mProperties;\r
+       private URL baseURL = null; \r
+       private URL url; // url to the package zip file\r
+       \r
+       private static final int LOWEST_ORDER = 100;\r
+       \r
+       public Package(List<Property> properties) {\r
+               this.mProperties = properties;\r
+       }\r
+\r
+       /**\r
+        * Make url of package.\r
+        * @param properties package\r
+        * @param repoBaseUrl url before snapshot path.\r
+        */\r
+       public Package(Properties properties, String repoBaseUrl) {\r
+               this(properties);\r
+               \r
+               try {\r
+                       this.baseURL = new URL(repoBaseUrl);\r
+                       this.url = new URL(PathUtil.addURLPath(repoBaseUrl, getValue(FIELD_FILE_PATH)));\r
+               } catch (MalformedURLException e) {\r
+                       Log.err("Invalid package url: "+repoBaseUrl + "/" +  getValue(FIELD_FILE_PATH));\r
+                       throw new IMFatalException(ErrorCode.WRONG_PACKAGE_URL);\r
+               }\r
+       }\r
+       \r
+       public void setProperties(List<Property> properties) {\r
+               mProperties = properties;\r
+       }\r
+\r
+       /**\r
+        * @return version of this package. If package does not have version, set version to 0.0.0\r
+        */\r
+       public Version getVersion() {\r
+               String version = getValue(FIELD_VERSION);\r
+               if (version == null || version.isEmpty()) {\r
+                       List<Property> props = this.getProperties();\r
+                       for (Property p : props) {\r
+                               if (p.getName().equalsIgnoreCase(Package.FIELD_VERSION)) {\r
+                                       p.setValue("0.0.0");\r
+                               }\r
+                       }\r
+               }\r
+               return new Version(getValue(FIELD_VERSION));                            \r
+       }\r
+       \r
+       /**\r
+        * @return package name of this package\r
+        */\r
+       public String getPackageName() {\r
+               return getValue(FIELD_PACKAGE);\r
+       }\r
+       \r
+       /**\r
+        * @return name of package.\r
+        */\r
+       public String getLabel() {\r
+               return getValue(FIELD_LABEL);\r
+       }\r
+       \r
+       /**\r
+        * @return the size of zipped package file \r
+        */\r
+       public Long getPackageSize() {\r
+               long result = 0;\r
+               try {\r
+                       result = Long.parseLong(getValue(FIELD_PACKAGE_SIZE));\r
+               } catch(NumberFormatException e) {\r
+                       Log.err(toString() + " size does not exist.");\r
+                       Log.ExceptionLog(e);\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       /**\r
+        * @return the real size of package file \r
+        */\r
+       public Long getUncompressedPackageSize() {\r
+               long result = 0;\r
+               try {\r
+                       result = Long.parseLong(getValue(FIELD_UNCOMPRESSED_SIZE));\r
+               } catch(NumberFormatException e) {\r
+                       // All packages do not have 'Uncompressed-size' filed.\r
+                       // In this case, InstallManager use 'Size' field.\r
+                       result = Long.parseLong(getValue(FIELD_PACKAGE_SIZE)); \r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       /**\r
+        * @return Path of this package File from repository. \r
+        */\r
+       public String getFileName() {\r
+               return getValue(FIELD_FILE_PATH);\r
+       }\r
+       \r
+       /**\r
+        * @return Description of this package.\r
+        */\r
+       public String getDescription() {\r
+               return getValue(FIELD_DESCRIPTION);\r
+       }\r
+       \r
+       /**\r
+        * @return SHA256 digest of this package file.\r
+        */\r
+       public String getSHA256() {\r
+               return getValue(FIELD_SHA256);\r
+       }\r
+       \r
+       /**\r
+        * @return URL to the package file in repository.\r
+        */\r
+       public URL getURL() {\r
+               return url;\r
+       }\r
+       \r
+       public URL getBaseURL() {\r
+               return baseURL;\r
+       }\r
+       \r
+       public String getPartner() {\r
+               return getValue(FIELD_PARTNER);\r
+       }\r
+       \r
+       /**\r
+        * @return Extension server of this package.\r
+        */\r
+       public String getExtensionServer() {\r
+               return getValue(FIELD_EXTENSION_SERVER);\r
+       }\r
+       \r
+       /**\r
+        * Set extension server to package information.\r
+        * @param extensionServer extension server of this packge\r
+        */\r
+       public void setExtensionServer(String extensionServer) {\r
+               Property property = getProperty(FIELD_EXTENSION_SERVER);\r
+\r
+               if (property != null) {\r
+                       property.setValue(extensionServer);\r
+               } else {\r
+                       property = new Property();\r
+                       property.setName(FIELD_EXTENSION_SERVER);\r
+                       property.setValue(extensionServer);\r
+\r
+                       mProperties.add(property);\r
+               }\r
+       }\r
+       /**\r
+        * Get package order for InstallManager displaying package tree.\r
+        * @return package order\r
+        */\r
+       public int getOrder() {\r
+               String order = getValue(FIELD_ORDER);\r
+               if (order.equals("")) {\r
+                       return LOWEST_ORDER;\r
+               } else {\r
+                       int nOrder = 0;\r
+                       try {\r
+                               nOrder = Integer.parseInt(order);\r
+                       } catch (NumberFormatException e) {\r
+                               Log.err("C-Order field value is not a integer format.");\r
+                               return 100;\r
+                       }\r
+                       return nOrder;                  \r
+               }\r
+       }\r
+       \r
+       /**\r
+        * @return Remove Script name of this package.\r
+        */\r
+       public String getRemoveScript() {\r
+               if (Platform.CURRENT_PLATFORM == Platform.LINUX_32\r
+                               || Platform.CURRENT_PLATFORM == Platform.LINUX_64\r
+                               || Platform.CURRENT_PLATFORM == Platform.MACOS_64\r
+                               || Platform.CURRENT_PLATFORM == Platform.MACOS_32) {\r
+                       return REMOVE_SCRIPT_LINUX;\r
+               } else if (Platform.CURRENT_PLATFORM == Platform.WINDOWS_32\r
+                               || Platform.CURRENT_PLATFORM == Platform.WINDOWS_64) {\r
+                       return REMOVE_SCRIPT_WINDOWS;\r
+               } else if (Platform.CURRENT_PLATFORM == Platform.MACOS_64) {\r
+                       return "";\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       /**\r
+        * @return Install script name of this package.\r
+        */\r
+       public String getInstallScript() {\r
+               if (Platform.isUbuntu() || Platform.isMacOS()) {\r
+                       return INSTALL_SCRIPT_LINUX;\r
+               } else if (Platform.isWindows()) {\r
+                       return INSTALL_SCRIPT_WINDOWS;\r
+               }\r
+               \r
+               return null;\r
+       }\r
+       \r
+       /**\r
+        * @return List of Property instance.\r
+        */\r
+       public List<Property> getProperties() {\r
+               return mProperties;\r
+       }\r
+       \r
+       /**\r
+        * Get Property instance from key.\r
+        * \r
+        * @param key\r
+        * @return\r
+        */\r
+       private Property getProperty(String key) {\r
+               if (mProperties != null && key != null) {\r
+                       for (int i = 0; i < mProperties.size(); i++) {\r
+                               if (key.compareTo(mProperties.get(i).getName()) == 0) {\r
+                                       return mProperties.get(i);\r
+                               }\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+\r
+       /**\r
+        * @param propertyName\r
+        * @return string value of the property name. empty string if there's no such property name\r
+        */\r
+       private String getValue(String propertyName) {\r
+               for(Property prop : mProperties) {\r
+                       if(prop.getName().equals(propertyName)) {\r
+                               return prop.getValue();\r
+                       }\r
+               }\r
+               return "";\r
+       }\r
+       \r
+       /**\r
+        * @return Attribute value.\r
+        */\r
+       public String getAttribute() {\r
+               return getValue(FIELD_ATTRIBUTE);\r
+       }\r
+\r
+       /**\r
+        * @return <code>true</code> if this package is a meta package.\r
+        */\r
+       public boolean isMeta() {\r
+               // onlyDownload option, in this case, do not need separate public meta package \r
+               // to partner meta package because installmanager should download all meta packages.\r
+               if (Options.onlyDownload) {\r
+                       if (isRootMeta() || isInstallMeta() || isExtraMeta() ||\r
+                                       isPublicMeta() || isPartnerMeta() || isMandatory()) {\r
+                               return true;\r
+                       } else {\r
+                               return false;\r
+                       }\r
+               }\r
+               \r
+               if (Options.doTest) { // include test packages for SDK testing\r
+                       if (isRootMeta() || isInstallMeta() || isExtraMeta() || isMandatory() || isPublicMeta() || isTestMeta()) {\r
+                               return true;\r
+                       } else {\r
+                               return false;\r
+                       }\r
+               } else { // except test packages for normal SDK.\r
+                       if (isRootMeta() || isInstallMeta() || isExtraMeta() || isMandatory() || isPublicMeta()) {\r
+                               return true;\r
+                       } else {\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * @return <code>true</code> if this package is a root meta package.\r
+        */\r
+       public boolean isRootMeta() {\r
+               String attributeValue = getAttribute().trim();\r
+               \r
+               if (attributeValue.equalsIgnoreCase(ATTRIBUTE_ROOT_META)) {\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * @return <code>true</code> if this package is a extra meta package.\r
+        */\r
+       public boolean isExtraMeta() {\r
+               String attributeValue = getAttribute().trim();\r
+               \r
+               if (attributeValue.equalsIgnoreCase(ATTRIBUTE_EXTRA_META)) {\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Check to belong to partner sdk given package\r
+        * @return <code>true</code> if this package is a partner package.\r
+        */\r
+       public boolean isPartnerMeta() {\r
+               String attributeValue = getAttribute().trim();\r
+               \r
+               if (attributeValue.equalsIgnoreCase(ATTRIBUTE_PARTNER)) {\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }               \r
+       }\r
+       \r
+       /**\r
+        * Check to belong to partner sdk given package\r
+        * @return <code>true</code> if this package is a partner package.\r
+        */\r
+       public boolean isPublicMeta() {\r
+               String attributeValue = getAttribute().trim();\r
+               \r
+               if (attributeValue.equalsIgnoreCase(ATTRIBUTE_PUBLIC)) {\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }       \r
+       \r
+       /**\r
+        * @return <code>true</code> if this meta package is a install meta package.\r
+        */\r
+       public boolean isInstallMeta() {\r
+               String attributeValue = getAttribute().trim();\r
+               \r
+               if (attributeValue.equalsIgnoreCase(ATTRIBUTE_INSTALL_META)) {\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * @return <code>true</code> if this meta package is a install meta package.\r
+        */\r
+       public boolean isTestMeta() {\r
+               String attributeValue = getAttribute().trim();\r
+               \r
+               if (attributeValue.equalsIgnoreCase(ATTRIBUTE_TEST_META)) {\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * @return <code>true</code>, if this package is a mandatory package. This package must install.\r
+        */\r
+       public boolean isMandatory() {\r
+               String attributeValue = getAttribute().trim();\r
+               \r
+               if (attributeValue.equalsIgnoreCase(ATTRIBUTE_MANDATORY)) {\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       public boolean isExtensionPackage() {\r
+               String extensionServer = getExtensionServer();\r
+               \r
+               if (extensionServer == null || extensionServer.isEmpty()) {\r
+                       return false;\r
+               } else {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * @return package names that this package directly depends on\r
+        */\r
+       public Collection<String> getDependentPackageNames() {\r
+               HashSet<String> depends = new HashSet<String>();\r
+               String dependsStr = getValue(FIELD_DEPENDS);\r
+               String deps[] = dependsStr.split(",");\r
+               for(int i = 0; i < deps.length; i++) {\r
+                       String dep = removeOSInformationOfDepends(deps[i]);\r
+\r
+                       if(!dep.isEmpty()) {\r
+                               depends.add(dep);\r
+                       }\r
+               }\r
+               return depends;\r
+       }\r
+       \r
+       private String removeOSInformationOfDepends(String info) {      \r
+               //Log.log("Package.removeOSInformation (info => " + info + ")");\r
+               \r
+               if (info.contains(START_OF_OS_DEPENDENCY)) {\r
+                       int index = info.indexOf(START_OF_OS_DEPENDENCY);\r
+                       String pkgInfo = info.substring(0, index).trim();\r
+                       \r
+                       return pkgInfo;\r
+               } else {\r
+                       return info.trim();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * @return package names that this package directly conflicts to\r
+        */\r
+       public Collection<String> getConflictPackageNames() {\r
+               HashSet<String> conflicts = new HashSet<String>();\r
+               String conflictsStr = getValue(FIELD_CONFLICTS);\r
+               String confs[] = conflictsStr.split(",");\r
+               for(int i = 0; i < confs.length; i++) {\r
+                       conflicts.add(confs[i].trim());\r
+               }\r
+               return conflicts;\r
+       }\r
+       \r
+       public String toString() {\r
+               return getPackageName();\r
+       }\r
+       \r
+       /**\r
+        * Checks equality symbolically only using their package names.\r
+        * @return <code>true</code> if they have the same package name.\r
+        */\r
+       public boolean equals(Object obj) {\r
+               if (obj instanceof Package) {\r
+                       Package pkg2 = (Package)obj;\r
+                       return this.getPackageName().equals(pkg2.getPackageName());\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       public int hashCode() {\r
+               return getPackageName().hashCode();\r
+       }\r
+}\r
index 163d3a1..e4be9c9 100644 (file)
-/*
-*  InstallManager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: 
-* Wooyoung Cho <wooyoung1.cho@samsung.com>
-* Shihyun Kim <shihyun.kim@samsung.com>
-* Taeyoung Son <taeyoung2.son@samsung.com>
-* Yongsung kim <yongsung1.kim@samsung.com>
-* 
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
-
-package org.tizen.installmanager.ui;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.Set;
-
-import org.eclipse.jface.window.ApplicationWindow;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StackLayout;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.layout.RowData;
-import org.eclipse.swt.layout.RowLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.tizen.installmanager.cli.InstallManagerNoUI;
-import org.tizen.installmanager.core.Config;
-import org.tizen.installmanager.core.IMExitException;
-import org.tizen.installmanager.core.IMFatalException;
-import org.tizen.installmanager.core.InstallManager;
-import org.tizen.installmanager.core.Options;
-import org.tizen.installmanager.core.Performance;
-import org.tizen.installmanager.lib.ErrorController;
-import org.tizen.installmanager.lib.IMError;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.lib.Platform;
-import org.tizen.installmanager.lib.ProgramController;
-import org.tizen.installmanager.lib.Registry;
-import org.tizen.installmanager.lib.exception.IMNetworkException;
-import org.tizen.installmanager.lib.mac.CocoaUtil;
-import org.tizen.installmanager.pkg.lib.PackageManager;
-import org.tizen.installmanager.pkg.model.ConfigFile;
-import org.tizen.installmanager.pkg.model.PackageSet;
-import org.tizen.installmanager.ui.dialog.AddExtraRepositoryDialog;
-import org.tizen.installmanager.ui.dialog.IndeterminateProgressDialog;
-import org.tizen.installmanager.ui.dialog.MessageBoxDlg;
-import org.tizen.installmanager.ui.dialog.MessageBoxDlg.DialogType;
-import org.tizen.installmanager.ui.dialog.ProxySettingsDialog;
-import org.tizen.installmanager.ui.model.Item;
-import org.tizen.installmanager.ui.page.CompletePage;
-import org.tizen.installmanager.ui.page.InstallableListPage;
-import org.tizen.installmanager.ui.page.InstallingPage;
-import org.tizen.installmanager.ui.page.LicensePage;
-import org.tizen.installmanager.ui.page.SetInstallDirectoryPage;
-import org.tizen.installmanager.ui.page.UninstallableListPage;
-import org.tizen.installmanager.ui.page.UninstallingPage;
-import org.tizen.installmanager.ui.page.UpdatableListPage;
-import org.tizen.installmanager.ui.page.ViewController;
-import org.tizen.installmanager.ui.page.WelcomePage;
-import org.tizen.installmanager.ui.page.InstallingPage.InstallProgressMonitor;
-import org.tizen.installmanager.ui.page.WelcomePage.RADIO_ACTION;
-import org.tizen.installmanager.util.PathUtil;
-import org.tizen.installmanager.pkg.model.Package;
-
-
-/**
- * This class is main class for install manager.
- * @author Taeyoung Son <taeyoung2.son@samsung.com>
- */
-public class InstallManagerWindow extends ApplicationWindow {
-       private static final RGB RGB_BACKGROUND = new RGB(242, 242, 242);
-
-       private static final Point POINT_MAIN_WINDOW = new Point(628, 478);
-       private static Image IMAGE_WINDOW_ICON;
-       private static Color COLOR_BACKGROUND;
-
-       private static InstallManagerWindow window;
-
-       private StackLayout sl_composite = new StackLayout();
-       private static Button btnClose;
-       private static Button btnBack;
-       private static Button btnNext;
-       private Button btnSettings;
-       private static Button addExtraButton;
-
-       private AddExtraRepositoryDialog extraDialog = null;
-       
-       private Composite pageComposite;
-       private WelcomePage compositeWelcomePage;
-       private LicensePage compositeLicensePage;
-       private InstallableListPage compositeInstallablePage;
-       private UninstallableListPage compositeUninstallablePage;
-       private InstallingPage compositeInstallingPage;
-       private UninstallingPage compositeUninstallingPage;
-       private CompletePage compositeCompletePage;
-       private SetInstallDirectoryPage compositeSetInstallDirectoryPage;
-       public UpdatableListPage compositeUpdatableListPage;
-
-       protected static ViewController controller;
-       private SelectionAdapter cancelBtnSelectionAdapter = null;
-       private SelectionAdapter closeBtnSelectionAdapter = null;
-
-       /**
-        * Create the application window.
-        */
-       public InstallManagerWindow() {
-               super(null);
-               setShellStyle(SWT.SHELL_TRIM);
-               setShellStyle(SWT.BORDER | SWT.TITLE);
-       }
-
-       /**
-        * Get installmanager window background color.
-        * @return background color
-        */
-       public static Color getBackgroundColor() {
-               if (COLOR_BACKGROUND == null) {
-                       COLOR_BACKGROUND = new Color(null, RGB_BACKGROUND);
-               }
-               return COLOR_BACKGROUND;
-       }
-
-       private static Image getWindowIconImage() {
-               if (IMAGE_WINDOW_ICON == null) {
-                       IMAGE_WINDOW_ICON = PathUtil.getImageFromResource("/res/icons/SDK_icon.png");
-               }
-               return IMAGE_WINDOW_ICON;
-       }
-
-       private void init() throws IMExitException{
-               Log.log("Window init start");
-               
-               //make waiting dialog.
-               final IndeterminateProgressDialog progressbar = IndeterminateProgressDialog.getInstance();
-               
-               final Shell shell = progressbar.getParent();
-               shell.getDisplay().asyncExec(new Runnable(){
-                       public void run() {                             
-                               //initialize installmanager
-                               progressbar.updateName("Connecting to package server.\nIt may take a minute...");
-                               
-                               shell.getDisplay().asyncExec(new Runnable() {
-                                       public void run() {
-                                               initInstallManager();
-                                       }
-                                       
-                               });
-                               
-                               //init end
-                               progressbar.finish();
-                       }
-               });
-               
-               if (!shell.isDisposed()) {
-                       progressbar.open();
-               }
-
-               Log.log("Window init end");
-       }
-       
-       private void updateInstallManager(Shell shell) {
-               if (controller.canInstallManagerUpdate()) {
-                       String msg = "There is a new installer on the server. \nNew install-manager will be started. \nIt may take a minute...";
-                       MessageBoxDlg.showDlg(shell, "InstallManager", msg, DialogType.NOTIFY, false);
-                       
-                       controller.updateInstallManager();
-               }
-       }
-       
-       /**
-        * init IM's configuation and packages information.
-        * @return
-        */
-       public boolean initInstallManager() {
-               ErrorController.setInstallationSuccess(true);
-               
-               controller = new ViewController();
-               
-               if (controller.init()) {
-                       if (Config.isSupportMultiSDK()) {
-                               Log.log("Multi SDK installation.");
-                       } else {
-                               Log.log("Single SDK installation.");
-                       }
-                       return true;
-               } else {
-                       Log.err("InstallManager init fail.");
-                       ErrorController.setInstallationSuccess(false);
-                       
-                       return false;
-               }
-       }
-
-       /**
-        * Create contents of the application window.
-        * 
-        * @param parent
-        */
-       @Override
-       protected Control createContents(Composite parent) {
-
-               IMError.setComposite(parent);
-               Composite container = new Composite(parent, SWT.NONE);
-               container.setBackground(getBackgroundColor());
-               RowLayout rl_container = new RowLayout(SWT.VERTICAL);
-               rl_container.spacing = 0;
-               rl_container.marginTop = 0;
-               rl_container.marginRight = 0;
-               rl_container.marginLeft = 0;
-               rl_container.marginBottom = 0;
-               container.setLayout(rl_container);
-
-               pageComposite = new Composite(container, SWT.NONE);
-               pageComposite.setLayoutData(new RowData(619, 395));
-               pageComposite.setLayout(sl_composite);
-               pageComposite.setBackground(InstallManagerWindow.getBackgroundColor());
-
-               Composite composite_1 = new Composite(container, SWT.NONE);
-               composite_1.setLayoutData(new RowData(619, 38));
-               composite_1.setBackground(InstallManagerWindow.getBackgroundColor());
-
-               Label label = new Label(composite_1, SWT.SEPARATOR | SWT.HORIZONTAL);
-               label.setBounds(0, 0, 620, 2);
-
-               btnClose = new Button(composite_1, SWT.NONE);
-               btnClose.setText("Cancel");
-               cancelBtnSelectionAdapter = new SelectionAdapter() {
-                       @Override
-                       public void widgetSelected(SelectionEvent e) {
-                               int result = MessageBoxDlg.NO;
-                               if (sl_composite.topControl == compositeInstallingPage) {
-                                       InstallProgressMonitor mon = compositeInstallingPage.getInstallProgressMonitor();
-                                       mon.setCancelRequested(true);
-                                       result = MessageBoxDlg.showDlg(
-                                                       e.display.getActiveShell(),
-                                                       "Tizen SDK Install Manager",
-                                                       "Are you sure you want to quit Install Manager?\n\nIf you click \"Yes\", the installation is stopped.",
-                                                       DialogType.WARNING, false);
-                                       if (result == MessageBoxDlg.YES) {
-                                               mon.setCanceled(true);
-                                       } else {
-                                               mon.setCancelRequested(false);
-                                       }
-                                       return;
-                               } else if (sl_composite.topControl == compositeUninstallingPage) {
-                                       result = MessageBoxDlg.showDlg(
-                                                       e.display.getActiveShell(),
-                                                       "Tizen SDK Install Manager",
-                                                       "Are you sure to quit Install Manager?\n\nIf you click \"Yes\", the uninstallation is stopped.",
-                                                       DialogType.WARNING, false);
-                               } else if (sl_composite.topControl == compositeCompletePage) {
-                                       controller.showChangeLog();
-                                       
-                                       if (!Options.doResumeDownloading) {
-                                               controller.cleanUpTargetDirectory();
-                                       }
-                                       
-                                       result = MessageBoxDlg.YES;
-                               } else {
-                                       result = MessageBoxDlg.showDlg(e.display.getActiveShell(),
-                                                       "Tizen SDK Install Manager",
-                                                       "Are you sure to quit Install Manager?",
-                                                       DialogType.WARNING, false);
-                               }
-                               
-                               if (result == MessageBoxDlg.YES) {
-                                       e.display.close();
-                               }
-                       }
-               };
-               
-               closeBtnSelectionAdapter = new SelectionAdapter() {
-                       @Override
-                       public void widgetSelected(SelectionEvent arg0) {
-                               arg0.display.close();
-                       }
-               };
-               
-               btnClose.addSelectionListener(cancelBtnSelectionAdapter);
-               btnClose.setBounds(531, 10, 78, 29);
-
-               btnNext = new Button(composite_1, SWT.NONE);
-               btnNext.setText("Next");
-               btnNext.addSelectionListener(new SelectionAdapter() {
-                       @Override
-                       public void widgetSelected(SelectionEvent e) {
-                               if (sl_composite.topControl == compositeWelcomePage) {
-                                       updateInstallManager(e.display.getActiveShell());
-                                       addExtraButton.setVisible(false);
-                                       btnSettings.setVisible(false);
-                                       if (compositeWelcomePage.getSelectedRadioButton() == RADIO_ACTION.INSTALL) {
-                                               if (!checkVaildPkgVersion()) {
-                                                       btnSettings.setVisible(true);
-                                                       return;
-                                               }
-                                               btnNext.setEnabled(compositeLicensePage.getAcceptButton().getSelection());
-                                               if (Config.isSupportMultiSDK()) {
-                                                       showComposite(compositeLicensePage);
-                                                       btnBack.setVisible(true);
-                                               } else {
-                                                       if (!controller.isNewInstallation()) {// Update case
-                                                               compositeUpdatableListPage.loadPage(controller);
-                                                               btnBack.setVisible(true);
-                                                               addExtraButton.setVisible(true);
-
-                                                               btnSettings.setVisible(false);
-                                                               showComposite(compositeUpdatableListPage);
-                                                               if (controller.existRemovablePackage()) {
-                                                                       btnNext.setText("Install");
-                                                               }
-                                                               btnBack.setVisible(true);
-                                                       } else {
-                                                               showComposite(compositeLicensePage);
-                                                               btnBack.setVisible(true);
-                                                       }
-                                               }
-                                       } else if (compositeWelcomePage.getSelectedRadioButton() == RADIO_ACTION.UPDATE) {
-                                               btnNext.setEnabled(compositeLicensePage.getAcceptButton().getSelection());
-                                               PackageManager.dispose();
-                                               initInstallManager();
-                                               compositeUpdatableListPage.loadPage(controller);
-                                               btnBack.setVisible(true);
-                                               addExtraButton.setVisible(true);
-                                               btnSettings.setVisible(false);
-                                               showComposite(compositeUpdatableListPage);
-                                               if (controller.existRemovablePackage()) {
-                                                       btnNext.setText("Install");
-                                               }
-                                               btnBack.setVisible(true);
-                                       } else if (compositeWelcomePage.getSelectedRadioButton() == RADIO_ACTION.UNINSTALL) {
-                                               int resultDialog = MessageBoxDlg.NO;
-                                               resultDialog = MessageBoxDlg.showDlg(
-                                                               e.display.getActiveShell(),
-                                                               "Tizen SDK Install Manager",
-                                                               "Are you sure you want to remove the Tizen SDK?\n\nIf you click \"Yes\", the Tizen SDK is uninstalled.",
-                                                               DialogType.WARNING, false);
-                                               if (resultDialog == MessageBoxDlg.YES) {
-                                                       showComposite(compositeUninstallingPage);
-                                                       btnBack.setVisible(false);
-                                                       btnNext.setVisible(false);
-                                                       btnClose.setEnabled(false);
-                                                       addExtraButton.setVisible(false);
-                                                       
-                                                       if (Config.isSupportMultiSDK()) {
-                                                               PackageManager.dispose();
-                                                               initInstallManager();                                                           
-                                                       }
-
-                                                       List<Item> items = compositeUninstallablePage.getItems();
-                                                       boolean result = compositeUninstallingPage.loadPage(getSelectedPackageNames(items) /* compositeInstallablePage.getCheckedPackageNames()*/,
-                                                                                                                                                               controller,
-                                                                                                                                                               window);
-                                                       if (!result) {
-                                                               showComposite(compositeWelcomePage);
-                                                               btnBack.setVisible(true);
-                                                               btnNext.setVisible(true);
-                                                               btnClose.setEnabled(true);
-                                                       }
-                                               } else {
-                                                       btnSettings.setVisible(true);
-                                                       return;
-                                               }
-                                       }
-                               } else if (sl_composite.topControl == compositeLicensePage) {
-                                       boolean hasItem = compositeInstallablePage.loadPage(controller);
-                                       if (hasItem) {
-                                               showComposite(compositeInstallablePage);
-                                               btnNext.setEnabled(hasItem);
-                                               btnBack.setVisible(hasItem);
-                                               addExtraButton.setVisible(true);
-                                               if (controller.existRemovablePackage()) {
-                                                       btnNext.setText("Install");
-                                               }
-                                       } else {
-                                               Log.err("Installable packages do not exist. This is error.");
-                                               //TODO
-                                       }
-                               } else if (sl_composite.topControl == compositeInstallablePage) {
-                                       List<Item> items = compositeInstallablePage.getItems();
-                                       if (getSelectedPackageNames(items).size() <= 0) {
-                                               return;
-                                       }
-                                       if (Config.isSupportMultiSDK()) {
-                                               showComposite(compositeSetInstallDirectoryPage);
-                                               compositeSetInstallDirectoryPage.loadPage(
-                                                                       controller, compositeInstallablePage.getCheckedPackageSize(false));
-                                               btnNext.setText("Install");
-                                               addExtraButton.setVisible(false);
-                                       } else {
-                                               if (controller.existRemovablePackage()) {
-                                                       btnBack.setVisible(false);
-                                                       btnNext.setVisible(false);
-                                                       showComposite(compositeInstallingPage);
-                                                       addExtraButton.setVisible(false);
-                                                       boolean result = compositeInstallingPage.loadPage(getSelectedPackageNames(items),
-                                                                                                                                                               controller,
-                                                                                                                                                               Registry.getInstalledPath(),
-                                                                                                                                                               window, true);
-                                                       if (!result) {
-                                                               showComposite(compositeInstallablePage);
-                                                               btnBack.setVisible(true);
-                                                               btnNext.setVisible(true);
-                                                               btnClose.setEnabled(true);
-                                                               addExtraButton.setVisible(true);
-                                                       }
-                                               } else {
-                                                       showComposite(compositeSetInstallDirectoryPage);
-                                                       compositeSetInstallDirectoryPage.loadPage(
-                                                                       controller, compositeInstallablePage.getCheckedPackageSize(false));
-                                                       btnNext.setText("Install");
-                                                       addExtraButton.setVisible(false);
-                                               }
-                                       }
-                               } else if (sl_composite.topControl == compositeUpdatableListPage) {
-                                       List<Item> items = compositeUpdatableListPage.getItems();
-                                       if (getSelectedPackageNames(items).size() <= 0) {
-                                               return;
-                                       }
-                                       
-                                       btnBack.setVisible(false);
-                                       btnNext.setVisible(false);
-                                       addExtraButton.setVisible(false);
-                                       showComposite(compositeInstallingPage);
-                                       boolean result = compositeInstallingPage.loadPage(getSelectedPackageNames(items), controller, Registry.getInstalledPath(), window, true);
-                                       
-                                       if (!result) {
-                                               showComposite(compositeUpdatableListPage);
-                                               btnBack.setVisible(true);
-                                               btnNext.setVisible(true);
-                                               btnClose.setEnabled(true);
-                                               addExtraButton.setVisible(true);
-                                       }
-                               } else if (sl_composite.topControl == compositeSetInstallDirectoryPage) {
-                                       boolean installable = compositeSetInstallDirectoryPage.isInstallablePath();
-
-                                       Config.USER_CONFIG_HOME_PATH = compositeSetInstallDirectoryPage.getSDKWorkSpacePath();
-                                       Registry.sdkDataPath = controller.getSDKWorkSpacePath();
-                                       Registry.targetPath = controller.getInstallPath();
-                                       Registry.saveSDKInfo(Registry.targetPath);
-                                       
-                                       InstallManager.getInstance().initPackageList();
-
-                                       if (!installable) {
-                                               MessageBoxDlg.showDlg(
-                                                               Display.getCurrent().getShells()[0],
-                                                                                               "Error",
-                                                                                               "Not enough disk space for the installation. Select a different installation path.",
-                                                                                               DialogType.ERROR, false);
-                                               return;
-                                       }
-                                       
-                                       if (Config.isSupportMultiSDK()) {
-                                               if (!compositeSetInstallDirectoryPage.isWorkSpaceDuplicate()) {
-                                                       int result = MessageBoxDlg.showDlg(
-                                                                       Display.getCurrent().getShells()[0],
-                                                                                                       "Warning",
-                                                                                                       "Tizen SDK data directory is used already. Do you want to continue?",
-                                                                                                       DialogType.WARNING, false);
-                                                       if (result == MessageBoxDlg.NO) {
-                                                               return;
-                                                       }
-                                               }
-                                       }
-                                       btnBack.setVisible(false);
-                                       btnNext.setVisible(false);
-                                       addExtraButton.setVisible(false);
-                                       List<Item> items = compositeInstallablePage.getItems();
-                                       showComposite(compositeInstallingPage);
-                                       boolean result = compositeInstallingPage.loadPage(getSelectedPackageNames(items),
-                                                                                                                                               controller,
-                                                                                                                                               compositeSetInstallDirectoryPage.getInstallPath(),
-                                                                                                                                               window, false);
-                                       if (!result) {
-                                               showComposite(compositeInstallablePage);
-                                               btnBack.setVisible(true);
-                                               btnNext.setVisible(true);
-                                               btnClose.setEnabled(true);
-                                       }
-                               } else if (sl_composite.topControl == compositeUninstallablePage) {
-                                       showComposite(compositeUninstallingPage);
-                                       btnBack.setVisible(false);
-                                       btnNext.setVisible(false);
-                                       btnClose.setEnabled(false);
-                                       addExtraButton.setVisible(false);
-                                       List<Item> items = compositeUninstallablePage.getItems();
-                                       boolean result = compositeUninstallingPage.loadPage(getSelectedPackageNames(items) /* compositeInstallablePage.getCheckedPackageNames()*/,
-                                                                                                                                               controller,
-                                                                                                                                               window);
-                                       if (!result) {
-                                               showComposite(compositeUninstallablePage);
-                                               btnBack.setVisible(true);
-                                               btnNext.setVisible(true);
-                                               btnClose.setEnabled(true);
-                                       }
-                               }
-                       }
-               });
-               btnNext.setBounds(447, 10, 78, 29);
-
-               btnBack = new Button(composite_1, SWT.NONE);
-               btnBack.addSelectionListener(new SelectionAdapter() {
-                       @Override
-                       public void widgetSelected(SelectionEvent e) {
-                               if (sl_composite.topControl == compositeLicensePage) {
-                                       btnNext.setEnabled(true);
-                                       btnBack.setVisible(false);
-                                       btnNext.setFocus();
-                                       btnSettings.setVisible(true);
-                                       addExtraButton.setVisible(false);
-                                       showComposite(compositeWelcomePage);
-                               } else if (sl_composite.topControl == compositeInstallablePage || sl_composite.topControl == compositeUpdatableListPage) {
-                                       compositeInstallablePage.getItems().clear();
-                                       addExtraButton.setVisible(false);
-                                       if (controller.existRemovablePackage()) {
-                                               btnBack.setVisible(false);
-                                               btnSettings.setVisible(true);
-                                               showComposite(compositeWelcomePage);
-                                       } else {
-                                               showComposite(compositeLicensePage);
-                                       }
-                                       btnNext.setEnabled(true);
-                                       btnNext.setText("Next");
-                               } else if (sl_composite.topControl == compositeSetInstallDirectoryPage) {
-                                       showComposite(compositeInstallablePage);
-                                       addExtraButton.setVisible(true);
-                                       btnNext.setText("Next");
-                                       btnNext.setEnabled(true);
-                               } else if (sl_composite.topControl == compositeUninstallablePage) {
-                                       showComposite(compositeWelcomePage);
-                                       addExtraButton.setVisible(false);
-                                       btnNext.setText("Next");
-                                       btnNext.setEnabled(true);
-                                       btnBack.setVisible(false);
-                               }
-                       }
-               });
-               btnBack.setBounds(363, 10, 78, 29);
-               btnBack.setText("Back");
-               btnBack.setVisible(false);
-               
-               createBtnSettings(composite_1);
-               setAddRepositoryButton(composite_1);
-
-               compositeWelcomePage = new WelcomePage(pageComposite, SWT.NONE);
-               compositeLicensePage = new LicensePage(pageComposite, SWT.NONE);
-               compositeCompletePage = new CompletePage(pageComposite, SWT.NONE);
-               compositeInstallingPage = new InstallingPage(pageComposite, SWT.NONE);
-               compositeInstallablePage = new InstallableListPage(pageComposite, SWT.NONE);
-               compositeUninstallingPage = new UninstallingPage(pageComposite, SWT.NONE);
-               compositeUninstallablePage = new UninstallableListPage(pageComposite, SWT.NONE);
-               compositeSetInstallDirectoryPage = new SetInstallDirectoryPage(pageComposite, SWT.NONE);
-               compositeUpdatableListPage = new UpdatableListPage(pageComposite, SWT.NONE);
-
-               registLicensePageListener();
-               registCompletePageListener();
-
-               initWelcomePage();
-               
-               return container;
-       }
-       
-       private void createBtnSettings(Composite composite) {
-               btnSettings = new Button(composite, SWT.NONE);
-               btnSettings.setText("Proxy settings");
-               btnSettings.setBounds(25, 10, 120, 29);
-               
-               btnSettings.addSelectionListener(new SelectionAdapter() {
-                       @Override
-                       public void widgetSelected(SelectionEvent e) {
-                               ConfigFile configFile = Config.getInstance().getConfigFile();
-                               ProxySettingsDialog psDialog = new ProxySettingsDialog(getShell());
-                               
-                               psDialog.setProxySettings(configFile.getProxyType(), 
-                                               configFile.getProxyHost(), 
-                                               configFile.getProxyPort());
-                               
-                               psDialog.open();
-                       }
-               });
-       }
-       
-       /**
-        * Set add Repository button. 
-        */
-       private void setAddRepositoryButton(final Composite composite) {
-               if (addExtraButton == null) {
-                       addExtraButton = new Button(composite ,SWT.NONE);                       
-               }
-
-               addExtraButton.setBounds(20, 10, 130, 29);
-               addExtraButton.setText("Extra repository");
-               addExtraButton.setVisible(false);
-               
-               addExtraButton.addSelectionListener(new SelectionAdapter() {
-                       public void widgetSelected(SelectionEvent e) {
-                               extraDialog = new AddExtraRepositoryDialog(composite.getShell(), controller);
-                               extraDialog.open();
-                               
-                               if (sl_composite.topControl == compositeInstallablePage) {
-                                       compositeInstallablePage.loadPage(controller);
-                               } else if (sl_composite.topControl == compositeUpdatableListPage) {
-                                       compositeUpdatableListPage.loadPage(controller);
-                               }
-                       }
-               });
-       }
-       
-       private void initWelcomePage() {
-               compositeWelcomePage.setViewController(controller);
-               
-               if (ErrorController.checkInstallationSuccess()) {
-                       compositeWelcomePage.setTitle(WelcomePage.STRING_TITLE);
-                       compositeWelcomePage.setSubTitleBounds(20, 190, 600, 40);
-                       compositeWelcomePage.setSubTitle(WelcomePage.STRING_SUBTITLE);
-                       
-                       compositeWelcomePage.setVisibleRadioButton(true);
-                       btnNext.setEnabled(true);
-                       btnNext.setVisible(true);
-                       btnClose.setText("Cancel");
-                       
-                       btnClose.removeSelectionListener(closeBtnSelectionAdapter);
-                       btnClose.removeSelectionListener(cancelBtnSelectionAdapter);
-                       btnClose.addSelectionListener(cancelBtnSelectionAdapter);
-                       
-                       compositeWelcomePage.setButtonStatus();
-               } else {
-                       compositeWelcomePage.setVisibleRadioButton(false);
-                       btnNext.setVisible(false);
-                       
-                       compositeWelcomePage.setTitle("Cannot start Tizen SDK Install Manager.");
-                       
-                       String errMsg = ErrorController.getErrorMessage();
-                       String repository = Config.getInstance().getConfigFile().getRepository();
-                       
-                       if (repository != null && !repository.isEmpty()) {
-                               errMsg = errMsg + "\n(" + repository + ")";
-                       }
-                       compositeWelcomePage.setSubTitleBounds(20, 190, 600, 100);
-                       compositeWelcomePage.setErrorSubTitle(errMsg);
-
-                       btnClose.setText("Close");
-                       
-                       btnClose.removeSelectionListener(closeBtnSelectionAdapter);
-                       btnClose.removeSelectionListener(cancelBtnSelectionAdapter);
-                       btnClose.addSelectionListener(closeBtnSelectionAdapter);
-               }
-               btnNext.setFocus();
-               sl_composite.topControl = compositeWelcomePage;
-       }
-       
-       /**
-        * Refresh InstallManager. 
-        * Refresh packages and configuration information.
-        */
-       public void refresh() {
-               final IndeterminateProgressDialog progressbar = IndeterminateProgressDialog.getInstance();
-               final Shell shell = progressbar.getParent();
-               shell.getDisplay().asyncExec(new Runnable(){
-                       public void run() {
-                               progressbar.updateName("Initializing...");
-                               
-                               shell.getDisplay().syncExec(new Runnable() {
-                                       public void run() {
-                                               PackageManager.dispose();
-                                               initInstallManager();
-                                               initWelcomePage();
-                                       }
-                               });
-                               
-                               //init end
-                               progressbar.finish();
-                       }
-               });
-               
-               if (!shell.isDisposed()) {
-                       progressbar.open();
-               }
-
-               Log.log("Window refresh end");
-       }
-
-       /**
-        * Checks if there's updatable meta package.
-        * Then print "updatable" to stdout.
-        */
-       private static void checkMetaPackageUpdate() {
-               if (PackageManager.getInstance().getUpdatableMetaPackages().size() != 0) {
-                       System.out.println("updatable");
-               }
-       }
-       
-       /**
-        * There is no UI, just download packages.
-        * @throws IMExitException
-        */
-       private static void onlyDownloadPackages() throws IMExitException {
-               ViewController controller = new ViewController();
-               controller.init();
-
-               InstallManager installManager = InstallManager.getInstance();
-               PackageManager packageManager = installManager.getPackageManager();
-               
-               // Get all meta packages list by boundary.(eg. public, partner, all....) 
-               PackageSet filteredMeta = filterPackageSet();
-               PackageSet downloadablePkgs = packageManager.getDependsPackagesFromRepository(filteredMeta);
-               
-               // Download all meta packages. 
-               boolean filteredPackages = false;
-               try {
-                       filteredPackages = installManager.downloadPackages(
-                               downloadablePkgs, null);
-               } catch (IMNetworkException e) {
-                       Log.ExceptionLog(e);
-                       return;
-               }
-               
-               if (filteredPackages) {
-                       Log.log("Success to download packages from repository");
-               } else {
-                       Log.err("Fail to download packages from repository");
-                       return;
-               }
-       }
-       
-       private static PackageSet filterPackageSet() {
-               PackageManager pm = PackageManager.getInstance();
-               
-               PackageSet downloadPackageList = pm.getLeafMetaPackages();
-               
-               String boundary = Options.boundary;
-               if (boundary.equalsIgnoreCase("public")) {
-                       PackageSet partnerMetaPackages = pm.getPartnerMetaPackages();
-                       
-                       if (!partnerMetaPackages.isEmpty()) {
-                               downloadPackageList.removeAll(partnerMetaPackages);
-                       }
-               } else if (boundary.equalsIgnoreCase("partner")) {
-                       PackageSet publicMetaPackages = pm.getPublicMetaPackages();
-                       
-                       if (!publicMetaPackages.isEmpty()) {
-                               downloadPackageList.removeAll(publicMetaPackages);
-                       }
-               }
-               
-               return downloadPackageList;
-       }
-       
-       private static void showInstallManagerVersion() {
-               System.out.println("InstallManager Version : " + 
-                               Config.getInstance().getInstallManagerVersion().toString());
-       }
-       
-       /**
-        * Logging all system information.
-        */
-       private static void loggingProperty() {
-               Log.log("=========== System properties ===========");
-               Properties sysprops = System.getProperties();
-               for (Enumeration e = sysprops.propertyNames(); e.hasMoreElements();) {
-                       String key = (String) e.nextElement();
-                       String value = sysprops.getProperty(key);
-                       Log.log(key + " = " + value);
-               }
-               
-               Log.log("=========== Environment variables ===========");
-
-               Map<String, String> env = System.getenv();
-               Set<String> set = env.keySet();
-               Iterator<String> iter = set.iterator();
-
-               while (iter.hasNext()) {
-                       String key = (String) iter.next();
-                       Set<Entry<String, String>> value = env.entrySet();
-                       Log.log(key + " = " + value);
-               }
-               Log.log("=============================================");
-       }
-
-       /**
-        * Launch the application.
-        * 
-        * @param args
-        */
-       public static void main(String args[]) {
-               //performance measurement
-               Performance.setIMStartTime();
-               
-               InstallManager.deleteTempFile();
-               
-               Log.open();
-               Log.LogTitle("Installmanager start");
-               Log.log(Platform.getPlatformInfo());
-               Log.log(PathUtil.getCurrentDir());
-               
-               if (Options.propertyLogging) {
-                       loggingProperty();
-               }
-               
-               try {
-                       Options.loadCmdArgs(args);
-               } catch (IMFatalException e) {
-                       Log.err("Check your options. => " + Arrays.toString(args));
-                       System.out.println("Check your options. => " + Arrays.toString(args));
-                       return;
-               }
-               
-               try {                   
-                       if (Options.onlyDownload) {
-                               onlyDownloadPackages();
-                               System.exit(0);
-                       } else if (Options.doInstallNoUI) {
-                               if (InstallManagerNoUI.cliInstall(Options.packages)) {
-                                       Log.log("Success to command line install.");
-                                       System.out.println("Success to console install.");
-                               } else {
-                                       Log.log("Fail to command line install.");
-                                       System.out.println("Fail to console install.");
-                               }
-                               
-                               Performance.setIMEndTime();
-                               if (Options.doTest) {
-                                       Performance.printTestResultXmlFormat();
-                                       Performance.printTestResultXmlFormat2();
-                               }
-                               
-                               System.exit(0);
-                       } else if (Options.doRemoveNoUI) {
-                               if (InstallManagerNoUI.cliUninstall(Options.packages)) {
-                                       Log.log("Success to command line remove.");
-                                       System.out.println("Success to remove.");
-                               } else {
-                                       Log.log("Fail to command line remove.");
-                                       System.out.println("Fail to remove.");
-                               }
-                               
-                               Performance.setIMEndTime();
-                               if (Options.doTest) {
-                                       Performance.printTestResultXmlFormat();
-                                       Performance.printTestResultXmlFormat2();
-                               }
-                               
-                               System.exit(0);
-                       } else if (Options.showVersion) {
-                               showInstallManagerVersion();
-                               System.exit(0);
-                       } else if (Options.doShowHelp) {
-                               InstallManagerNoUI.cliShowHelp();
-                               System.exit(0);
-                       }
-                       
-                       if (Platform.isMacOS()) {
-                               System.setProperty("apple.laf.useScreenMenuBar", "true");
-                               System.setProperty(
-                                               "com.apple.mrj.application.apple.menu.about.name",
-                                               "Emulator Manager");
-                               Display display = Display.getDefault();
-                               display.syncExec(new Runnable() {
-                                       @Override
-                                       public void run() {
-                                               new CocoaUtil().removeTopMenuItems();
-                                       }
-                               });
-                       }
-                       
-                       window = new InstallManagerWindow();
-                       window.setBlockOnOpen(true);
-                       
-                       window.init();
-                       
-                       Log.log("after init");
-                       if (Options.checkPackageUpdate) {
-                               checkMetaPackageUpdate();
-                       } else if (Options.printDepGraph) {
-                               InstallManager.getInstance().getPackageManager().printDepGraph();
-                       } else if (Options.doShowDistListNoUI) {
-                               InstallManagerNoUI.cliShowRepoInformation();
-                       } else if (Options.doShowPackageListNoUI) {
-                               InstallManagerNoUI.cliShowPackageList();
-                       } else if (Options.doShowSDKInstallStatus) {
-                               InstallManagerNoUI.cliShowInstallInformation();
-                       } else {
-                               window.open();
-                               if (Display.getCurrent() != null
-                                               && !Display.getCurrent().isDisposed()) {
-                                       Display.getCurrent().dispose();
-                               }
-                       }
-               } catch (IMExitException e) {
-                       // do not remove sdk temp dir if exit for self update
-                       if (ErrorController.getExitCode() == Config.EXITCODE_HAS_SELF_UPDATE) {
-                               Options.doRemoveTempTizenSDK = false;
-                       }
-                       
-                       Log.log("Gracefully exit");
-               } catch (Throwable e) {
-                       Log.err("Unexpected error occurred");
-                       Log.ExceptionLog(e);
-                       
-                       if (Options.doInstallNoUI || Options.doRemoveNoUI) {
-                               PathUtil.remove(Registry.REGISTRY_FILE_PATH);
-                               PathUtil.remove(Registry.MULTI_SDK_FILE_PATH);
-                               System.out.println("Fatal error occurred.");
-                               System.exit(0);
-                       }
-                       
-                       // show error message
-                       if (window != null) {
-                               window.open();
-                               
-                               if (Display.getCurrent() != null
-                                               && !Display.getCurrent().isDisposed()) {
-                                       Display.getCurrent().dispose();
-                               }
-                       }
-                       
-                       ErrorController.setExitCode(Config.EXITCODE_UNKNOWN_ERROR);
-               } finally {
-                       if (Platform.isWindows()) {
-                               ProgramController.createProgramController().removeSDKTempDir();
-                       }
-                       
-                       //performance measurement
-                       Performance.setIMEndTime();
-                       Performance.printToLogFile();
-                       
-                       if (Options.doTest) {
-                               Performance.printTestResultXmlFormat();
-                               Performance.printTestResultXmlFormat2();
-                       }
-                       
-                       Log.LogTitle("Installmanager finish");
-                       Log.close();
-                       
-                       if (Platform.isMacOS()) {
-                               System.exit(ErrorController.getExitCode());
-                       } else {
-                               if (ErrorController.getExitCode() == Config.EXITCODE_HAS_SELF_UPDATE) {
-                                       String binary = PathUtil.get(Registry.getInstalledPath(), Config.INSTALL_MANAGER_DIRECTORY, Config.EXECUTE_FILE_NAME_OF_INSTALL_MANAGER);
-                                       try {
-                                               Runtime.getRuntime().exec(binary);
-                                       } catch (IOException e) {
-                                               Log.ExceptionLog(e);
-                                       }
-                               } else if (ErrorController.getExitCode() != Config.EXITCODE_NORMAL) {
-                                       System.exit(ErrorController.getExitCode());
-                               }
-                       }
-               }
-       }
-
-       @Override
-       protected void configureShell(Shell newShell) {
-               newShell.setBackground(getBackgroundColor());
-               newShell.setMinimumSize(getInitialSize());
-               newShell.setSize(getInitialSize());
-               newShell.setImage(getWindowIconImage());
-               super.configureShell(newShell);
-
-               newShell.setText("Tizen SDK Install Manager");
-       }
-
-       @Override
-       /**
-        * Install manager window is close.
-        */
-       public boolean close() {
-               return false;
-       }
-
-       /**
-        * Return the initial size of the window.
-        */
-       @Override
-       protected Point getInitialSize() {
-               return POINT_MAIN_WINDOW;
-       }
-
-       /**
-        * Show the composite depending on parameter.
-        * @param composite
-        */
-       public void showComposite(Composite composite) {
-               StackLayout layout;
-               if (composite.getParent().getLayout() instanceof StackLayout) {
-                       layout = (StackLayout) composite.getParent().getLayout();
-                       layout.topControl = composite;
-               }
-               composite.getParent().layout();
-       }
-
-       private void registLicensePageListener() {
-               compositeLicensePage.getAcceptButton()
-                                                       .addSelectionListener(new SelectionAdapter() {
-
-                                                               @Override
-                                                               public void widgetSelected(SelectionEvent e) {
-                                                                       btnNext.setEnabled(compositeLicensePage.getAcceptButton()
-                                                                                                                                                       .getSelection());
-                                                               }
-                                                       });
-       }
-
-       private void registCompletePageListener() {
-               compositeCompletePage.addPaintListener(new PaintListener() {
-
-                       @Override
-                       public void paintControl(PaintEvent arg0) {
-                               btnClose.setText("Close");
-                       }
-               });
-       }
-       
-       public void setNameOfCancelButton(String name) {
-               btnClose.setText("Close");
-       }
-
-       /**
-        * Get selected package names on installing
-        * @param items
-        * @return list of selected package names.
-        */
-       public List<String> getSelectedPackageNames(List<Item> items) {
-               List<String> list = new ArrayList<String>();
-               for (int i = 0; i < items.size(); i++) {
-                       items.get(i).getTerminalPackages(list, true);
-               }
-
-               return list;
-       }
-       
-       /**
-        * Installed packages do not have package version, installmanager will show warning dialog.
-        * @return
-        */
-       private boolean checkVaildPkgVersion() {
-               PackageSet installedPkgs = controller.getInstalledPackages();
-               if (!installedPkgs.isEmpty()) {
-                       for (Package pkg : installedPkgs) {
-                               String vs = pkg.getVersion().toString();
-                               if (vs != "" && vs.equals("0.0.0")) {
-                               Log.err("Package version not found. ==> " + pkg.getPackageName());
-                               int confirm = MessageBoxDlg.showDlg(getShell(), 
-                                                   "WARNING", 
-                                                   "'" + pkg.getPackageName() + "'" + " package version is not found.\n" +
-                                                   "If you keep installing Tizen SDK, some unexpected may occur.\n" +
-                                                   "Do you want to continue?", 
-                                                   DialogType.WARNING, false);
-                               if (confirm == MessageBoxDlg.YES) {
-                                       return true;
-                               } else {
-                                       return false;
-                               }
-                               }
-                       }
-               }
-
-               return true;
-       }
-       
-       /**
-        * Get install manager window object.
-        * @return install manager window object.
-        */
-       public static InstallManagerWindow getInstallManagerWindow() {
-               return window;
-       }
-
-       /**
-        * Get complete page composite object
-        * @return complete page composite object
-        */
-       public CompletePage getCompletePage() {
-               return compositeCompletePage;
-       }
-       
-       public InstallableListPage getInstallableListPage() {
-               return compositeInstallablePage;
-       }
-       
-       public WelcomePage getWelcomePage() {
-               return compositeWelcomePage;
-       }
-       
-       /**
-        * Get setInstallDirectoryPage composite object
-        * @return complete page composite object
-        */
-       public SetInstallDirectoryPage getSetInstallDirectoryPage() {
-               return compositeSetInstallDirectoryPage;
-       }
-
-       /**
-        * If parameter is true, 'Next' button will be enabled. but false, 'Next' button will be disabled.
-        * @param enabled
-        */
-       public static void setNextBtnEnabled(boolean enabled) {
-               btnNext.setEnabled(enabled);
-       }
-
-       /**
-        * If parameter is true, 'Back' button will be enabled. but false, 'Back' button will be disabled.
-        * @param enabled
-        */
-       public static void setBackBtnEnabled(boolean enabled) {
-               btnBack.setEnabled(enabled);
-       }
-
-       /**
-        * If parameter is true, 'Cancel' button will be enabled. but false, 'Cancel' button will be disabled.
-        * @param enabled
-        */
-       public void setCancelBtnEnabled(boolean enabled) {
-               btnClose.setEnabled(enabled);
-       }
-       
-       public ViewController getViewController() {
-               return controller;
-       }
-}
+/*\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.ui;\r
+\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Enumeration;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Map.Entry;\r
+import java.util.Properties;\r
+import java.util.Set;\r
+\r
+import org.eclipse.jface.window.ApplicationWindow;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.StackLayout;\r
+import org.eclipse.swt.events.PaintEvent;\r
+import org.eclipse.swt.events.PaintListener;\r
+import org.eclipse.swt.events.SelectionAdapter;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.graphics.Color;\r
+import org.eclipse.swt.graphics.Image;\r
+import org.eclipse.swt.graphics.Point;\r
+import org.eclipse.swt.graphics.RGB;\r
+import org.eclipse.swt.layout.RowData;\r
+import org.eclipse.swt.layout.RowLayout;\r
+import org.eclipse.swt.widgets.Button;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.tizen.installmanager.cli.InstallManagerNoUI;\r
+import org.tizen.installmanager.core.Config;\r
+import org.tizen.installmanager.core.IMExitException;\r
+import org.tizen.installmanager.core.IMFatalException;\r
+import org.tizen.installmanager.core.InstallManager;\r
+import org.tizen.installmanager.core.Options;\r
+import org.tizen.installmanager.core.Performance;\r
+import org.tizen.installmanager.lib.ErrorController;\r
+import org.tizen.installmanager.lib.IMError;\r
+import org.tizen.installmanager.lib.Log;\r
+import org.tizen.installmanager.lib.Platform;\r
+import org.tizen.installmanager.lib.ProgramController;\r
+import org.tizen.installmanager.lib.Registry;\r
+import org.tizen.installmanager.lib.exception.IMNetworkException;\r
+import org.tizen.installmanager.lib.mac.CocoaUtil;\r
+import org.tizen.installmanager.pkg.lib.PackageManager;\r
+import org.tizen.installmanager.pkg.model.ConfigFile;\r
+import org.tizen.installmanager.pkg.model.PackageSet;\r
+import org.tizen.installmanager.ui.dialog.AddExtraRepositoryDialog;\r
+import org.tizen.installmanager.ui.dialog.IndeterminateProgressDialog;\r
+import org.tizen.installmanager.ui.dialog.MessageBoxDlg;\r
+import org.tizen.installmanager.ui.dialog.MessageBoxDlg.DialogType;\r
+import org.tizen.installmanager.ui.dialog.ProxySettingsDialog;\r
+import org.tizen.installmanager.ui.model.Item;\r
+import org.tizen.installmanager.ui.page.CompletePage;\r
+import org.tizen.installmanager.ui.page.InstallableListPage;\r
+import org.tizen.installmanager.ui.page.InstallingPage;\r
+import org.tizen.installmanager.ui.page.LicensePage;\r
+import org.tizen.installmanager.ui.page.SetInstallDirectoryPage;\r
+import org.tizen.installmanager.ui.page.UninstallableListPage;\r
+import org.tizen.installmanager.ui.page.UninstallingPage;\r
+import org.tizen.installmanager.ui.page.UpdatableListPage;\r
+import org.tizen.installmanager.ui.page.ViewController;\r
+import org.tizen.installmanager.ui.page.WelcomePage;\r
+import org.tizen.installmanager.ui.page.InstallingPage.InstallProgressMonitor;\r
+import org.tizen.installmanager.ui.page.WelcomePage.RADIO_ACTION;\r
+import org.tizen.installmanager.util.PathUtil;\r
+import org.tizen.installmanager.pkg.model.Package;\r
+\r
+\r
+/**\r
+ * This class is main class for install manager.\r
+ * @author Taeyoung Son <taeyoung2.son@samsung.com>\r
+ */\r
+public class InstallManagerWindow extends ApplicationWindow {\r
+       private static final RGB RGB_BACKGROUND = new RGB(242, 242, 242);\r
+\r
+       private static final Point POINT_MAIN_WINDOW = new Point(628, 478);\r
+       private static Image IMAGE_WINDOW_ICON;\r
+       private static Color COLOR_BACKGROUND;\r
+\r
+       private static InstallManagerWindow window;\r
+\r
+       private StackLayout sl_composite = new StackLayout();\r
+       private static Button btnClose;\r
+       private static Button btnBack;\r
+       private static Button btnNext;\r
+       private Button btnSettings;\r
+       private static Button addExtraButton;\r
+\r
+       private AddExtraRepositoryDialog extraDialog = null;\r
+       \r
+       private Composite pageComposite;\r
+       private WelcomePage compositeWelcomePage;\r
+       private LicensePage compositeLicensePage;\r
+       private InstallableListPage compositeInstallablePage;\r
+       private UninstallableListPage compositeUninstallablePage;\r
+       private InstallingPage compositeInstallingPage;\r
+       private UninstallingPage compositeUninstallingPage;\r
+       private CompletePage compositeCompletePage;\r
+       private SetInstallDirectoryPage compositeSetInstallDirectoryPage;\r
+       public UpdatableListPage compositeUpdatableListPage;\r
+\r
+       protected static ViewController controller;\r
+       private SelectionAdapter cancelBtnSelectionAdapter = null;\r
+       private SelectionAdapter closeBtnSelectionAdapter = null;\r
+\r
+       /**\r
+        * Create the application window.\r
+        */\r
+       public InstallManagerWindow() {\r
+               super(null);\r
+               setShellStyle(SWT.SHELL_TRIM);\r
+               setShellStyle(SWT.BORDER | SWT.TITLE);\r
+       }\r
+\r
+       /**\r
+        * Get installmanager window background color.\r
+        * @return background color\r
+        */\r
+       public static Color getBackgroundColor() {\r
+               if (COLOR_BACKGROUND == null) {\r
+                       COLOR_BACKGROUND = new Color(null, RGB_BACKGROUND);\r
+               }\r
+               return COLOR_BACKGROUND;\r
+       }\r
+\r
+       private static Image getWindowIconImage() {\r
+               if (IMAGE_WINDOW_ICON == null) {\r
+                       IMAGE_WINDOW_ICON = PathUtil.getImageFromResource("/res/icons/SDK_icon.png");\r
+               }\r
+               return IMAGE_WINDOW_ICON;\r
+       }\r
+\r
+       private void init() throws IMExitException{\r
+               Log.log("Window init start");\r
+               \r
+               //make waiting dialog.\r
+               final IndeterminateProgressDialog progressbar = IndeterminateProgressDialog.getInstance();\r
+               \r
+               final Shell shell = progressbar.getParent();\r
+               shell.getDisplay().asyncExec(new Runnable(){\r
+                       public void run() {                             \r
+                               //initialize installmanager\r
+                               progressbar.updateName("Connecting to package server.\nIt may take a minute...");\r
+                               \r
+                               shell.getDisplay().asyncExec(new Runnable() {\r
+                                       public void run() {\r
+                                               initInstallManager();\r
+                                       }\r
+                                       \r
+                               });\r
+                               \r
+                               //init end\r
+                               progressbar.finish();\r
+                       }\r
+               });\r
+               \r
+               if (!shell.isDisposed()) {\r
+                       progressbar.open();\r
+               }\r
+\r
+               Log.log("Window init end");\r
+       }\r
+       \r
+       private void updateInstallManager(Shell shell) {\r
+               if (controller.canInstallManagerUpdate()) {\r
+                       String msg = "There is a new installer on the server. \nNew install-manager will be started. \nIt may take a minute...";\r
+                       MessageBoxDlg.showDlg(shell, "InstallManager", msg, DialogType.NOTIFY, false);\r
+                       \r
+                       controller.updateInstallManager();\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * init IM's configuation and packages information.\r
+        * @return\r
+        */\r
+       public boolean initInstallManager() {\r
+               ErrorController.setInstallationSuccess(true);\r
+               \r
+               controller = new ViewController();\r
+               \r
+               if (controller.init()) {\r
+                       if (Config.isSupportMultiSDK()) {\r
+                               Log.log("Multi SDK installation.");\r
+                       } else {\r
+                               Log.log("Single SDK installation.");\r
+                       }\r
+                       return true;\r
+               } else {\r
+                       Log.err("InstallManager init fail.");\r
+                       ErrorController.setInstallationSuccess(false);\r
+                       \r
+                       return false;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Create contents of the application window.\r
+        * \r
+        * @param parent\r
+        */\r
+       @Override\r
+       protected Control createContents(Composite parent) {\r
+\r
+               IMError.setComposite(parent);\r
+               Composite container = new Composite(parent, SWT.NONE);\r
+               container.setBackground(getBackgroundColor());\r
+               RowLayout rl_container = new RowLayout(SWT.VERTICAL);\r
+               rl_container.spacing = 0;\r
+               rl_container.marginTop = 0;\r
+               rl_container.marginRight = 0;\r
+               rl_container.marginLeft = 0;\r
+               rl_container.marginBottom = 0;\r
+               container.setLayout(rl_container);\r
+\r
+               pageComposite = new Composite(container, SWT.NONE);\r
+               pageComposite.setLayoutData(new RowData(619, 395));\r
+               pageComposite.setLayout(sl_composite);\r
+               pageComposite.setBackground(InstallManagerWindow.getBackgroundColor());\r
+\r
+               Composite composite_1 = new Composite(container, SWT.NONE);\r
+               composite_1.setLayoutData(new RowData(619, 38));\r
+               composite_1.setBackground(InstallManagerWindow.getBackgroundColor());\r
+\r
+               Label label = new Label(composite_1, SWT.SEPARATOR | SWT.HORIZONTAL);\r
+               label.setBounds(0, 0, 620, 2);\r
+\r
+               btnClose = new Button(composite_1, SWT.NONE);\r
+               btnClose.setText("Cancel");\r
+               cancelBtnSelectionAdapter = new SelectionAdapter() {\r
+                       @Override\r
+                       public void widgetSelected(SelectionEvent e) {\r
+                               int result = MessageBoxDlg.NO;\r
+                               if (sl_composite.topControl == compositeInstallingPage) {\r
+                                       InstallProgressMonitor mon = compositeInstallingPage.getInstallProgressMonitor();\r
+                                       mon.setCancelRequested(true);\r
+                                       result = MessageBoxDlg.showDlg(\r
+                                                       e.display.getActiveShell(),\r
+                                                       "Tizen SDK Install Manager",\r
+                                                       "Are you sure you want to quit Install Manager?\n\nIf you click \"Yes\", the installation is stopped.",\r
+                                                       DialogType.WARNING, false);\r
+                                       if (result == MessageBoxDlg.YES) {\r
+                                               mon.setCanceled(true);\r
+                                       } else {\r
+                                               mon.setCancelRequested(false);\r
+                                       }\r
+                                       return;\r
+                               } else if (sl_composite.topControl == compositeUninstallingPage) {\r
+                                       result = MessageBoxDlg.showDlg(\r
+                                                       e.display.getActiveShell(),\r
+                                                       "Tizen SDK Install Manager",\r
+                                                       "Are you sure to quit Install Manager?\n\nIf you click \"Yes\", the uninstallation is stopped.",\r
+                                                       DialogType.WARNING, false);\r
+                               } else if (sl_composite.topControl == compositeCompletePage) {\r
+                                       controller.showChangeLog();\r
+                                       \r
+                                       if (!Options.doResumeDownloading) {\r
+                                               controller.cleanUpTargetDirectory();\r
+                                       }\r
+                                       \r
+                                       result = MessageBoxDlg.YES;\r
+                               } else {\r
+                                       result = MessageBoxDlg.showDlg(e.display.getActiveShell(),\r
+                                                       "Tizen SDK Install Manager",\r
+                                                       "Are you sure to quit Install Manager?",\r
+                                                       DialogType.WARNING, false);\r
+                               }\r
+                               \r
+                               if (result == MessageBoxDlg.YES) {\r
+                                       e.display.close();\r
+                               }\r
+                       }\r
+               };\r
+               \r
+               closeBtnSelectionAdapter = new SelectionAdapter() {\r
+                       @Override\r
+                       public void widgetSelected(SelectionEvent arg0) {\r
+                               arg0.display.close();\r
+                       }\r
+               };\r
+               \r
+               btnClose.addSelectionListener(cancelBtnSelectionAdapter);\r
+               btnClose.setBounds(531, 10, 78, 29);\r
+\r
+               btnNext = new Button(composite_1, SWT.NONE);\r
+               btnNext.setText("Next");\r
+               btnNext.addSelectionListener(new SelectionAdapter() {\r
+                       @Override\r
+                       public void widgetSelected(SelectionEvent e) {\r
+                               if (sl_composite.topControl == compositeWelcomePage) {\r
+                                       updateInstallManager(e.display.getActiveShell());\r
+                                       addExtraButton.setVisible(false);\r
+                                       btnSettings.setVisible(false);\r
+                                       if (compositeWelcomePage.getSelectedRadioButton() == RADIO_ACTION.INSTALL) {\r
+                                               if (!checkVaildPkgVersion()) {\r
+                                                       btnSettings.setVisible(true);\r
+                                                       return;\r
+                                               }\r
+                                               btnNext.setEnabled(compositeLicensePage.getAcceptButton().getSelection());\r
+                                               if (Config.isSupportMultiSDK()) {\r
+                                                       showComposite(compositeLicensePage);\r
+                                                       btnBack.setVisible(true);\r
+                                               } else {\r
+                                                       if (!controller.isNewInstallation()) {// Update case\r
+                                                               compositeUpdatableListPage.loadPage(controller);\r
+                                                               btnBack.setVisible(true);\r
+                                                               addExtraButton.setVisible(true);\r
+\r
+                                                               btnSettings.setVisible(false);\r
+                                                               showComposite(compositeUpdatableListPage);\r
+                                                               if (controller.existRemovablePackage()) {\r
+                                                                       btnNext.setText("Install");\r
+                                                               }\r
+                                                               btnBack.setVisible(true);\r
+                                                       } else {\r
+                                                               showComposite(compositeLicensePage);\r
+                                                               btnBack.setVisible(true);\r
+                                                       }\r
+                                               }\r
+                                       } else if (compositeWelcomePage.getSelectedRadioButton() == RADIO_ACTION.UPDATE) {\r
+                                               btnNext.setEnabled(compositeLicensePage.getAcceptButton().getSelection());\r
+                                               PackageManager.dispose();\r
+                                               initInstallManager();\r
+                                               compositeUpdatableListPage.loadPage(controller);\r
+                                               btnBack.setVisible(true);\r
+                                               addExtraButton.setVisible(true);\r
+                                               btnSettings.setVisible(false);\r
+                                               showComposite(compositeUpdatableListPage);\r
+                                               if (controller.existRemovablePackage()) {\r
+                                                       btnNext.setText("Install");\r
+                                               }\r
+                                               btnBack.setVisible(true);\r
+                                       } else if (compositeWelcomePage.getSelectedRadioButton() == RADIO_ACTION.UNINSTALL) {\r
+                                               int resultDialog = MessageBoxDlg.NO;\r
+                                               resultDialog = MessageBoxDlg.showDlg(\r
+                                                               e.display.getActiveShell(),\r
+                                                               "Tizen SDK Install Manager",\r
+                                                               "Are you sure you want to remove the Tizen SDK?\n\nIf you click \"Yes\", the Tizen SDK is uninstalled.",\r
+                                                               DialogType.WARNING, false);\r
+                                               if (resultDialog == MessageBoxDlg.YES) {\r
+                                                       showComposite(compositeUninstallingPage);\r
+                                                       btnBack.setVisible(false);\r
+                                                       btnNext.setVisible(false);\r
+                                                       btnClose.setEnabled(false);\r
+                                                       addExtraButton.setVisible(false);\r
+                                                       \r
+                                                       if (Config.isSupportMultiSDK()) {\r
+                                                               PackageManager.dispose();\r
+                                                               initInstallManager();                                                           \r
+                                                       }\r
+\r
+                                                       List<Item> items = compositeUninstallablePage.getItems();\r
+                                                       boolean result = compositeUninstallingPage.loadPage(getSelectedPackageNames(items) /* compositeInstallablePage.getCheckedPackageNames()*/,\r
+                                                                                                                                                               controller,\r
+                                                                                                                                                               window);\r
+                                                       if (!result) {\r
+                                                               showComposite(compositeWelcomePage);\r
+                                                               btnBack.setVisible(true);\r
+                                                               btnNext.setVisible(true);\r
+                                                               btnClose.setEnabled(true);\r
+                                                       }\r
+                                               } else {\r
+                                                       btnSettings.setVisible(true);\r
+                                                       return;\r
+                                               }\r
+                                       }\r
+                               } else if (sl_composite.topControl == compositeLicensePage) {\r
+                                       boolean hasItem = compositeInstallablePage.loadPage(controller);\r
+                                       if (hasItem) {\r
+                                               showComposite(compositeInstallablePage);\r
+                                               btnNext.setEnabled(hasItem);\r
+                                               btnBack.setVisible(hasItem);\r
+                                               addExtraButton.setVisible(true);\r
+                                               if (controller.existRemovablePackage()) {\r
+                                                       btnNext.setText("Install");\r
+                                               }\r
+                                       } else {\r
+                                               Log.err("Installable packages do not exist. This is error.");\r
+                                               //TODO\r
+                                       }\r
+                               } else if (sl_composite.topControl == compositeInstallablePage) {\r
+                                       List<Item> items = compositeInstallablePage.getItems();\r
+                                       if (getSelectedPackageNames(items).size() <= 0) {\r
+                                               return;\r
+                                       }\r
+                                       if (Config.isSupportMultiSDK()) {\r
+                                               showComposite(compositeSetInstallDirectoryPage);\r
+                                               compositeSetInstallDirectoryPage.loadPage(\r
+                                                                       controller, compositeInstallablePage.getCheckedPackageSize(false));\r
+                                               btnNext.setText("Install");\r
+                                               addExtraButton.setVisible(false);\r
+                                       } else {\r
+                                               if (controller.existRemovablePackage()) {\r
+                                                       btnBack.setVisible(false);\r
+                                                       btnNext.setVisible(false);\r
+                                                       showComposite(compositeInstallingPage);\r
+                                                       addExtraButton.setVisible(false);\r
+                                                       boolean result = compositeInstallingPage.loadPage(getSelectedPackageNames(items),\r
+                                                                                                                                                               controller,\r
+                                                                                                                                                               Registry.getInstalledPath(),\r
+                                                                                                                                                               window, true);\r
+                                                       if (!result) {\r
+                                                               showComposite(compositeInstallablePage);\r
+                                                               btnBack.setVisible(true);\r
+                                                               btnNext.setVisible(true);\r
+                                                               btnClose.setEnabled(true);\r
+                                                               addExtraButton.setVisible(true);\r
+                                                       }\r
+                                               } else {\r
+                                                       showComposite(compositeSetInstallDirectoryPage);\r
+                                                       compositeSetInstallDirectoryPage.loadPage(\r
+                                                                       controller, compositeInstallablePage.getCheckedPackageSize(false));\r
+                                                       btnNext.setText("Install");\r
+                                                       addExtraButton.setVisible(false);\r
+                                               }\r
+                                       }\r
+                               } else if (sl_composite.topControl == compositeUpdatableListPage) {\r
+                                       List<Item> items = compositeUpdatableListPage.getItems();\r
+                                       if (getSelectedPackageNames(items).size() <= 0) {\r
+                                               return;\r
+                                       }\r
+                                       \r
+                                       btnBack.setVisible(false);\r
+                                       btnNext.setVisible(false);\r
+                                       addExtraButton.setVisible(false);\r
+                                       showComposite(compositeInstallingPage);\r
+                                       boolean result = compositeInstallingPage.loadPage(getSelectedPackageNames(items), controller, Registry.getInstalledPath(), window, true);\r
+                                       \r
+                                       if (!result) {\r
+                                               showComposite(compositeUpdatableListPage);\r
+                                               btnBack.setVisible(true);\r
+                                               btnNext.setVisible(true);\r
+                                               btnClose.setEnabled(true);\r
+                                               addExtraButton.setVisible(true);\r
+                                       }\r
+                               } else if (sl_composite.topControl == compositeSetInstallDirectoryPage) {\r
+                                       boolean installable = compositeSetInstallDirectoryPage.isInstallablePath();\r
+\r
+                                       Config.USER_CONFIG_HOME_PATH = compositeSetInstallDirectoryPage.getSDKWorkSpacePath();\r
+                                       Registry.sdkDataPath = controller.getSDKWorkSpacePath();\r
+                                       Registry.targetPath = controller.getInstallPath();\r
+                                       Registry.saveSDKInfo(Registry.targetPath);\r
+                                       \r
+                                       InstallManager.getInstance().initPackageList();\r
+\r
+                                       if (!installable) {\r
+                                               MessageBoxDlg.showDlg(\r
+                                                               Display.getCurrent().getShells()[0],\r
+                                                                                               "Error",\r
+                                                                                               "Not enough disk space for the installation. Select a different installation path.",\r
+                                                                                               DialogType.ERROR, false);\r
+                                               return;\r
+                                       }\r
+                                       \r
+                                       if (Config.isSupportMultiSDK()) {\r
+                                               if (!compositeSetInstallDirectoryPage.isWorkSpaceDuplicate()) {\r
+                                                       int result = MessageBoxDlg.showDlg(\r
+                                                                       Display.getCurrent().getShells()[0],\r
+                                                                                                       "Warning",\r
+                                                                                                       "Tizen SDK data directory is used already. Do you want to continue?",\r
+                                                                                                       DialogType.WARNING, false);\r
+                                                       if (result == MessageBoxDlg.NO) {\r
+                                                               return;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       btnBack.setVisible(false);\r
+                                       btnNext.setVisible(false);\r
+                                       addExtraButton.setVisible(false);\r
+                                       List<Item> items = compositeInstallablePage.getItems();\r
+                                       showComposite(compositeInstallingPage);\r
+                                       boolean result = compositeInstallingPage.loadPage(getSelectedPackageNames(items),\r
+                                                                                                                                               controller,\r
+                                                                                                                                               compositeSetInstallDirectoryPage.getInstallPath(),\r
+                                                                                                                                               window, false);\r
+                                       if (!result) {\r
+                                               showComposite(compositeInstallablePage);\r
+                                               btnBack.setVisible(true);\r
+                                               btnNext.setVisible(true);\r
+                                               btnClose.setEnabled(true);\r
+                                       }\r
+                               } else if (sl_composite.topControl == compositeUninstallablePage) {\r
+                                       showComposite(compositeUninstallingPage);\r
+                                       btnBack.setVisible(false);\r
+                                       btnNext.setVisible(false);\r
+                                       btnClose.setEnabled(false);\r
+                                       addExtraButton.setVisible(false);\r
+                                       List<Item> items = compositeUninstallablePage.getItems();\r
+                                       boolean result = compositeUninstallingPage.loadPage(getSelectedPackageNames(items) /* compositeInstallablePage.getCheckedPackageNames()*/,\r
+                                                                                                                                               controller,\r
+                                                                                                                                               window);\r
+                                       if (!result) {\r
+                                               showComposite(compositeUninstallablePage);\r
+                                               btnBack.setVisible(true);\r
+                                               btnNext.setVisible(true);\r
+                                               btnClose.setEnabled(true);\r
+                                       }\r
+                               }\r
+                       }\r
+               });\r
+               btnNext.setBounds(447, 10, 78, 29);\r
+\r
+               btnBack = new Button(composite_1, SWT.NONE);\r
+               btnBack.addSelectionListener(new SelectionAdapter() {\r
+                       @Override\r
+                       public void widgetSelected(SelectionEvent e) {\r
+                               if (sl_composite.topControl == compositeLicensePage) {\r
+                                       btnNext.setEnabled(true);\r
+                                       btnBack.setVisible(false);\r
+                                       btnNext.setFocus();\r
+                                       btnSettings.setVisible(true);\r
+                                       addExtraButton.setVisible(false);\r
+                                       showComposite(compositeWelcomePage);\r
+                               } else if (sl_composite.topControl == compositeInstallablePage || sl_composite.topControl == compositeUpdatableListPage) {\r
+                                       compositeInstallablePage.getItems().clear();\r
+                                       addExtraButton.setVisible(false);\r
+                                       if (controller.existRemovablePackage()) {\r
+                                               btnBack.setVisible(false);\r
+                                               btnSettings.setVisible(true);\r
+                                               showComposite(compositeWelcomePage);\r
+                                       } else {\r
+                                               showComposite(compositeLicensePage);\r
+                                       }\r
+                                       btnNext.setEnabled(true);\r
+                                       btnNext.setText("Next");\r
+                               } else if (sl_composite.topControl == compositeSetInstallDirectoryPage) {\r
+                                       showComposite(compositeInstallablePage);\r
+                                       addExtraButton.setVisible(true);\r
+                                       btnNext.setText("Next");\r
+                                       btnNext.setEnabled(true);\r
+                               } else if (sl_composite.topControl == compositeUninstallablePage) {\r
+                                       showComposite(compositeWelcomePage);\r
+                                       addExtraButton.setVisible(false);\r
+                                       btnNext.setText("Next");\r
+                                       btnNext.setEnabled(true);\r
+                                       btnBack.setVisible(false);\r
+                               }\r
+                       }\r
+               });\r
+               btnBack.setBounds(363, 10, 78, 29);\r
+               btnBack.setText("Back");\r
+               btnBack.setVisible(false);\r
+               \r
+               createBtnSettings(composite_1);\r
+               setAddRepositoryButton(composite_1);\r
+\r
+               compositeWelcomePage = new WelcomePage(pageComposite, SWT.NONE);\r
+               compositeLicensePage = new LicensePage(pageComposite, SWT.NONE);\r
+               compositeCompletePage = new CompletePage(pageComposite, SWT.NONE);\r
+               compositeInstallingPage = new InstallingPage(pageComposite, SWT.NONE);\r
+               compositeInstallablePage = new InstallableListPage(pageComposite, SWT.NONE);\r
+               compositeUninstallingPage = new UninstallingPage(pageComposite, SWT.NONE);\r
+               compositeUninstallablePage = new UninstallableListPage(pageComposite, SWT.NONE);\r
+               compositeSetInstallDirectoryPage = new SetInstallDirectoryPage(pageComposite, SWT.NONE);\r
+               compositeUpdatableListPage = new UpdatableListPage(pageComposite, SWT.NONE);\r
+\r
+               registLicensePageListener();\r
+               registCompletePageListener();\r
+\r
+               initWelcomePage();\r
+               \r
+               return container;\r
+       }\r
+       \r
+       private void createBtnSettings(Composite composite) {\r
+               btnSettings = new Button(composite, SWT.NONE);\r
+               btnSettings.setText("Proxy settings");\r
+               btnSettings.setBounds(25, 10, 120, 29);\r
+               \r
+               btnSettings.addSelectionListener(new SelectionAdapter() {\r
+                       @Override\r
+                       public void widgetSelected(SelectionEvent e) {\r
+                               ConfigFile configFile = Config.getInstance().getConfigFile();\r
+                               ProxySettingsDialog psDialog = new ProxySettingsDialog(getShell());\r
+                               \r
+                               psDialog.setProxySettings(configFile.getProxyType(), \r
+                                               configFile.getProxyHost(), \r
+                                               configFile.getProxyPort());\r
+                               \r
+                               psDialog.open();\r
+                       }\r
+               });\r
+       }\r
+       \r
+       /**\r
+        * Set add Repository button. \r
+        */\r
+       private void setAddRepositoryButton(final Composite composite) {\r
+               if (addExtraButton == null) {\r
+                       addExtraButton = new Button(composite ,SWT.NONE);                       \r
+               }\r
+\r
+               addExtraButton.setBounds(20, 10, 130, 29);\r
+               addExtraButton.setText("Extra repository");\r
+               addExtraButton.setVisible(false);\r
+               \r
+               addExtraButton.addSelectionListener(new SelectionAdapter() {\r
+                       public void widgetSelected(SelectionEvent e) {\r
+                               extraDialog = new AddExtraRepositoryDialog(composite.getShell(), controller);\r
+                               extraDialog.open();\r
+                               \r
+                               if (sl_composite.topControl == compositeInstallablePage) {\r
+                                       compositeInstallablePage.loadPage(controller);\r
+                               } else if (sl_composite.topControl == compositeUpdatableListPage) {\r
+                                       compositeUpdatableListPage.loadPage(controller);\r
+                               }\r
+                       }\r
+               });\r
+       }\r
+       \r
+       private void initWelcomePage() {\r
+               compositeWelcomePage.setViewController(controller);\r
+               \r
+               if (ErrorController.checkInstallationSuccess()) {\r
+                       compositeWelcomePage.setTitle(WelcomePage.STRING_TITLE);\r
+                       compositeWelcomePage.setSubTitleBounds(20, 190, 600, 40);\r
+                       compositeWelcomePage.setSubTitle(WelcomePage.STRING_SUBTITLE);\r
+                       \r
+                       compositeWelcomePage.setVisibleRadioButton(true);\r
+                       btnNext.setEnabled(true);\r
+                       btnNext.setVisible(true);\r
+                       btnClose.setText("Cancel");\r
+                       \r
+                       btnClose.removeSelectionListener(closeBtnSelectionAdapter);\r
+                       btnClose.removeSelectionListener(cancelBtnSelectionAdapter);\r
+                       btnClose.addSelectionListener(cancelBtnSelectionAdapter);\r
+                       \r
+                       compositeWelcomePage.setButtonStatus();\r
+               } else {\r
+                       compositeWelcomePage.setVisibleRadioButton(false);\r
+                       btnNext.setVisible(false);\r
+                       \r
+                       compositeWelcomePage.setTitle("Cannot start Tizen SDK Install Manager.");\r
+                       \r
+                       String errMsg = ErrorController.getErrorMessage();\r
+                       String repository = Config.getInstance().getConfigFile().getRepository();\r
+                       \r
+                       if (repository != null && !repository.isEmpty()) {\r
+                               errMsg = errMsg + "\n(" + repository + ")";\r
+                       }\r
+                       compositeWelcomePage.setSubTitleBounds(20, 190, 600, 100);\r
+                       compositeWelcomePage.setErrorSubTitle(errMsg);\r
+\r
+                       btnClose.setText("Close");\r
+                       \r
+                       btnClose.removeSelectionListener(closeBtnSelectionAdapter);\r
+                       btnClose.removeSelectionListener(cancelBtnSelectionAdapter);\r
+                       btnClose.addSelectionListener(closeBtnSelectionAdapter);\r
+               }\r
+               btnNext.setFocus();\r
+               sl_composite.topControl = compositeWelcomePage;\r
+       }\r
+       \r
+       /**\r
+        * Refresh InstallManager. \r
+        * Refresh packages and configuration information.\r
+        */\r
+       public void refresh() {\r
+               final IndeterminateProgressDialog progressbar = IndeterminateProgressDialog.getInstance();\r
+               final Shell shell = progressbar.getParent();\r
+               shell.getDisplay().asyncExec(new Runnable(){\r
+                       public void run() {\r
+                               progressbar.updateName("Initializing...");\r
+                               \r
+                               shell.getDisplay().syncExec(new Runnable() {\r
+                                       public void run() {\r
+                                               PackageManager.dispose();\r
+                                               initInstallManager();\r
+                                               initWelcomePage();\r
+                                       }\r
+                               });\r
+                               \r
+                               //init end\r
+                               progressbar.finish();\r
+                       }\r
+               });\r
+               \r
+               if (!shell.isDisposed()) {\r
+                       progressbar.open();\r
+               }\r
+\r
+               Log.log("Window refresh end");\r
+       }\r
+\r
+       /**\r
+        * Checks if there's updatable meta package.\r
+        * Then print "updatable" to stdout.\r
+        */\r
+       private static void checkMetaPackageUpdate() {\r
+               if (PackageManager.getInstance().getUpdatableMetaPackages().size() != 0) {\r
+                       System.out.println("updatable");\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * There is no UI, just download packages.\r
+        * @throws IMExitException\r
+        */\r
+       private static void onlyDownloadPackages() throws IMExitException {\r
+               ViewController controller = new ViewController();\r
+               controller.init();\r
+\r
+               InstallManager installManager = InstallManager.getInstance();\r
+               PackageManager packageManager = installManager.getPackageManager();\r
+               \r
+               // Get all meta packages list by boundary.(eg. public, partner, all....) \r
+               PackageSet filteredMeta = filterPackageSet();\r
+               PackageSet downloadablePkgs = packageManager.getDependsPackagesFromRepository(filteredMeta);\r
+               \r
+               // Download all meta packages. \r
+               boolean bRet = false;\r
+               try {\r
+                       bRet = installManager.downloadPackages(\r
+                               downloadablePkgs, null);\r
+               } catch (IMNetworkException e) {\r
+                       Log.ExceptionLog(e);\r
+                       return;\r
+               }\r
+               \r
+               if (bRet) {\r
+                       Log.log("Success to download packages from repository");\r
+               } else {\r
+                       Log.err("Fail to download packages from repository");\r
+                       return;\r
+               }\r
+       }\r
+       \r
+       private static PackageSet filterPackageSet() {\r
+               PackageManager pm = PackageManager.getInstance();\r
+               \r
+               PackageSet downloadPackageList = pm.getLeafMetaPackages();\r
+               \r
+               String boundary = Options.boundary;\r
+               if (boundary.equalsIgnoreCase("public")) {\r
+                       PackageSet partnerMetaPackages = pm.getPartnerMetaPackages();\r
+                       \r
+                       if (!partnerMetaPackages.isEmpty()) {\r
+                               downloadPackageList.removeAll(partnerMetaPackages);\r
+                       }\r
+               } else if (boundary.equalsIgnoreCase("partner")) {\r
+                       PackageSet publicMetaPackages = pm.getPublicMetaPackages();\r
+                       \r
+                       if (!publicMetaPackages.isEmpty()) {\r
+                               downloadPackageList.removeAll(publicMetaPackages);\r
+                       }\r
+               }\r
+               \r
+               return downloadPackageList;\r
+       }\r
+       \r
+       private static void showInstallManagerVersion() {\r
+               System.out.println("InstallManager Version : " + \r
+                               Config.getInstance().getInstallManagerVersion().toString());\r
+       }\r
+       \r
+       /**\r
+        * Logging all system information.\r
+        */\r
+       private static void loggingProperty() {\r
+               Log.log("=========== System properties ===========");\r
+               Properties sysprops = System.getProperties();\r
+               for (Enumeration e = sysprops.propertyNames(); e.hasMoreElements();) {\r
+                       String key = (String) e.nextElement();\r
+                       String value = sysprops.getProperty(key);\r
+                       Log.log(key + " = " + value);\r
+               }\r
+               \r
+               Log.log("=========== Environment variables ===========");\r
+\r
+               Map<String, String> env = System.getenv();\r
+               Set<String> set = env.keySet();\r
+               Iterator<String> iter = set.iterator();\r
+\r
+               while (iter.hasNext()) {\r
+                       String key = (String) iter.next();\r
+                       Set<Entry<String, String>> value = env.entrySet();\r
+                       Log.log(key + " = " + value);\r
+               }\r
+               Log.log("=============================================");\r
+       }\r
+\r
+       /**\r
+        * Launch the application.\r
+        * \r
+        * @param args\r
+        */\r
+       public static void main(String args[]) {\r
+               //performance measurement\r
+               Performance.setIMStartTime();\r
+               \r
+               InstallManager.deleteTempFile();\r
+               \r
+               Log.open();\r
+               Log.LogTitle("Installmanager start");\r
+               Log.log(Platform.getPlatformInfo());\r
+               Log.log(PathUtil.getCurrentDir());\r
+               \r
+               if (Options.propertyLogging) {\r
+                       loggingProperty();\r
+               }\r
+               \r
+               try {\r
+                       Options.loadCmdArgs(args);\r
+               } catch (IMFatalException e) {\r
+                       Log.err("Check your options. => " + Arrays.toString(args));\r
+                       System.out.println("Check your options. => " + Arrays.toString(args));\r
+                       return;\r
+               }\r
+               \r
+               try {                   \r
+                       if (Options.onlyDownload) {\r
+                               onlyDownloadPackages();\r
+                               System.exit(0);\r
+                       } else if (Options.doInstallNoUI) {\r
+                               if (InstallManagerNoUI.cliInstall(Options.packages)) {\r
+                                       Log.log("Success to command line install.");\r
+                                       System.out.println("Success to console install.");\r
+                               } else {\r
+                                       Log.log("Fail to command line install.");\r
+                                       System.out.println("Fail to console install.");\r
+                               }\r
+                               \r
+                               Performance.setIMEndTime();\r
+                               if (Options.doTest) {\r
+                                       Performance.printTestResultXmlFormat();\r
+                                       Performance.printTestResultXmlFormat2();\r
+                               }\r
+                               \r
+                               System.exit(0);\r
+                       } else if (Options.doRemoveNoUI) {\r
+                               if (InstallManagerNoUI.cliUninstall(Options.packages)) {\r
+                                       Log.log("Success to command line remove.");\r
+                                       System.out.println("Success to remove.");\r
+                               } else {\r
+                                       Log.log("Fail to command line remove.");\r
+                                       System.out.println("Fail to remove.");\r
+                               }\r
+                               \r
+                               Performance.setIMEndTime();\r
+                               if (Options.doTest) {\r
+                                       Performance.printTestResultXmlFormat();\r
+                                       Performance.printTestResultXmlFormat2();\r
+                               }\r
+                               \r
+                               System.exit(0);\r
+                       } else if (Options.showVersion) {\r
+                               showInstallManagerVersion();\r
+                               System.exit(0);\r
+                       } else if (Options.doShowHelp) {\r
+                               InstallManagerNoUI.cliShowHelp();\r
+                               System.exit(0);\r
+                       }\r
+                       \r
+                       if (Platform.isMacOS()) {\r
+                               System.setProperty("apple.laf.useScreenMenuBar", "true");\r
+                               System.setProperty(\r
+                                               "com.apple.mrj.application.apple.menu.about.name",\r
+                                               "Emulator Manager");\r
+                               Display display = Display.getDefault();\r
+                               display.syncExec(new Runnable() {\r
+                                       @Override\r
+                                       public void run() {\r
+                                               new CocoaUtil().removeTopMenuItems();\r
+                                       }\r
+                               });\r
+                       }\r
+                       \r
+                       window = new InstallManagerWindow();\r
+                       window.setBlockOnOpen(true);\r
+                       \r
+                       window.init();\r
+                       \r
+                       Log.log("after init");\r
+                       if (Options.checkPackageUpdate) {\r
+                               checkMetaPackageUpdate();\r
+                       } else if (Options.printDepGraph) {\r
+                               InstallManager.getInstance().getPackageManager().printDepGraph();\r
+                       } else if (Options.doShowDistListNoUI) {\r
+                               InstallManagerNoUI.cliShowRepoInformation();\r
+                       } else if (Options.doShowPackageListNoUI) {\r
+                               InstallManagerNoUI.cliShowPackageList();\r
+                       } else if (Options.doShowSDKInstallStatus) {\r
+                               InstallManagerNoUI.cliShowInstallInformation();\r
+                       } else {\r
+                               window.open();\r
+                               if (Display.getCurrent() != null\r
+                                               && !Display.getCurrent().isDisposed()) {\r
+                                       Display.getCurrent().dispose();\r
+                               }\r
+                       }\r
+               } catch (IMExitException e) {\r
+                       // do not remove sdk temp dir if exit for self update\r
+                       if (ErrorController.getExitCode() == Config.EXITCODE_HAS_SELF_UPDATE) {\r
+                               Options.doRemoveTempTizenSDK = false;\r
+                       }\r
+                       \r
+                       Log.log("Gracefully exit");\r
+               } catch (Throwable e) {\r
+                       Log.err("Unexpected error occurred");\r
+                       Log.ExceptionLog(e);\r
+                       \r
+                       if (Options.doInstallNoUI || Options.doRemoveNoUI) {\r
+                               PathUtil.remove(Registry.REGISTRY_FILE_PATH);\r
+                               PathUtil.remove(Registry.MULTI_SDK_FILE_PATH);\r
+                               e.printStackTrace();\r
+                               System.out.println("Fatal error occurred.");\r
+                               System.exit(0);\r
+                       }\r
+                       \r
+                       // show error message\r
+                       if (window != null) {\r
+                               window.open();\r
+                               \r
+                               if (Display.getCurrent() != null\r
+                                               && !Display.getCurrent().isDisposed()) {\r
+                                       Display.getCurrent().dispose();\r
+                               }\r
+                       }\r
+                       \r
+                       ErrorController.setExitCode(Config.EXITCODE_UNKNOWN_ERROR);\r
+               } finally {\r
+                       if (Platform.isWindows()) {\r
+                               ProgramController.createProgramController().removeSDKTempDir();\r
+                       }\r
+                       \r
+                       //performance measurement\r
+                       Performance.setIMEndTime();\r
+                       Performance.printToLogFile();\r
+                       \r
+                       if (Options.doTest) {\r
+                               Performance.printTestResultXmlFormat();\r
+                               Performance.printTestResultXmlFormat2();\r
+                       }\r
+                       \r
+                       Log.LogTitle("Installmanager finish");\r
+                       Log.close();\r
+                       \r
+                       if (Platform.isMacOS()) {\r
+                               System.exit(ErrorController.getExitCode());\r
+                       } else {\r
+                               if (ErrorController.getExitCode() == Config.EXITCODE_HAS_SELF_UPDATE) {\r
+                                       String binary = PathUtil.get(Registry.getInstalledPath(), Config.INSTALL_MANAGER_DIRECTORY, Config.EXECUTE_FILE_NAME_OF_INSTALL_MANAGER);\r
+                                       try {\r
+                                               Runtime.getRuntime().exec(binary);\r
+                                       } catch (IOException e) {\r
+                                               Log.ExceptionLog(e);\r
+                                       }\r
+                               } else if (ErrorController.getExitCode() != Config.EXITCODE_NORMAL) {\r
+                                       System.exit(ErrorController.getExitCode());\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       @Override\r
+       protected void configureShell(Shell newShell) {\r
+               newShell.setBackground(getBackgroundColor());\r
+               newShell.setMinimumSize(getInitialSize());\r
+               newShell.setSize(getInitialSize());\r
+               newShell.setImage(getWindowIconImage());\r
+               super.configureShell(newShell);\r
+\r
+               newShell.setText("Tizen SDK Install Manager");\r
+       }\r
+\r
+       @Override\r
+       /**\r
+        * Install manager window is close.\r
+        */\r
+       public boolean close() {\r
+               return false;\r
+       }\r
+\r
+       /**\r
+        * Return the initial size of the window.\r
+        */\r
+       @Override\r
+       protected Point getInitialSize() {\r
+               return POINT_MAIN_WINDOW;\r
+       }\r
+\r
+       /**\r
+        * Show the composite depending on parameter.\r
+        * @param composite\r
+        */\r
+       public void showComposite(Composite composite) {\r
+               StackLayout layout;\r
+               if (composite.getParent().getLayout() instanceof StackLayout) {\r
+                       layout = (StackLayout) composite.getParent().getLayout();\r
+                       layout.topControl = composite;\r
+               }\r
+               composite.getParent().layout();\r
+       }\r
+\r
+       private void registLicensePageListener() {\r
+               compositeLicensePage.getAcceptButton()\r
+                                                       .addSelectionListener(new SelectionAdapter() {\r
+\r
+                                                               @Override\r
+                                                               public void widgetSelected(SelectionEvent e) {\r
+                                                                       btnNext.setEnabled(compositeLicensePage.getAcceptButton()\r
+                                                                                                                                                       .getSelection());\r
+                                                               }\r
+                                                       });\r
+       }\r
+\r
+       private void registCompletePageListener() {\r
+               compositeCompletePage.addPaintListener(new PaintListener() {\r
+\r
+                       @Override\r
+                       public void paintControl(PaintEvent arg0) {\r
+                               btnClose.setText("Close");\r
+                       }\r
+               });\r
+       }\r
+       \r
+       public void setNameOfCancelButton(String name) {\r
+               btnClose.setText("Close");\r
+       }\r
+\r
+       /**\r
+        * Get selected package names on installing\r
+        * @param items\r
+        * @return list of selected package names.\r
+        */\r
+       public List<String> getSelectedPackageNames(List<Item> items) {\r
+               List<String> list = new ArrayList<String>();\r
+               for (int i = 0; i < items.size(); i++) {\r
+                       items.get(i).getTerminalPackages(list, true);\r
+               }\r
+\r
+               return list;\r
+       }\r
+       \r
+       /**\r
+        * Installed packages do not have package version, installmanager will show warning dialog.\r
+        * @return\r
+        */\r
+       private boolean checkVaildPkgVersion() {\r
+               PackageSet installedPkgs = controller.getInstalledPackages();\r
+               if (!installedPkgs.isEmpty()) {\r
+                       for (Package pkg : installedPkgs) {\r
+                               String vs = pkg.getVersion().toString();\r
+                               if (vs != "" && vs.equals("0.0.0")) {\r
+                               Log.err("Package version not found. ==> " + pkg.getPackageName());\r
+                               int confirm = MessageBoxDlg.showDlg(getShell(), \r
+                                                   "WARNING", \r
+                                                   "'" + pkg.getPackageName() + "'" + " package version is not found.\n" +\r
+                                                   "If you keep installing Tizen SDK, some unexpected may occur.\n" +\r
+                                                   "Do you want to continue?", \r
+                                                   DialogType.WARNING, false);\r
+                               if (confirm == MessageBoxDlg.YES) {\r
+                                       return true;\r
+                               } else {\r
+                                       return false;\r
+                               }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               return true;\r
+       }\r
+       \r
+       /**\r
+        * Get install manager window object.\r
+        * @return install manager window object.\r
+        */\r
+       public static InstallManagerWindow getInstallManagerWindow() {\r
+               return window;\r
+       }\r
+\r
+       /**\r
+        * Get complete page composite object\r
+        * @return complete page composite object\r
+        */\r
+       public CompletePage getCompletePage() {\r
+               return compositeCompletePage;\r
+       }\r
+       \r
+       public InstallableListPage getInstallableListPage() {\r
+               return compositeInstallablePage;\r
+       }\r
+       \r
+       public WelcomePage getWelcomePage() {\r
+               return compositeWelcomePage;\r
+       }\r
+       \r
+       /**\r
+        * Get setInstallDirectoryPage composite object\r
+        * @return complete page composite object\r
+        */\r
+       public SetInstallDirectoryPage getSetInstallDirectoryPage() {\r
+               return compositeSetInstallDirectoryPage;\r
+       }\r
+\r
+       /**\r
+        * If parameter is true, 'Next' button will be enabled. but false, 'Next' button will be disabled.\r
+        * @param enabled\r
+        */\r
+       public static void setNextBtnEnabled(boolean enabled) {\r
+               btnNext.setEnabled(enabled);\r
+       }\r
+\r
+       /**\r
+        * If parameter is true, 'Back' button will be enabled. but false, 'Back' button will be disabled.\r
+        * @param enabled\r
+        */\r
+       public static void setBackBtnEnabled(boolean enabled) {\r
+               btnBack.setEnabled(enabled);\r
+       }\r
+\r
+       /**\r
+        * If parameter is true, 'Cancel' button will be enabled. but false, 'Cancel' button will be disabled.\r
+        * @param enabled\r
+        */\r
+       public void setCancelBtnEnabled(boolean enabled) {\r
+               btnClose.setEnabled(enabled);\r
+       }\r
+       \r
+       public ViewController getViewController() {\r
+               return controller;\r
+       }\r
+}\r
index ad6792d..ac0ff53 100644 (file)
-/*
-*  InstallManager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: 
-* Wooyoung Cho <wooyoung1.cho@samsung.com>
-* Shihyun Kim <shihyun.kim@samsung.com>
-* Taeyoung Son <taeyoung2.son@samsung.com>
-* Yongsung kim <yongsung1.kim@samsung.com>
-* 
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
-
-package org.tizen.installmanager.ui.page;
-
-import java.text.DecimalFormat;
-import java.util.List;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.ProgressBar;
-import org.tizen.installmanager.core.Config;
-import org.tizen.installmanager.core.IMExitException;
-import org.tizen.installmanager.core.IMFatalException;
-import org.tizen.installmanager.core.IMInstallCancelException;
-import org.tizen.installmanager.lib.ErrorController;
-import org.tizen.installmanager.lib.ErrorController.InfoCode;
-import org.tizen.installmanager.lib.IIMProgressMonitor;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.lib.Platform;
-import org.tizen.installmanager.lib.ProgramController;
-import org.tizen.installmanager.lib.Registry;
-import org.tizen.installmanager.lib.ErrorController.ErrorCode;
-import org.tizen.installmanager.ui.InstallManagerWindow;
-import org.tizen.installmanager.ui.dialog.MessageBoxDlg;
-import org.tizen.installmanager.ui.dialog.MessageBoxDlg.DialogType;
-
-/**
- * @author Taeyoung Son <taeyoung2.son@samsung.com>
- * 
- */
-public class InstallingPage extends PageTemplate {
-       static final String RSC_PATH_IMAGE = RESOURCE_PATH
-                       + "/install_manager_graphicmotif_003.png";
-       static final String STRING_TITLE = "Installation Progress";
-       static final String STRING_SUBTITLE = "Wait while the Tizen SDK installation is being processed.";
-
-       static final double KB_SIZE = 1;
-       static final double MB_SIZE = KB_SIZE * 1024;
-       static final double GB_SIZE = MB_SIZE * 1024;
-
-       static final int SEC = 1;
-       static final int MIN = SEC * 60;
-       static final int HOUR = MIN * 60;
-       static final int DAY = HOUR * 24;
-
-       private static String totalSize;
-       private static String currentSize;
-
-       private List<String> selectedList;
-       private ProgressBar progressBar;
-       private Label statusLabel;
-       private Label mSubTitleOfProgress;
-       private Label installedNumberLabel;
-       private Label mDownloadVelocity;
-
-       private ViewController viewController;
-       private String installPath;
-       private InstallProgressMonitor monitor;
-       private InstallManagerWindow mainWindow;
-       Display display;
-
-       /**
-        * Set basic environment of installing page.
-        * @param parent
-        * @param style
-        */
-       public InstallingPage(Composite parent, int style) {
-               super(parent, style);
-
-               setLeftImageFromResource(RSC_PATH_IMAGE);
-               setTitle(STRING_TITLE);
-               setSubTitle(STRING_SUBTITLE);
-
-               progressBar = new ProgressBar(customComposite, SWT.NONE);
-               progressBar.setBounds(30, 110, 406, 20);
-
-               statusLabel = new Label(customComposite, SWT.NONE);
-               statusLabel.setBounds(30, 65, 340, 23);
-               statusLabel.setBackground(InstallManagerWindow.getBackgroundColor());
-
-               mSubTitleOfProgress = new Label(customComposite, SWT.NONE);
-               mSubTitleOfProgress.setBounds(30, 138, 260, 23);
-               mSubTitleOfProgress.setForeground(new Color(null, 96, 96, 96));
-               mSubTitleOfProgress
-                               .setBackground(InstallManagerWindow.getBackgroundColor());
-               mSubTitleOfProgress.setText("");
-
-               installedNumberLabel = new Label(customComposite, SWT.NONE);
-               installedNumberLabel.setAlignment(SWT.RIGHT);
-               installedNumberLabel.setBounds(275, 90, 160, 23);
-               installedNumberLabel.setForeground(new Color(null, 0, 108, 209));
-               installedNumberLabel
-                               .setBackground(InstallManagerWindow.getBackgroundColor());
-               installedNumberLabel.setText("");
-
-               mDownloadVelocity = new Label(customComposite, SWT.NONE);
-               mDownloadVelocity.setAlignment(SWT.RIGHT);
-               mDownloadVelocity.setBounds(295, 138, 140, 23);
-               mDownloadVelocity.setBackground(InstallManagerWindow.getBackgroundColor());
-               mDownloadVelocity.setForeground(new Color(null, 0, 108, 209));
-               mDownloadVelocity.setText("");
-       }
-
-       /**
-        * First of all this function check package whether update or not and check install path(target directory)
-        * is empty. 
-        * @param selectedList
-        * @param viewController
-        * @param installPath
-        * @param mainWindow
-        * @param isUpdate
-        * @return true is success to install<br>false is fail to install
-        */
-       public boolean loadPage(List<String> selectedList,
-                       ViewController viewController, String installPath,
-                       InstallManagerWindow mainWindow, boolean isUpdate) {
-               this.selectedList = selectedList;
-               this.viewController = viewController;
-               this.installPath = installPath;
-               this.mainWindow = mainWindow;
-               monitor = new InstallProgressMonitor();
-               display = customComposite.getDisplay();
-
-               if (isUpdate == true) {
-                       ProgramController controller = ProgramController
-                                       .createProgramController();
-                       
-                       if (controller.runningProgramExists()) {
-                               int confirm = MessageBoxDlg
-                                               .showDlg(
-                                                               getShell(),
-                                                               "Warning",
-                                                               "The SDK is already running. If you update it, the current version will stop. Are you sure you want to update the SDK?",
-                                                               DialogType.WARNING, false);
-                               if (confirm == MessageBoxDlg.YES) {
-                                       controller.terminateRunningProgram();
-                               } else if (confirm == MessageBoxDlg.NO) {
-                                       return false;
-                               }
-                       }
-               } 
-               
-               new InstallThread(monitor).start();
-
-               return true;
-       }
-
-       /**
-        * This class controls process to install.
-        * @author Shihyun Kim <shihyun.kim@samsung.com>
-        */
-       class InstallThread extends Thread {
-
-               private InstallProgressMonitor monitor;
-
-               public InstallThread(InstallProgressMonitor monitor) {
-                       this.monitor = monitor;
-               }
-
-               /**
-                * Installing thread run
-                */
-               @Override
-               public void run() {
-                       boolean bResult = false;
-                       try {
-                               bResult = installProcess(monitor);
-                               ErrorController.setInstallationSuccess(bResult);
-                       } catch (IMFatalException e) {
-                               Log.err("internal error occurred");
-                               Log.ExceptionLog(e);
-                               ErrorController.setInstallationSuccess(false);
-                       } catch (Exception e) {
-                               Log.err("Unexpected exception occurred");
-                               Log.ExceptionLog(e);
-                               ErrorController.setInstallationSuccess(false);
-                       } finally {
-                               monitor.done();
-                       }
-                       Log.log("finish install thread");
-               }
-       }
-
-       /**
-        * After set selected package list and install path, start to install.
-        * @param monitor
-        * @throws IMExitException 
-        */
-       public boolean installProcess(InstallProgressMonitor monitor) throws IMExitException {
-               boolean bResult = false;
-
-               try {
-                       bResult = viewController.install(selectedList, installPath, monitor);
-//                     ErrorController.setError(ErrorCode.INSTALLATION_FAIL);
-               } catch (IMInstallCancelException e) {
-                       bResult = false;
-                       ErrorController.setError(ErrorCode.INSTALL_CANCELED);
-                       Log.log("Installation canceled");
-                       
-                       return false;
-               }
-               
-               return bResult;
-       }
-
-       /**
-        * Get install progress monitor object
-        * @return install progress monitor object
-        */
-       public InstallProgressMonitor getInstallProgressMonitor() {
-               return monitor;
-       }
-
-       /**
-        * @author Shihyun Kim <shihyun.kim@samsung.com>
-        */
-       public class InstallProgressMonitor implements IIMProgressMonitor {
-
-               private long totalWork;
-               private double mProgressSize = 0;
-               private String mProgressTitle;
-               private String mSubTitle;
-               private String status;
-               private long downloadStartTime = 0;
-               private boolean isCanceled = false;
-
-               private static final int MAX_LENGTH = 40;
-               private static final String STRING_ETC = "...";
-               private boolean cancelRequested;
-
-               /**
-                * Set start time to download.
-                */
-               public void setDownloadStartTime(long startTime) {
-                       this.downloadStartTime = startTime;
-               }
-
-               @Override
-               public void beginTask(String name, int totalWork) {
-                       if (display == null || display.isDisposed()) {
-                               setCanceled(true);
-                               return;
-                       }
-                       this.totalWork = totalWork;
-                       this.status = name;
-                       display.asyncExec(new Runnable() {
-                               @Override
-                               public void run() {
-                                       statusLabel.setText(status);
-                                       downloadStartTime = System.currentTimeMillis();
-                               }
-                       });
-               }
-
-               private boolean retContinue = false;
-
-               /**
-                * Check cancel button
-                * @return
-                * true : user press a cancel button
-                * false : user do nothing
-                */
-               public boolean checkCancelAndDisableCancelButton() {
-                       retContinue = false;
-                       if (display == null || display.isDisposed()) {
-                               setCanceled(true);
-                               return false;
-                       }
-                       display.syncExec(new Runnable() {
-                               @Override
-                               public void run() {
-                                       if (!cancelRequested) {
-                                               mainWindow.setCancelBtnEnabled(false);
-                                               mDownloadVelocity.setVisible(false);
-                                               mSubTitleOfProgress.setBounds(30, 138, 360, 23);
-                                               retContinue = true;
-                                       }
-                               }
-                       });
-                       return retContinue;
-               }
-
-               /**
-                * Control to finish install process
-                */
-               @Override
-               public void done() {
-                       if (display == null || display.isDisposed()) {
-                               setCanceled(true);
-                               return;
-                       }
-                       
-                       if (Config.status == Config.Status.INSTALL) {
-                               Registry.saveSDKInfo(installPath);
-                       }
-
-                       display.asyncExec(new Runnable() {
-                               @Override
-                               public void run() {
-                                       progressBar.setSelection(100);
-                                       
-                                       CompletePage completePage = mainWindow.getCompletePage();
-                                       
-                                       if (ErrorController.checkInstallationSuccess()) {
-                                               completePage.setTitle("Installation Completed");
-
-                                               String customMessage = "";
-                                               
-                                               if (Platform.isUbuntu()) {
-                                                       if (viewController.isUnityEnvironment()) {
-                                                               customMessage = "Thank you for installing the Tizen SDK. \n\n" + 
-                                                                           "To use the SDK, search and select 'Tizen IDE' on your unity dash. ";
-                                                       } else {
-                                                               customMessage = "Thank you for installing the Tizen SDK. \n\n" + 
-                                                                   "To use the SDK, go to Application > Tizen SDK > Tizen IDE. ";
-                                                       }
-                                               } else if (Platform.isWindows()) {
-                                                       customMessage = "Thank you for installing the Tizen SDK. " +
-                                                                        "To use the SDK, go to Start > All Programs > Tizen SDK > Tizen IDE. \n\n";
-                                               } else {
-                                                       customMessage = "Thank you for installing the Tizen SDK. ";
-                                               }
-                                               
-                                               completePage.setCustomMessage(customMessage);
-                                               completePage.setErrorTextMsg();
-                                               
-//                                             if (ErrorController.existInfoMessage()) {
-                                                       completePage.setInfoMessage(InfoCode.RESTART_THE_COMPUTER.getInfoMessage()/*ErrorController.getInfoMessage()*/);
-//                                             }
-                                               
-                                               Log.log("installation complete");
-                                       } else {
-                                               Log.log("(un)installation failed");
-                                               completePage.setTitle("(Un)Installation failed");
-                                               completePage.setCustomErrorMessage(ErrorController.getErrorMessage() + "\n");
-                                               mainWindow.getCompletePage().showCheckButton(false);
-                                       }
-
-                                       mainWindow.setNameOfCancelButton("Close");
-                                       mainWindow.setCancelBtnEnabled(true);
-                                       mainWindow.showComposite(completePage);
-                               }
-                       });
-               }
-
-               @Override
-               public void internalWorked(double work) {
-                       // Do nothing.
-               }
-
-               @Override
-               public boolean isCanceled() {
-                       return isCanceled;
-               }
-
-               @Override
-               public void setCanceled(boolean value) {
-                       isCanceled = value;
-               }
-
-               @Override
-               public void setTaskName(String name) {
-                       // Do nothing.
-               }
-
-               @Override
-               public void subTask(String name) {
-                       // Do nothing.
-               }
-
-               /**
-                * set working package name to show during installing
-                */
-               @Override
-               public void worked(final int work) {
-                       if (display == null || display.isDisposed()) {
-                               setCanceled(true);
-                               return;
-                       }
-                       display.syncExec(new Runnable() {
-                               @Override
-                               public void run() {
-                                       installedNumberLabel.setText(work + "/" + (totalWork));
-                                       progressBar.setSelection(100 * work / (int) totalWork);
-                               }
-                       });
-               }
-               
-               /**
-                * set working file name to show during installing 
-                */
-               @Override
-               public void workedTitle(String title) {
-                       mProgressTitle = title;
-                       
-                       if (display == null || display.isDisposed()) {
-                               setCanceled(true);
-                               return;
-                       }
-                       
-                       display.syncExec(new Runnable() {
-                               @Override
-                               public void run() {
-                                       statusLabel.setText(mProgressTitle);
-                               }
-                       });
-               }
-
-               /**
-                * set working file name to show during installing 
-                */
-               @Override
-               public void workedSubTitle(String subTitle) {
-                       if (subTitle.length() > MAX_LENGTH) {
-                               mSubTitle = subTitle.substring(0, MAX_LENGTH - 2);
-                               mSubTitle = mSubTitle + STRING_ETC;
-                       } else {
-                               mSubTitle = subTitle;
-                       }
-                       
-                       if (display == null || display.isDisposed()) {
-                               setCanceled(true);
-                               return;
-                       }
-                       
-                       display.syncExec(new Runnable() {
-                               @Override
-                               public void run() {
-                                       mSubTitleOfProgress.setText(mSubTitle);
-                               }
-                       });
-               }
-               
-               @Override
-               public void workedProcess(String title) {
-                       if (title == null || title.isEmpty()) {
-                               return;
-                       }
-                       
-                       String processTitle = "Processing : package \"" + title + "\"";
-                       workedTitle(processTitle);
-               }
-               
-               @Override
-               public void workedDownload(String title) {
-                       if (title == null || title.isEmpty()) {
-                               return;
-                       }
-                       
-                       workedTitle("Downloading : " + title);
-               }
-               
-               @Override
-               public void workedChecksum(String title) {
-                       if (title == null || title.isEmpty()) {
-                               return;
-                       }
-                       
-                       workedTitle("File checking : " + title);
-               }
-
-               /**
-                * check validation of download
-                */
-               public void workedChecksum(final long size) {
-                       if (display == null || display.isDisposed()) {
-                               setCanceled(true);
-                               return;
-                       }
-                       display.asyncExec(new Runnable() {
-                               private String pattern = ".##";
-                               private DecimalFormat dformat = new DecimalFormat(pattern);
-
-                               public void run() {
-                                       /* set total size */
-                                       mProgressSize += size / (double) 1024;
-                                       if (totalWork >= GB_SIZE) {
-                                               totalSize = dformat.format((totalWork / GB_SIZE)) + "GB";
-                                       } else if (totalWork >= MB_SIZE) {
-                                               totalSize = dformat.format((totalWork / MB_SIZE)) + "MB";
-                                       } else {
-                                               totalSize = totalWork + "KB";
-                                       }
-
-                                       /* set current download size */
-                                       if (mProgressSize >= GB_SIZE) {
-                                               currentSize = dformat.format((mProgressSize / GB_SIZE)) + "GB";
-                                       } else if (mProgressSize >= MB_SIZE) {
-                                               currentSize = dformat.format((mProgressSize / MB_SIZE)) + "MB";
-                                       } else {
-                                               currentSize = dformat.format(mProgressSize) + "KB";
-                                       }
-                                       
-                                       installedNumberLabel.setText(currentSize + "/" + totalSize);
-                                       mSubTitleOfProgress.setText("");
-                                       mDownloadVelocity.setText("");
-                                       progressBar.setSelection((int) (100 * mProgressSize / totalWork));
-
-                               }
-                       });
-               }
-
-               /**
-                * Control download and show download information.
-                */
-               @Override
-               public void workedDownload(final long size) {
-                       if (display == null || display.isDisposed()) {
-                               setCanceled(true);
-                               return;
-                       }
-                       display.asyncExec(new Runnable() {
-                               private String pattern = ".00";
-                               private DecimalFormat dformat = new DecimalFormat(pattern);
-                               private String remainTimeStr = "";
-                               private String downloadVelocityStr = "";
-
-                               @Override
-                               public void run() {
-                                       /* set total size */
-                                       mProgressSize += size / (double) 1024;
-                                       if (totalWork >= GB_SIZE) {
-                                               totalSize = dformat.format((totalWork / GB_SIZE)) + "GB";
-                                       } else if (totalWork >= MB_SIZE) {
-                                               totalSize = dformat.format((totalWork / MB_SIZE)) + "MB";
-                                       } else {
-                                               totalSize = totalWork + "KB";
-                                       }
-
-                                       /* set current download size */
-                                       if (mProgressSize >= GB_SIZE) {
-                                               currentSize = dformat.format((mProgressSize / GB_SIZE)) + "GB";
-                                       } else if (mProgressSize >= MB_SIZE) {
-                                               currentSize = dformat.format((mProgressSize / MB_SIZE)) + "MB";
-                                       } else {
-                                               currentSize = dformat.format(mProgressSize) + "KB";
-                                       }
-
-                                       long pastTimes = System.currentTimeMillis()
-                                                       - downloadStartTime;
-
-                                       /* set download velocity */
-
-                                       double downloadVelocity = 0;
-
-                                       if (pastTimes > 5000) {
-                                               downloadVelocity = mProgressSize / (double) (pastTimes / (double) 1000);
-                                               
-                                               if (downloadVelocity >= GB_SIZE)  {
-                                                       downloadVelocityStr = dformat.format(downloadVelocity / GB_SIZE) + "GB/s";
-                                               } else if (downloadVelocity >= MB_SIZE) {
-                                                       downloadVelocityStr = dformat.format(downloadVelocity / MB_SIZE) + "MB/s";
-                                               } else {
-                                                       downloadVelocityStr = dformat.format(downloadVelocity / KB_SIZE) + "KB/s";
-                                               }
-                                       }
-                                       /* set remain time */
-                                       double remainTime = 0;
-                                       if (downloadVelocity == 0) {
-                                               remainTimeStr = "estimating...";
-                                       } else {
-                                               double remainSize = totalWork - mProgressSize;
-                                               remainTime = remainSize / downloadVelocity;
-                                               
-                                               int day = (int) (remainTime / DAY);
-                                               int hour = (int) ((remainTime % DAY) / HOUR);
-                                               int min = (int) ((remainTime % HOUR) / MIN);
-                                               int sec = (int) (remainTime % MIN);
-
-                                               if (day > 0) {
-                                                       remainTimeStr = day + "day ";
-                                               }
-                                               
-                                               if (hour > 0) {
-                                                       remainTimeStr += hour + "hour ";
-                                               }
-                                               
-                                               if (min > 0) {
-                                                       remainTimeStr += min + "min ";
-                                               }
-                                               
-                                               if (sec > 0) {
-                                                       remainTimeStr += sec + "sec";
-                                               }
-                                       }
-
-                                       installedNumberLabel.setText(currentSize + "/" + totalSize);
-                                       mSubTitleOfProgress.setText("Remaining time : " + remainTimeStr);
-                                       mDownloadVelocity.setText(downloadVelocityStr);
-                                       progressBar.setSelection((int) (100 * mProgressSize / totalWork));
-                               }
-                       });
-               }
-
-
-               /**
-                * Show percentage for progress bar
-                */
-               @Override
-               public void workedProgressbar(final int percent) {
-                       if (display == null || display.isDisposed()) {
-                               setCanceled(true);
-                               return;
-                       }
-                       display.asyncExec(new Runnable() {
-                               @Override
-                               public void run() {
-                                       progressBar.setSelection(percent);
-                               }
-                       });
-               }
-
-               public void setCancelRequested(boolean b) {
-                       cancelRequested = b;
-               }
-
-               @Override
-               public void workedRefresh() {
-                       mProgressSize = 0;
-               }
-               
-               @Override
-               public void setError(int errorCode) {
-                       // TODO Auto-generated method stub
-                       
-               }
-       }
-}
+/*\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.ui.page;\r
+\r
+import java.text.DecimalFormat;\r
+import java.util.List;\r
+\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.graphics.Color;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.ProgressBar;\r
+import org.tizen.installmanager.core.Config;\r
+import org.tizen.installmanager.core.IMExitException;\r
+import org.tizen.installmanager.core.IMFatalException;\r
+import org.tizen.installmanager.core.IMInstallCancelException;\r
+import org.tizen.installmanager.lib.ErrorController;\r
+import org.tizen.installmanager.lib.ErrorController.InfoCode;\r
+import org.tizen.installmanager.lib.IIMProgressMonitor;\r
+import org.tizen.installmanager.lib.Log;\r
+import org.tizen.installmanager.lib.Platform;\r
+import org.tizen.installmanager.lib.ProgramController;\r
+import org.tizen.installmanager.lib.Registry;\r
+import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
+import org.tizen.installmanager.ui.InstallManagerWindow;\r
+import org.tizen.installmanager.ui.dialog.MessageBoxDlg;\r
+import org.tizen.installmanager.ui.dialog.MessageBoxDlg.DialogType;\r
+\r
+/**\r
+ * @author Taeyoung Son <taeyoung2.son@samsung.com>\r
+ * \r
+ */\r
+public class InstallingPage extends PageTemplate {\r
+       static final String RSC_PATH_IMAGE = RESOURCE_PATH\r
+                       + "/install_manager_graphicmotif_003.png";\r
+       static final String STRING_TITLE = "Installation Progress";\r
+       static final String STRING_SUBTITLE = "Wait while the Tizen SDK installation is being processed.";\r
+\r
+       static final double KB_SIZE = 1;\r
+       static final double MB_SIZE = KB_SIZE * 1024;\r
+       static final double GB_SIZE = MB_SIZE * 1024;\r
+\r
+       static final int SEC = 1;\r
+       static final int MIN = SEC * 60;\r
+       static final int HOUR = MIN * 60;\r
+       static final int DAY = HOUR * 24;\r
+\r
+       private List<String> selectedList;\r
+       private ProgressBar downloadProgressBar;\r
+       private Label downloadProgressTitleLabel;\r
+       private Label downloadFileNameLabel;\r
+       private Label downloadProgressLabel;\r
+       private Label downloadSpeedLabel;\r
+\r
+       private ProgressBar installProgressBar;\r
+       private Label installProgressTitleLabel;\r
+       private Label installFileNameLabel;\r
+       private Label installProgressLabel;\r
+       private Label installRemainingTimeLabel;\r
+\r
+       private ViewController viewController;\r
+       private String installPath;\r
+       private InstallProgressMonitor monitor;\r
+       private InstallManagerWindow mainWindow;\r
+       Display display;\r
+\r
+       /**\r
+        * Set basic environment of installing page.\r
+        * \r
+        * @param parent\r
+        * @param style\r
+        */\r
+       public InstallingPage(Composite parent, int style) {\r
+               super(parent, style);\r
+\r
+               setLeftImageFromResource(RSC_PATH_IMAGE);\r
+               setTitle(STRING_TITLE);\r
+               setSubTitle(STRING_SUBTITLE);\r
+\r
+               // download progress bar\r
+               downloadProgressBar = new ProgressBar(customComposite, SWT.NONE);\r
+               downloadProgressBar.setBounds(30, 93, 406, 20);\r
+\r
+               downloadProgressTitleLabel = new Label(customComposite, SWT.NONE);\r
+               downloadProgressTitleLabel.setBounds(30, 65, 240, 23);\r
+               downloadProgressTitleLabel.setBackground(InstallManagerWindow\r
+                               .getBackgroundColor());\r
+\r
+               downloadProgressLabel = new Label(customComposite, SWT.NONE);\r
+               downloadProgressLabel.setAlignment(SWT.RIGHT);\r
+               downloadProgressLabel.setBounds(315, 65, 80, 23);\r
+               downloadProgressLabel.setForeground(new Color(null, 0, 108, 209));\r
+               downloadProgressLabel.setText("");\r
+\r
+               downloadFileNameLabel = new Label(customComposite, SWT.NONE);\r
+               downloadFileNameLabel.setBounds(30, 121, 260, 23);\r
+               downloadFileNameLabel.setForeground(new Color(null, 96, 96, 96));\r
+               downloadFileNameLabel.setBackground(InstallManagerWindow\r
+                               .getBackgroundColor());\r
+               downloadFileNameLabel.setText("download file name");\r
+\r
+               downloadSpeedLabel = new Label(customComposite, SWT.NONE);\r
+               downloadSpeedLabel.setAlignment(SWT.RIGHT);\r
+               downloadSpeedLabel.setBounds(295, 121, 120, 23);\r
+               downloadSpeedLabel.setBackground(InstallManagerWindow\r
+                               .getBackgroundColor());\r
+               downloadSpeedLabel.setForeground(new Color(null, 0, 108, 209));\r
+               downloadSpeedLabel.setText("Download speed");\r
+\r
+               // install progress bar\r
+               installProgressBar = new ProgressBar(customComposite, SWT.NONE);\r
+               installProgressBar.setBounds(30, 190, 406, 20);\r
+\r
+               installProgressTitleLabel = new Label(customComposite, SWT.NONE);\r
+               installProgressTitleLabel.setBounds(30, 162, 240, 23);\r
+               installProgressTitleLabel.setBackground(InstallManagerWindow\r
+                               .getBackgroundColor());\r
+\r
+               installProgressLabel = new Label(customComposite, SWT.NONE);\r
+               installProgressLabel.setAlignment(SWT.RIGHT);\r
+               installProgressLabel.setBounds(315, 162, 80, 23);\r
+               installProgressLabel.setForeground(new Color(null, 0, 108, 209));\r
+               installProgressLabel.setText("");\r
+\r
+               installFileNameLabel = new Label(customComposite, SWT.NONE);\r
+               installFileNameLabel.setBounds(30, 218, 260, 23);\r
+               installFileNameLabel.setForeground(new Color(null, 96, 96, 96));\r
+               installFileNameLabel.setBackground(InstallManagerWindow\r
+                               .getBackgroundColor());\r
+               installFileNameLabel.setText("install file name");\r
+\r
+               installRemainingTimeLabel = new Label(customComposite, SWT.NONE);\r
+               installRemainingTimeLabel.setAlignment(SWT.RIGHT);\r
+               installRemainingTimeLabel.setBounds(295, 218, 120, 23);\r
+               installRemainingTimeLabel.setBackground(InstallManagerWindow\r
+                               .getBackgroundColor());\r
+               installRemainingTimeLabel.setForeground(new Color(null, 0, 108, 209));\r
+               installRemainingTimeLabel.setText("Remaining time");\r
+       }\r
+\r
+       /**\r
+        * First of all this function check package whether update or not and check\r
+        * install path(target directory) is empty.\r
+        * \r
+        * @param selectedList\r
+        * @param viewController\r
+        * @param installPath\r
+        * @param mainWindow\r
+        * @param isUpdate\r
+        * @return true is success to install<br>\r
+        *         false is fail to install\r
+        */\r
+       public boolean loadPage(List<String> selectedList,\r
+                       ViewController viewController, String installPath,\r
+                       InstallManagerWindow mainWindow, boolean isUpdate) {\r
+               this.selectedList = selectedList;\r
+               this.viewController = viewController;\r
+               this.installPath = installPath;\r
+               this.mainWindow = mainWindow;\r
+               monitor = new InstallProgressMonitor();\r
+               display = customComposite.getDisplay();\r
+\r
+               if (isUpdate == true) {\r
+                       ProgramController controller = ProgramController\r
+                                       .createProgramController();\r
+\r
+                       if (controller.runningProgramExists()) {\r
+                               int confirm = MessageBoxDlg\r
+                                               .showDlg(\r
+                                                               getShell(),\r
+                                                               "Warning",\r
+                                                               "The SDK is already running. If you update it, the current version will stop. Are you sure you want to update the SDK?",\r
+                                                               DialogType.WARNING, false);\r
+                               if (confirm == MessageBoxDlg.YES) {\r
+                                       controller.terminateRunningProgram();\r
+                               } else if (confirm == MessageBoxDlg.NO) {\r
+                                       return false;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               new InstallThread(monitor).start();\r
+\r
+               return true;\r
+       }\r
+\r
+       /**\r
+        * This class controls process to install.\r
+        * \r
+        * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+        */\r
+       class InstallThread extends Thread {\r
+\r
+               private InstallProgressMonitor monitor;\r
+\r
+               public InstallThread(InstallProgressMonitor monitor) {\r
+                       this.monitor = monitor;\r
+               }\r
+\r
+               /**\r
+                * Installing thread run\r
+                */\r
+               @Override\r
+               public void run() {\r
+                       boolean bResult = false;\r
+                       try {\r
+                               bResult = installProcess(monitor);\r
+                               ErrorController.setInstallationSuccess(bResult);\r
+                       } catch (IMFatalException e) {\r
+                               Log.err("internal error occurred");\r
+                               Log.ExceptionLog(e);\r
+                               ErrorController.setInstallationSuccess(false);\r
+                       } catch (Exception e) {\r
+                               Log.err("Unexpected exception occurred");\r
+                               Log.ExceptionLog(e);\r
+                               ErrorController.setInstallationSuccess(false);\r
+                       } finally {\r
+                               monitor.done();\r
+                       }\r
+                       Log.log("finish install thread");\r
+               }\r
+       }\r
+\r
+       /**\r
+        * After set selected package list and install path, start to install.\r
+        * \r
+        * @param monitor\r
+        * @throws IMExitException\r
+        */\r
+       public boolean installProcess(InstallProgressMonitor monitor)\r
+                       throws IMExitException {\r
+               boolean bResult = false;\r
+\r
+               try {\r
+                       bResult = viewController\r
+                                       .install(selectedList, installPath, monitor);\r
+                       // ErrorController.setError(ErrorCode.INSTALLATION_FAIL);\r
+               } catch (IMInstallCancelException e) {\r
+                       bResult = false;\r
+                       ErrorController.setError(ErrorCode.INSTALL_CANCELED);\r
+                       Log.log("Installation canceled");\r
+\r
+                       return false;\r
+               }\r
+\r
+               return bResult;\r
+       }\r
+\r
+       /**\r
+        * Get install progress monitor object\r
+        * \r
+        * @return install progress monitor object\r
+        */\r
+       public InstallProgressMonitor getInstallProgressMonitor() {\r
+               return monitor;\r
+       }\r
+\r
+       /**\r
+        * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+        */\r
+       public class InstallProgressMonitor implements IIMProgressMonitor {\r
+\r
+               private long totalWork = 0;\r
+               private long downloadProgressWork = 0;\r
+               private long installProgressWork = 0;\r
+               private double downloadProgressSize = 0;\r
+               private double installProgressSize = 0;\r
+               private long downloadStartTime = 0;\r
+               private long installStartTime = 0;\r
+               private boolean isCanceled = false;\r
+\r
+               private static final int MAX_LENGTH = 40;\r
+               private static final String STRING_ETC = "...";\r
+               private boolean cancelRequested;\r
+\r
+               private double totalDownloadSize = 0;\r
+               private double totalInstallSize = 0;\r
+               \r
+               private static final String PATTERN = ".00";\r
+               private DecimalFormat dformat = new DecimalFormat(PATTERN);\r
+\r
+               @Override\r
+               public void beginTask(String title, int totalWork) {\r
+                       if (display == null || display.isDisposed()) {\r
+                               setCanceled(true);\r
+                               return;\r
+                       }\r
+               }\r
+\r
+               public void beginTask(int totalWork, long totalDownloadSize,\r
+                               long totalInstallSize) {\r
+                       if (display == null || display.isDisposed()) {\r
+                               setCanceled(true);\r
+                               return;\r
+                       }\r
+\r
+                       this.totalWork = totalWork;\r
+                       this.totalDownloadSize = totalDownloadSize / (double) 1024;\r
+                       this.totalInstallSize = totalInstallSize / (double) 1024;\r
+\r
+                       display.syncExec(new Runnable() {\r
+                               @Override\r
+                               public void run() {\r
+                                       // initialize the download\r
+                                       downloadProgressTitleLabel\r
+                                                       .setText("Downloading the sdk packages");\r
+                                       downloadFileNameLabel.setText("Preparing the download");\r
+\r
+                                       //initialize the installation\r
+                                       installProgressTitleLabel.setText("Installing the sdk packages");\r
+                                       installFileNameLabel.setText("Waiting for download");\r
+                               }\r
+                       });\r
+               }\r
+\r
+               private boolean retContinue = false;\r
+\r
+               /**\r
+                * Check cancel button\r
+                * \r
+                * @return true : user press a cancel button false : user do nothing\r
+                */\r
+               public boolean checkCancelAndDisableCancelButton() {\r
+                       retContinue = false;\r
+                       if (display == null || display.isDisposed()) {\r
+                               setCanceled(true);\r
+                               return false;\r
+                       }\r
+                       display.syncExec(new Runnable() {\r
+                               @Override\r
+                               public void run() {\r
+                                       if (!cancelRequested) {\r
+                                               System.out.println("cancel");\r
+                                               mainWindow.setCancelBtnEnabled(false);\r
+//                                             downloadSpeedLabel.setVisible(false);\r
+                                               retContinue = true;\r
+                                       }\r
+                               }\r
+                       });\r
+                       return retContinue;\r
+               }\r
+\r
+               /**\r
+                * Control to finish install process\r
+                */\r
+               @Override\r
+               public void done() {\r
+                       if (display == null || display.isDisposed()) {\r
+                               setCanceled(true);\r
+                               return;\r
+                       }\r
+\r
+                       if (Config.status == Config.Status.INSTALL) {\r
+                               Registry.saveSDKInfo(installPath);\r
+                       }\r
+\r
+                       display.asyncExec(new Runnable() {\r
+                               @Override\r
+                               public void run() {\r
+                                       downloadProgressBar.setSelection(100);\r
+                                       installProgressBar.setSelection(100);\r
+\r
+                                       CompletePage completePage = mainWindow.getCompletePage();\r
+\r
+                                       if (ErrorController.checkInstallationSuccess()) {\r
+                                               completePage.setTitle("Installation Completed");\r
+\r
+                                               String customMessage = "";\r
+\r
+                                               if (Platform.isUbuntu()) {\r
+                                                       if (viewController.isUnityEnvironment()) {\r
+                                                               customMessage = "Thank you for installing the Tizen SDK. \n\n"\r
+                                                                               + "To use the SDK, search and select 'Tizen IDE' on your unity dash. ";\r
+                                                       } else {\r
+                                                               customMessage = "Thank you for installing the Tizen SDK. \n\n"\r
+                                                                               + "To use the SDK, go to Application > Tizen SDK > Tizen IDE. ";\r
+                                                       }\r
+                                               } else if (Platform.isWindows()) {\r
+                                                       customMessage = "Thank you for installing the Tizen SDK. "\r
+                                                                       + "To use the SDK, go to Start > All Programs > Tizen SDK > Tizen IDE. \n\n";\r
+                                               } else {\r
+                                                       customMessage = "Thank you for installing the Tizen SDK. ";\r
+                                               }\r
+\r
+                                               completePage.setCustomMessage(customMessage);\r
+                                               completePage.setErrorTextMsg();\r
+\r
+                                               // if (ErrorController.existInfoMessage()) {\r
+                                               completePage\r
+                                                               .setInfoMessage(InfoCode.RESTART_THE_COMPUTER\r
+                                                                               .getInfoMessage()/*\r
+                                                                                                                * ErrorController.\r
+                                                                                                                * getInfoMessage()\r
+                                                                                                                */);\r
+                                               // }\r
+\r
+                                               Log.log("installation complete");\r
+                                       } else {\r
+                                               Log.log("(un)installation failed");\r
+                                               completePage.setTitle("(Un)Installation failed");\r
+                                               completePage.setCustomErrorMessage(ErrorController\r
+                                                               .getErrorMessage() + "\n");\r
+                                               mainWindow.getCompletePage().showCheckButton(false);\r
+                                       }\r
+\r
+                                       mainWindow.setNameOfCancelButton("Close");\r
+                                       mainWindow.setCancelBtnEnabled(true);\r
+                                       mainWindow.showComposite(completePage);\r
+                               }\r
+                       });\r
+               }\r
+\r
+               @Override\r
+               public void internalWorked(double work) {\r
+                       // Do nothing.\r
+               }\r
+\r
+               @Override\r
+               public boolean isCanceled() {\r
+                       return isCanceled;\r
+               }\r
+\r
+               @Override\r
+               public void setCanceled(boolean value) {\r
+                       isCanceled = value;\r
+               }\r
+\r
+               @Override\r
+               public void setTaskName(String name) {\r
+                       // Do nothing.\r
+               }\r
+\r
+               @Override\r
+               public void subTask(String name) {\r
+                       // Do nothing.\r
+               }\r
+\r
+               /**\r
+                * set working package name to show during installing\r
+                */\r
+               @Override\r
+               public void worked(final int work) {\r
+                       if (display == null || display.isDisposed()) {\r
+                               setCanceled(true);\r
+                               return;\r
+                       }\r
+\r
+                       downloadProgressWork += work;\r
+                       display.syncExec(new Runnable() {\r
+                               @Override\r
+                               public void run() {\r
+                                       installProgressLabel.setText(downloadProgressWork + "/"\r
+                                                       + (totalWork));\r
+                                       downloadProgressBar\r
+                                                       .setSelection(100 * ((int) downloadProgressWork / (int) totalWork));\r
+                               }\r
+                       });\r
+               }\r
+\r
+               public void workedDownloadProgress(final String fileName, int i) {\r
+                       if (downloadStartTime <= 0) {\r
+                               downloadStartTime = System.currentTimeMillis();\r
+                       }\r
+\r
+                       downloadProgressWork += i;\r
+\r
+                       display.asyncExec(new Runnable() {\r
+                               @Override\r
+                               public void run() {\r
+                                       downloadProgressLabel.setText(downloadProgressWork + "/"\r
+                                                       + (totalWork));\r
+                                       downloadFileNameLabel.setText(fileName);\r
+                               }\r
+                       });\r
+               }\r
+\r
+               /**\r
+                * Control download and show download information.\r
+                */\r
+               @Override\r
+               public void workedDownloadSize(final long size) {\r
+                       if (display == null || display.isDisposed()) {\r
+                               setCanceled(true);\r
+                               return;\r
+                       }\r
+\r
+                       display.asyncExec(new Runnable() {\r
+                               @Override\r
+                               public void run() {\r
+                                       /* set total size */\r
+                                       String totalSize = "";\r
+                                       if (totalDownloadSize >= GB_SIZE) {\r
+                                               totalSize = dformat\r
+                                                               .format((totalDownloadSize / GB_SIZE)) + "GB";\r
+                                       } else if (totalDownloadSize >= MB_SIZE) {\r
+                                               totalSize = dformat\r
+                                                               .format((totalDownloadSize / MB_SIZE)) + "MB";\r
+                                       } else {\r
+                                               totalSize = totalDownloadSize + "KB";\r
+                                       }\r
+\r
+                                       /* set current download size */\r
+                                       downloadProgressSize += size / (double) 1024;\r
+                                       String currentSize = "";\r
+                                       if (downloadProgressSize >= GB_SIZE) {\r
+                                               currentSize = dformat\r
+                                                               .format((downloadProgressSize / GB_SIZE))\r
+                                                               + "GB";\r
+                                       } else if (downloadProgressSize >= MB_SIZE) {\r
+                                               currentSize = dformat\r
+                                                               .format((downloadProgressSize / MB_SIZE))\r
+                                                               + "MB";\r
+                                       } else {\r
+                                               currentSize = dformat.format(downloadProgressSize)\r
+                                                               + "KB";\r
+                                       }\r
+\r
+                                       // set size to progress bar.\r
+//                                     downloadProgressBar.setToolTipText(currentSize + "/"\r
+//                                                     + totalSize);\r
+\r
+                                       long pastTimes = System.currentTimeMillis()\r
+                                                       - downloadStartTime;\r
+\r
+                                       double downloadVelocity = 0;\r
+\r
+                                       String downloadVelocityStr = "estimating...";\r
+                                       if (pastTimes > 5000) {\r
+                                               downloadVelocity = downloadProgressSize\r
+                                                               / (double) (pastTimes / (double) 1000);\r
+\r
+                                               if (downloadVelocity >= GB_SIZE) {\r
+                                                       downloadVelocityStr = dformat\r
+                                                                       .format(downloadVelocity / GB_SIZE)\r
+                                                                       + "GB/s";\r
+                                               } else if (downloadVelocity >= MB_SIZE) {\r
+                                                       downloadVelocityStr = dformat\r
+                                                                       .format(downloadVelocity / MB_SIZE)\r
+                                                                       + "MB/s";\r
+                                               } else {\r
+                                                       downloadVelocityStr = dformat\r
+                                                                       .format(downloadVelocity / KB_SIZE)\r
+                                                                       + "KB/s";\r
+                                               }\r
+                                       }\r
+\r
+                                       System.out.println(downloadVelocityStr);\r
+                                       downloadSpeedLabel.setText("speed : "\r
+                                                       + downloadVelocityStr);\r
+                                       downloadProgressBar\r
+                                                       .setSelection((int) (100 * downloadProgressSize / totalDownloadSize));\r
+                               }\r
+                       });\r
+               }\r
+\r
+               @Override\r
+               public void workedInstallProgress(final String fileName, int i) {\r
+                       if (installStartTime <= 0) {\r
+                               installStartTime = System.currentTimeMillis();\r
+                       }\r
+\r
+                       installProgressWork += i;\r
+\r
+                       display.asyncExec(new Runnable() {\r
+                               @Override\r
+                               public void run() {\r
+                                       installProgressLabel.setText(installProgressWork + "/"\r
+                                                       + (totalWork));\r
+                                       installFileNameLabel.setText(fileName);\r
+                               }\r
+                       });\r
+               }\r
+\r
+               @Override\r
+               public void workedInstallSize(final long size) {\r
+                       if (display == null || display.isDisposed()) {\r
+                               setCanceled(true);\r
+                               return;\r
+                       }\r
+\r
+                       display.asyncExec(new Runnable() {\r
+                               private String remainTimeStr = "";\r
+\r
+                               @Override\r
+                               public void run() {\r
+                                       /* set total size */\r
+\r
+                                       String totalSize = "";\r
+                                       if (totalInstallSize >= GB_SIZE) {\r
+                                               totalSize = dformat\r
+                                                               .format((totalInstallSize / GB_SIZE)) + "GB";\r
+                                       } else if (totalInstallSize >= MB_SIZE) {\r
+                                               totalSize = dformat\r
+                                                               .format((totalInstallSize / MB_SIZE)) + "MB";\r
+                                       } else {\r
+                                               totalSize = totalInstallSize + "KB";\r
+                                       }\r
+\r
+                                       /* set current download size */\r
+                                       installProgressSize += size / (double) 1024;\r
+\r
+                                       String currentSize = "";\r
+                                       if (installProgressSize >= GB_SIZE) {\r
+                                               currentSize = dformat\r
+                                                               .format((installProgressSize / GB_SIZE)) + "GB";\r
+                                       } else if (downloadProgressSize >= MB_SIZE) {\r
+                                               currentSize = dformat\r
+                                                               .format((installProgressSize / MB_SIZE)) + "MB";\r
+                                       } else {\r
+                                               currentSize = dformat.format(installProgressSize)\r
+                                                               + "KB";\r
+                                       }\r
+\r
+                                       // set size to progress bar.\r
+//                                     installProgressBar.setToolTipText(currentSize + "/"\r
+//                                                     + totalSize);\r
+\r
+                                       long pastTimes = System.currentTimeMillis()\r
+                                                       - installStartTime;\r
+\r
+                                       // set remain time\r
+                                       if (pastTimes > 5000) {\r
+                                               double installVelocity = installProgressSize\r
+                                                               / (double) (pastTimes / (double) 1000);\r
+\r
+                                               double remainSize = totalInstallSize\r
+                                                               - installProgressSize;\r
+                                               double remainTime = remainSize / installVelocity;\r
+\r
+                                               int day = (int) (remainTime / DAY);\r
+                                               int hour = (int) ((remainTime % DAY) / HOUR);\r
+                                               int min = (int) ((remainTime % HOUR) / MIN);\r
+                                               int sec = (int) (remainTime % MIN);\r
+\r
+                                               if (day > 0) {\r
+                                                       remainTimeStr = day + "day ";\r
+                                               }\r
+\r
+                                               if (hour > 0) {\r
+                                                       remainTimeStr += hour + "hour ";\r
+                                               }\r
+\r
+                                               if (min > 0) {\r
+                                                       remainTimeStr += min + "min ";\r
+                                               }\r
+\r
+                                               if (sec > 0) {\r
+                                                       remainTimeStr += sec + "sec";\r
+                                               }\r
+                                       } else {\r
+                                               remainTimeStr = "estimating...";\r
+                                       }\r
+\r
+                                       installRemainingTimeLabel.setText(remainTimeStr);\r
+                                       installProgressBar\r
+                                                       .setSelection((int) (100 * installProgressSize / totalInstallSize));\r
+                               }\r
+                       });\r
+               }\r
+\r
+               /**\r
+                * set working file name to show during installing\r
+                */\r
+               @Override\r
+               public void workedTitle(final String title) {\r
+                       if (display == null || display.isDisposed()) {\r
+                               setCanceled(true);\r
+                               return;\r
+                       }\r
+\r
+                       display.syncExec(new Runnable() {\r
+                               @Override\r
+                               public void run() {\r
+                                       downloadProgressTitleLabel.setText(title);\r
+                               }\r
+                       });\r
+               }\r
+\r
+               public void setCancelRequested(boolean b) {\r
+                       cancelRequested = b;\r
+               }\r
+\r
+               @Override\r
+               public void workedRefresh() {\r
+                       downloadProgressSize = 0;\r
+               }\r
+\r
+               @Override\r
+               public void setError(int errorCode) {\r
+                       // TODO Auto-generated method stub\r
+\r
+               }\r
+       }\r
+}\r
index df410c2..f8bcafd 100644 (file)
-/*
-*  InstallManager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: 
-* Wooyoung Cho <wooyoung1.cho@samsung.com>
-* Shihyun Kim <shihyun.kim@samsung.com>
-* Taeyoung Son <taeyoung2.son@samsung.com>
-* Yongsung kim <yongsung1.kim@samsung.com>
-* 
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
-
-package org.tizen.installmanager.ui.page;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.ProgressBar;
-import org.tizen.installmanager.core.IMFatalException;
-import org.tizen.installmanager.core.InstallManager;
-import org.tizen.installmanager.lib.ErrorController;
-import org.tizen.installmanager.lib.IIMProgressMonitor;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.lib.ProgramController;
-import org.tizen.installmanager.pkg.model.PackageSet;
-import org.tizen.installmanager.ui.InstallManagerWindow;
-import org.tizen.installmanager.ui.dialog.MessageBoxDlg;
-import org.tizen.installmanager.ui.dialog.MessageBoxDlg.DialogType;
-import org.tizen.installmanager.pkg.model.Package;
-
-/**
- * @author Taeyoung Son <taeyoung2.son@samsung.com>
- * @author Shihyun Kim <shihyun.kim@samsung.com>
- */
-public class UninstallingPage extends PageTemplate {
-       static final String RSC_PATH_IMAGE = RESOURCE_PATH + "/uninstaller_graphicmotif_002.png";
-       static final String STRING_TITLE = "Uninstalling...";
-       static final String STRING_SUBTITLE = "";
-
-
-       private ProgressBar progressBar;
-       private Label statusLabel;
-       private Label uninstalledNumberLabel;
-       private Label mSubTitleOfProgress;
-
-       private ViewController viewController;
-       private UninstallProgressMonitor monitor;
-       private InstallManagerWindow mainWindow;
-       Display display;
-
-       /**
-        * Set basic environment of uninstalling page.
-        * @param parent
-        * @param style
-        */
-       public UninstallingPage(Composite parent, int style) {
-               super(parent, style);
-               setLeftImageFromResource(RSC_PATH_IMAGE);
-               setTitle(STRING_TITLE);
-               setSubTitle(STRING_SUBTITLE);
-
-               progressBar = new ProgressBar(customComposite, SWT.NONE);
-               progressBar.setBounds(40, 110, 396, 20);
-
-               statusLabel = new Label(customComposite, SWT.NONE);
-               statusLabel.setBounds(40, 80, 343, 23);
-               statusLabel.setForeground(new Color(null, 96, 96, 96));
-               statusLabel.setBackground(InstallManagerWindow.getBackgroundColor());
-
-               mSubTitleOfProgress = new Label(customComposite, SWT.NONE);
-               mSubTitleOfProgress.setBounds(40, 138, 250, 23);
-               mSubTitleOfProgress.setBackground(InstallManagerWindow.getBackgroundColor());
-               mSubTitleOfProgress.setText("");
-
-               uninstalledNumberLabel = new Label(customComposite, SWT.CENTER);
-               uninstalledNumberLabel.setBounds(353, 138, 80, 23);
-               uninstalledNumberLabel.setBackground(InstallManagerWindow.getBackgroundColor());
-               uninstalledNumberLabel.setText("");
-       }
-
-       /**
-        * Display uninstalling page, if sdk is running during uninstalling, page will show warning dialog.
-        * @param selectedList
-        * @param vController
-        * @param mainWindow
-        * @return
-        */
-       public boolean loadPage(
-                       List<String> selectedList, ViewController vController,
-                       InstallManagerWindow mainWindow) {
-               this.viewController = vController;
-               this.mainWindow = mainWindow;
-               monitor = new UninstallProgressMonitor();
-               display = customComposite.getDisplay();
-
-               //kill running process.
-               ProgramController controller = ProgramController.createProgramController();
-               if (controller.runningProgramExists()) {
-                       int confirm = MessageBoxDlg.showDlg(
-                                       getShell(),
-                                       "Warning",
-                                       "The SDK is already running. If you uninstall it, the current version will stop. Are you sure you want to uninstall the SDK?",
-                                       DialogType.WARNING, false);
-                       if (confirm == MessageBoxDlg.YES) {
-                               controller.terminateRunningProgram();
-                       } else if (confirm == MessageBoxDlg.NO) {
-                               return false;
-                       }
-               }
-               
-               //start uninstall.
-               final UninstallThread uninstallThread = new UninstallThread(monitor);
-               uninstallThread.start();                
-               
-               return true;
-       }
-
-       /**
-        * This class controls process to uninstall.
-        * @author Shihyun Kim <Shihyun.kim@samsung.com>
-        */
-       class UninstallThread extends Thread {
-               private IIMProgressMonitor monitor;
-
-               public UninstallThread(IIMProgressMonitor monitor) {
-                       this.monitor = monitor;
-               }
-
-               /**
-                * Uninstalling thread run
-                */
-               @Override
-               public void run() {
-                       try {
-                               uninstallProcess(monitor);
-                       } catch (IMFatalException e) {
-                               Log.err("internal error occurred");
-                               Log.ExceptionLog(e);
-                               ErrorController.setInstallationSuccess(false);
-                       } catch (Exception e) {
-                               Log.err("Unexpected exception occurred");
-                               Log.ExceptionLog(e);
-                               ErrorController.setInstallationSuccess(false);
-                       } finally {
-                               monitor.done();
-                       }
-                       Log.log("finish uninstall thread");
-               }
-       }
-
-       /**
-        * After check selected package list size, start to uninstall.
-        * @param monitor
-        */
-       public void uninstallProcess(IIMProgressMonitor monitor) { boolean result = false;
-               Log.log("****** Uninstall SDK ******");
-               PackageSet pkgs = InstallManager.getInstance().getPackageManager().getInstalledPackages();
-               List<String> installedList = new ArrayList<String>();
-               for (Package pkg : pkgs) {
-                       installedList.add(pkg.getPackageName());
-               }
-               
-               if (installedList.size() <= 0) {
-                       return;
-               } else {
-                       Log.log("Uninstalling SDK : " + viewController.getInstalledPath());
-                       result = viewController.uninstall(installedList, monitor);
-               }
-
-               ErrorController.setInstallationSuccess(result);
-       }
-
-       /**
-        * @author Shihyun Kim <shihyun.kim@samsung.com>
-        */
-       public class UninstallProgressMonitor implements IIMProgressMonitor {
-
-               private int totalWork;
-               private String mProgressTitle = "";
-               private String mSubTitle = "";
-
-               private static final int MAX_LENGTH = 40;
-               private static final String STRING_ETC = "...";
-
-               @Override
-               public void beginTask(final String name, int totalWork) {
-                       this.mProgressTitle = name;
-                       this.totalWork = totalWork;
-                       display.asyncExec(new Runnable() {
-
-                               @Override
-                               public void run() {
-                                       statusLabel.setText(name);
-                               }
-                       });
-               }
-
-               /**
-                * Control to finish uninstall process
-                */
-               @Override
-               public void done() {
-                       display.asyncExec(new Runnable() {
-                               @Override
-                               public void run() {
-                                       progressBar.setSelection(100);
-
-                                       CompletePage completePage = mainWindow.getCompletePage();
-                                       completePage.setLeftImageFromResource(CompletePage.RSC_PATH_UNINSTALL_IMAGE);
-                                       completePage.showCheckButton(false);
-                                       mainWindow.setCancelBtnEnabled(true);
-                                       mainWindow.showComposite(completePage);
-
-                                       if (ErrorController.checkInstallationSuccess()) {
-                                               completePage.setTitle("Uninstallation Completed!");
-                                               if (!viewController.existRemovablePackage()) {
-                                                       completePage.removeTargetDir();
-                                               }
-                                               
-                                               String msg = "Thank you for using Tizen SDK. "; 
-                                               completePage.setCustomMessage(msg);
-                                               
-                                               if (ErrorController.existInfoMessage()) {
-                                                       completePage.setInfoMessage(ErrorController.getInfoMessage());
-                                               }
-                                       } else {
-                                               completePage.setTitle("Uninstallation Failed!");
-                                               completePage.setCustomErrorMessage("Sorry, Uninstallation was not success. Please try uninstall again.\n"
-                                                               + "Datail : " + ErrorController.getErrorMessage());
-                                       }
-                               }
-                       });
-               }
-
-               @Override
-               public void internalWorked(double work) {
-                       // Do nothing.
-               }
-
-               @Override
-               public boolean isCanceled() {
-                       return false;
-               }
-
-               @Override
-               public void setCanceled(boolean value) {
-                       // Do nothing.
-               }
-
-               @Override
-               public void setTaskName(String name) {
-                       // Do nothing.
-               }
-
-               @Override
-               public void subTask(String name) {
-                       // Do nothing.
-               }
-
-               /**
-                * set working package name to show during uninstalling
-                */
-               @Override
-               public void worked(final int work) {
-                       display.asyncExec(new Runnable() {
-                               @Override
-                               public void run() {
-                                       mSubTitleOfProgress.setText(mSubTitle);
-                                       uninstalledNumberLabel.setText(work + "/" + totalWork);
-                                       progressBar.setSelection(100 * work / totalWork);
-                               }
-                       });
-               }
-               
-               /**
-                * set working file name to show during installing 
-                */
-               @Override
-               public void workedTitle(String title) {
-                       mProgressTitle = title;
-                       
-                       if (display == null || display.isDisposed()) {
-                               setCanceled(true);
-                               return;
-                       }
-                       
-                       display.syncExec(new Runnable() {
-                               @Override
-                               public void run() {
-                                       statusLabel.setText(mProgressTitle);
-                               }
-                       });
-               }
-
-               /**
-                * set working file name to show during uninstalling 
-                */
-               @Override
-               public void workedSubTitle(String subTitle) {
-                       if (subTitle.length() > MAX_LENGTH) {
-                               mSubTitle = subTitle.substring(0, MAX_LENGTH - 2);
-                               mSubTitle = mSubTitle + STRING_ETC;
-                       } else {
-                               mSubTitle = subTitle;
-                       }
-                       
-                       if (display == null || display.isDisposed()) {
-                               setCanceled(true);
-                               return;
-                       }
-                       
-                       display.asyncExec(new Runnable() {
-                               @Override
-                               public void run() {
-                                       mSubTitleOfProgress.setText(mSubTitle);
-                               }
-                       });
-               }
-               
-               @Override
-               public void workedProcess(String title) {
-                       if (title == null || title.isEmpty()) {
-                               return;
-                       }
-                       
-                       workedTitle("Processing : package \"" + mProgressTitle + "\"");
-               }
-
-               @Override
-               public void workedDownload(long size) {
-                       //Do nothing
-               }
-
-               @Override
-               public void setDownloadStartTime(long startTime) {
-                       //Do nothing
-               }
-
-               @Override
-               public void workedChecksum(long size) {
-                       //Do nothing
-               }
-
-               @Override
-               public void workedProgressbar(int percent) {
-                       progressBar.setSelection(percent);
-               }
-
-               @Override
-               public void workedRefresh() {
-                       //Do nothing
-
-               }
-               
-               @Override
-               public void setError(int errorCode) {
-                       //Do nothing
-                       
-               }
-
-               @Override
-               public void workedDownload(String title) {
-                       //Do nothing                    
-               }
-
-               @Override
-               public void workedChecksum(String title) {
-                       //Do nothing
-                       
-               }
-       }
-}
+/*\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.ui.page;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.graphics.Color;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.ProgressBar;\r
+import org.tizen.installmanager.core.IMFatalException;\r
+import org.tizen.installmanager.core.InstallManager;\r
+import org.tizen.installmanager.lib.ErrorController;\r
+import org.tizen.installmanager.lib.IIMProgressMonitor;\r
+import org.tizen.installmanager.lib.Log;\r
+import org.tizen.installmanager.lib.ProgramController;\r
+import org.tizen.installmanager.pkg.model.PackageSet;\r
+import org.tizen.installmanager.ui.InstallManagerWindow;\r
+import org.tizen.installmanager.ui.dialog.MessageBoxDlg;\r
+import org.tizen.installmanager.ui.dialog.MessageBoxDlg.DialogType;\r
+import org.tizen.installmanager.pkg.model.Package;\r
+\r
+/**\r
+ * @author Taeyoung Son <taeyoung2.son@samsung.com>\r
+ * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+ */\r
+public class UninstallingPage extends PageTemplate {\r
+       static final String RSC_PATH_IMAGE = RESOURCE_PATH + "/uninstaller_graphicmotif_002.png";\r
+       static final String STRING_TITLE = "Uninstalling...";\r
+       static final String STRING_SUBTITLE = "";\r
+\r
+\r
+       private ProgressBar progressBar;\r
+       private Label statusLabel;\r
+       private Label uninstalledNumberLabel;\r
+       private Label mSubTitleOfProgress;\r
+\r
+       private ViewController viewController;\r
+       private UninstallProgressMonitor monitor;\r
+       private InstallManagerWindow mainWindow;\r
+       Display display;\r
+\r
+       /**\r
+        * Set basic environment of uninstalling page.\r
+        * @param parent\r
+        * @param style\r
+        */\r
+       public UninstallingPage(Composite parent, int style) {\r
+               super(parent, style);\r
+               setLeftImageFromResource(RSC_PATH_IMAGE);\r
+               setTitle(STRING_TITLE);\r
+               setSubTitle(STRING_SUBTITLE);\r
+\r
+               progressBar = new ProgressBar(customComposite, SWT.NONE);\r
+               progressBar.setBounds(40, 110, 396, 20);\r
+\r
+               statusLabel = new Label(customComposite, SWT.NONE);\r
+               statusLabel.setBounds(40, 80, 343, 23);\r
+               statusLabel.setForeground(new Color(null, 96, 96, 96));\r
+               statusLabel.setBackground(InstallManagerWindow.getBackgroundColor());\r
+\r
+               mSubTitleOfProgress = new Label(customComposite, SWT.NONE);\r
+               mSubTitleOfProgress.setBounds(40, 138, 250, 23);\r
+               mSubTitleOfProgress.setBackground(InstallManagerWindow.getBackgroundColor());\r
+               mSubTitleOfProgress.setText("");\r
+\r
+               uninstalledNumberLabel = new Label(customComposite, SWT.CENTER);\r
+               uninstalledNumberLabel.setBounds(353, 138, 80, 23);\r
+               uninstalledNumberLabel.setBackground(InstallManagerWindow.getBackgroundColor());\r
+               uninstalledNumberLabel.setText("");\r
+       }\r
+\r
+       /**\r
+        * Display uninstalling page, if sdk is running during uninstalling, page will show warning dialog.\r
+        * @param selectedList\r
+        * @param vController\r
+        * @param mainWindow\r
+        * @return\r
+        */\r
+       public boolean loadPage(\r
+                       List<String> selectedList, ViewController vController,\r
+                       InstallManagerWindow mainWindow) {\r
+               this.viewController = vController;\r
+               this.mainWindow = mainWindow;\r
+               monitor = new UninstallProgressMonitor();\r
+               display = customComposite.getDisplay();\r
+\r
+               //kill running process.\r
+               ProgramController controller = ProgramController.createProgramController();\r
+               if (controller.runningProgramExists()) {\r
+                       int confirm = MessageBoxDlg.showDlg(\r
+                                       getShell(),\r
+                                       "Warning",\r
+                                       "The SDK is already running. If you uninstall it, the current version will stop. Are you sure you want to uninstall the SDK?",\r
+                                       DialogType.WARNING, false);\r
+                       if (confirm == MessageBoxDlg.YES) {\r
+                               controller.terminateRunningProgram();\r
+                       } else if (confirm == MessageBoxDlg.NO) {\r
+                               return false;\r
+                       }\r
+               }\r
+               \r
+               //start uninstall.\r
+               final UninstallThread uninstallThread = new UninstallThread(monitor);\r
+               uninstallThread.start();                \r
+               \r
+               return true;\r
+       }\r
+\r
+       /**\r
+        * This class controls process to uninstall.\r
+        * @author Shihyun Kim <Shihyun.kim@samsung.com>\r
+        */\r
+       class UninstallThread extends Thread {\r
+               private IIMProgressMonitor monitor;\r
+\r
+               public UninstallThread(IIMProgressMonitor monitor) {\r
+                       this.monitor = monitor;\r
+               }\r
+\r
+               /**\r
+                * Uninstalling thread run\r
+                */\r
+               @Override\r
+               public void run() {\r
+                       try {\r
+                               uninstallProcess(monitor);\r
+                       } catch (IMFatalException e) {\r
+                               Log.err("internal error occurred");\r
+                               Log.ExceptionLog(e);\r
+                               ErrorController.setInstallationSuccess(false);\r
+                       } catch (Exception e) {\r
+                               Log.err("Unexpected exception occurred");\r
+                               Log.ExceptionLog(e);\r
+                               ErrorController.setInstallationSuccess(false);\r
+                       } finally {\r
+                               monitor.done();\r
+                       }\r
+                       Log.log("finish uninstall thread");\r
+               }\r
+       }\r
+\r
+       /**\r
+        * After check selected package list size, start to uninstall.\r
+        * @param monitor\r
+        */\r
+       public void uninstallProcess(IIMProgressMonitor monitor) { boolean result = false;\r
+               Log.log("****** Uninstall SDK ******");\r
+               PackageSet pkgs = InstallManager.getInstance().getPackageManager().getInstalledPackages();\r
+               List<String> installedList = new ArrayList<String>();\r
+               for (Package pkg : pkgs) {\r
+                       installedList.add(pkg.getPackageName());\r
+               }\r
+               \r
+               if (installedList.size() <= 0) {\r
+                       return;\r
+               } else {\r
+                       Log.log("Uninstalling SDK : " + viewController.getInstalledPath());\r
+                       result = viewController.uninstall(installedList, monitor);\r
+               }\r
+\r
+               ErrorController.setInstallationSuccess(result);\r
+       }\r
+\r
+       /**\r
+        * @author Shihyun Kim <shihyun.kim@samsung.com>\r
+        */\r
+       public class UninstallProgressMonitor implements IIMProgressMonitor {\r
+\r
+               private int totalWork;\r
+               private String mProgressTitle = "";\r
+               private String mSubTitle = "";\r
+\r
+               private static final int MAX_LENGTH = 40;\r
+               private static final String STRING_ETC = "...";\r
+\r
+               @Override\r
+               public void beginTask(final String name, int totalWork) {\r
+                       this.mProgressTitle = name;\r
+                       this.totalWork = totalWork;\r
+                       display.asyncExec(new Runnable() {\r
+\r
+                               @Override\r
+                               public void run() {\r
+                                       statusLabel.setText(name);\r
+                               }\r
+                       });\r
+               }\r
+\r
+               /**\r
+                * Control to finish uninstall process\r
+                */\r
+               @Override\r
+               public void done() {\r
+                       display.asyncExec(new Runnable() {\r
+                               @Override\r
+                               public void run() {\r
+                                       progressBar.setSelection(100);\r
+\r
+                                       CompletePage completePage = mainWindow.getCompletePage();\r
+                                       completePage.setLeftImageFromResource(CompletePage.RSC_PATH_UNINSTALL_IMAGE);\r
+                                       completePage.showCheckButton(false);\r
+                                       mainWindow.setCancelBtnEnabled(true);\r
+                                       mainWindow.showComposite(completePage);\r
+\r
+                                       if (ErrorController.checkInstallationSuccess()) {\r
+                                               completePage.setTitle("Uninstallation Completed!");\r
+                                               if (!viewController.existRemovablePackage()) {\r
+                                                       completePage.removeTargetDir();\r
+                                               }\r
+                                               \r
+                                               String msg = "Thank you for using Tizen SDK. "; \r
+                                               completePage.setCustomMessage(msg);\r
+                                               \r
+                                               if (ErrorController.existInfoMessage()) {\r
+                                                       completePage.setInfoMessage(ErrorController.getInfoMessage());\r
+                                               }\r
+                                       } else {\r
+                                               completePage.setTitle("Uninstallation Failed!");\r
+                                               completePage.setCustomErrorMessage("Sorry, Uninstallation was not success. Please try uninstall again.\n"\r
+                                                               + "Datail : " + ErrorController.getErrorMessage());\r
+                                       }\r
+                               }\r
+                       });\r
+               }\r
+\r
+               @Override\r
+               public void internalWorked(double work) {\r
+                       // Do nothing.\r
+               }\r
+\r
+               @Override\r
+               public boolean isCanceled() {\r
+                       return false;\r
+               }\r
+\r
+               @Override\r
+               public void setCanceled(boolean value) {\r
+                       // Do nothing.\r
+               }\r
+\r
+               @Override\r
+               public void setTaskName(String name) {\r
+                       // Do nothing.\r
+               }\r
+\r
+               @Override\r
+               public void subTask(String name) {\r
+                       // Do nothing.\r
+               }\r
+\r
+               /**\r
+                * set working package name to show during uninstalling\r
+                */\r
+               @Override\r
+               public void worked(final int work) {\r
+                       display.asyncExec(new Runnable() {\r
+                               @Override\r
+                               public void run() {\r
+                                       mSubTitleOfProgress.setText(mSubTitle);\r
+                                       uninstalledNumberLabel.setText(work + "/" + totalWork);\r
+                                       progressBar.setSelection(100 * work / totalWork);\r
+                               }\r
+                       });\r
+               }\r
+               \r
+               /**\r
+                * set working file name to show during installing \r
+                */\r
+               @Override\r
+               public void workedTitle(String title) {\r
+                       mProgressTitle = title;\r
+                       \r
+                       if (display == null || display.isDisposed()) {\r
+                               setCanceled(true);\r
+                               return;\r
+                       }\r
+                       \r
+                       display.syncExec(new Runnable() {\r
+                               @Override\r
+                               public void run() {\r
+                                       statusLabel.setText(mProgressTitle);\r
+                               }\r
+                       });\r
+               }\r
+\r
+               /**\r
+                * set working file name to show during uninstalling \r
+                */\r
+               @Override\r
+               public void workedDownloadProgress(String subTitle, int i) {\r
+                       if (subTitle.length() > MAX_LENGTH) {\r
+                               mSubTitle = subTitle.substring(0, MAX_LENGTH - 2);\r
+                               mSubTitle = mSubTitle + STRING_ETC;\r
+                       } else {\r
+                               mSubTitle = subTitle;\r
+                       }\r
+                       \r
+                       if (display == null || display.isDisposed()) {\r
+                               setCanceled(true);\r
+                               return;\r
+                       }\r
+                       \r
+                       display.asyncExec(new Runnable() {\r
+                               @Override\r
+                               public void run() {\r
+                                       mSubTitleOfProgress.setText(mSubTitle);\r
+                               }\r
+                       });\r
+               }\r
+\r
+               @Override\r
+               public void workedDownloadSize(long size) {\r
+                       //Do nothing\r
+               }\r
+\r
+               @Override\r
+               public void workedRefresh() {\r
+                       //Do nothing\r
+\r
+               }\r
+               \r
+               @Override\r
+               public void setError(int errorCode) {\r
+                       //Do nothing\r
+                       \r
+               }\r
+\r
+               @Override\r
+               public void workedInstallProgress(String subTitle, int i) {\r
+                       //Do nothing\r
+                       \r
+               }\r
+\r
+               @Override\r
+               public void workedInstallSize(long size) {\r
+                       //Do nothing\r
+               }\r
+       }\r
+}\r
index efe6afb..d76078f 100644 (file)
-/*
-*  InstallManager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact: 
-* Wooyoung Cho <wooyoung1.cho@samsung.com>
-* Shihyun Kim <shihyun.kim@samsung.com>
-* Taeyoung Son <taeyoung2.son@samsung.com>
-* Yongsung kim <yongsung1.kim@samsung.com>
-* 
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
-
-package org.tizen.installmanager.ui.page;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.swt.SWT;
-import org.tizen.installmanager.core.Config;
-import org.tizen.installmanager.core.IMExitException;
-import org.tizen.installmanager.core.IMFatalException;
-import org.tizen.installmanager.core.InstallManager;
-import org.tizen.installmanager.core.InstallManagerConstants;
-import org.tizen.installmanager.core.Options;
-import org.tizen.installmanager.core.Performance;
-import org.tizen.installmanager.core.SDKExtensionInfo;
-import org.tizen.installmanager.core.Config.ServerType;
-import org.tizen.installmanager.lib.Documents;
-import org.tizen.installmanager.lib.Downloader;
-import org.tizen.installmanager.lib.ErrorController;
-import org.tizen.installmanager.lib.IIMProgressMonitor;
-import org.tizen.installmanager.lib.Log;
-import org.tizen.installmanager.lib.Platform;
-import org.tizen.installmanager.lib.Registry;
-import org.tizen.installmanager.lib.ErrorController.ErrorCode;
-import org.tizen.installmanager.lib.SDKPackageFormat;
-import org.tizen.installmanager.lib.exception.IMNetworkConnectException;
-import org.tizen.installmanager.lib.exception.IMNetworkDownloadException;
-import org.tizen.installmanager.lib.exception.IMNetworkException;
-import org.tizen.installmanager.lib.linux.LinuxShellRunningProgramParser;
-import org.tizen.installmanager.pkg.lib.PackageManager;
-import org.tizen.installmanager.pkg.model.Package;
-import org.tizen.installmanager.pkg.model.PackageSet;
-import org.tizen.installmanager.pkg.model.ProcessInformation;
-import org.tizen.installmanager.pkg.model.Version;
-import org.tizen.installmanager.ui.InstallManagerWindow;
-import org.tizen.installmanager.ui.dialog.MessageBoxDlg;
-import org.tizen.installmanager.ui.dialog.MessageBoxDlg.DialogType;
-import org.tizen.installmanager.ui.model.Item;
-import org.tizen.installmanager.ui.model.Item.InstallState;
-import org.tizen.installmanager.ui.page.InstallingPage.InstallProgressMonitor;
-import org.tizen.installmanager.util.IMShellCommandFail;
-import org.tizen.installmanager.util.PathUtil;
-import org.tizen.installmanager.util.ShellUtil;
-
-/**
- * This class is a connector between Model and View. Model and View can communicate each other via ViewController. 
- * @author Taeyoung Son <taeyoung2.son@samsung.com>
- */
-public class ViewController {
-
-       private InstallManager installManager;
-       private PackageManager packageManager;
-       private SDKExtensionInfo sdkExtensionInfo;
-
-       /**
-        * Initialize objects which need to install.
-        * @return
-        * true : Success to Initialize<br>
-        * false : Fail to Initialize
-        */
-       public boolean init() {
-               Log.log("ViewController init");
-               
-               try {
-                       installManager = InstallManager.getInstance();
-                       installManager.init();
-                       packageManager = installManager.getPackageManager();
-                       
-                       if (packageManager == null) {
-                               throw new IMFatalException("Cannot read package information.");
-                       } else {
-                               if (existInstallableOrRemovablePackages()) {
-                                       sdkExtensionInfo = packageManager.getSdkExtensionInfo();
-                                       
-                                       
-                                       // InstallManager maintains the newest extension package list always.
-                                       sdkExtensionInfo.refreshCache();
-                                       
-                                       return true;
-                               } else {
-                                       ErrorController.setInstallationSuccess(false);
-                                       Log.log("existInstallableOrRemovablePackages() is false.");
-                                       return false;
-                               }
-                       }
-               } catch(IMFatalException e) {
-                       Log.ExceptionLog(e);
-                       return false;
-               }
-       }
-
-       /**
-        * Get meta packages that are available to install or to update.
-        * @return Meta package set
-        */
-       public PackageSet getInstallableOrUpdatableMetaPackages() {
-               if (packageManager == null) {
-                       Log.err("PackageManage is null.");
-                       return null;
-               } else {
-                       return packageManager.getInstallableOrUpdatableMetaPackages();
-               }
-       }
-
-       /**
-        * Get meta packages that are available to install.
-        * @return Meta package set
-        */
-       public PackageSet getInstallableMetaPackageList() {
-               if (packageManager == null) {
-                       return null;
-               } else {
-                       return packageManager.getInstallableMetaPackages();
-               }
-       }
-       
-       public PackageSet getAllMetaPackages() {
-               if (packageManager == null) {
-                       return null;
-               } else {
-                       return packageManager.getAllMetaPackages();
-               }
-       }
-       
-       /**
-        * Get meta packages in repository.
-        * @return Meta package set
-        */
-       public PackageSet getRootMetaPackageListOfRepository() {
-               if (packageManager == null) {
-                       return null;
-               } else {
-                       return packageManager.getRootMetaPackagesOfRepository();
-               }
-       }
-       
-       public PackageSet getTreeMetaPackageListOfRepository() {
-               if (packageManager == null) {
-                       return null;
-               } else {
-                       return packageManager.getRecentMetaPackages();
-               }
-       }
-       
-       public PackageSet getRootMetaPackageListOfExtension() {
-               if (packageManager == null) {
-                       return null;
-               } else {
-                       return packageManager.getRootMetaPackagesOfExtensionServer();
-               }               
-       }
-
-       /**
-        * Get meta packages that are available to update.
-        * @return Meta package set
-        */
-       public PackageSet getUpdatableMetapackageList() {
-               if (packageManager == null) {
-                       return null;
-               } else {
-                       return packageManager.getUpdatableMetaPackages();
-               }
-       }
-       
-       /**
-        * Get meta packages that are available to update.
-        * @return Meta package set
-        */
-       public PackageSet getNotUpdatableMetapackageList() {
-               if (packageManager == null) {
-                       return null;
-               } else {
-                       return packageManager.getNotInstallableAndNotUpdatablePackages();
-               }
-       }
-
-       /**
-        * Get meta packages that are available to remove.
-        * @return Meta package set
-        */
-       public PackageSet getRemovableMetaPackageList() {
-               if (packageManager == null) {
-                       return null;
-               } else {
-                       return packageManager.getRemovableMetaPackages();
-               }
-       }
-       
-       public PackageSet getInstallablePackageListInSnapshot() {
-               if (packageManager == null) {
-                       return null;
-               } else {
-                       return packageManager.getInstallableMetaPackagesInSnapshot();
-               }
-       }
-
-       /**
-        * Get packages that are available to remove.
-        * @return package set
-        */
-       public PackageSet getRemovablePackageList() {
-               if (packageManager == null) {
-                       Log.err("packageManage is null");
-                       return null;
-               } else {
-                       return packageManager.getInstalledPackages();
-               }
-       }
-
-       /**
-        * Check to exist removable packages.
-        * @return if installed package exists, return true. if not return false.
-        */
-       public boolean existRemovablePackage() {
-               if (packageManager == null) {
-                       return false;
-               } else {
-                       return packageManager.existInstalledPackages();
-               }
-       }
-       
-       /**
-        * Check to need new installation.
-        * @return If it needs new installation, return true. otherwise return false.
-        */
-       public boolean isNewInstallation() {    
-//             if (packageManager == null) {
-//                     return false;
-//             }
-               
-               if (packageManager.isReInstallable()) {
-                       return true;
-               } else {
-                       return !packageManager.existInstalledPackages();
-               }
-       }
-       
-       /**
-        * Check that package server has web or native minimal install type package.
-        * @return If package server has web or native minimal install type package, return true
-        * . Others return false.
-        */
-       public boolean hasWebNativeMinimal() {
-               Package webMinimalPkg = packageManager.getPackageByName("WEB-MINIMAL");
-               Package nativeMinimalPkg = packageManager.getPackageByName("NATIVE-MINIMAL");
-               if (webMinimalPkg != null && nativeMinimalPkg != null) {
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-
-       /**
-        * Start to install and update.
-        * @param installList : selected mata packages
-        * @param targetPath : install path
-        * @param monitor
-        * @return If installation is succeeded, return true. if not return false.
-        * @throws IMExitException 
-        */
-       public boolean install(Collection<String> installList, String targetPath,
-                       InstallProgressMonitor monitor) throws IMExitException {                
-               Log.log("======== Start Installing ========");
-               Log.log("Selected package list => " + installList);
-               Log.log("target path => " + targetPath);
-
-               if (packageManager == null) {
-                       Log.err("Package list does not exist.");
-                       return false;
-               }
-               
-               PackageSet installablePackages = null;
-               if (installList.size() == 0) {
-                       Log.log("Package install success.");
-                       return true;
-               } else {
-                       installablePackages = getInstallablePackages(installList);
-               }
-               
-               Registry.setSDKinfoBySDKPath(targetPath);
-               Registry.saveSDKInfo(targetPath);
-               
-               boolean bResult = false;
-               while(true) {
-                       try {
-                               bResult = installManager.install(installablePackages, targetPath, monitor);
-                               break;
-                       } catch (IMNetworkException e) {
-                               Log.ExceptionLog(e);
-                               showRetryDialog(e.getMessage());
-                               
-                               continue;
-                       } catch (Exception e) {
-                               Log.ExceptionLog(e);
-                               throw new IMFatalException(e.getMessage());
-                       }
-               }
-               
-               if (bResult) {
-                       PathUtil.remove(Config.getInstance().getDownloadDirPath());
-               }
-               
-               return bResult;
-       }
-       
-       public void showRetryDialog(String msg) {
-               //retry dialog.
-               String errorMsg = msg + "\nWould you like to retry?";
-               int ret = MessageBoxDlg.showDlg(
-                               InstallManagerWindow.getInstallManagerWindow().getShell(),
-                               "Warning",
-                               errorMsg,
-                               DialogType.WARNING, false);
-               
-               if (ret == SWT.NO) { //cancel
-                       throw new IMFatalException(msg);
-               }
-       }
-       
-       /**
-        * Get installable packages.
-        * @param installList package name list from UI.
-        * @return set of installable packages.
-        */
-       public PackageSet getInstallablePackages(Collection<String> installList) {
-               //get installable packages
-               PackageSet selectedMetas = packageManager.getPackagesByNames(installList);
-               
-               //add mandatory packages, madatory packages always reinstall.
-               selectedMetas.addAll(packageManager.getMandatoryPackages());
-               
-               return packageManager.getInstallablePackages(selectedMetas);
-       }
-
-       /**
-        * Start to uninstall
-        * @param uninstallList
-        * @param monitor
-        * @return If uninstallation is succeed, return true. if not return false.
-        * @see ViewController#uninstallPackages(PackageSet, IIMProgressMonitor)
-        */
-       public boolean uninstall(List<String> uninstallList, IIMProgressMonitor monitor) {              
-               Log.log("ViewController Uninstall Start => " + uninstallList);
-               
-               //performance measurement
-               Performance.setRemovalStartTime();
-               if (packageManager == null || uninstallList.size() == 0) {
-                       Log.err("ViewController.uninstall() uninstalllist does not exist. => " + uninstallList);
-                       ErrorController.setError(ErrorCode.UNKNOWN_ERROR);
-                       
-                       Performance.setRemovalEndTime();
-                       return false;
-               }
-
-               if (Options.doRemoveOldSDK || (uninstallList.size() == 1 && uninstallList.get(0).equals(Config.SDK_NAME))) {
-                       uninstallAll(monitor);
-                       
-                       //performance measurement
-                       Performance.setRemovalEndTime();
-                       
-                       return true;
-               } else {
-                       PackageSet removablePackages = packageManager.getInstalledPackagesByName(uninstallList);
-
-                       //performance measurement
-                       Performance.sdkPackageSize = packageManager.getTotalSizeOfRemovablePackages(removablePackages);
-                       
-                       boolean result = uninstallPackages(removablePackages, monitor);
-                       
-                       //performance measurement
-                       Performance.setRemovalEndTime();
-                       return result;
-               }
-       }
-
-       /**
-        * Uninstall removable packages.
-        * @param removableMetapkgs
-        * @param monitor
-        * @return If removable packages can success to uninstall, return true. if not return false.
-        */
-       public boolean uninstallPackages(PackageSet removableMetapkgs, IIMProgressMonitor monitor) {
-               boolean bRet = installManager.removePackages(removableMetapkgs, monitor);
-
-               Log.log("ViewController Uninstall End => " + bRet);
-               return bRet;
-       }
-
-       /**
-        * Remove all packages.
-        * @param monitor
-        */
-       public void uninstallAll(IIMProgressMonitor monitor) {
-               Log.log("ViewController Unintall All");
-               installManager.removeAll(monitor);
-               Registry.removeRegistry();
-       }
-
-       /**
-        * Get package version that is installed already.
-        * @param pkgName is installed packages already.
-        * @return version
-        */
-       public Package getInstalledPackage(String pkgName) {
-               return packageManager.getInstalledPackageByName(pkgName);
-       }
-       
-       public PackageSet getInstalledPackages() {
-               return packageManager.getInstalledPackages();
-       }
-       
-       /**
-        * Get items of tree
-        * @return
-        */
-       public List<Item> getPackageSetOfTree() {               
-               if (packageManager == null) {
-                       return new ArrayList<Item>();
-               }
-               
-               //get all meta packages (installable packages)
-               //TODO : show all packages. (installable, installed)
-               PackageSet metaPackageSet = packageManager.getRootMetaPackagesOfRepository();   
-               
-               return makeTreeItem(metaPackageSet);
-       }
-       
-       /**
-        * Make tree item from package set.
-        * @param pkgSet
-        * @return
-        */
-       public List<Item> makeTreeItem(PackageSet pkgSet) {
-               List<Item> treeItemList = new ArrayList<Item>();
-               Item extraItem = null;
-               
-               if (pkgSet == null) {
-                       return treeItemList;
-               }
-               
-               for (Package pkg : pkgSet) {
-                       if (!pkg.isMeta() || pkg.isMandatory()) {
-                               continue;
-                       }
-                       
-                       InstallState itemState = getState(pkg);
-                       
-                       if (pkg.getPackageName().equalsIgnoreCase("EXTRAS")) {
-                               extraItem = new Item(pkg, pkg, itemState);
-                               continue;
-                       }
-                       
-                       Item newItem = null;
-                       if (itemState == InstallState.INSTALL) {
-                               newItem = new Item(pkg, pkg, itemState);
-                       } else if (itemState == InstallState.UPDATE) {
-                               Package installedPkg = packageManager.getInstalledMetaPackages().getPackage(pkg);
-                               newItem = new Item(pkg, installedPkg, itemState); 
-                       } else if (itemState == InstallState.UNINSTALL) {
-                               newItem = new Item(pkg, pkg, itemState);
-                       } else {
-                               Log.err("Cannot find install state. => " + itemState);
-                               continue;
-                       }
-
-                       treeItemList.add(newItem);
-               }
-
-               if (extraItem != null) {
-                       treeItemList.add(extraItem);
-               }
-               
-               return treeItemList;
-       }
-       
-       public void refreshTreeItemStatus(List<Item> items) {
-               
-       }
-       
-       private InstallState getState(Package pkg) {
-               if (PackageManager.getInstance().isReInstallable()) {
-                       return InstallState.INSTALL;
-               } else if (Config.isSupportMultiSDK()) {
-                       if (Config.status == Config.Status.INSTALL) {
-                               return InstallState.INSTALL;                            
-                       } else if (Config.status == Config.Status.UPDATE) {
-                               if (packageManager.getInstallableMetaPackages().contains(pkg)) {
-                                       return InstallState.INSTALL;
-                               } else if (packageManager.getUpdatableMetaPackages().contains(pkg)) {
-                                       return InstallState.UPDATE;
-                               } else {
-                                       return InstallState.UNINSTALL;
-                               }
-                       }
-               } else {
-                       if (packageManager.getInstallableMetaPackages().contains(pkg)) {
-                               return InstallState.INSTALL;
-                       } else if (packageManager.getUpdatableMetaPackages().contains(pkg)) {
-                               return InstallState.UPDATE;
-                       } else {
-                               return InstallState.UNINSTALL;
-                       }
-               }
-               
-               return null;
-       }
-
-       /**
-        * Get total size depends on a package list.
-        * @param pkgList is list.
-        * @param isUncompressed Uncompressed is true, not false.
-        * @return size
-        */
-       public long getTotalSizeWithDepends(Collection<String> pkgList, boolean isUncompressed) {
-               PackageSet pkgSet = packageManager.getPackagesByNames(pkgList);
-               return getTotalSizeWithDepends(pkgSet, isUncompressed);
-       }
-       
-       /**
-        * Get total size depends on a package format.
-        * @param pkg is package format.
-        * @return size
-        */
-       public long getRemovablePackagesSize(Package pkg) {
-               return packageManager.getTotalSizeOfRemovablePackages(pkg);
-       }
-
-       /**
-        * Get total size depends on a package set.
-        * @param pkgs is package set
-        * @param isUncompressed Uncompressed is true, not false.
-        * @return size
-        */
-       public long getTotalSizeWithDepends(PackageSet pkgs, boolean isUncompressed) {
-               return packageManager.getTotalSizeOfInstallablePackages(pkgs, isUncompressed);
-       }
-       
-       /**
-        * Get installed path.
-        * @return Installed target path
-        */
-       public String getInstalledPath() {
-               return Registry.getInstalledPath();
-       }
-       
-       public String getInstallPath() {
-               String path = InstallManagerWindow.getInstallManagerWindow().getSetInstallDirectoryPage().getInstallPath();
-               return path;
-       }
-       
-       public String getSDKWorkSpacePath() {
-               String path = InstallManagerWindow.getInstallManagerWindow().getSetInstallDirectoryPage().getSDKWorkSpacePath();
-               return path;
-       }
-       
-
-       /**
-        * Check to exist package which can install or remove.
-        * @return There are packages to install or remove, return true. if not false.
-        */
-       public boolean existInstallableOrRemovablePackages() {
-               PackageSet rmPkgs = getRemovablePackageList();
-               PackageSet insPkgs = getInstallableOrUpdatableMetaPackages();
-               
-               if (!rmPkgs.isEmpty() || !insPkgs.isEmpty()) {
-                       Log.log("existInstallableOrRemovablePackages() is true.");
-                       return (getRemovablePackageList().size() > 0 || getInstallableOrUpdatableMetaPackages().size() > 0);                    
-               } else {
-                       Log.err("Both Removable Package List and Installable or Updatable Meta Packages are null");                             
-                       return false;
-               }
-       }
-       
-       /**
-        * Check to exist package which can install or update.
-        * @return There are packages to install or remove, return true. if not false.
-        */
-       public boolean existInstallableOrUpdatablePackages() {
-               PackageSet ps = getInstallablePackageListInSnapshot();
-               
-               if (ps != null) {
-                       if (Options.snapshot || Config.fromWhere == Config.ConfDialog.LOCAL_IMAGE) {
-                               return (ps.size() > 0);
-                       } else {
-                               return (ps.size() > 0);
-                       }
-               } else {
-                       return false;
-               }
-       }
-
-       /**
-        * Get Install configure.
-        * @return configure object.
-        */
-       public Config getConfig() {
-               return installManager.getConfig();
-       }
-
-       /**
-        * Get description of package.
-        * @param pkgName
-        * @return decription of package.
-        */
-       public String getDescription(String pkgName) {
-               Package pkg = packageManager.getPackageByName(pkgName);
-
-               if (pkg == null) {
-                       return "";
-               } else {
-                       return pkg.getDescription();
-               }
-       }
-
-       /**
-        * Check to exist files in target directory.
-        * @param targetDir is installed directory.
-        * @return If there are files in directory, return true. if not false.
-        */
-       public boolean existFilesInTargetDirectory(String targetDir) {
-               File targetFile = new File(targetDir);
-
-               if (!targetFile.exists()) {
-                       return false;
-               }
-
-               File[] targetFileList = targetFile.listFiles();
-               if (targetFileList == null || targetFileList.length <= 0) {
-                       return false;
-               } else {
-                       return true;
-               }
-       }
-
-       /**
-        * Remove file or directory from parameter
-        * @param targetPath
-        */
-       public void removeTargetPath(String targetPath) {
-               PathUtil.remove(targetPath);
-       }
-       
-       /**
-        * save information of server.
-        * @param repository Base-repository of sdk. if repository is null, it do not save repository.
-        * @param type type of repository. if type is null, it do not save type.
-        * @param packageServer package server of sdk. if packageServer is null, it do not save packageServer.
-        * @param packageType set ServerType.snapshot or ServerType.package. if serverType is null, it do not save serverType.
-        */
-       public void saveSnapshotSettings(String repository, String distribution, ServerType packageType, String snapshotPath) {
-               Config.getInstance().saveSnapshotSettings(repository, distribution,  packageType, snapshotPath);
-       }
-       
-       public SDKExtensionInfo getSdkExtensionInfo() {
-               return sdkExtensionInfo;
-       }
-       
-       public void loadSdkExtension() {
-               sdkExtensionInfo.load();
-       }
-       
-       /**
-        * Check the environment of ubuntu.
-        * @return If true, this is unity panel service.
-        */
-       public boolean isUnityEnvironment() {
-               String command = "ps -ax";
-               
-               try {
-                       LinuxShellRunningProgramParser parser = new LinuxShellRunningProgramParser();
-                       int ret = ShellUtil.execute(command, parser);
-                       
-                       if (ret != 0 ){
-                               return false;
-                       } else {
-                               for (ProcessInformation pInfo : parser.getProcessInformation()) {
-                                       if (pInfo.getCommand().contains("unity-panel-service")) {
-                                               return true;
-                                       }
-                               }
-                               return false;
-                       }
-                       
-               } catch (IMShellCommandFail e) {
-                       Log.ExceptionLog(e);
-                       return false;
-               }
-       }
-       
-       public PackageSet getConflictPackages(PackageSet pkgs) {
-               PackageSet pkgSet = packageManager.getDependsPackagesFromRepository(pkgs);              
-               return packageManager.getConflictPackages(pkgSet);
-       }
-       
-       public PackageSet getCauseOfConflict(PackageSet checkedPackages, Package conflictPackage) {
-               PackageSet causePackages = new PackageSet();
-               
-               for (Package pkg : checkedPackages) {
-                       if (packageManager.conflictPackages(pkg).contains(conflictPackage)) {
-                               causePackages.add(pkg);
-                       }
-               }
-               
-               return causePackages;
-       }
-       
-       public void showChangeLog() {
-               if (Documents.isChecked()) {
-                       Documents.showChangeLog(); // show the change log(history)
-               }
-       }
-       
-       public void cleanUpTargetDirectory() {
-               Log.log("Clean up the target directory => " + Registry.getInstalledPath());
-               if (packageManager == null || packageManager.getInstalledPackages().isEmpty()) {
-                       String targetPath = Config.getInstance().getTargetDir();
-                       
-                       if (targetPath.isEmpty()) {
-                               return;
-                       } else {
-                               removeTargetPath(targetPath);
-                       }
-               }
-       }
-       
-       public boolean canInstallManagerUpdate() {
-               Package pkg = packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);
-               
-               if (pkg == null) {
-                       return false;
-               }
-               String version = Config.getInstance().getCurrentConfigFile().getInstallManagerVersion();
-               
-               Log.log("Current InstallManager version => " + version);
-               if (version == null || version.isEmpty()) {
-                       return true;
-               }
-               
-               Log.log("Update version => " + pkg.getVersion().toString());
-               if (Version.compareTo(new Version(version), pkg.getVersion()) < 0) {
-                       Log.log("Update version is higher than current version. So, installmanager will be updated.");
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-       
-       public boolean isInstalledInstallManager() {
-               Package installedPackage = packageManager.getInstalledPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);
-               
-               if (installedPackage != null) {
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-       
-       public boolean updateInstallManager() {
-               Package pkg = packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);
-
-               if (pkg == null) {
-                       return false;
-               }
-               
-               if (installInstallManagerToTemp()) {
-                       Log.log("## Success to update the InstallManager, and restart now.");
-                       System.out.println("## Success to update the InstallManager, and restart now.");
-                       
-                       runNewInstallManager();
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-       
-       public boolean installInstallManagerToTemp() {
-               String imPackage = downloadInstallManager();
-               if (imPackage == null) {
-                       return false;
-               }
-               
-               if (extractIMPackage(imPackage)) {
-                       Log.log("Success to extract updatable InstallManager.");
-                       runNewInstallManager();
-                       return true;
-               } else {
-                       Log.err("Fail to extract updatable InstallManager. Cannot execute it.");
-                       return false;
-               }
-       }
-       
-       private String downloadInstallManager() {
-               Package pkg = packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);
-               
-               Downloader downloader = new Downloader();
-               
-               String packagePath = pkg.getFileName();
-               String installManagerTempPath = PathUtil.get(PathUtil.getTempDir(), PathUtil.getFileName(packagePath));
-               File tempInstaller = new File(installManagerTempPath);
-               
-               if (tempInstaller.exists()) {
-                       if (!PathUtil.remove(installManagerTempPath)) {
-                               Log.err("Cannot remove installmanager. => " + tempInstaller);
-                       }
-               }
-               
-               try {
-                       long size = downloader.download(pkg.getURL(), installManagerTempPath, null);
-                       
-                       if (size > 0) {
-                               return installManagerTempPath;
-                       } else {
-                               return null;
-                       }
-               } catch (IMNetworkConnectException e) {
-                       Log.ExceptionLog(e);
-                       return null;
-               } catch (IMNetworkDownloadException e) {
-                       Log.ExceptionLog(e);
-                       return null;
-               }
-       }
-       
-       private boolean extractIMPackage(String imPath) {
-               removeIMBinaryInTemp();
-               
-               SDKPackageFormat format = SDKPackageFormat.createSDKPackageFormat();
-               long size = format.unZip(imPath, PathUtil.getTempDir(), null);
-               
-               if (size > 0) {
-                       return true;
-               } else {
-                       throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);
-               }
-       }
-       
-       private void removeIMBinaryInTemp() {
-               String tempDir = PathUtil.getTempDir();
-               
-               File tempDirFile = new File(tempDir);
-               
-               for (File childFile : tempDirFile.listFiles()) {
-                       if (isIMBinary(childFile.getName())) {
-                               if (!childFile.delete()) {
-                                       Log.err("Cannot delete " + childFile.getAbsolutePath());
-                               }
-                       }
-               }
-       }
-       
-       private boolean isIMBinary(String fileName) {
-               if (fileName.equals(InstallManagerConstants.INSTALLMANAGERV2_JAR_FILE_NAME)){
-                       return true;
-               } else {
-                       return false;
-               }
-       }
-       
-       private void runNewInstallManager() {
-               File tempIMJarFile = new File(PathUtil.get(
-                               PathUtil.getTempDir(), "data", "install-manager",
-                               InstallManagerConstants.INSTALLMANAGERV2_JAR_FILE_NAME));
-
-               if (tempIMJarFile.exists()) {
-                       try {
-                               ArrayList<String> commands = new ArrayList<String>();
-                               
-                               String javaHome = System.getProperty("java.home");
-                               File java = null;
-                               if (Platform.isLinux() || Platform.isMacOS()) {
-                                       java = new File(PathUtil.get(javaHome, "bin", "java"));
-                               } else if (Platform.isWindows()) {
-                                       java = new File(PathUtil.get(javaHome, "bin", "java.exe"));
-                               }
-                               
-                               String forceBitOption = "-d" + System.getProperty("sun.arch.data.model");
-
-                               String jarPath = PathUtil.get(tempIMJarFile.getAbsolutePath());
-                               if (java.exists()) {
-                                       commands.add(java.getAbsolutePath());
-                               } else {
-                                       commands.add("java");
-                               }
-                               
-                               if (Platform.isMacOS()) {
-                                       commands.add("-XstartOnFirstThread");
-                               }
-                               
-                               commands.add(forceBitOption);
-                               commands.add("-jar");
-                               commands.add(jarPath);
-                               
-                               if (Options.executablePath != null) {
-                                       commands.add("-path");
-                                       commands.add(Options.executablePath);
-                               }
-                               
-                               String repo = Config.getInstance().getConfigFile().getRepository();
-                               if (repo != null & !repo.isEmpty()) {
-                                       commands.add("-repository");
-                                       commands.add(repo);
-                               }
-                               
-                               String dist = Config.getInstance().getConfigFile().getDistribution();
-                               if (repo != null & !repo.isEmpty()) {
-                                       commands.add("-distribution");
-                                       commands.add(dist);
-                               }
-                               
-                               String proxyHost = Config.getInstance().getConfigFile().getProxyHost();
-                               int proxyPort = Config.getInstance().getConfigFile().getProxyPort();
-                               if (proxyHost != null & !proxyHost.isEmpty()) {
-                                       if (proxyPort > 0) {
-                                               commands.add("-proxy");
-                                               commands.add(proxyHost + ":" + proxyPort);
-                                       }
-                               }
-                               
-                               Config.getInstance().getConfigFile().setInstallManagerVersion(packageManager.getPackageByName("install-manager").getVersion().toString());
-                               Config.getInstance().getConfigFile().saveConfig(PathUtil.get(tempIMJarFile.getParent(), "installmanager.conf"));
-                               
-                               Log.log("Updatable commands => " + commands);
-                               
-                               ProcessBuilder pb = new ProcessBuilder(commands);
-                               pb.directory(tempIMJarFile.getParentFile());
-                               pb.start();
-                               
-                               System.exit(0);
-                       } catch (IOException e) {
-                               Log.ExceptionLog(e);
-                               return;
-                       }
-               }
-       }
-}
+/*\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.ui.page;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.List;\r
+\r
+import org.eclipse.swt.SWT;\r
+import org.tizen.installmanager.core.Config;\r
+import org.tizen.installmanager.core.IMExitException;\r
+import org.tizen.installmanager.core.IMFatalException;\r
+import org.tizen.installmanager.core.InstallManager;\r
+import org.tizen.installmanager.core.InstallManagerConstants;\r
+import org.tizen.installmanager.core.Options;\r
+import org.tizen.installmanager.core.Performance;\r
+import org.tizen.installmanager.core.SDKExtensionInfo;\r
+import org.tizen.installmanager.core.Config.ServerType;\r
+import org.tizen.installmanager.lib.Documents;\r
+import org.tizen.installmanager.lib.Downloader;\r
+import org.tizen.installmanager.lib.ErrorController;\r
+import org.tizen.installmanager.lib.IIMProgressMonitor;\r
+import org.tizen.installmanager.lib.Log;\r
+import org.tizen.installmanager.lib.Platform;\r
+import org.tizen.installmanager.lib.Registry;\r
+import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
+import org.tizen.installmanager.lib.SDKPackageFormat;\r
+import org.tizen.installmanager.lib.exception.IMNetworkConnectException;\r
+import org.tizen.installmanager.lib.exception.IMNetworkDownloadException;\r
+import org.tizen.installmanager.lib.exception.IMNetworkException;\r
+import org.tizen.installmanager.lib.linux.LinuxShellRunningProgramParser;\r
+import org.tizen.installmanager.pkg.lib.PackageManager;\r
+import org.tizen.installmanager.pkg.model.Package;\r
+import org.tizen.installmanager.pkg.model.PackageSet;\r
+import org.tizen.installmanager.pkg.model.ProcessInformation;\r
+import org.tizen.installmanager.pkg.model.Version;\r
+import org.tizen.installmanager.ui.InstallManagerWindow;\r
+import org.tizen.installmanager.ui.dialog.MessageBoxDlg;\r
+import org.tizen.installmanager.ui.dialog.MessageBoxDlg.DialogType;\r
+import org.tizen.installmanager.ui.model.Item;\r
+import org.tizen.installmanager.ui.model.Item.InstallState;\r
+import org.tizen.installmanager.ui.page.InstallingPage.InstallProgressMonitor;\r
+import org.tizen.installmanager.util.IMShellCommandFail;\r
+import org.tizen.installmanager.util.PathUtil;\r
+import org.tizen.installmanager.util.ShellUtil;\r
+\r
+/**\r
+ * This class is a connector between Model and View. Model and View can communicate each other via ViewController. \r
+ * @author Taeyoung Son <taeyoung2.son@samsung.com>\r
+ */\r
+public class ViewController {\r
+\r
+       private InstallManager installManager;\r
+       private PackageManager packageManager;\r
+       private SDKExtensionInfo sdkExtensionInfo;\r
+\r
+       /**\r
+        * Initialize objects which need to install.\r
+        * @return\r
+        * true : Success to Initialize<br>\r
+        * false : Fail to Initialize\r
+        */\r
+       public boolean init() {\r
+               Log.log("ViewController init");\r
+               \r
+               try {\r
+                       installManager = InstallManager.getInstance();\r
+                       installManager.init();\r
+                       packageManager = installManager.getPackageManager();\r
+                       \r
+                       if (packageManager == null) {\r
+                               throw new IMFatalException("Cannot read package information.");\r
+                       } else {\r
+                               if (existInstallableOrRemovablePackages()) {\r
+                                       sdkExtensionInfo = packageManager.getSdkExtensionInfo();\r
+                                       \r
+                                       \r
+                                       // InstallManager maintains the newest extension package list always.\r
+                                       sdkExtensionInfo.refreshCache();\r
+                                       \r
+                                       return true;\r
+                               } else {\r
+                                       ErrorController.setInstallationSuccess(false);\r
+                                       Log.log("existInstallableOrRemovablePackages() is false.");\r
+                                       return false;\r
+                               }\r
+                       }\r
+               } catch(IMFatalException e) {\r
+                       Log.ExceptionLog(e);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Get meta packages that are available to install or to update.\r
+        * @return Meta package set\r
+        */\r
+       public PackageSet getInstallableOrUpdatableMetaPackages() {\r
+               if (packageManager == null) {\r
+                       Log.err("PackageManage is null.");\r
+                       return null;\r
+               } else {\r
+                       return packageManager.getInstallableOrUpdatableMetaPackages();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Get meta packages that are available to install.\r
+        * @return Meta package set\r
+        */\r
+       public PackageSet getInstallableMetaPackageList() {\r
+               if (packageManager == null) {\r
+                       return null;\r
+               } else {\r
+                       return packageManager.getInstallableMetaPackages();\r
+               }\r
+       }\r
+       \r
+       public PackageSet getAllMetaPackages() {\r
+               if (packageManager == null) {\r
+                       return null;\r
+               } else {\r
+                       return packageManager.getAllMetaPackages();\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Get meta packages in repository.\r
+        * @return Meta package set\r
+        */\r
+       public PackageSet getRootMetaPackageListOfRepository() {\r
+               if (packageManager == null) {\r
+                       return null;\r
+               } else {\r
+                       return packageManager.getRootMetaPackagesOfRepository();\r
+               }\r
+       }\r
+       \r
+       public PackageSet getTreeMetaPackageListOfRepository() {\r
+               if (packageManager == null) {\r
+                       return null;\r
+               } else {\r
+                       return packageManager.getRecentMetaPackages();\r
+               }\r
+       }\r
+       \r
+       public PackageSet getRootMetaPackageListOfExtension() {\r
+               if (packageManager == null) {\r
+                       return null;\r
+               } else {\r
+                       return packageManager.getRootMetaPackagesOfExtensionServer();\r
+               }               \r
+       }\r
+\r
+       /**\r
+        * Get meta packages that are available to update.\r
+        * @return Meta package set\r
+        */\r
+       public PackageSet getUpdatableMetapackageList() {\r
+               if (packageManager == null) {\r
+                       return null;\r
+               } else {\r
+                       return packageManager.getUpdatableMetaPackages();\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Get meta packages that are available to update.\r
+        * @return Meta package set\r
+        */\r
+       public PackageSet getNotUpdatableMetapackageList() {\r
+               if (packageManager == null) {\r
+                       return null;\r
+               } else {\r
+                       return packageManager.getNotInstallableAndNotUpdatablePackages();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Get meta packages that are available to remove.\r
+        * @return Meta package set\r
+        */\r
+       public PackageSet getRemovableMetaPackageList() {\r
+               if (packageManager == null) {\r
+                       return null;\r
+               } else {\r
+                       return packageManager.getRemovableMetaPackages();\r
+               }\r
+       }\r
+       \r
+       public PackageSet getInstallablePackageListInSnapshot() {\r
+               if (packageManager == null) {\r
+                       return null;\r
+               } else {\r
+                       return packageManager.getInstallableMetaPackagesInSnapshot();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Get packages that are available to remove.\r
+        * @return package set\r
+        */\r
+       public PackageSet getRemovablePackageList() {\r
+               if (packageManager == null) {\r
+                       Log.err("packageManage is null");\r
+                       return null;\r
+               } else {\r
+                       return packageManager.getInstalledPackages();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Check to exist removable packages.\r
+        * @return if installed package exists, return true. if not return false.\r
+        */\r
+       public boolean existRemovablePackage() {\r
+               if (packageManager == null) {\r
+                       return false;\r
+               } else {\r
+                       return packageManager.existInstalledPackages();\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Check to need new installation.\r
+        * @return If it needs new installation, return true. otherwise return false.\r
+        */\r
+       public boolean isNewInstallation() {    \r
+//             if (packageManager == null) {\r
+//                     return false;\r
+//             }\r
+               \r
+               if (packageManager.isReInstall()) {\r
+                       return true;\r
+               } else {\r
+                       return !packageManager.existInstalledPackages();\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Check that package server has web or native minimal install type package.\r
+        * @return If package server has web or native minimal install type package, return true\r
+        * . Others return false.\r
+        */\r
+       public boolean hasWebNativeMinimal() {\r
+               Package webMinimalPkg = packageManager.getPackageByName("WEB-MINIMAL");\r
+               Package nativeMinimalPkg = packageManager.getPackageByName("NATIVE-MINIMAL");\r
+               if (webMinimalPkg != null && nativeMinimalPkg != null) {\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Start to install and update.\r
+        * @param installList : selected mata packages\r
+        * @param targetPath : install path\r
+        * @param monitor\r
+        * @return If installation is succeeded, return true. if not return false.\r
+        * @throws IMExitException \r
+        */\r
+       public boolean install(Collection<String> installList, String targetPath,\r
+                       InstallProgressMonitor monitor) throws IMExitException {                \r
+               Log.log("======== Start Installing ========");\r
+               Log.log("Selected package list => " + installList);\r
+               Log.log("target path => " + targetPath);\r
+\r
+               if (packageManager == null) {\r
+                       Log.err("Package list does not exist.");\r
+                       return false;\r
+               }\r
+               \r
+               PackageSet installablePackages = null;\r
+               if (installList.size() == 0) {\r
+                       Log.log("Package install success.");\r
+                       return true;\r
+               } else {\r
+                       installablePackages = getInstallablePackages(installList);\r
+               }\r
+               \r
+               Registry.setSDKinfoBySDKPath(targetPath);\r
+               Registry.saveSDKInfo(targetPath);\r
+               \r
+               boolean bResult = false;\r
+               while(true) {\r
+                       try {\r
+                               bResult = installManager.install(installablePackages, targetPath, monitor);\r
+                               break;\r
+                       } catch (IMNetworkException e) {\r
+                               Log.ExceptionLog(e);\r
+                               showRetryDialog(e.getMessage());\r
+                               \r
+                               if (monitor != null) {\r
+                                       monitor.workedRefresh();\r
+                               }\r
+                               continue;\r
+                       } catch (Exception e) {\r
+                               Log.ExceptionLog(e);\r
+                               throw new IMFatalException(e.getMessage());\r
+                       }\r
+               }\r
+               \r
+               if (bResult) {\r
+                       PathUtil.remove(Config.getInstance().getDownloadDirPath());\r
+               }\r
+               \r
+               return bResult;\r
+       }\r
+       \r
+       public void showRetryDialog(String msg) {\r
+               //retry dialog.\r
+               String errorMsg = msg + "\nWould you like to retry?";\r
+               int ret = MessageBoxDlg.showDlg(\r
+                               InstallManagerWindow.getInstallManagerWindow().getShell(),\r
+                               "Warning",\r
+                               errorMsg,\r
+                               DialogType.WARNING, false);\r
+               \r
+               if (ret == SWT.NO) { //cancel\r
+                       throw new IMFatalException(msg);\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Get installable packages.\r
+        * @param installList package name list from UI.\r
+        * @return set of installable packages.\r
+        */\r
+       public PackageSet getInstallablePackages(Collection<String> installList) {\r
+               //get installable packages\r
+               PackageSet selectedMetas = packageManager.getPackagesByNames(installList);\r
+               \r
+               //add mandatory packages, madatory packages always reinstall.\r
+               selectedMetas.addAll(packageManager.getMandatoryPackages());\r
+               \r
+               return packageManager.getInstallablePackages(selectedMetas);\r
+       }\r
+\r
+       /**\r
+        * Start to uninstall\r
+        * @param uninstallList\r
+        * @param monitor\r
+        * @return If uninstallation is succeed, return true. if not return false.\r
+        * @see ViewController#uninstallPackages(PackageSet, IIMProgressMonitor)\r
+        */\r
+       public boolean uninstall(List<String> uninstallList, IIMProgressMonitor monitor) {              \r
+               Log.log("ViewController Uninstall Start => " + uninstallList);\r
+               \r
+               //performance measurement\r
+               Performance.setRemovalStartTime();\r
+               if (packageManager == null || uninstallList.size() == 0) {\r
+                       Log.err("ViewController.uninstall() uninstalllist does not exist. => " + uninstallList);\r
+                       ErrorController.setError(ErrorCode.UNKNOWN_ERROR);\r
+                       \r
+                       Performance.setRemovalEndTime();\r
+                       return false;\r
+               }\r
+\r
+               if (Options.doRemoveOldSDK || (uninstallList.size() == 1 && uninstallList.get(0).equals(Config.SDK_NAME))) {\r
+                       uninstallAll(monitor);\r
+                       \r
+                       //performance measurement\r
+                       Performance.setRemovalEndTime();\r
+                       \r
+                       return true;\r
+               } else {\r
+                       PackageSet removablePackages = packageManager.getInstalledPackagesByName(uninstallList);\r
+\r
+                       //performance measurement\r
+                       Performance.sdkPackageSize = packageManager.getTotalSizeOfRemovablePackages(removablePackages);\r
+                       \r
+                       boolean result = uninstallPackages(removablePackages, monitor);\r
+                       \r
+                       //performance measurement\r
+                       Performance.setRemovalEndTime();\r
+                       return result;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Uninstall removable packages.\r
+        * @param removableMetapkgs\r
+        * @param monitor\r
+        * @return If removable packages can success to uninstall, return true. if not return false.\r
+        */\r
+       public boolean uninstallPackages(PackageSet removableMetapkgs, IIMProgressMonitor monitor) {\r
+               boolean bRet = installManager.removePackages(removableMetapkgs, monitor);\r
+\r
+               Log.log("ViewController Uninstall End => " + bRet);\r
+               return bRet;\r
+       }\r
+\r
+       /**\r
+        * Remove all packages.\r
+        * @param monitor\r
+        */\r
+       public void uninstallAll(IIMProgressMonitor monitor) {\r
+               Log.log("ViewController Unintall All");\r
+               installManager.removeAll(monitor);\r
+               Registry.removeRegistry();\r
+       }\r
+\r
+       /**\r
+        * Get package version that is installed already.\r
+        * @param pkgName is installed packages already.\r
+        * @return version\r
+        */\r
+       public Package getInstalledPackage(String pkgName) {\r
+               return packageManager.getInstalledPackageByName(pkgName);\r
+       }\r
+       \r
+       public PackageSet getInstalledPackages() {\r
+               return packageManager.getInstalledPackages();\r
+       }\r
+       \r
+       /**\r
+        * Get items of tree\r
+        * @return\r
+        */\r
+       public List<Item> getPackageSetOfTree() {               \r
+               if (packageManager == null) {\r
+                       return new ArrayList<Item>();\r
+               }\r
+               \r
+               //get all meta packages (installable packages)\r
+               //TODO : show all packages. (installable, installed)\r
+               PackageSet metaPackageSet = packageManager.getRootMetaPackagesOfRepository();   \r
+               \r
+               return makeTreeItem(metaPackageSet);\r
+       }\r
+       \r
+       /**\r
+        * Make tree item from package set.\r
+        * @param pkgSet\r
+        * @return\r
+        */\r
+       public List<Item> makeTreeItem(PackageSet pkgSet) {\r
+               List<Item> treeItemList = new ArrayList<Item>();\r
+               Item extraItem = null;\r
+               \r
+               if (pkgSet == null) {\r
+                       return treeItemList;\r
+               }\r
+               \r
+               for (Package pkg : pkgSet) {\r
+                       if (!pkg.isMeta() || pkg.isMandatory()) {\r
+                               continue;\r
+                       }\r
+                       \r
+                       InstallState itemState = getState(pkg);\r
+                       \r
+                       if (pkg.getPackageName().equalsIgnoreCase("EXTRAS")) {\r
+                               extraItem = new Item(pkg, pkg, itemState);\r
+                               continue;\r
+                       }\r
+                       \r
+                       Item newItem = null;\r
+                       if (itemState == InstallState.INSTALL) {\r
+                               newItem = new Item(pkg, pkg, itemState);\r
+                       } else if (itemState == InstallState.UPDATE) {\r
+                               Package installedPkg = packageManager.getInstalledMetaPackages().getPackage(pkg);\r
+                               newItem = new Item(pkg, installedPkg, itemState); \r
+                       } else if (itemState == InstallState.UNINSTALL) {\r
+                               newItem = new Item(pkg, pkg, itemState);\r
+                       } else {\r
+                               Log.err("Cannot find install state. => " + itemState);\r
+                               continue;\r
+                       }\r
+\r
+                       treeItemList.add(newItem);\r
+               }\r
+\r
+               if (extraItem != null) {\r
+                       treeItemList.add(extraItem);\r
+               }\r
+               \r
+               return treeItemList;\r
+       }\r
+       \r
+       public void refreshTreeItemStatus(List<Item> items) {\r
+               \r
+       }\r
+       \r
+       private InstallState getState(Package pkg) {\r
+               if (PackageManager.getInstance().isReInstall()) {\r
+                       return InstallState.INSTALL;\r
+               } else if (Config.isSupportMultiSDK()) {\r
+                       if (Config.status == Config.Status.INSTALL) {\r
+                               return InstallState.INSTALL;                            \r
+                       } else if (Config.status == Config.Status.UPDATE) {\r
+                               if (packageManager.getInstallableMetaPackages().contains(pkg)) {\r
+                                       return InstallState.INSTALL;\r
+                               } else if (packageManager.getUpdatableMetaPackages().contains(pkg)) {\r
+                                       return InstallState.UPDATE;\r
+                               } else {\r
+                                       return InstallState.UNINSTALL;\r
+                               }\r
+                       }\r
+               } else {\r
+                       if (packageManager.getInstallableMetaPackages().contains(pkg)) {\r
+                               return InstallState.INSTALL;\r
+                       } else if (packageManager.getUpdatableMetaPackages().contains(pkg)) {\r
+                               return InstallState.UPDATE;\r
+                       } else {\r
+                               return InstallState.UNINSTALL;\r
+                       }\r
+               }\r
+               \r
+               return null;\r
+       }\r
+\r
+       /**\r
+        * Get total size depends on a package list.\r
+        * @param pkgList is list.\r
+        * @param isUncompressed Uncompressed is true, not false.\r
+        * @return size\r
+        */\r
+       public long getTotalSizeWithDepends(Collection<String> pkgList, boolean isUncompressed) {\r
+               PackageSet pkgSet = packageManager.getPackagesByNames(pkgList);\r
+               return getTotalSizeWithDepends(pkgSet, isUncompressed);\r
+       }\r
+       \r
+       /**\r
+        * Get total size depends on a package format.\r
+        * @param pkg is package format.\r
+        * @return size\r
+        */\r
+       public long getRemovablePackagesSize(Package pkg) {\r
+               return packageManager.getTotalSizeOfRemovablePackages(pkg);\r
+       }\r
+\r
+       /**\r
+        * Get total size depends on a package set.\r
+        * @param pkgs is package set\r
+        * @param isUncompressed Uncompressed is true, not false.\r
+        * @return size\r
+        */\r
+       public long getTotalSizeWithDepends(PackageSet pkgs, boolean isUncompressed) {\r
+               return packageManager.getTotalSizeOfInstallablePackages(pkgs, isUncompressed);\r
+       }\r
+       \r
+       /**\r
+        * Get installed path.\r
+        * @return Installed target path\r
+        */\r
+       public String getInstalledPath() {\r
+               return Registry.getInstalledPath();\r
+       }\r
+       \r
+       public String getInstallPath() {\r
+               String path = InstallManagerWindow.getInstallManagerWindow().getSetInstallDirectoryPage().getInstallPath();\r
+               return path;\r
+       }\r
+       \r
+       public String getSDKWorkSpacePath() {\r
+               String path = InstallManagerWindow.getInstallManagerWindow().getSetInstallDirectoryPage().getSDKWorkSpacePath();\r
+               return path;\r
+       }\r
+       \r
+\r
+       /**\r
+        * Check to exist package which can install or remove.\r
+        * @return There are packages to install or remove, return true. if not false.\r
+        */\r
+       public boolean existInstallableOrRemovablePackages() {\r
+               PackageSet rmPkgs = getRemovablePackageList();\r
+               PackageSet insPkgs = getInstallableOrUpdatableMetaPackages();\r
+               \r
+               if (!rmPkgs.isEmpty() || !insPkgs.isEmpty()) {\r
+                       Log.log("existInstallableOrRemovablePackages() is true.");\r
+                       return (getRemovablePackageList().size() > 0 || getInstallableOrUpdatableMetaPackages().size() > 0);                    \r
+               } else {\r
+                       Log.err("Both Removable Package List and Installable or Updatable Meta Packages are null");                             \r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Check to exist package which can install or update.\r
+        * @return There are packages to install or remove, return true. if not false.\r
+        */\r
+       public boolean existInstallableOrUpdatablePackages() {\r
+               PackageSet ps = getInstallablePackageListInSnapshot();\r
+               \r
+               if (ps != null) {\r
+                       if (Options.snapshot || Config.fromWhere == Config.ConfDialog.LOCAL_IMAGE) {\r
+                               return (ps.size() > 0);\r
+                       } else {\r
+                               return (ps.size() > 0);\r
+                       }\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Get Install configure.\r
+        * @return configure object.\r
+        */\r
+       public Config getConfig() {\r
+               return installManager.getConfig();\r
+       }\r
+\r
+       /**\r
+        * Get description of package.\r
+        * @param pkgName\r
+        * @return decription of package.\r
+        */\r
+       public String getDescription(String pkgName) {\r
+               Package pkg = packageManager.getPackageByName(pkgName);\r
+\r
+               if (pkg == null) {\r
+                       return "";\r
+               } else {\r
+                       return pkg.getDescription();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Check to exist files in target directory.\r
+        * @param targetDir is installed directory.\r
+        * @return If there are files in directory, return true. if not false.\r
+        */\r
+       public boolean existFilesInTargetDirectory(String targetDir) {\r
+               File targetFile = new File(targetDir);\r
+\r
+               if (!targetFile.exists()) {\r
+                       return false;\r
+               }\r
+\r
+               File[] targetFileList = targetFile.listFiles();\r
+               if (targetFileList == null || targetFileList.length <= 0) {\r
+                       return false;\r
+               } else {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Remove file or directory from parameter\r
+        * @param targetPath\r
+        */\r
+       public void removeTargetPath(String targetPath) {\r
+               PathUtil.remove(targetPath);\r
+       }\r
+       \r
+       /**\r
+        * save information of server.\r
+        * @param repository Base-repository of sdk. if repository is null, it do not save repository.\r
+        * @param type type of repository. if type is null, it do not save type.\r
+        * @param packageServer package server of sdk. if packageServer is null, it do not save packageServer.\r
+        * @param packageType set ServerType.snapshot or ServerType.package. if serverType is null, it do not save serverType.\r
+        */\r
+       public void saveSnapshotSettings(String repository, String distribution, ServerType packageType, String snapshotPath) {\r
+               Config.getInstance().saveSnapshotSettings(repository, distribution,  packageType, snapshotPath);\r
+       }\r
+       \r
+       public SDKExtensionInfo getSdkExtensionInfo() {\r
+               return sdkExtensionInfo;\r
+       }\r
+       \r
+       public void loadSdkExtension() {\r
+               sdkExtensionInfo.load();\r
+       }\r
+       \r
+       /**\r
+        * Check the environment of ubuntu.\r
+        * @return If true, this is unity panel service.\r
+        */\r
+       public boolean isUnityEnvironment() {\r
+               String command = "ps -ax";\r
+               \r
+               try {\r
+                       LinuxShellRunningProgramParser parser = new LinuxShellRunningProgramParser();\r
+                       int ret = ShellUtil.execute(command, parser);\r
+                       \r
+                       if (ret != 0 ){\r
+                               return false;\r
+                       } else {\r
+                               for (ProcessInformation pInfo : parser.getProcessInformation()) {\r
+                                       if (pInfo.getCommand().contains("unity-panel-service")) {\r
+                                               return true;\r
+                                       }\r
+                               }\r
+                               return false;\r
+                       }\r
+                       \r
+               } catch (IMShellCommandFail e) {\r
+                       Log.ExceptionLog(e);\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       public PackageSet getConflictPackages(PackageSet pkgs) {\r
+               PackageSet pkgSet = packageManager.getDependsPackagesFromRepository(pkgs);              \r
+               return packageManager.getConflictPackages(pkgSet);\r
+       }\r
+       \r
+       public PackageSet getCauseOfConflict(PackageSet checkedPackages, Package conflictPackage) {\r
+               PackageSet causePackages = new PackageSet();\r
+               \r
+               for (Package pkg : checkedPackages) {\r
+                       if (packageManager.conflictPackages(pkg).contains(conflictPackage)) {\r
+                               causePackages.add(pkg);\r
+                       }\r
+               }\r
+               \r
+               return causePackages;\r
+       }\r
+       \r
+       public void showChangeLog() {\r
+               if (Documents.isChecked()) {\r
+                       Documents.showChangeLog(); // show the change log(history)\r
+               }\r
+       }\r
+       \r
+       public void cleanUpTargetDirectory() {\r
+               Log.log("Clean up the target directory => " + Registry.getInstalledPath());\r
+               if (packageManager == null || packageManager.getInstalledPackages().isEmpty()) {\r
+                       String targetPath = Config.getInstance().getTargetDir();\r
+                       \r
+                       if (targetPath.isEmpty()) {\r
+                               return;\r
+                       } else {\r
+                               removeTargetPath(targetPath);\r
+                       }\r
+               }\r
+       }\r
+       \r
+       public boolean canInstallManagerUpdate() {\r
+               Package pkg = packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);\r
+               \r
+               if (pkg == null) {\r
+                       return false;\r
+               }\r
+               String version = Config.getInstance().getCurrentConfigFile().getInstallManagerVersion();\r
+               \r
+               Log.log("Current InstallManager version => " + version);\r
+               if (version == null || version.isEmpty()) {\r
+                       return true;\r
+               }\r
+               \r
+               Log.log("Update version => " + pkg.getVersion().toString());\r
+               if (Version.compareTo(new Version(version), pkg.getVersion()) < 0) {\r
+                       Log.log("Update version is higher than current version. So, installmanager will be updated.");\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       public boolean isInstalledInstallManager() {\r
+               Package installedPackage = packageManager.getInstalledPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);\r
+               \r
+               if (installedPackage != null) {\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       public boolean updateInstallManager() {\r
+               Package pkg = packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);\r
+\r
+               if (pkg == null) {\r
+                       return false;\r
+               }\r
+               \r
+               if (installInstallManagerToTemp()) {\r
+                       Log.log("## Success to update the InstallManager, and restart now.");\r
+                       System.out.println("## Success to update the InstallManager, and restart now.");\r
+                       \r
+                       runNewInstallManager();\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       public boolean installInstallManagerToTemp() {\r
+               String imPackage = downloadInstallManager();\r
+               if (imPackage == null) {\r
+                       return false;\r
+               }\r
+               \r
+               if (extractIMPackage(imPackage)) {\r
+                       Log.log("Success to extract updatable InstallManager.");\r
+                       runNewInstallManager();\r
+                       return true;\r
+               } else {\r
+                       Log.err("Fail to extract updatable InstallManager. Cannot execute it.");\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       private String downloadInstallManager() {\r
+               Package pkg = packageManager.getPackageByName(InstallManagerConstants.INSTALLMANAGER_PACKAGE_NAME);\r
+               \r
+               Downloader downloader = new Downloader();\r
+               \r
+               String packagePath = pkg.getFileName();\r
+               String installManagerTempPath = PathUtil.get(PathUtil.getTempDir(), PathUtil.getFileName(packagePath));\r
+               File tempInstaller = new File(installManagerTempPath);\r
+               \r
+               if (tempInstaller.exists()) {\r
+                       if (!PathUtil.remove(installManagerTempPath)) {\r
+                               Log.err("Cannot remove installmanager. => " + tempInstaller);\r
+                       }\r
+               }\r
+               \r
+               try {\r
+                       long size = downloader.download(pkg.getURL(), installManagerTempPath, null);\r
+                       \r
+                       if (size > 0) {\r
+                               return installManagerTempPath;\r
+                       } else {\r
+                               return null;\r
+                       }\r
+               } catch (IMNetworkConnectException e) {\r
+                       Log.ExceptionLog(e);\r
+                       return null;\r
+               } catch (IMNetworkDownloadException e) {\r
+                       Log.ExceptionLog(e);\r
+                       return null;\r
+               }\r
+       }\r
+       \r
+       private boolean extractIMPackage(String imPath) {\r
+               removeIMBinaryInTemp();\r
+               \r
+               SDKPackageFormat format = SDKPackageFormat.createSDKPackageFormat();\r
+               long size = format.unZip(imPath, PathUtil.getTempDir(), null);\r
+               \r
+               if (size > 0) {\r
+                       return true;\r
+               } else {\r
+                       throw new IMFatalException(ErrorCode.CANNOT_UNPACK_PACKAGE);\r
+               }\r
+       }\r
+       \r
+       private void removeIMBinaryInTemp() {\r
+               String tempDir = PathUtil.getTempDir();\r
+               \r
+               File tempDirFile = new File(tempDir);\r
+               \r
+               for (File childFile : tempDirFile.listFiles()) {\r
+                       if (isIMBinary(childFile.getName())) {\r
+                               if (!childFile.delete()) {\r
+                                       Log.err("Cannot delete " + childFile.getAbsolutePath());\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       \r
+       private boolean isIMBinary(String fileName) {\r
+               if (fileName.equals(InstallManagerConstants.INSTALLMANAGERV2_JAR_FILE_NAME)){\r
+                       return true;\r
+               } else {\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       private void runNewInstallManager() {\r
+               File tempIMJarFile = new File(PathUtil.get(\r
+                               PathUtil.getTempDir(), "data", "install-manager",\r
+                               InstallManagerConstants.INSTALLMANAGERV2_JAR_FILE_NAME));\r
+\r
+               if (tempIMJarFile.exists()) {\r
+                       try {\r
+                               ArrayList<String> commands = new ArrayList<String>();\r
+                               \r
+                               String javaHome = System.getProperty("java.home");\r
+                               File java = null;\r
+                               if (Platform.isLinux() || Platform.isMacOS()) {\r
+                                       java = new File(PathUtil.get(javaHome, "bin", "java"));\r
+                               } else if (Platform.isWindows()) {\r
+                                       java = new File(PathUtil.get(javaHome, "bin", "java.exe"));\r
+                               }\r
+                               \r
+                               String forceBitOption = "-d" + System.getProperty("sun.arch.data.model");\r
+\r
+                               String jarPath = PathUtil.get(tempIMJarFile.getAbsolutePath());\r
+                               if (java.exists()) {\r
+                                       commands.add(java.getAbsolutePath());\r
+                               } else {\r
+                                       commands.add("java");\r
+                               }\r
+                               \r
+                               if (Platform.isMacOS()) {\r
+                                       commands.add("-XstartOnFirstThread");\r
+                               }\r
+                               \r
+                               commands.add(forceBitOption);\r
+                               commands.add("-jar");\r
+                               commands.add(jarPath);\r
+                               \r
+                               if (Options.executablePath != null) {\r
+                                       commands.add("-path");\r
+                                       commands.add(Options.executablePath);\r
+                               }\r
+                               \r
+                               String repo = Config.getInstance().getConfigFile().getRepository();\r
+                               if (repo != null & !repo.isEmpty()) {\r
+                                       commands.add("-repository");\r
+                                       commands.add(repo);\r
+                               }\r
+                               \r
+                               String dist = Config.getInstance().getConfigFile().getDistribution();\r
+                               if (repo != null & !repo.isEmpty()) {\r
+                                       commands.add("-distribution");\r
+                                       commands.add(dist);\r
+                               }\r
+                               \r
+                               String proxyHost = Config.getInstance().getConfigFile().getProxyHost();\r
+                               int proxyPort = Config.getInstance().getConfigFile().getProxyPort();\r
+                               if (proxyHost != null & !proxyHost.isEmpty()) {\r
+                                       if (proxyPort > 0) {\r
+                                               commands.add("-proxy");\r
+                                               commands.add(proxyHost + ":" + proxyPort);\r
+                                       }\r
+                               }\r
+                               \r
+                               Config.getInstance().getConfigFile().setInstallManagerVersion(packageManager.getPackageByName("install-manager").getVersion().toString());\r
+                               Config.getInstance().getConfigFile().saveConfig(PathUtil.get(tempIMJarFile.getParent(), "installmanager.conf"));\r
+                               \r
+                               Log.log("Updatable commands => " + commands);\r
+                               \r
+                               ProcessBuilder pb = new ProcessBuilder(commands);\r
+                               pb.directory(tempIMJarFile.getParentFile());\r
+                               pb.start();\r
+                               \r
+                               System.exit(0);\r
+                       } catch (IOException e) {\r
+                               Log.ExceptionLog(e);\r
+                               return;\r
+                       }\r
+               }\r
+       }\r
+}\r