Search in sources :

Example 1 with MoveLauncherPackage

use of net.technicpack.autoupdate.tasks.MoveLauncherPackage in project LauncherV3 by TechnicPack.

the class InstallerFrame method portableInstall.

protected void portableInstall() {
    String targetPath = null;
    final Relauncher relauncher = new TechnicRelauncher(null, settings.getBuildStream(), 0, new TechnicLauncherDirectories(settings.getTechnicRoot()), resources, params);
    try {
        String currentPath = relauncher.getRunningPath();
        String launcher = (currentPath.endsWith(".exe")) ? "TechnicLauncher.exe" : "TechnicLauncher.jar";
        targetPath = new File(portableInstallDir.getText(), launcher).getAbsolutePath();
        File targetExe = new File(portableInstallDir.getText(), launcher);
        if (!(new File(currentPath).equals(targetExe))) {
            if (targetExe.exists() && !targetExe.delete()) {
                JOptionPane.showMessageDialog(this, resources.getString("installer.portable.replacefailed"), resources.getString("installer.portable.replacefailtitle"), JOptionPane.ERROR_MESSAGE);
                return;
            }
            MoveLauncherPackage moveTask = new MoveLauncherPackage("", targetExe, relauncher);
            moveTask.runTask(null);
        }
    } catch (UnsupportedEncodingException ex) {
        ex.printStackTrace();
        return;
    } catch (IOException ex) {
        ex.printStackTrace();
        return;
    } catch (InterruptedException ex) {
        ex.printStackTrace();
        return;
    }
    glassPane.setVisible(true);
    final String threadTargetPath = targetPath;
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            File oldRoot = settings.getTechnicRoot();
            File newRoot = new File(portableInstallDir.getText(), "technic");
            File oldSettingsFile = settings.getFilePath();
            File newSettingsFile = new File(newRoot, "settings.json");
            if (oldSettingsFile.exists() && !oldSettingsFile.getAbsolutePath().equals(newSettingsFile.getAbsolutePath()))
                oldSettingsFile.delete();
            boolean rootHasChanged = false;
            if (oldRoot.exists() && !oldRoot.getAbsolutePath().equals(newRoot.getAbsolutePath())) {
                rootHasChanged = true;
                try {
                    if (!newRoot.exists())
                        newRoot.mkdirs();
                    FileUtils.copyDirectory(oldRoot, newRoot);
                    FileUtils.deleteDirectory(oldRoot);
                } catch (IOException ex) {
                    Utils.getLogger().log(Level.SEVERE, "Copying install to new directory failed: ", ex);
                }
            }
            settings.setPortable();
            settings.setFilePath(newSettingsFile);
            settings.getTechnicRoot();
            settings.setLanguageCode(((LanguageItem) portableLanguages.getSelectedItem()).getLangCode());
            settings.save();
            VersionFileBuildNumber buildNumber = new VersionFileBuildNumber(resources);
            Utils.sendTracking("installLauncher", "portable", buildNumber.getBuildNumber(), settings.getClientId());
            relauncher.launch(threadTargetPath, params.getArgs());
            System.exit(0);
        }
    });
    thread.start();
}
Also used : VersionFileBuildNumber(net.technicpack.launcher.autoupdate.VersionFileBuildNumber) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) MoveLauncherPackage(net.technicpack.autoupdate.tasks.MoveLauncherPackage) TechnicRelauncher(net.technicpack.launcher.autoupdate.TechnicRelauncher) Relauncher(net.technicpack.autoupdate.Relauncher) TechnicLauncherDirectories(net.technicpack.launcher.io.TechnicLauncherDirectories) TechnicRelauncher(net.technicpack.launcher.autoupdate.TechnicRelauncher) LanguageItem(net.technicpack.ui.listitems.LanguageItem) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Relauncher (net.technicpack.autoupdate.Relauncher)1 MoveLauncherPackage (net.technicpack.autoupdate.tasks.MoveLauncherPackage)1 TechnicRelauncher (net.technicpack.launcher.autoupdate.TechnicRelauncher)1 VersionFileBuildNumber (net.technicpack.launcher.autoupdate.VersionFileBuildNumber)1 TechnicLauncherDirectories (net.technicpack.launcher.io.TechnicLauncherDirectories)1 LanguageItem (net.technicpack.ui.listitems.LanguageItem)1