mirror of
https://github.com/SKCraft/Launcher.git
synced 2025-01-21 21:31:32 +01:00
Support unpacked jars in self-updater
This commit is contained in:
parent
662162392e
commit
ffd3e54fc8
@ -15,5 +15,6 @@ public class LatestVersionInfo {
|
|||||||
|
|
||||||
private String version;
|
private String version;
|
||||||
private URL url;
|
private URL url;
|
||||||
|
private boolean packed = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,14 @@ public class SelfUpdater implements Callable<File>, ProgressObservable {
|
|||||||
private final Launcher launcher;
|
private final Launcher launcher;
|
||||||
private final URL url;
|
private final URL url;
|
||||||
private final Installer installer;
|
private final Installer installer;
|
||||||
|
private final boolean packed;
|
||||||
private ProgressObservable progress = new DefaultProgress(0, SharedLocale.tr("updater.updating"));
|
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.launcher = launcher;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.installer = new Installer(launcher.getInstallerDir());
|
this.installer = new Installer(launcher.getInstallerDir());
|
||||||
|
this.packed = packed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -38,9 +40,10 @@ public class SelfUpdater implements Callable<File>, ProgressObservable {
|
|||||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
String extension = packed ? ".jar.pack" : ".jar";
|
||||||
File dir = launcher.getLauncherBinariesDir();
|
File dir = launcher.getLauncherBinariesDir();
|
||||||
File file = new File(dir, String.valueOf(System.currentTimeMillis()) + ".jar.pack");
|
File file = new File(dir, System.currentTimeMillis() + extension);
|
||||||
File tempFile = installer.getDownloader().download(url, "", 10000, "launcher.jar.pack");
|
File tempFile = installer.getDownloader().download(url, "", 10000, "launcher" + extension);
|
||||||
|
|
||||||
progress = installer.getDownloader();
|
progress = installer.getDownloader();
|
||||||
installer.download();
|
installer.download();
|
||||||
|
@ -21,7 +21,7 @@ import java.util.concurrent.Callable;
|
|||||||
* if there is an update to be downloaded.
|
* if there is an update to be downloaded.
|
||||||
*/
|
*/
|
||||||
@Log
|
@Log
|
||||||
public class UpdateChecker implements Callable<URL> {
|
public class UpdateChecker implements Callable<LatestVersionInfo> {
|
||||||
|
|
||||||
private final Launcher launcher;
|
private final Launcher launcher;
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ public class UpdateChecker implements Callable<URL> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URL call() throws Exception {
|
public LatestVersionInfo call() throws Exception {
|
||||||
try {
|
try {
|
||||||
UpdateChecker.log.info("Checking for update...");
|
UpdateChecker.log.info("Checking for update...");
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ public class UpdateChecker implements Callable<URL> {
|
|||||||
|
|
||||||
if (latest.compareTo(current) >= 1) {
|
if (latest.compareTo(current) >= 1) {
|
||||||
UpdateChecker.log.info("Update available at " + versionInfo.getUrl());
|
UpdateChecker.log.info("Update available at " + versionInfo.getUrl());
|
||||||
return versionInfo.getUrl();
|
return versionInfo;
|
||||||
} else {
|
} else {
|
||||||
UpdateChecker.log.info("No update required.");
|
UpdateChecker.log.info("No update required.");
|
||||||
return null;
|
return null;
|
||||||
|
@ -12,6 +12,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||||||
import com.skcraft.concurrency.ObservableFuture;
|
import com.skcraft.concurrency.ObservableFuture;
|
||||||
import com.skcraft.launcher.Launcher;
|
import com.skcraft.launcher.Launcher;
|
||||||
import com.skcraft.launcher.dialog.ProgressDialog;
|
import com.skcraft.launcher.dialog.ProgressDialog;
|
||||||
|
import com.skcraft.launcher.selfupdate.LatestVersionInfo;
|
||||||
import com.skcraft.launcher.selfupdate.SelfUpdater;
|
import com.skcraft.launcher.selfupdate.SelfUpdater;
|
||||||
import com.skcraft.launcher.selfupdate.UpdateChecker;
|
import com.skcraft.launcher.selfupdate.UpdateChecker;
|
||||||
import com.skcraft.launcher.swing.SwingHelper;
|
import com.skcraft.launcher.swing.SwingHelper;
|
||||||
@ -31,7 +32,7 @@ public class UpdateManager {
|
|||||||
@Getter
|
@Getter
|
||||||
private final SwingPropertyChangeSupport propertySupport = new SwingPropertyChangeSupport(this);
|
private final SwingPropertyChangeSupport propertySupport = new SwingPropertyChangeSupport(this);
|
||||||
private final Launcher launcher;
|
private final Launcher launcher;
|
||||||
private URL pendingUpdateUrl;
|
private LatestVersionInfo pendingUpdate;
|
||||||
|
|
||||||
public UpdateManager(Launcher launcher) {
|
public UpdateManager(Launcher launcher) {
|
||||||
this.launcher = launcher;
|
this.launcher = launcher;
|
||||||
@ -46,15 +47,15 @@ public class UpdateManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean getPendingUpdate() {
|
public boolean getPendingUpdate() {
|
||||||
return pendingUpdateUrl != null;
|
return pendingUpdate != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkForUpdate() {
|
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
|
@Override
|
||||||
public void onSuccess(URL result) {
|
public void onSuccess(LatestVersionInfo result) {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
requestUpdate(result);
|
requestUpdate(result);
|
||||||
}
|
}
|
||||||
@ -68,10 +69,10 @@ public class UpdateManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void performUpdate(final Window window) {
|
public void performUpdate(final Window window) {
|
||||||
final URL url = pendingUpdateUrl;
|
final URL url = pendingUpdate.getUrl();
|
||||||
|
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
SelfUpdater downloader = new SelfUpdater(launcher, url);
|
SelfUpdater downloader = new SelfUpdater(launcher, url, pendingUpdate.isPacked());
|
||||||
ObservableFuture<File> future = new ObservableFuture<File>(
|
ObservableFuture<File> future = new ObservableFuture<File>(
|
||||||
launcher.getExecutor().submit(downloader), downloader);
|
launcher.getExecutor().submit(downloader), downloader);
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ public class UpdateManager {
|
|||||||
@Override
|
@Override
|
||||||
public void onSuccess(File result) {
|
public void onSuccess(File result) {
|
||||||
propertySupport.firePropertyChange("pendingUpdate", true, false);
|
propertySupport.firePropertyChange("pendingUpdate", true, false);
|
||||||
UpdateManager.this.pendingUpdateUrl = null;
|
UpdateManager.this.pendingUpdate = null;
|
||||||
|
|
||||||
SwingHelper.showMessageDialog(
|
SwingHelper.showMessageDialog(
|
||||||
window,
|
window,
|
||||||
@ -101,9 +102,9 @@ public class UpdateManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestUpdate(URL url) {
|
private void requestUpdate(LatestVersionInfo url) {
|
||||||
propertySupport.firePropertyChange("pendingUpdate", getPendingUpdate(), url != null);
|
propertySupport.firePropertyChange("pendingUpdate", getPendingUpdate(), url != null);
|
||||||
this.pendingUpdateUrl = url;
|
this.pendingUpdate = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user