diff --git a/src/main/kotlin/link/infra/packwiz/installer/Main.kt b/src/main/kotlin/link/infra/packwiz/installer/Main.kt index a243252..d0e9282 100644 --- a/src/main/kotlin/link/infra/packwiz/installer/Main.kt +++ b/src/main/kotlin/link/infra/packwiz/installer/Main.kt @@ -103,10 +103,13 @@ class Main(args: Array) { val manifestFile = ui.wrap("Invalid manifest file path") { packFolder / (cmd.getOptionValue("meta-file") ?: "packwiz.json") } + val timeout = ui.wrap("Invalid timeout value") { + cmd.getOptionValue("timeout")?.toLong() ?: 10 + } // Start update process! try { - UpdateManager(UpdateManager.Options(packFile, manifestFile, packFolder, multimcFolder, side), ui) + UpdateManager(UpdateManager.Options(packFile, manifestFile, packFolder, multimcFolder, side, timeout), ui) } catch (e: Exception) { ui.showErrorAndExit("Update process failed", e) } @@ -123,6 +126,7 @@ class Main(args: Array) { options.addOption(null, "pack-folder", true, "Folder to install the pack to (defaults to the JAR directory)") options.addOption(null, "multimc-folder", true, "The MultiMC pack folder (defaults to the parent of the pack directory)") options.addOption(null, "meta-file", true, "JSON file to store pack metadata, relative to the pack folder (defaults to packwiz.json)") + options.addOption("t", "timeout", true, "Seconds to wait before automatically launching when asking about optional mods (defaults to 10)") } // TODO: link these somehow so they're only defined once? diff --git a/src/main/kotlin/link/infra/packwiz/installer/UpdateManager.kt b/src/main/kotlin/link/infra/packwiz/installer/UpdateManager.kt index 687f3e4..c9bd758 100644 --- a/src/main/kotlin/link/infra/packwiz/installer/UpdateManager.kt +++ b/src/main/kotlin/link/infra/packwiz/installer/UpdateManager.kt @@ -48,7 +48,8 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse val manifestFile: PackwizFilePath, val packFolder: PackwizFilePath, val multimcFolder: PackwizFilePath, - val side: Side + val side: Side, + val timeout: Long, ) // TODO: make this return a value based on results? @@ -157,7 +158,7 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse // todo: --force? ui.submitProgress(InstallProgress("Modpack is already up to date!", 1, 1)) if (manifest.cachedFiles.any { it.value.isOptional }) { - ui.awaitOptionalButton(false) + ui.awaitOptionalButton(false, opts.timeout) } if (!ui.optionsButtonPressed) { return @@ -206,7 +207,7 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse if (manifest.indexFileHash == indexHash && invalidatedFiles.isEmpty()) { ui.submitProgress(InstallProgress("Modpack files are already up to date!", 1, 1)) if (manifest.cachedFiles.any { it.value.isOptional }) { - ui.awaitOptionalButton(false) + ui.awaitOptionalButton(false, opts.timeout) } if (!ui.optionsButtonPressed) { return @@ -338,7 +339,7 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse if (!ui.optionsButtonPressed) { // TODO: this is so ugly ui.submitProgress(InstallProgress("Reconfigure optional mods?", 0,1)) - ui.awaitOptionalButton(true) + ui.awaitOptionalButton(true, opts.timeout) if (ui.cancelButtonPressed) { showCancellationDialog() return diff --git a/src/main/kotlin/link/infra/packwiz/installer/ui/IUserInterface.kt b/src/main/kotlin/link/infra/packwiz/installer/ui/IUserInterface.kt index fe0f3e4..525e247 100644 --- a/src/main/kotlin/link/infra/packwiz/installer/ui/IUserInterface.kt +++ b/src/main/kotlin/link/infra/packwiz/installer/ui/IUserInterface.kt @@ -25,7 +25,7 @@ interface IUserInterface { fun showUpdateConfirmationDialog(oldVersions: List>, newVersions: List>): UpdateConfirmationResult = UpdateConfirmationResult.CANCELLED - fun awaitOptionalButton(showCancel: Boolean) + fun awaitOptionalButton(showCancel: Boolean, timeout: Long) enum class ExceptionListResult { CONTINUE, CANCEL, IGNORE diff --git a/src/main/kotlin/link/infra/packwiz/installer/ui/cli/CLIHandler.kt b/src/main/kotlin/link/infra/packwiz/installer/ui/cli/CLIHandler.kt index f5233e7..a81abbb 100644 --- a/src/main/kotlin/link/infra/packwiz/installer/ui/cli/CLIHandler.kt +++ b/src/main/kotlin/link/infra/packwiz/installer/ui/cli/CLIHandler.kt @@ -63,7 +63,7 @@ class CLIHandler : IUserInterface { return ExceptionListResult.CANCEL } - override fun awaitOptionalButton(showCancel: Boolean) { + override fun awaitOptionalButton(showCancel: Boolean, timeout: Long) { // Do nothing } } \ No newline at end of file diff --git a/src/main/kotlin/link/infra/packwiz/installer/ui/gui/GUIHandler.kt b/src/main/kotlin/link/infra/packwiz/installer/ui/gui/GUIHandler.kt index 5c0f3d2..d84de02 100644 --- a/src/main/kotlin/link/infra/packwiz/installer/ui/gui/GUIHandler.kt +++ b/src/main/kotlin/link/infra/packwiz/installer/ui/gui/GUIHandler.kt @@ -7,11 +7,13 @@ import link.infra.packwiz.installer.ui.data.IOptionDetails import link.infra.packwiz.installer.ui.data.InstallProgress import link.infra.packwiz.installer.util.Log import java.awt.EventQueue +import java.util.Timer import java.util.concurrent.CompletableFuture import java.util.concurrent.CountDownLatch import javax.swing.JDialog import javax.swing.JOptionPane import javax.swing.UIManager +import kotlin.concurrent.timer import kotlin.system.exitProcess class GUIHandler : IUserInterface { @@ -220,12 +222,28 @@ class GUIHandler : IUserInterface { return future.get() } - override fun awaitOptionalButton(showCancel: Boolean) { + override fun awaitOptionalButton(showCancel: Boolean, timeout: Long) { EventQueue.invokeAndWait { frmPackwizlauncher.showOk(!showCancel) } visibleCountdownLatch.await() + + var closeTimer: Timer? = null + if (timeout >= 0) { + var count = 0 + closeTimer = timer("timeout", true, 0, 1000) { + if (count >= timeout) { + optionalSelectedLatch.countDown() + cancel() + } else { + frmPackwizlauncher.timeoutOk(timeout - count) + count += 1 + } + }; + } + optionalSelectedLatch.await() + closeTimer?.cancel() EventQueue.invokeLater { frmPackwizlauncher.hideOk() } diff --git a/src/main/kotlin/link/infra/packwiz/installer/ui/gui/InstallWindow.kt b/src/main/kotlin/link/infra/packwiz/installer/ui/gui/InstallWindow.kt index 9431372..7d0b446 100644 --- a/src/main/kotlin/link/infra/packwiz/installer/ui/gui/InstallWindow.kt +++ b/src/main/kotlin/link/infra/packwiz/installer/ui/gui/InstallWindow.kt @@ -121,4 +121,8 @@ class InstallWindow(private val handler: GUIHandler) : JFrame() { } buttonsPanel.revalidate() } + + fun timeoutOk(remaining: Long) { + btnOk.text = "Continue ($remaining)" + } } \ No newline at end of file