[Title]If you fail to install sdk, remove the target directory
authorshihyun <shihyun@shihyun-Samsung-Desktop-System.(none)>
Thu, 4 Jul 2013 06:26:14 +0000 (15:26 +0900)
committershihyun <shihyun@shihyun-Samsung-Desktop-System.(none)>
Thu, 4 Jul 2013 06:26:14 +0000 (15:26 +0900)
InstallManager_java/src/org/tizen/installmanager/core/InstallManager.java
InstallManager_java/src/org/tizen/installmanager/core/InstallManagerConstants.java
InstallManager_java/src/org/tizen/installmanager/lib/Registry.java
InstallManager_java/src/org/tizen/installmanager/ui/InstallManagerWindow.java
InstallManager_java/src/org/tizen/installmanager/ui/page/SetInstallDirectoryPage.java
InstallManager_java/src/org/tizen/installmanager/ui/page/ViewController.java

index a8ecc17..b1cbaeb 100644 (file)
@@ -123,10 +123,6 @@ public class InstallManager {
                                Log.log("Loading config file failed");
                                throw new IMFatalException("Loading configuration file failed");
                        }
-
-                       if (!Registry.getInstalledPath().isEmpty()) {
-                               mConfig.setTargetDir(Registry.getInstalledPath());
-                       }
                }
        }
        
@@ -704,12 +700,14 @@ public class InstallManager {
                        InstallProgressMonitor monitor) throws IMExitException, IMNetworkException{
                Log.log("InstallManager.install() installable packages : " + installablePackages);
                
-               if (installablePackages == null || targetDir == null) {
+               if (installablePackages == null || targetDir == null || targetDir.isEmpty()) {
                        Log.err("packaegs => " + installablePackages + ", targetDir => "
                                        + targetDir);
                        return false;
                }
                
+               mConfig.setTargetDir(targetDir);
+               
                // download packages from repository
                if (downloadPackages(installablePackages, monitor)) {
                        Log.log("Success to download packages from repository.");
index 38c454b..1596694 100644 (file)
@@ -21,6 +21,14 @@ public class InstallManagerConstants {
        final static public String DESKTOP_SHORTCUT_IMAGE_NAME = getDesktopShortcutImageName();
        final static public String DESKTOP_SHORTCUT_IMAGE_PATH = PathUtil.get("/res", "desktop_directory", DESKTOP_SHORTCUT_IMAGE_NAME);
        
+       //target directory path
+       final static public String WINDOWS_DEFAULT_TARGET_PATH = "C:\\tizen-sdk";
+       final static public String WINDOWS_DEFAULT_DATA_PATH = "C:\\tizen-sdk-data";
+       
+       //sdk configuration file
+       final static public String SDK_INFORMATION_FILE_NAME = "sdk.info";
+       
+       
        static String getInstallManagerBinaryName() {
                if (Platform.isLinux()) {
                        return INSTALLMANAGER_EXECUTALBE_FILE_NAME_FOR_LINUX;
index 9a7e0a3..f955e55 100644 (file)
@@ -40,6 +40,7 @@ import java.util.ArrayList;
 
 import org.tizen.installmanager.core.Config;
 import org.tizen.installmanager.core.IMFatalException;
+import org.tizen.installmanager.core.InstallManagerConstants;
 import org.tizen.installmanager.lib.ErrorController.ErrorCode;
 import org.tizen.installmanager.util.PathUtil;
 
@@ -53,7 +54,6 @@ public class Registry {
        //installed path.
        public static final String REGISTRY_FILE_NAME = "tizensdkpath";
        public static final String MULTI_SDK_FILE_NAME = "multisdkpath";
-       private static final String SDK_INFORMATION_FILE_NAME = "sdk.info";
        private static final String REGISTRY_FILE_PATH = PathUtil.get(
                        Config.INSTALL_MANAGER_CONFIG, REGISTRY_FILE_NAME);
        private static final String OLD_REGISTRY_FILE_PATH = PathUtil.get(
@@ -221,7 +221,7 @@ public class Registry {
                
                String sdkInfoPath = "";
                if (current != null) {
-                       sdkInfoPath = PathUtil.get(current.getParent(), SDK_INFORMATION_FILE_NAME);
+                       sdkInfoPath = PathUtil.get(current.getParent(), InstallManagerConstants.SDK_INFORMATION_FILE_NAME);
                }
                
                File sdkInfoFile = new File(sdkInfoPath);
@@ -441,7 +441,7 @@ public class Registry {
                        throw new IMFatalException(ErrorCode.INVALID_INSTALL_PATH);
                }
 
-               String sdkInfoPath = PathUtil.get(installPath, SDK_INFORMATION_FILE_NAME);
+               String sdkInfoPath = PathUtil.get(installPath, InstallManagerConstants.SDK_INFORMATION_FILE_NAME);
                String target = INSTALLED_PATH_KEY + REGISTRY_SEPERATOR + installPath;
                String workSpace = SDK_DATA_PATH_KEY + REGISTRY_SEPERATOR + sdkWorkSpacePath;
 
index 04a46a7..9ea256a 100644 (file)
@@ -29,6 +29,7 @@
 package org.tizen.installmanager.ui;
 
 import java.io.IOException;
+import java.nio.channels.OverlappingFileLockException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Enumeration;
@@ -282,10 +283,9 @@ public class InstallManagerWindow extends ApplicationWindow {
                                                        "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) {
-                                       btnClose.setText("close");
-                                       if (Documents.isChecked()) {
-                                               Documents.showChangeLog(); // show the change log(history)
-                                       }
+                                       controller.showChangeLog();
+                                       controller.cleanUpTargetDirectory();
+                                       
                                        result = MessageBoxDlg.YES;
                                } else {
                                        result = MessageBoxDlg.showDlg(e.display.getActiveShell(),
@@ -463,6 +463,10 @@ public class InstallManagerWindow extends ApplicationWindow {
                                        Config.USER_CONFIG_HOME_PATH = compositeSetInstallDirectoryPage.getSDKWorkSpacePath();
                                        Registry.sdkWorkSpacePath = controller.getSDKWorkSpacePath();
                                        Registry.targetPath = controller.getInstallPath();
+                                       Registry.saveSDKInfo(Registry.targetPath);
+                                       
+                                       
+                                       
                                        
                                        InstallManager.getInstance().initPackageList();
 
index 264c1cf..4901533 100644 (file)
@@ -47,6 +47,7 @@ import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 import org.tizen.installmanager.core.Config;
 import org.tizen.installmanager.core.IMFatalException;
+import org.tizen.installmanager.core.InstallManagerConstants;
 import org.tizen.installmanager.lib.IFileSystemInformation;
 import org.tizen.installmanager.lib.Log;
 import org.tizen.installmanager.lib.Platform;
@@ -69,8 +70,6 @@ public class SetInstallDirectoryPage extends PageTemplate {
        private static final String RSC_PATH_IMAGE = RESOURCE_PATH + "/install_manager_graphicmotif_002.png";
        private static final String STRING_TITLE = "Location";
        private static final String STRING_SUBTITLE = "Select the installation location.";
-       private static final String WINDOWS_DEFAULT_TARGET_PATH = "C:\\tizen-sdk";
-       private static final String WINDOWS_DEFAULT_DATA_PATH = "C:\\tizen-sdk-data";
 
        private Text installDirectoryText;
        private Label installDirectoryLabel;
@@ -107,7 +106,7 @@ public class SetInstallDirectoryPage extends PageTemplate {
                if (Platform.isLinux() || Platform.isMacOS()) {
                        installDirectoryText.setText(System.getProperty("user.home") + File.separator + Config.SDK_DIRECTORY);
                } else if (Platform.isWindows()) {
-                       installDirectoryText.setText(WINDOWS_DEFAULT_TARGET_PATH);
+                       installDirectoryText.setText(InstallManagerConstants.WINDOWS_DEFAULT_TARGET_PATH);
                } else {
                        throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);
                }
@@ -119,9 +118,9 @@ public class SetInstallDirectoryPage extends PageTemplate {
        private void setConfigDirectory() {
                if (Platform.isLinux() || Platform.isMacOS()) {
                        sdkWorkSpaceText.setText(Config.getConfigHome());
-               } else {
+               } else if (Platform.isWindows()){
                        if (Config.isNewPackageServer) {
-                               sdkWorkSpaceText.setText(WINDOWS_DEFAULT_DATA_PATH);                            
+                               sdkWorkSpaceText.setText(InstallManagerConstants.WINDOWS_DEFAULT_DATA_PATH);                            
                        } else {
                                sdkWorkSpaceText.setText(Config.getConfigHome());
                        }
index 6bbf3c4..3773efd 100644 (file)
 package org.tizen.installmanager.ui.page;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.nio.channels.OverlappingFileLockException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -43,6 +48,7 @@ import org.tizen.installmanager.core.InstallManagerConstants;
 import org.tizen.installmanager.core.Options;
 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;
@@ -78,6 +84,9 @@ public class ViewController {
        private InstallManager installManager;
        private PackageManager packageManager;
        private SDKExtensionInfo sdkExtensionInfo;
+       
+       private FileLock lock = null;
+       private FileChannel channel = null;
 
        /**
         * Initialize objects which need to install.
@@ -304,6 +313,8 @@ public class ViewController {
                        installablePackages = getInstallablePackages(installList);
                }
                
+               Registry.saveSDKInfo(targetPath);
+               
                boolean bResult = false;
                while(true) {
                        try {
@@ -311,26 +322,33 @@ public class ViewController {
                                break;
                        } catch (IMNetworkException e) {
                                Log.ExceptionLog(e);
+                               showRetryDialog(e.getMessage());
                                
-                               //retry dialog.
-                               String errorMsg = e.getMessage() + "\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(e.getMessage());
-                               } else {//retry
-                                       continue;
-                               }
+                               continue;
+                       } catch (Exception e) {
+                               Log.ExceptionLog(e);
+                               throw new IMFatalException(e.getMessage());
                        }
                }
                
+               releaseTargetDirectory();
                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.
@@ -438,6 +456,41 @@ public class ViewController {
                return makeTreeItem(metaPackageSet);
        }
        
+       public void lockTargetDirectory(String targetDir) throws IOException{
+               File targetFile = new File(PathUtil.get(targetDir, InstallManagerConstants.SDK_INFORMATION_FILE_NAME));
+               
+               if (!targetFile.exists()) {
+                       return;
+               }
+               
+               try {
+                       channel = new RandomAccessFile(targetFile, "rw").getChannel();
+               } catch (FileNotFoundException e) {
+                       Log.ExceptionLog(e);
+                       return;
+               }
+               
+               lock = channel.tryLock();               
+       }
+       
+       public void releaseTargetDirectory() {
+               try {
+                       if (lock != null) {
+                               lock.release();
+                       }
+               } catch (IOException e) {
+                       Log.ExceptionLog(e);
+               }
+               
+               try {
+                       if (channel != null) {
+                               channel.close();
+                       }
+               } catch (IOException e) {
+                       Log.ExceptionLog(e);
+               }
+       }
+       
        /**
         * Make tree item from package set.
         * @param pkgSet
@@ -717,6 +770,25 @@ public class ViewController {
                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);