Compare commits
3 Commits
9e1c20737d
...
c94c8b59af
Author | SHA1 | Date |
---|---|---|
Johannes Frohnmeyer | c94c8b59af | |
Johannes Frohnmeyer | 475717b6b4 | |
Johannes Frohnmeyer | 5cc650921b |
|
@ -22,6 +22,7 @@ import io.gitlab.jfronny.inceptum.launcher.system.launch.LaunchType
|
|||
import io.gitlab.jfronny.inceptum.launcher.system.setup.Steps
|
||||
import io.gitlab.jfronny.inceptum.launcher.util.ProcessState
|
||||
import org.gnome.gio.Cancellable
|
||||
import org.gnome.gio.Menu
|
||||
import org.gnome.gtk.*
|
||||
import java.awt.Toolkit
|
||||
import java.awt.datatransfer.DataFlavor
|
||||
|
@ -67,7 +68,7 @@ object GtkMenubar {
|
|||
file.button("exit") { app.quit() }
|
||||
launchMenu = menu.submenu("launch")
|
||||
generateLaunchMenu(app)
|
||||
accountsMenu = menu.submenu("account")
|
||||
accountsMenu = MenuBuilder(app, Menu(), "account") // this should ideally be menu.submenu("account"), but that causes a segfault
|
||||
generateAccountsMenu(app)
|
||||
val help = menu.submenu("help")
|
||||
help.button("about") { AboutWindow.createAndShow() }
|
||||
|
@ -79,7 +80,7 @@ object GtkMenubar {
|
|||
@JvmStatic
|
||||
fun generateNewMenu(app: Application) {
|
||||
newMenu!!.clear()
|
||||
newMenu!!.button("new") { NewInstanceWindow(app).show() }
|
||||
newMenu!!.button("new") { NewInstanceWindow(app).visible = true }
|
||||
newMenu!!.button("file") {
|
||||
val dialog = FileChooserNative(
|
||||
I18n["menu.file.new.file"],
|
||||
|
@ -202,11 +203,11 @@ object GtkMenubar {
|
|||
@JvmStatic
|
||||
fun generateAccountsMenu(app: Application) {
|
||||
accountsMenu!!.clear()
|
||||
accountsMenu!!.button("new") { MicrosoftLoginDialog(GtkEnvBackend.dialogParent).show() }
|
||||
accountsMenu!!.button("new") { MicrosoftLoginDialog(GtkEnvBackend.dialogParent).visible = true }
|
||||
accountsMenu!!.button("manage") {
|
||||
val window = LauncherSettingsWindow(app)
|
||||
window.activePage = "settings.accounts"
|
||||
window.show()
|
||||
window.visible = true
|
||||
}
|
||||
val accounts: MutableList<MicrosoftAccount?> = ArrayList(AccountManager.getAccounts())
|
||||
accounts.add(null)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package io.gitlab.jfronny.inceptum.gtk.menu
|
||||
|
||||
import io.github.jwharm.javagi.glib.types.VariantTypes
|
||||
import io.gitlab.jfronny.commons.throwable.ThrowingRunnable
|
||||
import io.gitlab.jfronny.inceptum.gtk.util.I18n
|
||||
import io.gitlab.jfronny.inceptum.gtk.util.Log
|
||||
import org.gnome.gio.*
|
||||
import org.gnome.glib.Variant
|
||||
import org.gnome.glib.VariantType
|
||||
import org.gnome.gtk.Application
|
||||
import org.gnome.gtk.MenuButton
|
||||
import org.gnome.gtk.PopoverMenu
|
||||
|
@ -88,7 +88,7 @@ class MenuBuilder private constructor(map: ActionMap, menu: Menu, prefix: String
|
|||
): BuiltRadioItem<T> {
|
||||
var name = name
|
||||
name = prefix + name
|
||||
val action = SimpleAction.newStateful(name, VariantType("i"), Variant.newInt32(options.indexOf(initial)))
|
||||
val action = SimpleAction.newStateful(name, VariantTypes.INT32, Variant.newInt32(options.indexOf(initial)))
|
||||
addAction(name, action)
|
||||
action.onActivate { variant: Variant? ->
|
||||
action.state = variant
|
||||
|
|
|
@ -25,7 +25,7 @@ class AboutWindow : AboutDialog() {
|
|||
companion object {
|
||||
@JvmStatic
|
||||
fun createAndShow() {
|
||||
AboutWindow().show()
|
||||
AboutWindow().visible = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ class MainWindow(app: Application) : ApplicationWindow(app) {
|
|||
|
||||
val uiMenu = MenuBuilder(app, Menu(), "hamburger")
|
||||
uiMenu.button("support") { Utils.openWebBrowser(URI("https://git.frohnmeyer-wds.de/JfMods/Inceptum/issues")) }
|
||||
uiMenu.button("preferences") { LauncherSettingsWindow(app).show() }
|
||||
uiMenu.button("preferences") { LauncherSettingsWindow(app).visible = true }
|
||||
uiMenu.button("about") { AboutWindow.createAndShow() }
|
||||
val menuButton = MenuButton()
|
||||
menuButton.iconName = "open-menu-symbolic"
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -95,7 +95,7 @@ class ProcessStateWatcherDialog(
|
|||
executor: ThrowingRunnable<*>
|
||||
): ProcessStateWatcherDialog {
|
||||
val dialog = ProcessStateWatcherDialog(parent, title, errorMessage, state, executor)
|
||||
dialog.show()
|
||||
dialog.visible = true
|
||||
return dialog
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ class GeneralTab(window: InstanceSettingsWindow) : SectionedSettingsTab<Instance
|
|||
else -> {}
|
||||
}
|
||||
}
|
||||
dialog.show()
|
||||
dialog.visible = true
|
||||
}
|
||||
}
|
||||
row("instance.directory", "instance.directory.subtitle") {
|
||||
|
|
|
@ -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,24 +29,28 @@ public class Steps {
|
|||
|
||||
public static void reDownload(Instance instance, ProcessState state) throws IOException {
|
||||
if (instance.isLocked()) return;
|
||||
boolean found = false;
|
||||
for (VersionsListInfo version : McApi.getVersions().versions()) {
|
||||
if (version.id.equals(instance.getGameVersion())) {
|
||||
found = true;
|
||||
VersionInfo vi = McApi.getVersionInfo(version);
|
||||
if (instance.isFabric())
|
||||
vi = FabricMetaApi.addFabric(vi, instance.getLoaderVersion(), FabricMetaApi.FabricVersionInfoType.Both);
|
||||
LoaderInfo li = instance.isFabric()
|
||||
? new LoaderInfo(LoaderInfo.Type.Fabric, instance.getLoaderVersion())
|
||||
: LoaderInfo.NONE;
|
||||
SetupStepInfo info = new SetupStepInfo(vi, li, instance.getName(), state);
|
||||
for (Step step : Steps.STEPS) {
|
||||
state.incrementStep(step.getName());
|
||||
step.execute(info);
|
||||
if (state.isCancelled()) return;
|
||||
try {
|
||||
boolean found = false;
|
||||
for (VersionsListInfo version : McApi.getVersions().versions()) {
|
||||
if (version.id.equals(instance.getGameVersion())) {
|
||||
found = true;
|
||||
VersionInfo vi = McApi.getVersionInfo(version);
|
||||
if (instance.isFabric())
|
||||
vi = FabricMetaApi.addFabric(vi, instance.getLoaderVersion(), FabricMetaApi.FabricVersionInfoType.Both);
|
||||
LoaderInfo li = instance.isFabric()
|
||||
? new LoaderInfo(LoaderInfo.Type.Fabric, instance.getLoaderVersion())
|
||||
: LoaderInfo.NONE;
|
||||
SetupStepInfo info = new SetupStepInfo(vi, li, instance.getName(), state);
|
||||
for (Step step : Steps.STEPS) {
|
||||
state.incrementStep(step.getName());
|
||||
step.execute(info);
|
||||
if (state.isCancelled()) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) throw new IOException("Could not identify minecraft version " + instance.getGameVersion());
|
||||
} finally {
|
||||
instance.setSetupLock(false);
|
||||
}
|
||||
if (!found) throw new IOException("Could not identify minecraft version " + instance.getGameVersion());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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