Disable automatic updates without the wrapper (they wouldn't work anyways)

This commit is contained in:
JFronny 2021-10-31 18:55:51 +01:00
parent 60c5a30868
commit 6a6b5a62a3
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
5 changed files with 35 additions and 12 deletions

View File

@ -52,15 +52,15 @@ public class Inceptum {
public static InceptumVersion VERSION;
public static Config CONFIG;
public static void main(String[] args) throws IOException {
public static void main(String[] _args) throws IOException {
try (InputStream is = Inceptum.class.getClassLoader().getResourceAsStream("version.json");
InputStreamReader isr = new InputStreamReader(is)) {
VERSION = GSON.fromJson(isr, InceptumVersion.class);
}
if (args.length == 0) args = new String[]{"gui"};
CommandArguments arg = new CommandArguments(_args);
Command cmd = null;
for (Command command : COMMANDS) {
if (command.isAlias(args[0])) {
if (command.isAlias(arg.command)) {
cmd = command;
break;
}
@ -82,7 +82,7 @@ public class Inceptum {
if (!Files.exists(ASSETS_DIR)) Files.createDirectories(ASSETS_DIR);
if (!Files.exists(LIBRARIES_DIR)) Files.createDirectories(LIBRARIES_DIR);
cmd.invoke(new CommandArguments(args));
cmd.invoke(arg);
}
public static void saveConfig() {

View File

@ -4,9 +4,11 @@ import io.gitlab.jfronny.inceptum.Inceptum;
import io.gitlab.jfronny.inceptum.InceptumGui;
import io.gitlab.jfronny.inceptum.model.inceptum.CommandArguments;
import io.gitlab.jfronny.inceptum.model.inceptum.UpdateInfo;
import io.gitlab.jfronny.inceptum.util.Utils;
import io.gitlab.jfronny.inceptum.windows.MainWindow;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class GuiCommand extends Command {
@ -21,7 +23,7 @@ public class GuiCommand extends Command {
InceptumGui.main(args, () -> {
if (update == null) {
InceptumGui.WINDOWS.add(new MainWindow());
} else {
} else if (args.wrapped) {
Inceptum.showOkCancel("An update was found. Should it be installed automatically?", "Update found", () -> {
try {
UpdateCheckCommand.update(update, true);
@ -30,6 +32,15 @@ public class GuiCommand extends Command {
Inceptum.showError("Could not download update", e);
}
}, () -> InceptumGui.WINDOWS.add(new MainWindow()));
} else {
Inceptum.showOkCancel("An update was found. Automatic installs are not supported without the wrapper but you can download it nonetheless", "Update found", () -> {
try {
Utils.openWebBrowser(new URI(update.url()));
InceptumGui.exit();
} catch (URISyntaxException e) {
Inceptum.showError("Could not download update", e);
}
}, () -> InceptumGui.WINDOWS.add(new MainWindow()));
}
});
}

View File

@ -1,7 +1,6 @@
package io.gitlab.jfronny.inceptum.cli;
import io.gitlab.jfronny.inceptum.Inceptum;
import io.gitlab.jfronny.inceptum.model.OSType;
import io.gitlab.jfronny.inceptum.model.inceptum.CommandArguments;
import io.gitlab.jfronny.inceptum.model.inceptum.UpdateInfo;
import io.gitlab.jfronny.inceptum.util.JvmUtils;
@ -21,8 +20,8 @@ public class UpdateCheckCommand extends Command {
@Override
public void invoke(CommandArguments args) {
if (args.contains("install") && OSCheck.OS == OSType.WINDOWS) {
System.err.println("Automatic update installation is not possible on windows");
if (args.contains("install") && !args.wrapped) {
System.err.println("Automatic updates are not supported without the wrapper");
return;
}
UpdateInfo updateUrl = getUpdate();

View File

@ -8,8 +8,14 @@ import java.util.Locale;
public class CommandArguments {
private final List<String> args;
public final int length;
public final boolean wrapped;
public final String command;
public CommandArguments(String[] args) {
this.args = Arrays.asList(args).subList(1, args.length);
if (args.length == 0) args = new String[]{"gui"};
wrapped = args[0].equals("wrapper");
if (wrapped && args.length == 1) args = new String[] {"wrapper", "gui"};
command = wrapped ? args[1] : args[0];
this.args = Arrays.asList(args).subList(wrapped ? 2 : 1, args.length);
this.length = args.length;
}

View File

@ -12,6 +12,9 @@ import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Wrapper {
public static void main(String[] args) throws IOException {
@ -60,9 +63,13 @@ public class Wrapper {
System.err.println("Something went wrong, please try again");
return;
}
new ProcessBuilder(JvmUtils.getJvm(),
"-jar",
pathChosen.resolve("Inceptum-" + chosenVer + '-' + OSCheck.OS.getMojName() + ".jar").toString())
List<String> newArgs = new ArrayList<>();
newArgs.add(JvmUtils.getJvm());
newArgs.add("-jar");
newArgs.add(pathChosen.resolve("Inceptum-" + chosenVer + '-' + OSCheck.OS.getMojName() + ".jar").toString());
newArgs.add("wrapper");
newArgs.addAll(Arrays.asList(args));
new ProcessBuilder(newArgs.toArray(new String[0]))
.inheritIO()
.start();
}