From 1a27630a8c6022536453f7a19d63f94b26d15f4d Mon Sep 17 00:00:00 2001 From: MCTian-mi <35869948+MCTian-mi@users.noreply.github.com> Date: Sun, 22 Dec 2024 14:43:22 +0800 Subject: [PATCH] feat: allow skip on fail --- src/main/kotlin/link/infra/packwiz/installer/Main.kt | 5 ++++- .../kotlin/link/infra/packwiz/installer/UpdateManager.kt | 3 ++- .../link/infra/packwiz/installer/ui/cli/CLIHandler.kt | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/link/infra/packwiz/installer/Main.kt b/src/main/kotlin/link/infra/packwiz/installer/Main.kt index d0e9282..292e879 100644 --- a/src/main/kotlin/link/infra/packwiz/installer/Main.kt +++ b/src/main/kotlin/link/infra/packwiz/installer/Main.kt @@ -107,9 +107,11 @@ class Main(args: Array) { cmd.getOptionValue("timeout")?.toLong() ?: 10 } + val skipOnFail = cmd.hasOption("skip-on-fail") + // Start update process! try { - UpdateManager(UpdateManager.Options(packFile, manifestFile, packFolder, multimcFolder, side, timeout), ui) + UpdateManager(UpdateManager.Options(packFile, manifestFile, packFolder, multimcFolder, side, timeout, skipOnFail), ui) } catch (e: Exception) { ui.showErrorAndExit("Update process failed", e) } @@ -127,6 +129,7 @@ class Main(args: Array) { 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)") + options.addOption(null, "skip-on-fail", false, "Skip the file if download fails instead of exiting") } // 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 1f1c2dc..ea538c4 100644 --- a/src/main/kotlin/link/infra/packwiz/installer/UpdateManager.kt +++ b/src/main/kotlin/link/infra/packwiz/installer/UpdateManager.kt @@ -49,6 +49,7 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse val multimcFolder: PackwizFilePath, val side: Side, val timeout: Long, + val skipOnFail: Boolean ) // TODO: make this return a value based on results? @@ -446,7 +447,7 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse if (cfFiles.isNotEmpty()) { ui.submitProgress(InstallProgress("Resolving CurseForge metadata...")) val resolveFailures = resolveCfMetadata(cfFiles, opts.packFolder, clientHolder) - if (resolveFailures.isNotEmpty()) { + if (resolveFailures.isNotEmpty() && !opts.skipOnFail) { errorsOccurred = true return when (ui.showExceptions(resolveFailures, cfFiles.size, true)) { ExceptionListResult.CONTINUE -> { 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 a81abbb..10a37b1 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 @@ -60,6 +60,13 @@ class CLIHandler : IUserInterface { print(ex.name + ": ") ex.exception.printStackTrace() } + if (allowsIgnore) { + print("Do you want to ignore them and continue? (Y/N): ") + val input = readlnOrNull() + if (input.equals("Y", ignoreCase = true)) { + return ExceptionListResult.CONTINUE + } + } return ExceptionListResult.CANCEL }