diff --git a/launcher/src/main/java/com/skcraft/launcher/selfupdate/LatestVersionInfo.java b/launcher/src/main/java/com/skcraft/launcher/selfupdate/LatestVersionInfo.java index b299a3c..58f264f 100644 --- a/launcher/src/main/java/com/skcraft/launcher/selfupdate/LatestVersionInfo.java +++ b/launcher/src/main/java/com/skcraft/launcher/selfupdate/LatestVersionInfo.java @@ -15,5 +15,6 @@ public class LatestVersionInfo { private String version; private URL url; + private boolean packed = true; } diff --git a/launcher/src/main/java/com/skcraft/launcher/selfupdate/SelfUpdater.java b/launcher/src/main/java/com/skcraft/launcher/selfupdate/SelfUpdater.java index 4155df6..6f14105 100644 --- a/launcher/src/main/java/com/skcraft/launcher/selfupdate/SelfUpdater.java +++ b/launcher/src/main/java/com/skcraft/launcher/selfupdate/SelfUpdater.java @@ -25,12 +25,14 @@ public class SelfUpdater implements Callable, ProgressObservable { private final Launcher launcher; private final URL url; private final Installer installer; + private final boolean packed; private ProgressObservable progress = new DefaultProgress(0, SharedLocale.tr("updater.updating")); - public SelfUpdater(@NonNull Launcher launcher, @NonNull URL url) { + public SelfUpdater(@NonNull Launcher launcher, @NonNull URL url, boolean packed) { this.launcher = launcher; this.url = url; this.installer = new Installer(launcher.getInstallerDir()); + this.packed = packed; } @Override @@ -38,9 +40,10 @@ public class SelfUpdater implements Callable, ProgressObservable { ExecutorService executor = Executors.newSingleThreadExecutor(); try { + String extension = packed ? ".jar.pack" : ".jar"; File dir = launcher.getLauncherBinariesDir(); - File file = new File(dir, String.valueOf(System.currentTimeMillis()) + ".jar.pack"); - File tempFile = installer.getDownloader().download(url, "", 10000, "launcher.jar.pack"); + File file = new File(dir, System.currentTimeMillis() + extension); + File tempFile = installer.getDownloader().download(url, "", 10000, "launcher" + extension); progress = installer.getDownloader(); installer.download(); diff --git a/launcher/src/main/java/com/skcraft/launcher/selfupdate/UpdateChecker.java b/launcher/src/main/java/com/skcraft/launcher/selfupdate/UpdateChecker.java index 8373916..2acfc1e 100644 --- a/launcher/src/main/java/com/skcraft/launcher/selfupdate/UpdateChecker.java +++ b/launcher/src/main/java/com/skcraft/launcher/selfupdate/UpdateChecker.java @@ -21,7 +21,7 @@ import java.util.concurrent.Callable; * if there is an update to be downloaded. */ @Log -public class UpdateChecker implements Callable { +public class UpdateChecker implements Callable { private final Launcher launcher; @@ -30,7 +30,7 @@ public class UpdateChecker implements Callable { } @Override - public URL call() throws Exception { + public LatestVersionInfo call() throws Exception { try { UpdateChecker.log.info("Checking for update..."); @@ -49,7 +49,7 @@ public class UpdateChecker implements Callable { if (latest.compareTo(current) >= 1) { UpdateChecker.log.info("Update available at " + versionInfo.getUrl()); - return versionInfo.getUrl(); + return versionInfo; } else { UpdateChecker.log.info("No update required."); return null; diff --git a/launcher/src/main/java/com/skcraft/launcher/update/UpdateManager.java b/launcher/src/main/java/com/skcraft/launcher/update/UpdateManager.java index b1a4daa..27ad877 100644 --- a/launcher/src/main/java/com/skcraft/launcher/update/UpdateManager.java +++ b/launcher/src/main/java/com/skcraft/launcher/update/UpdateManager.java @@ -12,6 +12,7 @@ import com.google.common.util.concurrent.ListenableFuture; import com.skcraft.concurrency.ObservableFuture; import com.skcraft.launcher.Launcher; import com.skcraft.launcher.dialog.ProgressDialog; +import com.skcraft.launcher.selfupdate.LatestVersionInfo; import com.skcraft.launcher.selfupdate.SelfUpdater; import com.skcraft.launcher.selfupdate.UpdateChecker; import com.skcraft.launcher.swing.SwingHelper; @@ -31,7 +32,7 @@ public class UpdateManager { @Getter private final SwingPropertyChangeSupport propertySupport = new SwingPropertyChangeSupport(this); private final Launcher launcher; - private URL pendingUpdateUrl; + private LatestVersionInfo pendingUpdate; public UpdateManager(Launcher launcher) { this.launcher = launcher; @@ -46,15 +47,15 @@ public class UpdateManager { } public boolean getPendingUpdate() { - return pendingUpdateUrl != null; + return pendingUpdate != null; } public void checkForUpdate() { - ListenableFuture future = launcher.getExecutor().submit(new UpdateChecker(launcher)); + ListenableFuture future = launcher.getExecutor().submit(new UpdateChecker(launcher)); - Futures.addCallback(future, new FutureCallback() { + Futures.addCallback(future, new FutureCallback() { @Override - public void onSuccess(URL result) { + public void onSuccess(LatestVersionInfo result) { if (result != null) { requestUpdate(result); } @@ -68,10 +69,10 @@ public class UpdateManager { } public void performUpdate(final Window window) { - final URL url = pendingUpdateUrl; + final URL url = pendingUpdate.getUrl(); if (url != null) { - SelfUpdater downloader = new SelfUpdater(launcher, url); + SelfUpdater downloader = new SelfUpdater(launcher, url, pendingUpdate.isPacked()); ObservableFuture future = new ObservableFuture( launcher.getExecutor().submit(downloader), downloader); @@ -79,7 +80,7 @@ public class UpdateManager { @Override public void onSuccess(File result) { propertySupport.firePropertyChange("pendingUpdate", true, false); - UpdateManager.this.pendingUpdateUrl = null; + UpdateManager.this.pendingUpdate = null; SwingHelper.showMessageDialog( window, @@ -101,9 +102,9 @@ public class UpdateManager { } } - private void requestUpdate(URL url) { + private void requestUpdate(LatestVersionInfo url) { propertySupport.firePropertyChange("pendingUpdate", getPendingUpdate(), url != null); - this.pendingUpdateUrl = url; + this.pendingUpdate = url; }