launcher now checks if there is an update before downloading it

This commit is contained in:
ryannathans 2022-04-26 19:03:48 +10:00
parent a6e855a740
commit 99c798daad
3 changed files with 9 additions and 27 deletions

View file

@ -9,18 +9,6 @@ import java.security.NoSuchAlgorithmException
import kotlin.experimental.and
object Checksum {
val localChecksum: String?
get() {
val local: File = File(Settings.SAVE_DIR + Settings.SAVE_NAME)
try {
FileInputStream(local).use { fis -> return calculateMd5(fis) }
} catch (e: Exception) {
e.printStackTrace()
MainWindow.loadingLabel.text = e.message
MainWindow.loadingLabel.repaint()
}
return null
}
fun getLocalChecksum(file: URI?): String {
val local = File(file!!)
@ -28,21 +16,14 @@ object Checksum {
else FileInputStream(local).use { fis -> return calculateMd5(fis) }
}
val remoteChecksum: String?
get() {
try {
URL(Settings.DOWNLOAD_URL).openStream().use { stream -> return calculateMd5(stream) }
} catch (e: Exception) {
e.printStackTrace()
MainWindow.loadingLabel.text = e.message
MainWindow.loadingLabel.repaint()
return null
}
}
fun getRemoteChecksum(url: String?): String? {
fun getRemoteChecksum(url: String?, checksumFile: Boolean = false): String? {
try {
URL(url).openStream().use { stream -> return calculateMd5(stream) }
if (checksumFile) {
URL(url).openStream().use { stream -> return stream.bufferedReader().use { it.readText().trim() } }
}
else {
URL(url).openStream().use { stream -> return calculateMd5(stream) }
}
} catch (e: Exception) {
e.printStackTrace()
MainWindow.loadingLabel.text = e.message