Search in sources :

Example 1 with TechnicRelauncher

use of net.technicpack.launcher.autoupdate.TechnicRelauncher in project LauncherV3 by TechnicPack.

the class LauncherMain method main.

public static void main(String[] args) {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception ex) {
        Utils.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
    }
    ToolTipManager.sharedInstance().setDismissDelay(Integer.MAX_VALUE);
    StartupParameters params = new StartupParameters(args);
    try {
        new JCommander(params, args);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    TechnicSettings settings = null;
    try {
        settings = SettingsFactory.buildSettingsObject(Relauncher.getRunningPath(LauncherMain.class), params.isMover());
    } catch (UnsupportedEncodingException ex) {
        ex.printStackTrace();
    }
    if (settings == null) {
        ResourceLoader installerResources = new ResourceLoader(null, "net", "technicpack", "launcher", "resources");
        installerResources.setSupportedLanguages(supportedLanguages);
        installerResources.setLocale(ResourceLoader.DEFAULT_LOCALE);
        InstallerFrame dialog = new InstallerFrame(installerResources, params);
        dialog.setVisible(true);
        return;
    }
    LauncherDirectories directories = new TechnicLauncherDirectories(settings.getTechnicRoot());
    ResourceLoader resources = new ResourceLoader(directories, "net", "technicpack", "launcher", "resources");
    resources.setSupportedLanguages(supportedLanguages);
    resources.setLocale(settings.getLanguageCode());
    IBuildNumber buildNumber = null;
    if (params.getBuildNumber() != null && !params.getBuildNumber().isEmpty())
        buildNumber = new CommandLineBuildNumber(params);
    else
        buildNumber = new VersionFileBuildNumber(resources);
    setupLogging(directories, resources, buildNumber);
    String launcherBuild = buildNumber.getBuildNumber();
    int build = -1;
    try {
        build = Integer.parseInt((new VersionFileBuildNumber(resources)).getBuildNumber());
    } catch (NumberFormatException ex) {
    // This is probably a debug build or something, build number is invalid
    }
    Relauncher launcher = new TechnicRelauncher(new HttpUpdateStream("http://api.technicpack.net/launcher/"), settings.getBuildStream() + "4", build, directories, resources, params);
    try {
        if (launcher.runAutoUpdater())
            startLauncher(settings, params, directories, resources, buildNumber);
    } catch (InterruptedException e) {
    // Canceled by user
    } catch (DownloadException e) {
    // JOptionPane.showMessageDialog(null, resources.getString("launcher.updateerror.download", pack.getDisplayName(), e.getMessage()), resources.getString("launcher.installerror.title"), JOptionPane.WARNING_MESSAGE);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : VersionFileBuildNumber(net.technicpack.launcher.autoupdate.VersionFileBuildNumber) ResourceLoader(net.technicpack.ui.lang.ResourceLoader) IBuildNumber(net.technicpack.autoupdate.IBuildNumber) LauncherDirectories(net.technicpack.launchercore.install.LauncherDirectories) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DownloadException(net.technicpack.launchercore.exception.DownloadException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) HttpUpdateStream(net.technicpack.autoupdate.http.HttpUpdateStream) JCommander(com.beust.jcommander.JCommander) Relauncher(net.technicpack.autoupdate.Relauncher) TechnicRelauncher(net.technicpack.launcher.autoupdate.TechnicRelauncher) DownloadException(net.technicpack.launchercore.exception.DownloadException) TechnicRelauncher(net.technicpack.launcher.autoupdate.TechnicRelauncher) TechnicSettings(net.technicpack.launcher.settings.TechnicSettings) InstallerFrame(net.technicpack.launcher.ui.InstallerFrame) StartupParameters(net.technicpack.launcher.settings.StartupParameters) CommandLineBuildNumber(net.technicpack.launcher.autoupdate.CommandLineBuildNumber)

Example 2 with TechnicRelauncher

use of net.technicpack.launcher.autoupdate.TechnicRelauncher 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)

Example 3 with TechnicRelauncher

use of net.technicpack.launcher.autoupdate.TechnicRelauncher in project LauncherV3 by TechnicPack.

the class InstallerFrame method standardInstall.

protected void standardInstall() {
    glassPane.setVisible(true);
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            File oldSettings = settings.getFilePath();
            File newSettings = new File(OperatingSystem.getOperatingSystem().getUserDirectoryForApp("technic"), "settings.json");
            if (oldSettings.exists() && !oldSettings.getAbsolutePath().equals(newSettings.getAbsolutePath())) {
                oldSettings.delete();
            }
            File oldRoot = settings.getTechnicRoot();
            File newRoot = new File(standardInstallDir.getText());
            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.setFilePath(newSettings);
            if (settings.isPortable() || rootHasChanged || !standardInstallDir.getText().equals(OperatingSystem.getOperatingSystem().getUserDirectoryForApp("technic").getAbsolutePath()))
                settings.installTo(standardInstallDir.getText());
            settings.getTechnicRoot();
            settings.setLanguageCode(((LanguageItem) standardLanguages.getSelectedItem()).getLangCode());
            settings.save();
            VersionFileBuildNumber buildNumber = new VersionFileBuildNumber(resources);
            Utils.sendTracking("installLauncher", "standard", buildNumber.getBuildNumber(), settings.getClientId());
            Relauncher relauncher = new TechnicRelauncher(null, settings.getBuildStream(), 0, new TechnicLauncherDirectories(settings.getTechnicRoot()), resources, params);
            try {
                String currentPath = relauncher.getRunningPath();
                relauncher.launch(currentPath, params.getArgs());
                System.exit(0);
                return;
            } catch (UnsupportedEncodingException ex) {
                ex.printStackTrace();
                return;
            }
        }
    });
    thread.start();
}
Also used : VersionFileBuildNumber(net.technicpack.launcher.autoupdate.VersionFileBuildNumber) TechnicRelauncher(net.technicpack.launcher.autoupdate.TechnicRelauncher) Relauncher(net.technicpack.autoupdate.Relauncher) TechnicLauncherDirectories(net.technicpack.launcher.io.TechnicLauncherDirectories) TechnicRelauncher(net.technicpack.launcher.autoupdate.TechnicRelauncher) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) LanguageItem(net.technicpack.ui.listitems.LanguageItem) File(java.io.File)

Aggregations

IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Relauncher (net.technicpack.autoupdate.Relauncher)3 TechnicRelauncher (net.technicpack.launcher.autoupdate.TechnicRelauncher)3 VersionFileBuildNumber (net.technicpack.launcher.autoupdate.VersionFileBuildNumber)3 File (java.io.File)2 TechnicLauncherDirectories (net.technicpack.launcher.io.TechnicLauncherDirectories)2 LanguageItem (net.technicpack.ui.listitems.LanguageItem)2 JCommander (com.beust.jcommander.JCommander)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 IBuildNumber (net.technicpack.autoupdate.IBuildNumber)1 HttpUpdateStream (net.technicpack.autoupdate.http.HttpUpdateStream)1 MoveLauncherPackage (net.technicpack.autoupdate.tasks.MoveLauncherPackage)1 CommandLineBuildNumber (net.technicpack.launcher.autoupdate.CommandLineBuildNumber)1 StartupParameters (net.technicpack.launcher.settings.StartupParameters)1 TechnicSettings (net.technicpack.launcher.settings.TechnicSettings)1 InstallerFrame (net.technicpack.launcher.ui.InstallerFrame)1 DownloadException (net.technicpack.launchercore.exception.DownloadException)1 LauncherDirectories (net.technicpack.launchercore.install.LauncherDirectories)1