-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
81 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 0 additions & 59 deletions
59
src/main/kotlin/ru/lionzxy/tplauncher/downloader/MinecraftDownloader.kt
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
src/main/kotlin/ru/lionzxy/tplauncher/downloader/Updater.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ru.lionzxy.tplauncher.downloader | ||
|
||
import com.google.gson.Gson | ||
import com.google.gson.annotations.SerializedName | ||
import com.google.gson.reflect.TypeToken | ||
import ru.lionzxy.tplauncher.utils.ConfigHelper | ||
import sk.tomsik68.mclauncher.api.ui.IProgressMonitor | ||
import sk.tomsik68.mclauncher.util.FileUtils | ||
import sk.tomsik68.mclauncher.util.HttpUtils | ||
import java.io.File | ||
|
||
const val UPDATER_JSON_URL = "http://download.glitchless.ru/minecraft_dist/first_server/changelog.json" | ||
const val HOST_URL = "http://download.glitchless.ru/minecraft_dist/first_server/" | ||
|
||
class Updater { | ||
val changes = HashMap<String, Action>() | ||
val gson = Gson() | ||
var lastChangeTimestamp = 0L | ||
|
||
fun initUpdater() { | ||
val lastUpdateTimestamp = ConfigHelper.config.lastUpdateFromChangeLog ?: 0 | ||
val json = HttpUtils.httpGet(UPDATER_JSON_URL) | ||
val type = object : TypeToken<Map<String, Map<String, Action>>>() {}.type | ||
val map = gson.fromJson<Map<String, Map<String, Action>>>(json, type) | ||
val changeLog = map.map { it.key.toLong() to it.value } | ||
.filter { it.first > lastUpdateTimestamp }.sortedBy { it.first } | ||
lastChangeTimestamp = changeLog.lastOrNull()?.first ?: 0 | ||
changeLog.forEach { changes.putAll(it.second) } | ||
} | ||
|
||
fun update(monitor: IProgressMonitor) { | ||
val base = ConfigHelper.getDefaultDirectory() | ||
changes.forEach { | ||
val file = File(base, it.key) | ||
if (it.value == Action.REMOVE) { | ||
file.delete() | ||
} else if (it.value == Action.ADD) { | ||
file.delete() | ||
monitor.setStatus("Downloading ${it.key}") | ||
FileUtils.downloadFileWithProgress(HOST_URL + it.key, file, monitor) | ||
} | ||
} | ||
ConfigHelper.writeToConfig { | ||
lastUpdateFromChangeLog = lastChangeTimestamp | ||
} | ||
} | ||
} | ||
|
||
enum class Action(code: Int) { | ||
@SerializedName("0") | ||
REMOVE(0), | ||
@SerializedName("1") | ||
ADD(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters