Show error for wrong wrapper or java version before trying to update
This commit is contained in:
parent
0b65231175
commit
2c30e2e76a
|
@ -22,8 +22,8 @@ public class Updater {
|
|||
private static final String ARTIFACTS_URL = "https://pages.frohnmeyer-wds.de/JfMods/Inceptum/artifacts/";
|
||||
private static final String STABLE_URL = "https://pages.frohnmeyer-wds.de/JfMods/Inceptum/stable/";
|
||||
|
||||
public static UpdateMetadata getUpdate() {
|
||||
return Updater.check(InceptumConfig.channel, true, channel -> {
|
||||
public static UpdateMetadata getUpdate(boolean versionCompare, boolean checkEnv) throws UpdateCheckException {
|
||||
return Updater.check(InceptumConfig.channel, versionCompare, checkEnv, channel -> {
|
||||
Utils.LOGGER.error("No stable version was found, switching to experimental channel");
|
||||
InceptumConfig.channel = channel;
|
||||
InceptumConfig.saveConfig();
|
||||
|
@ -31,14 +31,6 @@ public class Updater {
|
|||
}
|
||||
|
||||
public static void update(UpdateMetadata source, boolean relaunch) throws IOException, URISyntaxException {
|
||||
if (Runtime.version().feature() < source.jvm) {
|
||||
throw new OutdatedException("A newer JVM version is required for the current build of Inceptum. Please update!");
|
||||
} else if (source.wrapperVersion > BuildMetadata.WRAPPER_VERSION) {
|
||||
throw new OutdatedException("The current build of Inceptum requires a newer wrapper version. Please update!");
|
||||
} else if (source.wrapperVersion < BuildMetadata.WRAPPER_VERSION) {
|
||||
throw new OutdatedException("The current build of Inceptum requires an older wrapper version. Please update!");
|
||||
}
|
||||
|
||||
Utils.LOGGER.info("Downloading version " + source.version);
|
||||
|
||||
WrapperConfig config = new WrapperConfig();
|
||||
|
@ -146,7 +138,7 @@ public class Updater {
|
|||
throw e;
|
||||
}
|
||||
|
||||
public static @Nullable UpdateMetadata check(UpdateChannel channel, boolean versionCompare, Consumer<UpdateChannel> channelInvalid) {
|
||||
public static @Nullable UpdateMetadata check(UpdateChannel channel, boolean versionCompare, boolean checkEnv, Consumer<UpdateChannel> channelInvalid) throws UpdateCheckException {
|
||||
try {
|
||||
UpdateMetadata experimental = Net.downloadObject(ARTIFACTS_URL + "version.json", GC_UpdateMetadata::read);
|
||||
UpdateMetadata stable = null;
|
||||
|
@ -161,10 +153,9 @@ public class Updater {
|
|||
case CI -> experimental;
|
||||
case Stable -> stable;
|
||||
};
|
||||
if (info.jvm > Runtime.version().feature()) {
|
||||
//TODO visual indication for this
|
||||
Utils.LOGGER.error("A newer JVM is required to use the latest inceptum version. Please update!");
|
||||
return null;
|
||||
if (checkEnv) {
|
||||
if (info.jvm > Runtime.version().feature()) throw new UpdateCheckException("A newer JVM is required to use the latest inceptum version. Please update!", "Outdated Java");
|
||||
if (info.wrapperVersion != BuildMetadata.WRAPPER_VERSION) throw new UpdateCheckException("A different version of the Inceptum Wrapper is required for this update!", "Mismatched Wrapper");
|
||||
}
|
||||
if (versionCompare) {
|
||||
Utils.LOGGER.info("Latest version is " + info.version + ", current is " + BuildMetadata.VERSION);
|
||||
|
@ -186,4 +177,15 @@ public class Updater {
|
|||
case Stable -> STABLE_URL;
|
||||
} + "/Inceptum-" + Utils.getCurrentFlavor() + ".jar";
|
||||
}
|
||||
|
||||
public static class UpdateCheckException extends Exception {
|
||||
public final String message;
|
||||
public final String title;
|
||||
|
||||
public UpdateCheckException(String message, String title) {
|
||||
super(message);
|
||||
this.message = message;
|
||||
this.title = title;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,19 +30,25 @@ public class UpdateCheckCommand extends Command {
|
|||
Utils.LOGGER.error("Automatic updates are not supported without the wrapper");
|
||||
return;
|
||||
}
|
||||
UpdateMetadata updateUrl = BuildMetadata.IS_PUBLIC ? Updater.getUpdate() : null;
|
||||
if (updateUrl == null) {
|
||||
UpdateMetadata update;
|
||||
try {
|
||||
update = BuildMetadata.IS_PUBLIC ? Updater.getUpdate(true, true) : null;
|
||||
} catch (Updater.UpdateCheckException e) {
|
||||
Utils.LOGGER.error("Latest update is not compatible: " + e.message);
|
||||
return;
|
||||
}
|
||||
if (update == null) {
|
||||
Utils.LOGGER.info("No update was found");
|
||||
} else {
|
||||
if (install) {
|
||||
Utils.LOGGER.info("Installing from " + updateUrl);
|
||||
Utils.LOGGER.info("Installing from " + update);
|
||||
try {
|
||||
Updater.update(updateUrl, false);
|
||||
Updater.update(update, false);
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
Utils.LOGGER.error("Could not download update", e);
|
||||
}
|
||||
} else {
|
||||
Utils.LOGGER.info("An update was found: " + updateUrl);
|
||||
Utils.LOGGER.info("An update was found: " + update);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,13 @@ public class GuiMain {
|
|||
|
||||
public static void showGui() {
|
||||
Logger.registerFactory(name -> new CompoundLogger(name, InceptumEnvironmentInitializer.defaultFactory(name), MEMLOG));
|
||||
UpdateMetadata update = BuildMetadata.IS_PUBLIC ? Updater.getUpdate() : null;
|
||||
UpdateMetadata update = null;
|
||||
Updater.UpdateCheckException updateCheckFail = null;
|
||||
try {
|
||||
update = BuildMetadata.IS_PUBLIC ? Updater.getUpdate(true, true) : null;
|
||||
} catch (Updater.UpdateCheckException e) {
|
||||
updateCheckFail = e;
|
||||
}
|
||||
AccountManager.loadAccounts();
|
||||
Utils.LOGGER.info("Initializing UI");
|
||||
try {
|
||||
|
@ -64,11 +70,13 @@ public class GuiMain {
|
|||
}
|
||||
init();
|
||||
if (update == null) {
|
||||
if (updateCheckFail != null) LauncherEnv.showError(updateCheckFail.message, updateCheckFail.title);
|
||||
WINDOWS.add(new MainWindow());
|
||||
} else if (MetaHolder.isWrapper()) {
|
||||
final UpdateMetadata finalUpdate = update; // Due to the lambda, this is needed
|
||||
LauncherEnv.showOkCancel("An update was found. Should it be installed automatically?", "Update found", () -> {
|
||||
try {
|
||||
Updater.update(update, true);
|
||||
Updater.update(finalUpdate, true);
|
||||
exit();
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
LauncherEnv.showError("Could not download update", e);
|
||||
|
|
|
@ -11,6 +11,7 @@ import io.gitlab.jfronny.inceptum.launcher.system.setup.Step;
|
|||
import io.gitlab.jfronny.inceptum.launcher.util.*;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.*;
|
||||
|
@ -60,11 +61,17 @@ public class DownloadLibrariesStep implements Step {
|
|||
}
|
||||
}
|
||||
|
||||
public static ArtifactMeta getLaunchWrapperArtifact() {
|
||||
public static ArtifactMeta getLaunchWrapperArtifact() throws FileNotFoundException {
|
||||
ArtifactMeta meta = new ArtifactMeta();
|
||||
meta.groupId = "io.gitlab.jfronny.inceptum";
|
||||
meta.artifactId = "launchwrapper";
|
||||
meta.version = BuildMetadata.IS_PUBLIC ? BuildMetadata.VERSION : Updater.getUpdate().version;
|
||||
String version = BuildMetadata.IS_PUBLIC ? BuildMetadata.VERSION : null;
|
||||
try {
|
||||
if (version == null) version = Updater.getUpdate(false, false).version;
|
||||
} catch (Updater.UpdateCheckException ignored) {
|
||||
}
|
||||
if (version == null) throw new FileNotFoundException("Could not find a valid launch wrapper version");
|
||||
meta.version = version;
|
||||
return meta;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,12 @@ import java.util.List;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
public class Wrapper {
|
||||
public static void main(String[] args) throws IOException, URISyntaxException {
|
||||
public static void main(String[] args) throws IOException, URISyntaxException, Updater.UpdateCheckException {
|
||||
System.out.println("Inceptum Wrapper v" + BuildMetadata.VERSION);
|
||||
System.out.println("Loading from " + MetaHolder.BASE_PATH);
|
||||
InceptumEnvironmentInitializer.initialize();
|
||||
if (!Files.exists(MetaHolder.WRAPPER_CONFIG_PATH)) {
|
||||
UpdateMetadata update = Updater.check(UpdateChannel.Stable, false, R::nop);
|
||||
UpdateMetadata update = Updater.check(UpdateChannel.Stable, false, true, R::nop);
|
||||
if (update == null) {
|
||||
throw new FileNotFoundException("Could not identify a valid inceptum version. Are you connected to the internet?");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue