diff options
author | nea <nea@nea.moe> | 2023-10-21 17:28:00 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-10-21 17:28:00 +0200 |
commit | e887067b7ecfa9d8e040008cca8d26c194f8c1a5 (patch) | |
tree | 8c558ed23edabd7722bf869ce24d5561b6644e44 /src/main/kotlin/moe/nea/firmament/repo | |
parent | bc758d17e2ac5c507117f85bf76b081a05f2baca (diff) | |
download | Firmament-e887067b7ecfa9d8e040008cca8d26c194f8c1a5.tar.gz Firmament-e887067b7ecfa9d8e040008cca8d26c194f8c1a5.tar.bz2 Firmament-e887067b7ecfa9d8e040008cca8d26c194f8c1a5.zip |
Add tab completion to /warp
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/repo')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/repo/RepoDownloadManager.kt | 33 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt | 9 |
2 files changed, 23 insertions, 19 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/repo/RepoDownloadManager.kt b/src/main/kotlin/moe/nea/firmament/repo/RepoDownloadManager.kt index ffb4b6e..1c27a97 100644 --- a/src/main/kotlin/moe/nea/firmament/repo/RepoDownloadManager.kt +++ b/src/main/kotlin/moe/nea/firmament/repo/RepoDownloadManager.kt @@ -31,17 +31,17 @@ object RepoDownloadManager { val repoMetadataLocation = Firmament.DATA_DIR.resolve("loaded-repo-sha.txt") private fun loadSavedVersionHash(): String? = - if (repoSavedLocation.exists()) { - if (repoMetadataLocation.exists()) { - try { - repoMetadataLocation.readText().trim() - } catch (e: IOException) { - null - } - } else { + if (repoSavedLocation.exists()) { + if (repoMetadataLocation.exists()) { + try { + repoMetadataLocation.readText().trim() + } catch (e: IOException) { null } - } else null + } else { + null + } + } else null private fun saveVersionHash(versionHash: String) { latestSavedVersionHash = versionHash @@ -56,7 +56,7 @@ object RepoDownloadManager { private suspend fun requestLatestGithubSha(): String? { val response = - Firmament.httpClient.get("https://api.github.com/repos/${RepoManager.Config.username}/${RepoManager.Config.reponame}/commits/${RepoManager.Config.branch}") + Firmament.httpClient.get("https://api.github.com/repos/${RepoManager.Config.username}/${RepoManager.Config.reponame}/commits/${RepoManager.Config.branch}") if (response.status.value != 200) { return null } @@ -83,7 +83,8 @@ object RepoDownloadManager { } val currentSha = loadSavedVersionHash() if (latestSha != currentSha || force) { - val requestUrl = "https://github.com/${RepoManager.Config.username}/${RepoManager.Config.reponame}/archive/$latestSha.zip" + val requestUrl = + "https://github.com/${RepoManager.Config.username}/${RepoManager.Config.reponame}/archive/$latestSha.zip" logger.info("Planning to upgrade repository from $currentSha to $latestSha from $requestUrl") val zipFile = downloadGithubArchive(requestUrl) logger.info("Download repository zip file to $zipFile. Deleting old repository") @@ -106,17 +107,15 @@ object RepoDownloadManager { val entry = cis.nextEntry ?: break if (entry.isDirectory) continue val extractedLocation = - repoSavedLocation.resolve( - entry.name.substringAfter('/', missingDelimiterValue = "") - ) + repoSavedLocation.resolve( + entry.name.substringAfter('/', missingDelimiterValue = "") + ) if (repoSavedLocation !in extractedLocation.iterate { it.parent }) { logger.error("Firmament detected an invalid zip file. This is a potential security risk, please report this in the Firmament discord.") throw RuntimeException("Firmament detected an invalid zip file. This is a potential security risk, please report this in the Firmament discord.") } extractedLocation.parent.createDirectories() - cis.use { - extractedLocation.outputStream().use { cis.copyTo(it) } - } + extractedLocation.outputStream().use { cis.copyTo(it) } } } } diff --git a/src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt b/src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt index 6c877ec..cad1a0f 100644 --- a/src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt +++ b/src/main/kotlin/moe/nea/firmament/repo/RepoManager.kt @@ -99,8 +99,13 @@ object RepoManager { Firmament.coroutineScope.launch { progressBar.reportProgress("Downloading", 0, null) CottonHud.add(progressBar) - RepoDownloadManager.downloadUpdate(force) - progressBar.reportProgress("Download complete", 1, 1) + try { + RepoDownloadManager.downloadUpdate(force) + progressBar.reportProgress("Download complete", 1, 1) + } finally { + CottonHud.remove(progressBar) + + } reload() } } |