59 lines
2.5 KiB
Java
59 lines
2.5 KiB
Java
package io.gitlab.jfronny.inceptum.frontend.gui.window;
|
|
|
|
import io.gitlab.jfronny.inceptum.Inceptum;
|
|
import io.gitlab.jfronny.inceptum.InceptumGui;
|
|
import io.gitlab.jfronny.inceptum.frontend.gui.window.dialog.ProcessStateWatcherWindow;
|
|
import io.gitlab.jfronny.inceptum.util.MetaHolder;
|
|
import io.gitlab.jfronny.inceptum.util.ProcessState;
|
|
import io.gitlab.jfronny.inceptum.util.Utils;
|
|
import io.gitlab.jfronny.inceptum.util.install.SetupStepInfo;
|
|
import io.gitlab.jfronny.inceptum.util.install.Step;
|
|
import io.gitlab.jfronny.inceptum.util.install.Steps;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.file.Path;
|
|
import java.util.List;
|
|
|
|
public class GuiUtil {
|
|
public static final int INPUT_FIELD_LENGTH = 1024; // Arbitrary value, can be any int 0<=x<MAX_VALUE. Be aware that an array of this length will be allocated for every input box
|
|
|
|
public static void reload() {
|
|
try {
|
|
List<Path> paths = Utils.ls(MetaHolder.INSTANCE_DIR);
|
|
ProcessState state = Steps.createProcessState().extend(paths.size());
|
|
InceptumGui.open(new ProcessStateWatcherWindow("Reloading data", "Could not reload resources", state, cToken -> {
|
|
for (Path path : paths) {
|
|
Steps.reDownload(path, state);
|
|
}
|
|
}, null));
|
|
} catch (IOException e) {
|
|
Inceptum.showError("Could not reload", e);
|
|
}
|
|
}
|
|
|
|
public static void reload(Path instanceDir) {
|
|
ProcessState state = Steps.createProcessState();
|
|
InceptumGui.open(new ProcessStateWatcherWindow("Reloading data", "Could not reload resources", state, cToken -> {
|
|
Steps.reDownload(instanceDir, state);
|
|
}, null));
|
|
}
|
|
|
|
public static void createInstance(SetupStepInfo state) {
|
|
ProcessState pState = Steps.createProcessState();
|
|
pState.updateStep("Starting install process");
|
|
InceptumGui.open(new ProcessStateWatcherWindow("Creating Instance", "Could not create instance", pState, cToken -> {
|
|
for (Step step : Steps.STEPS) {
|
|
if (cToken.get()) return;
|
|
step.execute(state, cToken);
|
|
}
|
|
Inceptum.showInfo("The instance was successfully created. You can now launch it using the main menu", "Successfully installed");
|
|
}, () -> {
|
|
try {
|
|
Utils.deleteRecursive(MetaHolder.INSTANCE_DIR.resolve(state.name()));
|
|
} catch (IOException e) {
|
|
Utils.LOGGER.error("Could not delete instance dir", e);
|
|
}
|
|
}));
|
|
}
|
|
}
|