Inceptum/src/main/java/io/gitlab/jfronny/inceptum/windows/InstanceCreateProcessWindow.java

67 lines
2.1 KiB
Java
Raw Normal View History

package io.gitlab.jfronny.inceptum.windows;
import imgui.ImGui;
import io.gitlab.jfronny.inceptum.Inceptum;
2021-10-30 22:05:24 +02:00
import io.gitlab.jfronny.inceptum.InceptumGui;
import io.gitlab.jfronny.inceptum.install.SetupStepInfo;
import io.gitlab.jfronny.inceptum.install.Step;
import io.gitlab.jfronny.inceptum.install.Steps;
import io.gitlab.jfronny.inceptum.util.Utils;
import java.io.IOException;
import java.nio.file.Files;
import java.util.concurrent.atomic.AtomicBoolean;
public class InstanceCreateProcessWindow extends Window {
private final SetupStepInfo stepInfo;
private final AtomicBoolean finalize = new AtomicBoolean(false);
public InstanceCreateProcessWindow(SetupStepInfo stepInfo) {
super("Creating Instance");
this.stepInfo = stepInfo;
new Thread(this::creationThread).start();
}
@Override
public void draw() {
if (finalize.get()) {
close();
return;
}
2021-10-30 19:26:59 +02:00
ImGui.textUnformatted(stepInfo.currentState().get());
if (ImGui.button("Cancel")) finalize.set(true);
}
private void creationThread() {
if (Files.exists(Inceptum.INSTANCE_DIR.resolve(stepInfo.name()))) {
finalize.set(true);
return;
}
Inceptum.LOGGER.info("Starting install process");
try {
for (Step step : Steps.STEPS) {
if (finalize.get()) {
cleanUp();
return;
}
step.execute(stepInfo, finalize);
}
finalize.set(true);
2021-10-30 22:05:24 +02:00
Inceptum.showInfo("The instance was successfully created. You can now launch it using the main menu", "Successfully installed");
close();
} catch (Throwable e) {
2021-10-30 22:05:24 +02:00
Inceptum.showError("Could not create the instance", e);
close();
cleanUp();
}
}
private void cleanUp() {
try {
Utils.deleteRecursive(Inceptum.INSTANCE_DIR.resolve(stepInfo.name()));
} catch (IOException e) {
Inceptum.LOGGER.error("Could not delete instance dir", e);
}
}
}