2021-10-30 16:12:39 +02:00
|
|
|
package io.gitlab.jfronny.inceptum.windows.control;
|
|
|
|
|
|
|
|
import imgui.ImGui;
|
|
|
|
import imgui.flag.ImGuiTableFlags;
|
|
|
|
import io.gitlab.jfronny.inceptum.Inceptum;
|
2021-10-30 22:05:24 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.InceptumGui;
|
2021-11-25 17:55:50 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.install.Steps;
|
2021-10-30 16:12:39 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
|
2022-01-04 12:51:51 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.util.InceptumLockReader;
|
2021-12-08 21:45:46 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.util.launch.ClientLauncher;
|
2021-10-30 16:12:39 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.util.ProcessUtils;
|
|
|
|
import io.gitlab.jfronny.inceptum.util.Utils;
|
|
|
|
import io.gitlab.jfronny.inceptum.windows.InstanceEditWindow;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class InstanceView {
|
|
|
|
public static void draw(List<Path> paths) {
|
|
|
|
if (ImGui.beginTable("Instances", 2, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.Borders)) {
|
|
|
|
for (Path path : paths) {
|
2022-01-04 12:51:51 +01:00
|
|
|
if (InceptumLockReader.isSetupLocked(path)) {
|
2021-10-30 16:12:39 +02:00
|
|
|
ImGui.tableNextColumn();
|
|
|
|
ImGui.text("Setting up");
|
|
|
|
ImGui.tableNextColumn();
|
|
|
|
ImGui.text("This instance is currently being set up");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!Files.exists(path.resolve("instance.json"))) {
|
|
|
|
Inceptum.LOGGER.error("Invalid instance (doesn't contain instance.json): " + path);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
InstanceMeta instance;
|
|
|
|
try {
|
|
|
|
instance = Utils.loadObject(path.resolve("instance.json"), InstanceMeta.class);
|
|
|
|
} catch (IOException e) {
|
|
|
|
Inceptum.LOGGER.error("Could not load instance.json", e);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ImGui.tableNextColumn();
|
|
|
|
boolean disabled = false;
|
2022-01-04 12:51:51 +01:00
|
|
|
try {
|
|
|
|
if (InceptumLockReader.isRunningLocked(path))
|
|
|
|
disabled = true;
|
|
|
|
} catch (IOException e) {
|
|
|
|
continue;
|
2021-10-30 16:12:39 +02:00
|
|
|
}
|
|
|
|
if (disabled) ImGui.beginDisabled();
|
2021-11-24 19:53:06 +01:00
|
|
|
if (ImGui.button(path.getFileName().toString())) {
|
2021-11-25 17:55:50 +01:00
|
|
|
try {
|
|
|
|
Steps.reDownload(path);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2021-11-24 19:53:06 +01:00
|
|
|
ClientLauncher.launch(path, instance);
|
|
|
|
}
|
2021-10-30 16:12:39 +02:00
|
|
|
ImGui.tableNextColumn();
|
2021-10-30 22:05:24 +02:00
|
|
|
if (ImGui.button("Edit##" + path)) InceptumGui.open(new InstanceEditWindow(path, instance));
|
2021-10-30 16:12:39 +02:00
|
|
|
if (disabled) ImGui.endDisabled();
|
|
|
|
}
|
|
|
|
ImGui.endTable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|