Пример #1
0
  public LauncherVersion fetchRemoteVersion() {
    try {
      String versionJson = Downloader.create(removeVersionURL).downloadToString();

      return LauncherVersion.fromJson(versionJson);
    } catch (Throwable e) {
      Logger.warning("Unable to fetch remote version: %s", e.getMessage());
      e.printStackTrace();
    }

    return null;
  }
Пример #2
0
  public static void main(String args[]) throws Exception {
    if (args.length < 2) {
      System.out.println("Invalid usage!");
      return;
    }

    final File currentPath = PlatformUtils.getApplicationPath("mualauncher");
    Logger.initialize(new File(currentPath, "updater.log"));

    File tempFile = new File(args[0]);
    File launcherFile = new File(args[1]);

    try {
      Logger.info("Removing old version");

      if (!launcherFile.delete()) {
        throw new IOException("Unable to remove old file " + launcherFile);
      }

      Logger.info("Copying new launcher from %s", tempFile.getAbsolutePath());
      FileUtils.copyFile(tempFile, launcherFile);
    } catch (IOException e) {
      Logger.info("Autoupdate failed: %s ", e.getMessage());
    }

    // Start launcher
    Logger.info("Starting launcher %s", launcherFile.getAbsolutePath());

    PlatformUtils.launchJavaApplication(
        launcherFile.getAbsolutePath(), Launcher.class.getCanonicalName(), "updated");

    Logger.info("Update done!");

    System.exit(0);
  }
Пример #3
0
  public void updateLauncher() {
    Logger.info("Checking lastest version");

    LauncherVersion localVersion = LauncherVersion.getLocalVersion();
    Logger.info("Local version is %s", localVersion);

    LauncherVersion remoteVersion = fetchRemoteVersion();
    Logger.info("Remote version is %s", remoteVersion);

    if (localVersion.compareTo(remoteVersion) >= 0) { // already lastest version
      Logger.info("Already lastest version (%s/%s", localVersion, remoteVersion);
      return;
    }

    Logger.info("Performing update to %s", remoteVersion);

    try {
      File localBinary = getLocalFile();
      String format = getExtension(localBinary);

      Logger.info("Local file: %s", localBinary.getAbsolutePath());

      Logger.info("Downloading update");

      File tempUpdater = downloadUpdate(remoteVersion, format);

      Logger.info("Downloaded update to %s", tempUpdater.getAbsolutePath());

      Logger.info("Launching self-updater");
      String updater = tempUpdater.getAbsolutePath();

      PlatformUtils.launchJavaApplication(
          updater,
          LauncherUpdater.class.getCanonicalName(),
          updater,
          localBinary.getAbsolutePath());

      Logger.info("Now exiting to unlock file");

      System.exit(0);

      Logger.info("If you are watching this you are pretty much a pirate now!");
    } catch (IOException e) {
      Logger.error("Error during launcher update: ", e.getMessage());
    }
  }