mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-04-19 13:06:30 +02:00
Improve handling of manual downloads; "Continue" now rechecks files
This commit is contained in:
parent
73d21a475a
commit
c2ee6fca8b
@ -292,7 +292,7 @@ internal class DownloadTask private constructor(val metadata: IndexFile.File, de
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun createTasksFromIndex(index: IndexFile, defaultFormat: String, downloadSide: Side): List<DownloadTask> {
|
fun createTasksFromIndex(index: IndexFile, defaultFormat: String, downloadSide: Side): MutableList<DownloadTask> {
|
||||||
val tasks = ArrayList<DownloadTask>()
|
val tasks = ArrayList<DownloadTask>()
|
||||||
for (file in Objects.requireNonNull(index.files)) {
|
for (file in Objects.requireNonNull(index.files)) {
|
||||||
tasks.add(DownloadTask(file, defaultFormat, downloadSide))
|
tasks.add(DownloadTask(file, defaultFormat, downloadSide))
|
||||||
|
@ -314,8 +314,8 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: task failed function?
|
// TODO: task failed function?
|
||||||
val nonFailedFirstTasks = tasks.filter { t -> !t.failed() }.toList()
|
tasks.removeAll { it.failed() }
|
||||||
val optionTasks = nonFailedFirstTasks.filter(DownloadTask::correctSide).filter(DownloadTask::isOptional).toList()
|
val optionTasks = tasks.filter(DownloadTask::correctSide).filter(DownloadTask::isOptional).toList()
|
||||||
val optionsChanged = optionTasks.any(DownloadTask::isNewOptional)
|
val optionsChanged = optionTasks.any(DownloadTask::isNewOptional)
|
||||||
if (optionTasks.isNotEmpty() && !optionsChanged) {
|
if (optionTasks.isNotEmpty() && !optionsChanged) {
|
||||||
if (!ui.optionsButtonPressed) {
|
if (!ui.optionsButtonPressed) {
|
||||||
@ -339,35 +339,11 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
|
|||||||
// TODO: keep this enabled? then apply changes after download process?
|
// TODO: keep this enabled? then apply changes after download process?
|
||||||
ui.disableOptionsButton(optionTasks.isNotEmpty())
|
ui.disableOptionsButton(optionTasks.isNotEmpty())
|
||||||
|
|
||||||
ui.submitProgress(InstallProgress("Validating existing files..."))
|
while (true) {
|
||||||
|
when (validateAndResolve(tasks)) {
|
||||||
// Validate existing files
|
ResolveResult.RETRY -> {}
|
||||||
for (downloadTask in nonFailedFirstTasks.filter(DownloadTask::correctSide)) {
|
ResolveResult.QUIT -> return
|
||||||
downloadTask.validateExistingFile(opts.packFolder)
|
ResolveResult.SUCCESS -> break
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve CurseForge metadata
|
|
||||||
val cfFiles = nonFailedFirstTasks.asSequence().filter { !it.alreadyUpToDate }
|
|
||||||
.filter(DownloadTask::correctSide)
|
|
||||||
.map { it.metadata }
|
|
||||||
.filter { it.linkedFile != null }
|
|
||||||
.filter { it.linkedFile?.download?.mode == "metadata:curseforge" }.toList()
|
|
||||||
if (cfFiles.isNotEmpty()) {
|
|
||||||
ui.submitProgress(InstallProgress("Resolving CurseForge metadata..."))
|
|
||||||
val resolveFailures = resolveCfMetadata(cfFiles)
|
|
||||||
if (resolveFailures.isNotEmpty()) {
|
|
||||||
errorsOccurred = true
|
|
||||||
when (ui.showExceptions(resolveFailures, cfFiles.size, true)) {
|
|
||||||
ExceptionListResult.CONTINUE -> {}
|
|
||||||
ExceptionListResult.CANCEL -> {
|
|
||||||
cancelled = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ExceptionListResult.IGNORE -> {
|
|
||||||
cancelledStartGame = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,7 +394,7 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
|
|||||||
// Shut down the thread pool when the update is done
|
// Shut down the thread pool when the update is done
|
||||||
threadPool.shutdown()
|
threadPool.shutdown()
|
||||||
|
|
||||||
val failedTasks2ElectricBoogaloo = nonFailedFirstTasks.asSequence().map(DownloadTask::exceptionDetails).filterNotNull().toList()
|
val failedTasks2ElectricBoogaloo = tasks.asSequence().map(DownloadTask::exceptionDetails).filterNotNull().toList()
|
||||||
if (failedTasks2ElectricBoogaloo.isNotEmpty()) {
|
if (failedTasks2ElectricBoogaloo.isNotEmpty()) {
|
||||||
errorsOccurred = true
|
errorsOccurred = true
|
||||||
when (ui.showExceptions(failedTasks2ElectricBoogaloo, tasks.size, false)) {
|
when (ui.showExceptions(failedTasks2ElectricBoogaloo, tasks.size, false)) {
|
||||||
@ -429,6 +405,49 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class ResolveResult {
|
||||||
|
RETRY,
|
||||||
|
QUIT,
|
||||||
|
SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun validateAndResolve(nonFailedFirstTasks: List<DownloadTask>): ResolveResult {
|
||||||
|
ui.submitProgress(InstallProgress("Validating existing files..."))
|
||||||
|
|
||||||
|
// Validate existing files
|
||||||
|
for (downloadTask in nonFailedFirstTasks.filter(DownloadTask::correctSide)) {
|
||||||
|
downloadTask.validateExistingFile(opts.packFolder)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve CurseForge metadata
|
||||||
|
val cfFiles = nonFailedFirstTasks.asSequence().filter { !it.alreadyUpToDate }
|
||||||
|
.filter(DownloadTask::correctSide)
|
||||||
|
.map { it.metadata }
|
||||||
|
.filter { it.linkedFile != null }
|
||||||
|
.filter { it.linkedFile?.download?.mode == "metadata:curseforge" }.toList()
|
||||||
|
if (cfFiles.isNotEmpty()) {
|
||||||
|
ui.submitProgress(InstallProgress("Resolving CurseForge metadata..."))
|
||||||
|
val resolveFailures = resolveCfMetadata(cfFiles)
|
||||||
|
if (resolveFailures.isNotEmpty()) {
|
||||||
|
errorsOccurred = true
|
||||||
|
return when (ui.showExceptions(resolveFailures, cfFiles.size, true)) {
|
||||||
|
ExceptionListResult.CONTINUE -> {
|
||||||
|
ResolveResult.RETRY
|
||||||
|
}
|
||||||
|
ExceptionListResult.CANCEL -> {
|
||||||
|
cancelled = true
|
||||||
|
ResolveResult.QUIT
|
||||||
|
}
|
||||||
|
ExceptionListResult.IGNORE -> {
|
||||||
|
cancelledStartGame = true
|
||||||
|
ResolveResult.QUIT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ResolveResult.SUCCESS
|
||||||
|
}
|
||||||
|
|
||||||
private fun showCancellationDialog() {
|
private fun showCancellationDialog() {
|
||||||
when (ui.showCancellationDialog()) {
|
when (ui.showCancellationDialog()) {
|
||||||
CancellationResult.QUIT -> cancelled = true
|
CancellationResult.QUIT -> cancelled = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user