67 lines
2.1 KiB
Java
67 lines
2.1 KiB
Java
package io.gitlab.jfronny.inceptum.windows;
|
|
|
|
import imgui.ImGui;
|
|
import io.gitlab.jfronny.inceptum.Inceptum;
|
|
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;
|
|
}
|
|
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);
|
|
Inceptum.showInfo("The instance was successfully created. You can now launch it using the main menu", "Successfully installed");
|
|
close();
|
|
} catch (Throwable e) {
|
|
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);
|
|
}
|
|
}
|
|
}
|