1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2025-01-20 21:21:19 +01:00

Support unpacked jars in self-updater

This commit is contained in:
Henry Le Grys 2021-02-02 03:36:01 +00:00
parent 662162392e
commit ffd3e54fc8
4 changed files with 21 additions and 16 deletions

View File

@ -15,5 +15,6 @@ public class LatestVersionInfo {
private String version;
private URL url;
private boolean packed = true;
}

View File

@ -25,12 +25,14 @@ public class SelfUpdater implements Callable<File>, 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<File>, 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();

View File

@ -21,7 +21,7 @@ import java.util.concurrent.Callable;
* if there is an update to be downloaded.
*/
@Log
public class UpdateChecker implements Callable<URL> {
public class UpdateChecker implements Callable<LatestVersionInfo> {
private final Launcher launcher;
@ -30,7 +30,7 @@ public class UpdateChecker implements Callable<URL> {
}
@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<URL> {
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;

View File

@ -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<URL> future = launcher.getExecutor().submit(new UpdateChecker(launcher));
ListenableFuture<LatestVersionInfo> future = launcher.getExecutor().submit(new UpdateChecker(launcher));
Futures.addCallback(future, new FutureCallback<URL>() {
Futures.addCallback(future, new FutureCallback<LatestVersionInfo>() {
@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<File> future = new ObservableFuture<File>(
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;
}