public File downloadUpdate(LauncherVersion remoteVersion, String format) throws IOException {
    if (remoteVersion.getSource() == null) { // malformed file, or local version
      throw new RuntimeException("Invalid remote version: source is null");
    }

    // check current format

    String remoteURL = remoteVersion.getSource() + format;

    String fileName =
        "mualauncher_" + remoteVersion.getVersion() + "_" + remoteVersion.getBuild() + "-";

    File temporaryFile = File.createTempFile(fileName, format);

    DownloadAdapter downloader = Downloader.create(remoteURL);

    DownloadWindow window = new DownloadWindow(Resources.string("selfupdate_title"));

    downloader.setDownloadListener(window);

    downloader.downloadToFile(temporaryFile);

    window.dispose(); // not needed anymore

    return temporaryFile;
  }
  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());
    }
  }
  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;
  }