Minor Mod Manager fixes (mods having dashes in their repo name not shown right away) (#9894)

* Fix Mod Manager not displaying some freshly downloaded mods immediately
(and scroll it into view)

* Mod Manager DL-from-URL stays open after invalid link

* Minor lint

* Another lint on an unfortunate lint
This commit is contained in:
SomeTroglodyte 2023-08-08 23:46:59 +02:00 committed by GitHub
parent 0561a7951c
commit 6c841e52c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View File

@ -498,8 +498,10 @@ class ModManagementScreen(
actualDownloadButton.disable()
val repo = Github.Repo().parseUrl(textField.text)
if (repo == null) {
ToastPopup("Invalid link!", this@ModManagementScreen)
popup.close() // Re-enabling button would be nice, but Toast doesn't work over other Popups
ToastPopup("«RED»{Invalid link!}«»", this@ModManagementScreen)
.apply { isVisible = true }
actualDownloadButton.setText("Download".tr())
actualDownloadButton.enable()
} else
downloadMod(repo) { popup.close() }
}
@ -568,19 +570,21 @@ class ModManagementScreen(
repo,
Gdx.files.local("mods")
)
?: throw Exception("downloadAndExtract returns null for 404 errors and the like") // downloadAndExtract returns null for 404 errors and the like -> display something!
?: throw Exception("Exception during GitHub download") // downloadAndExtract returns null for 404 errors and the like -> display something!
Github.rewriteModOptions(repo, modFolder)
launchOnGLThread {
ToastPopup("[${repo.name}] Downloaded!", this@ModManagementScreen)
val repoName = modFolder.name() // repo.name still has the replaced "-"'s
ToastPopup("[$repoName] Downloaded!", this@ModManagementScreen)
RulesetCache.loadRulesets()
TileSetCache.loadTileSetConfigs(false)
UncivGame.Current.translations.tryReadTranslationForCurrentLanguage()
RulesetCache[repo.name]?.let {
installedModInfo[repo.name] = ModUIData(it)
RulesetCache[repoName]?.let {
installedModInfo[repoName] = ModUIData(it)
}
refreshInstalledModTable()
showModDescription(repo.name)
unMarkUpdatedMod(repo.name)
lastSelectedButton?.let { syncOnlineSelected(repoName, it) }
showModDescription(repoName)
unMarkUpdatedMod(repoName)
postAction()
}
} catch (ex: Exception) {

View File

@ -462,8 +462,8 @@ object Github {
*
* Replaces '-' with blanks but ensures no leading or trailing blanks.
* As mad modders know no limits, trailing "-" did indeed happen, causing things to break due to trailing blanks on a folder name.
* As "test-" and "test" are different allowed repository names, trimmed blanks are replaced with one overscore per side.
* @param onlyOuterBlanks If `true` ignores inner dashes - only start and end are treated. Useful when modders have manually creted local folder names using dashes.
* As "test-" and "test" are different allowed repository names, trimmed blanks are replaced with one equals sign per side.
* @param onlyOuterBlanks If `true` ignores inner dashes - only start and end are treated. Useful when modders have manually created local folder names using dashes.
*/
fun String.repoNameToFolderName(onlyOuterBlanks: Boolean = false): String {
var result = if (onlyOuterBlanks) this else replace('-', ' ')