2021-10-29 23:16:03 +02:00
|
|
|
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;
|
2021-10-29 23:16:03 +02:00
|
|
|
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());
|
2021-10-29 23:16:03 +02:00
|
|
|
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");
|
2021-10-29 23:16:03 +02:00
|
|
|
close();
|
|
|
|
} catch (Throwable e) {
|
2021-10-30 22:05:24 +02:00
|
|
|
Inceptum.showError("Could not create the instance", e);
|
2021-10-29 23:16:03 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|