2022-09-04 21:21:24 +02:00
|
|
|
package io.gitlab.jfronny.inceptum;
|
|
|
|
|
|
|
|
import io.gitlab.jfronny.inceptum.cli.Command;
|
|
|
|
import io.gitlab.jfronny.inceptum.cli.CommandArgs;
|
2022-09-06 11:15:21 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.common.*;
|
|
|
|
import io.gitlab.jfronny.inceptum.common.model.inceptum.UpdateMetadata;
|
2022-09-04 21:21:24 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class UpdateCheckCommand extends Command {
|
|
|
|
private final boolean install;
|
|
|
|
|
|
|
|
public UpdateCheckCommand() {
|
|
|
|
super("Checks for inceptum updates", "", List.of("update"), List.of(
|
|
|
|
new UpdateCheckCommand("Automatically install updates", "install", true)
|
|
|
|
));
|
|
|
|
install = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private UpdateCheckCommand(String help, String name, boolean install) {
|
|
|
|
super(help, "", name);
|
|
|
|
this.install = install;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void invoke(CommandArgs args) {
|
2022-09-06 14:55:36 +02:00
|
|
|
if (install && !MetaHolder.isWrapper()) {
|
2022-09-04 21:21:24 +02:00
|
|
|
Utils.LOGGER.error("Automatic updates are not supported without the wrapper");
|
|
|
|
return;
|
|
|
|
}
|
2022-11-04 13:00:37 +01:00
|
|
|
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) {
|
2022-09-04 21:21:24 +02:00
|
|
|
Utils.LOGGER.info("No update was found");
|
|
|
|
} else {
|
|
|
|
if (install) {
|
2022-11-04 13:00:37 +01:00
|
|
|
Utils.LOGGER.info("Installing from " + update);
|
2022-09-04 21:21:24 +02:00
|
|
|
try {
|
2022-11-04 13:00:37 +01:00
|
|
|
Updater.update(update, false);
|
2022-09-04 21:21:24 +02:00
|
|
|
} catch (IOException | URISyntaxException e) {
|
|
|
|
Utils.LOGGER.error("Could not download update", e);
|
|
|
|
}
|
|
|
|
} else {
|
2022-11-04 13:00:37 +01:00
|
|
|
Utils.LOGGER.info("An update was found: " + update);
|
2022-09-04 21:21:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|