Fix invalidation issues when changing --side without updating pack

This commit is contained in:
comp500 2023-10-23 23:36:17 +01:00
parent b2421cfea7
commit c9543f74ee

View File

@ -127,40 +127,44 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
ui.submitProgress(InstallProgress("Checking local files...")) ui.submitProgress(InstallProgress("Checking local files..."))
// Invalidation checking must be done here, as it must happen before pack/index hashes are checked // If the side changes, invalidate EVERYTHING (even when the index hasn't changed)
val invalidateAll = opts.side != manifest.cachedSide
val invalidatedUris: MutableList<PackwizFilePath> = ArrayList() val invalidatedUris: MutableList<PackwizFilePath> = ArrayList()
for ((fileUri, file) in manifest.cachedFiles) { if (!invalidateAll) {
// ignore onlyOtherSide files // Invalidation checking must be done here, as it must happen before pack/index hashes are checked
if (file.onlyOtherSide) { for ((fileUri, file) in manifest.cachedFiles) {
continue // ignore onlyOtherSide files
} if (file.onlyOtherSide) {
continue
}
var invalid = false var invalid = false
// if isn't optional, or is optional but optionValue == true // if isn't optional, or is optional but optionValue == true
if (!file.isOptional || file.optionValue) { if (!file.isOptional || file.optionValue) {
if (file.cachedLocation != null) { if (file.cachedLocation != null) {
if (!file.cachedLocation!!.nioPath.toFile().exists()) { if (!file.cachedLocation!!.nioPath.toFile().exists()) {
invalid = true
}
} else {
// if cachedLocation == null, should probably be installed!!
invalid = true invalid = true
} }
} else { }
// if cachedLocation == null, should probably be installed!! if (invalid) {
invalid = true Log.info("File ${fileUri.filename} invalidated, marked for redownloading")
invalidatedUris.add(fileUri)
} }
} }
if (invalid) {
Log.info("File ${fileUri.filename} invalidated, marked for redownloading")
invalidatedUris.add(fileUri)
}
}
if (manifest.packFileHash?.let { it == packFileSource.hash } == true && invalidatedUris.isEmpty()) { if (manifest.packFileHash?.let { it == packFileSource.hash } == true && invalidatedUris.isEmpty()) {
// todo: --force? // todo: --force?
ui.submitProgress(InstallProgress("Modpack is already up to date!", 1, 1)) ui.submitProgress(InstallProgress("Modpack is already up to date!", 1, 1))
if (manifest.cachedFiles.any { it.value.isOptional }) { if (manifest.cachedFiles.any { it.value.isOptional }) {
ui.awaitOptionalButton(false, opts.timeout) ui.awaitOptionalButton(false, opts.timeout)
} }
if (!ui.optionsButtonPressed) { if (!ui.optionsButtonPressed) {
return return
}
} }
} }
@ -177,6 +181,7 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
pf.index.hashFormat, pf.index.hashFormat,
manifest, manifest,
invalidatedUris, invalidatedUris,
invalidateAll,
clientHolder clientHolder
) )
} catch (e1: Exception) { } catch (e1: Exception) {
@ -202,18 +207,20 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
} }
} }
private fun processIndex(indexUri: PackwizPath<*>, indexHash: Hash<*>, hashFormat: HashFormat<*>, manifest: ManifestFile, invalidatedFiles: List<PackwizFilePath>, clientHolder: ClientHolder) { private fun processIndex(indexUri: PackwizPath<*>, indexHash: Hash<*>, hashFormat: HashFormat<*>, manifest: ManifestFile, invalidatedFiles: List<PackwizFilePath>, invalidateAll: Boolean, clientHolder: ClientHolder) {
if (manifest.indexFileHash == indexHash && invalidatedFiles.isEmpty()) { if (!invalidateAll) {
ui.submitProgress(InstallProgress("Modpack files are already up to date!", 1, 1)) if (manifest.indexFileHash == indexHash && invalidatedFiles.isEmpty()) {
if (manifest.cachedFiles.any { it.value.isOptional }) { ui.submitProgress(InstallProgress("Modpack files are already up to date!", 1, 1))
ui.awaitOptionalButton(false, opts.timeout) if (manifest.cachedFiles.any { it.value.isOptional }) {
} ui.awaitOptionalButton(false, opts.timeout)
if (!ui.optionsButtonPressed) { }
return if (!ui.optionsButtonPressed) {
} return
if (ui.cancelButtonPressed) { }
showCancellationDialog() if (ui.cancelButtonPressed) {
return showCancellationDialog()
return
}
} }
} }
manifest.indexFileHash = indexHash manifest.indexFileHash = indexHash
@ -281,9 +288,6 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
Log.warn("Index is empty!") Log.warn("Index is empty!")
} }
val tasks = createTasksFromIndex(indexFile, opts.side) val tasks = createTasksFromIndex(indexFile, opts.side)
// If the side changes, invalidate EVERYTHING just in case
// Might not be needed, but done just to be safe
val invalidateAll = opts.side != manifest.cachedSide
if (invalidateAll) { if (invalidateAll) {
Log.info("Side changed, invalidating all mods") Log.info("Side changed, invalidating all mods")
} }