mirror of
https://gitlab.com/2009scape/09launcher.git
synced 2025-12-09 16:45:54 -07:00
v1.1 - More UI responsiveness, increased download buffer
This commit is contained in:
parent
dee36e793b
commit
8fd259183b
5 changed files with 56 additions and 18 deletions
|
|
@ -3,7 +3,7 @@ plugins {
|
|||
}
|
||||
|
||||
group 'org.rs09'
|
||||
version '1.0'
|
||||
version '1.1'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
import java.awt.Component
|
||||
|
||||
fun Component.placeAt(x: Int, y: Int, width: Int, height: Int){
|
||||
this.setBounds(x,y,width,height)
|
||||
if(this is ImgButton) this.scale(width,height)
|
||||
}
|
||||
13
src/main/kotlin/Globals.kt
Normal file
13
src/main/kotlin/Globals.kt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import java.awt.Component
|
||||
import java.io.File
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
fun Component.placeAt(x: Int, y: Int, width: Int, height: Int){
|
||||
this.setBounds(x,y,width,height)
|
||||
if(this is ImgButton) this.scale(width,height)
|
||||
}
|
||||
|
||||
fun launchClient() {
|
||||
println("Launching client now.")
|
||||
Runtime.getRuntime().exec("java -jar " + Settings.SAVE_DIR + File.separator + Settings.SAVE_NAME, null, File(System.getProperty("user.home"))).also { exitProcess(0) }
|
||||
}
|
||||
|
|
@ -50,8 +50,30 @@ object MainWindow : JFrame("2009scape Launcher") {
|
|||
val loadingFrame = JLabel(ImageIcon(javaClass.getResource("/loadingFrame.png")))
|
||||
playButton.isEnabled = true
|
||||
playButton.onClick {
|
||||
if(Updater.checkUpdate()) Updater.runUpdate()
|
||||
else Runtime.getRuntime().exec("java -jar " + Settings.SAVE_DIR + File.separator + Settings.SAVE_NAME, null, File(System.getProperty("user.home"))).also { exitProcess(0) }
|
||||
val t = Thread {
|
||||
val oldText = loadingLabel.text
|
||||
loadingLabel.text = "Checking for updates"
|
||||
playButton.isEnabled = false
|
||||
var counter = 0
|
||||
var dotCounter = 0
|
||||
while(Updater.status == Updater.UpdateStatus.CHECKING){
|
||||
if(counter++ % 5 == 0){
|
||||
dotCounter++
|
||||
loadingLabel.text = "Checking for updates${".".repeat((dotCounter % 4) + 1)}"
|
||||
}
|
||||
Thread.sleep(50L)
|
||||
}
|
||||
if(Updater.remoteMD5 != "-1" && Updater.remoteMD5 != Updater.localMD5){
|
||||
println("Update required, running update...")
|
||||
loadingLabel.text = oldText
|
||||
Updater.runUpdate()
|
||||
} else {
|
||||
loadingLabel.text = oldText
|
||||
playButton.isEnabled = true
|
||||
launchClient()
|
||||
}
|
||||
}.start()
|
||||
Thread { Updater.checkUpdate() }.start()
|
||||
}
|
||||
loadingFrame.placeAt(96,MainWindow.height - 35, 704, 35)
|
||||
loadingBar.placeAt(103, MainWindow.height - 33, 695, 31)
|
||||
|
|
|
|||
|
|
@ -7,13 +7,16 @@ import javax.swing.ImageIcon
|
|||
|
||||
object Updater {
|
||||
|
||||
private var status = UpdateStatus.DOWNLOADING
|
||||
var status = UpdateStatus.CHECKING
|
||||
var localMD5 = "-1"
|
||||
var remoteMD5 = "-1"
|
||||
|
||||
fun checkUpdate(): Boolean{
|
||||
val localMD5 = Checksum.getLocalChecksum(Settings.SAVE_DIR + File.separator + Settings.SAVE_NAME)
|
||||
val remoteMD5 = Checksum.getRemoteChecksum(Settings.DOWNLOAD_URL)
|
||||
|
||||
return localMD5 != remoteMD5
|
||||
fun checkUpdate(){
|
||||
status = UpdateStatus.CHECKING
|
||||
localMD5 = Checksum.getLocalChecksum(Settings.SAVE_DIR + File.separator + Settings.SAVE_NAME)
|
||||
remoteMD5 = Checksum.getRemoteChecksum(Settings.DOWNLOAD_URL) ?: "-1"
|
||||
println("Local: $localMD5 || Remote: $remoteMD5")
|
||||
status = UpdateStatus.COMPLETE
|
||||
}
|
||||
|
||||
fun runUpdate(){
|
||||
|
|
@ -42,9 +45,12 @@ object Updater {
|
|||
|
||||
val stream = connection.getInputStream()
|
||||
|
||||
status = UpdateStatus.DOWNLOADING
|
||||
var start = System.currentTimeMillis()
|
||||
|
||||
while(status == UpdateStatus.DOWNLOADING){
|
||||
val buffer = if(length - downloaded > 1024){
|
||||
ByteArray(1024)
|
||||
val buffer = if(length - downloaded > 4096){
|
||||
ByteArray(4096)
|
||||
} else {
|
||||
ByteArray(length - downloaded)
|
||||
}
|
||||
|
|
@ -74,12 +80,15 @@ object Updater {
|
|||
status = UpdateStatus.COMPLETE
|
||||
}
|
||||
}
|
||||
println("Time taken: ${System.currentTimeMillis() - start}ms")
|
||||
MainWindow.loadingBar.icon = ImageIcon((MainWindow.loadingBar.icon as ImageIcon).image.getScaledInstance(695, 31, Image.SCALE_FAST))
|
||||
MainWindow.loadingBar.placeAt(103, MainWindow.height - 33, 695, 31)
|
||||
launchClient()
|
||||
}.start()
|
||||
}
|
||||
|
||||
internal enum class UpdateStatus{
|
||||
enum class UpdateStatus{
|
||||
CHECKING,
|
||||
DOWNLOADING,
|
||||
COMPLETE
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue