From f52cd19ad4b8a95b521bb16d1dbfb350f59f7dde Mon Sep 17 00:00:00 2001 From: comp500 Date: Fri, 11 Dec 2020 18:18:10 +0000 Subject: [PATCH] Show download exceptions properly in CLI --- .../link/infra/packwiz/installer/DownloadTask.kt | 9 ++++++++- .../link/infra/packwiz/installer/ui/CLIHandler.kt | 10 +++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/link/infra/packwiz/installer/DownloadTask.kt b/src/main/kotlin/link/infra/packwiz/installer/DownloadTask.kt index 9e4d3fb..b158d4a 100644 --- a/src/main/kotlin/link/infra/packwiz/installer/DownloadTask.kt +++ b/src/main/kotlin/link/infra/packwiz/installer/DownloadTask.kt @@ -152,6 +152,9 @@ internal class DownloadTask private constructor(val metadata: IndexFile.File, de } } + // TODO: if already exists and has correct hash, ignore? + // TODO: add .disabled support? + try { val hash: Hash val fileHashFormat: String @@ -177,8 +180,12 @@ internal class DownloadTask private constructor(val metadata: IndexFile.File, de if (fileSource.hashIsEqual(hash)) { // isDirectory follows symlinks, but createDirectories doesn't - if (!Files.isDirectory(destPath.parent)) { + try { Files.createDirectories(destPath.parent) + } catch (e: FileAlreadyExistsException) { + if (!Files.isDirectory(destPath.parent)) { + throw e + } } Files.copy(data.inputStream(), destPath, StandardCopyOption.REPLACE_EXISTING) data.clear() diff --git a/src/main/kotlin/link/infra/packwiz/installer/ui/CLIHandler.kt b/src/main/kotlin/link/infra/packwiz/installer/ui/CLIHandler.kt index b15ef0d..6fbf3d9 100644 --- a/src/main/kotlin/link/infra/packwiz/installer/ui/CLIHandler.kt +++ b/src/main/kotlin/link/infra/packwiz/installer/ui/CLIHandler.kt @@ -3,6 +3,7 @@ package link.infra.packwiz.installer.ui import link.infra.packwiz.installer.ui.IUserInterface.ExceptionListResult import java.util.concurrent.CompletableFuture import java.util.concurrent.Future +import kotlin.system.exitProcess class CLIHandler : IUserInterface { override fun handleException(e: Exception) { @@ -40,8 +41,11 @@ class CLIHandler : IUserInterface { } override fun showExceptions(exceptions: List, numTotal: Int, allowsIgnore: Boolean): Future { - val future = CompletableFuture() - future.complete(ExceptionListResult.CANCEL) - return future + println("Failed to download modpack, the following errors were encountered:") + for (ex in exceptions) { + println(ex.name + ": ") + ex.exception.printStackTrace() + } + exitProcess(1) } } \ No newline at end of file