mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-09-17 08:51:31 +00:00
Small amount of inspection cleanup.
This commit is contained in:
@ -7,7 +7,7 @@ import java.security.MessageDigest
|
|||||||
|
|
||||||
class SmartDownloader(val localFilePath: Path, val remoteDownloadUrl: URI, val sha256: String) {
|
class SmartDownloader(val localFilePath: Path, val remoteDownloadUrl: URI, val sha256: String) {
|
||||||
fun download(): Boolean {
|
fun download(): Boolean {
|
||||||
if (!checkLocalFileHash()) {
|
if (checkLocalFileHash() == HashResult.ValidHash) {
|
||||||
downloadRemoteFile()
|
downloadRemoteFile()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -19,14 +19,14 @@ class SmartDownloader(val localFilePath: Path, val remoteDownloadUrl: URI, val s
|
|||||||
val remoteFileStream = url.openStream()
|
val remoteFileStream = url.openStream()
|
||||||
val localFileStream = Files.newOutputStream(localFilePath)
|
val localFileStream = Files.newOutputStream(localFilePath)
|
||||||
remoteFileStream.transferTo(localFileStream)
|
remoteFileStream.transferTo(localFileStream)
|
||||||
if (!checkLocalFileHash()) {
|
if (checkLocalFileHash() != HashResult.ValidHash) {
|
||||||
throw RuntimeException("Download of ${remoteDownloadUrl} did not result in valid hash.")
|
throw RuntimeException("Download of $remoteDownloadUrl did not result in valid hash.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkLocalFileHash(): Boolean {
|
private fun checkLocalFileHash(): HashResult {
|
||||||
if (!Files.exists(localFilePath)) {
|
if (!Files.exists(localFilePath)) {
|
||||||
return false
|
return HashResult.DoesNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
val digest = MessageDigest.getInstance("SHA-256")
|
val digest = MessageDigest.getInstance("SHA-256")
|
||||||
@ -45,7 +45,11 @@ class SmartDownloader(val localFilePath: Path, val remoteDownloadUrl: URI, val s
|
|||||||
|
|
||||||
val sha256Bytes = digest.digest()
|
val sha256Bytes = digest.digest()
|
||||||
val localSha256Hash = bytesToHex(sha256Bytes)
|
val localSha256Hash = bytesToHex(sha256Bytes)
|
||||||
return localSha256Hash.equals(sha256, ignoreCase = true)
|
return if (localSha256Hash.equals(sha256, ignoreCase = true)) {
|
||||||
|
HashResult.ValidHash
|
||||||
|
} else {
|
||||||
|
HashResult.InvalidHash
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun bytesToHex(hash: ByteArray): String {
|
private fun bytesToHex(hash: ByteArray): String {
|
||||||
@ -59,4 +63,10 @@ class SmartDownloader(val localFilePath: Path, val remoteDownloadUrl: URI, val s
|
|||||||
}
|
}
|
||||||
return hexString.toString()
|
return hexString.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class HashResult {
|
||||||
|
DoesNotExist,
|
||||||
|
InvalidHash,
|
||||||
|
ValidHash
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,6 @@ import kotlin.io.path.inputStream
|
|||||||
class GameplayFeature : Feature() {
|
class GameplayFeature : Feature() {
|
||||||
private val config by inject<GameplayConfig>()
|
private val config by inject<GameplayConfig>()
|
||||||
|
|
||||||
override fun enable() {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun disable() {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun module() = module {
|
override fun module() = module {
|
||||||
single {
|
single {
|
||||||
val configPath = Util.copyDefaultConfig<FoundationCorePlugin>(
|
val configPath = Util.copyDefaultConfig<FoundationCorePlugin>(
|
||||||
|
Reference in New Issue
Block a user