diff options
author | nea <romangraef@gmail.com> | 2022-08-03 02:31:05 +0200 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2022-08-03 02:31:05 +0200 |
commit | 2625eeb7dedb05b524b08721e1267acdcd93e5c1 (patch) | |
tree | 476117af52a76f22c445b8b8dac4778f24ce5c51 /src/main/kotlin/moe/nea/notenoughupdates/repo/RepoDownloadManager.kt | |
parent | b9455467863f194accf30a89b2c2998822f2c105 (diff) | |
download | Firmament-2625eeb7dedb05b524b08721e1267acdcd93e5c1.tar.gz Firmament-2625eeb7dedb05b524b08721e1267acdcd93e5c1.tar.bz2 Firmament-2625eeb7dedb05b524b08721e1267acdcd93e5c1.zip |
scuffed config screen
Diffstat (limited to 'src/main/kotlin/moe/nea/notenoughupdates/repo/RepoDownloadManager.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/notenoughupdates/repo/RepoDownloadManager.kt | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoDownloadManager.kt b/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoDownloadManager.kt index 977c035..34279af 100644 --- a/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoDownloadManager.kt +++ b/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoDownloadManager.kt @@ -24,22 +24,18 @@ object RepoDownloadManager { val repoSavedLocation = NotEnoughUpdates.DATA_DIR.resolve("repo-extracted") val repoMetadataLocation = NotEnoughUpdates.DATA_DIR.resolve("loaded-repo-sha.txt") - val user = "NotEnoughUpdates" - val repo = "NotEnoughUpdates-REPO" - val branch = "dangerous" - private fun loadSavedVersionHash(): String? = - if (repoSavedLocation.exists()) { - if (repoMetadataLocation.exists()) { - try { - repoMetadataLocation.readText().trim() - } catch (e: IOException) { + if (repoSavedLocation.exists()) { + if (repoMetadataLocation.exists()) { + try { + repoMetadataLocation.readText().trim() + } catch (e: IOException) { + null + } + } else { null } - } else { - null - } - } else null + } else null private fun saveVersionHash(versionHash: String) { latestSavedVersionHash = versionHash @@ -54,7 +50,7 @@ object RepoDownloadManager { private suspend fun requestLatestGithubSha(): String? { val response = - NotEnoughUpdates.httpClient.get("https://api.github.com/repos/$user/$repo/commits/$branch") + NotEnoughUpdates.httpClient.get("https://api.github.com/repos/${RepoManager.config.user}/${RepoManager.config.repo}/commits/${RepoManager.config.branch}") if (response.status.value != 200) { return null } @@ -81,11 +77,11 @@ object RepoDownloadManager { } val currentSha = loadSavedVersionHash() if (latestSha != currentSha) { - val requestUrl = "https://github.com/$user/$repo/archive/$latestSha.zip" + val requestUrl = "https://github.com/${RepoManager.config.user}/${RepoManager.config.repo}/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") - withContext(IO) { repoSavedLocation.deleteIfExists() } + withContext(IO) { repoSavedLocation.toFile().deleteRecursively() } logger.info("Extracting new repository") withContext(IO) { extractNewRepository(zipFile) } logger.info("Repository loaded on disk.") @@ -104,9 +100,9 @@ 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("Not Enough Updates detected an invalid zip file. This is a potential security risk, please report this in the Moulberry discord.") throw RuntimeException("Not Enough Updates detected an invalid zip file. This is a potential security risk, please report this in the Moulberry discord.") |