mirror of
https://gitlab.com/2009scape/09launcher.git
synced 2025-12-09 16:45:54 -07:00
launcher now checks if there is an update before downloading it
This commit is contained in:
parent
a6e855a740
commit
99c798daad
3 changed files with 9 additions and 27 deletions
|
|
@ -9,18 +9,6 @@ import java.security.NoSuchAlgorithmException
|
||||||
import kotlin.experimental.and
|
import kotlin.experimental.and
|
||||||
|
|
||||||
object Checksum {
|
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 {
|
fun getLocalChecksum(file: URI?): String {
|
||||||
val local = File(file!!)
|
val local = File(file!!)
|
||||||
|
|
@ -28,21 +16,14 @@ object Checksum {
|
||||||
else FileInputStream(local).use { fis -> return calculateMd5(fis) }
|
else FileInputStream(local).use { fis -> return calculateMd5(fis) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val remoteChecksum: String?
|
fun getRemoteChecksum(url: String?, checksumFile: Boolean = false): 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? {
|
|
||||||
try {
|
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) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
MainWindow.loadingLabel.text = e.message
|
MainWindow.loadingLabel.text = e.message
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ object Settings {
|
||||||
}
|
}
|
||||||
val SAVE_NAME = "2009scape.jar"
|
val SAVE_NAME = "2009scape.jar"
|
||||||
val DOWNLOAD_URL = "http://play.2009scape.org/2009scape.jar"
|
val DOWNLOAD_URL = "http://play.2009scape.org/2009scape.jar"
|
||||||
|
val DOWNLOAD_MD5_URL = "http://play.2009scape.org/2009scape.md5sum"
|
||||||
val LAUNCHER_URL = "https://gitlab.com/2009scape/09launcher/-/jobs/artifacts/master/raw/build/libs/2009scape.jar?job=build"
|
val LAUNCHER_URL = "https://gitlab.com/2009scape/09launcher/-/jobs/artifacts/master/raw/build/libs/2009scape.jar?job=build"
|
||||||
var HAS_UPDATED = false
|
var HAS_UPDATED = false
|
||||||
var CHECK_FOR_UPDATES = true
|
var CHECK_FOR_UPDATES = true
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ object Updater {
|
||||||
val fileUri = File(Settings.SAVE_DIR + File.separator + Settings.SAVE_NAME).toURI()
|
val fileUri = File(Settings.SAVE_DIR + File.separator + Settings.SAVE_NAME).toURI()
|
||||||
status = UpdateStatus.CHECKING
|
status = UpdateStatus.CHECKING
|
||||||
localMD5 = Checksum.getLocalChecksum(fileUri)
|
localMD5 = Checksum.getLocalChecksum(fileUri)
|
||||||
remoteMD5 = Checksum.getRemoteChecksum(Settings.DOWNLOAD_URL) ?: "-1"
|
remoteMD5 = Checksum.getRemoteChecksum(Settings.DOWNLOAD_MD5_URL, checksumFile = true) ?: "-1"
|
||||||
println("Local: $localMD5 || Remote: $remoteMD5")
|
println("Local: $localMD5 || Remote: $remoteMD5")
|
||||||
status = UpdateStatus.COMPLETE
|
status = UpdateStatus.COMPLETE
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue