fix: prevent instance not exiting setup stage when redownload cancelled
This commit is contained in:
parent
9e1c20737d
commit
5cc650921b
|
@ -1,9 +1,7 @@
|
|||
package io.gitlab.jfronny.inceptum.gtk.window.create
|
||||
|
||||
import io.gitlab.jfronny.commons.StringFormatter
|
||||
import io.gitlab.jfronny.commons.io.JFiles
|
||||
import io.gitlab.jfronny.inceptum.common.InceptumConfig
|
||||
import io.gitlab.jfronny.inceptum.common.MetaHolder
|
||||
import io.gitlab.jfronny.inceptum.gtk.control.KDropDown
|
||||
import io.gitlab.jfronny.inceptum.gtk.control.KEntry
|
||||
import io.gitlab.jfronny.inceptum.gtk.control.assistant.KAssistant
|
||||
|
@ -22,7 +20,6 @@ import io.gitlab.jfronny.inceptum.launcher.system.setup.SetupStepInfo
|
|||
import io.gitlab.jfronny.inceptum.launcher.system.setup.Steps
|
||||
import org.gnome.glib.GLib
|
||||
import org.gnome.gtk.*
|
||||
import java.io.IOException
|
||||
|
||||
|
||||
class NewInstanceWindow(app: Application) : KAssistant(app) {
|
||||
|
@ -143,21 +140,19 @@ class NewInstanceWindow(app: Application) : KAssistant(app) {
|
|||
try {
|
||||
for (step in Steps.STEPS) {
|
||||
if (state.isCancelled) {
|
||||
try {
|
||||
JFiles.deleteRecursive(MetaHolder.INSTANCE_DIR.resolve(state.name))
|
||||
} catch (e: IOException) {
|
||||
Log.error("Could not delete instance dir", e)
|
||||
}
|
||||
state.tryRemoveInstance()
|
||||
return@Thread
|
||||
}
|
||||
pState.incrementStep(step.name)
|
||||
step.execute(state)
|
||||
}
|
||||
state.clearSetupLock()
|
||||
} catch (e: Throwable) {
|
||||
pState.cancel()
|
||||
Log.error("Could not create instance")
|
||||
failureMessage = StringFormatter.toString(e)
|
||||
isFailure = true
|
||||
state.tryRemoveInstance()
|
||||
} finally {
|
||||
finished = true
|
||||
schedule { setComplete(true) }
|
||||
|
|
|
@ -40,7 +40,7 @@ class GeneralTab(window: InstanceSettingsWindow) : SectionedSettingsTab<Instance
|
|||
val newPath = MetaHolder.INSTANCE_DIR.resolve(InstanceNameTool.getNextValid(entry.text))
|
||||
Files.move(instance.path, newPath)
|
||||
window.close()
|
||||
InstanceSettingsWindow(window.application, InstanceList.read(newPath)).show()
|
||||
InstanceSettingsWindow(window.application, InstanceList.read(newPath)).visible = true
|
||||
} catch (e: IOException) {
|
||||
showError("Could not rename", e)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package io.gitlab.jfronny.inceptum.imgui.window;
|
|||
|
||||
import io.gitlab.jfronny.commons.io.JFiles;
|
||||
import io.gitlab.jfronny.inceptum.common.MetaHolder;
|
||||
import io.gitlab.jfronny.inceptum.common.Utils;
|
||||
import io.gitlab.jfronny.inceptum.imgui.GuiMain;
|
||||
import io.gitlab.jfronny.inceptum.imgui.window.dialog.ProcessStateWatcherWindow;
|
||||
import io.gitlab.jfronny.inceptum.launcher.LauncherEnv;
|
||||
|
@ -44,17 +43,14 @@ public class GuiUtil {
|
|||
GuiMain.open(new ProcessStateWatcherWindow("Creating Instance", "Could not create instance", pState, () -> {
|
||||
for (Step step : Steps.STEPS) {
|
||||
if (state.isCancelled()) {
|
||||
try {
|
||||
JFiles.deleteRecursive(MetaHolder.INSTANCE_DIR.resolve(state.name()));
|
||||
} catch (IOException e) {
|
||||
Utils.LOGGER.error("Could not delete instance dir", e);
|
||||
}
|
||||
state.tryRemoveInstance();
|
||||
return;
|
||||
}
|
||||
pState.incrementStep(step.getName());
|
||||
step.execute(state);
|
||||
}
|
||||
state.clearSetupLock();
|
||||
LauncherEnv.showInfo("The instance was successfully created. You can now launch it using the main menu", "Successfully installed");
|
||||
}));
|
||||
}, t -> state.tryRemoveInstance()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
package io.gitlab.jfronny.inceptum.imgui.window.dialog;
|
||||
|
||||
import imgui.ImGui;
|
||||
import io.gitlab.jfronny.commons.ref.R;
|
||||
import io.gitlab.jfronny.commons.throwable.ThrowingRunnable;
|
||||
import io.gitlab.jfronny.inceptum.imgui.window.Window;
|
||||
import io.gitlab.jfronny.inceptum.launcher.LauncherEnv;
|
||||
import io.gitlab.jfronny.inceptum.launcher.util.ProcessState;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ProcessStateWatcherWindow extends Window {
|
||||
private final ProcessState state;
|
||||
private boolean finished;
|
||||
|
||||
public ProcessStateWatcherWindow(String title, String errorMessage, ProcessState state, ThrowingRunnable<?> executor) {
|
||||
this(title, errorMessage, state, executor, R::nop);
|
||||
}
|
||||
|
||||
public ProcessStateWatcherWindow(String title, String errorMessage, ProcessState state, ThrowingRunnable<?> executor, Consumer<Throwable> onFail) {
|
||||
super(title);
|
||||
this.state = state;
|
||||
new Thread(() -> {
|
||||
|
@ -18,6 +24,7 @@ public class ProcessStateWatcherWindow extends Window {
|
|||
executor.run();
|
||||
} catch (Throwable e) {
|
||||
state.cancel();
|
||||
onFail.accept(e);
|
||||
LauncherEnv.showError(errorMessage, e);
|
||||
} finally {
|
||||
finished = true;
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
package io.gitlab.jfronny.inceptum.launcher.system.setup;
|
||||
|
||||
import io.gitlab.jfronny.commons.io.JFiles;
|
||||
import io.gitlab.jfronny.inceptum.common.MetaHolder;
|
||||
import io.gitlab.jfronny.inceptum.common.Utils;
|
||||
import io.gitlab.jfronny.inceptum.launcher.model.mojang.VersionInfo;
|
||||
import io.gitlab.jfronny.inceptum.launcher.system.instance.Instance;
|
||||
import io.gitlab.jfronny.inceptum.launcher.system.instance.LoaderInfo;
|
||||
import io.gitlab.jfronny.inceptum.launcher.util.ProcessState;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public record SetupStepInfo(VersionInfo version,
|
||||
LoaderInfo loader,
|
||||
String name,
|
||||
|
@ -15,4 +22,23 @@ public record SetupStepInfo(VersionInfo version,
|
|||
public boolean isCancelled() {
|
||||
return currentState.isCancelled();
|
||||
}
|
||||
|
||||
public void tryRemoveInstance() {
|
||||
try {
|
||||
removeInstance();
|
||||
} catch (IOException e) {
|
||||
Utils.LOGGER.error("Could not delete instance dir", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeInstance() throws IOException {
|
||||
JFiles.deleteRecursive(MetaHolder.INSTANCE_DIR.resolve(name));
|
||||
}
|
||||
|
||||
public void clearSetupLock() {
|
||||
try {
|
||||
Files.deleteIfExists(MetaHolder.INSTANCE_DIR.resolve(name).resolve(Instance.SETUP_LOCK_NAME));
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@ import java.util.*;
|
|||
public class Steps {
|
||||
public static Set<Step> STEPS = new LinkedHashSet<>(List.of(
|
||||
new SetupDirsStep(),
|
||||
new WriteMetadataStep(),
|
||||
new DownloadJavaStep(),
|
||||
new DownloadClientStep(),
|
||||
new DownloadLibrariesStep(),
|
||||
new DownloadAssetsStep(),
|
||||
new WriteMetadataStep(),
|
||||
new RunMdsStep()
|
||||
));
|
||||
|
||||
|
@ -29,6 +29,7 @@ public class Steps {
|
|||
|
||||
public static void reDownload(Instance instance, ProcessState state) throws IOException {
|
||||
if (instance.isLocked()) return;
|
||||
try {
|
||||
boolean found = false;
|
||||
for (VersionsListInfo version : McApi.getVersions().versions()) {
|
||||
if (version.id.equals(instance.getGameVersion())) {
|
||||
|
@ -48,5 +49,8 @@ public class Steps {
|
|||
}
|
||||
}
|
||||
if (!found) throw new IOException("Could not identify minecraft version " + instance.getGameVersion());
|
||||
} finally {
|
||||
instance.setSetupLock(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ public class WriteMetadataStep implements Step {
|
|||
meta.gameVersion = info.version().id;
|
||||
GC_InstanceMeta.write(meta, metaPath);
|
||||
}
|
||||
Instance.setSetupLock(instance, false);
|
||||
if (!Files.exists(instance.resolve(".gitignore"))) {
|
||||
Files.writeString(instance.resolve(".gitignore"), """
|
||||
realms_persistence.json
|
||||
|
|
Loading…
Reference in New Issue