diff options
| author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-01-03 11:12:54 +0700 |
|---|---|---|
| committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-01-03 11:12:54 +0700 |
| commit | 487709996c22fb0dbcac792076be799a09865600 (patch) | |
| tree | 5ab6f27a54d673fb057fd3eafd9a5e27816f898c /src/main/kotlin/cc/woverflow/chattils/updater | |
| parent | df895d122a8a2ea249e686578e026c1d0a8b8c47 (diff) | |
| download | Chatting-487709996c22fb0dbcac792076be799a09865600.tar.gz Chatting-487709996c22fb0dbcac792076be799a09865600.tar.bz2 Chatting-487709996c22fb0dbcac792076be799a09865600.zip | |
Chattils -> Chatting (1.1.0)
Update images (ty Mo2men)
update screenshot line tooltip (ty Mo2men)
Diffstat (limited to 'src/main/kotlin/cc/woverflow/chattils/updater')
| -rw-r--r-- | src/main/kotlin/cc/woverflow/chattils/updater/DownloadGui.kt | 54 | ||||
| -rw-r--r-- | src/main/kotlin/cc/woverflow/chattils/updater/Updater.kt | 103 |
2 files changed, 0 insertions, 157 deletions
diff --git a/src/main/kotlin/cc/woverflow/chattils/updater/DownloadGui.kt b/src/main/kotlin/cc/woverflow/chattils/updater/DownloadGui.kt deleted file mode 100644 index c7f59ec..0000000 --- a/src/main/kotlin/cc/woverflow/chattils/updater/DownloadGui.kt +++ /dev/null @@ -1,54 +0,0 @@ -package cc.woverflow.chattils.updater - -import cc.woverflow.chattils.Chattils -import gg.essential.api.EssentialAPI -import gg.essential.api.gui.buildConfirmationModal -import gg.essential.api.utils.Multithreading -import gg.essential.elementa.ElementaVersion -import gg.essential.elementa.WindowScreen -import gg.essential.elementa.dsl.childOf -import java.io.File - -class DownloadGui : WindowScreen(ElementaVersion.V1, true, true, true, -1) { - override fun initScreen(width: Int, height: Int) { - super.initScreen(width, height) - EssentialAPI.getEssentialComponentFactory().buildConfirmationModal { - this.text = "Are you sure you want to update?" - this.secondaryText = - "(This will update from v${Chattils.VER} to ${Updater.latestTag})" - this.onConfirm = { - restorePreviousScreen() - Multithreading.runAsync { - if (Updater.download( - Updater.updateUrl, - File( - "mods/${Chattils.NAME}-${ - Updater.latestTag!!.substringAfter("v") - }.jar" - ) - ) && Updater.download( - "https://github.com/Wyvest/Deleter/releases/download/v1.2/Deleter-1.2.jar", - File(Chattils.modDir.parentFile, "Deleter-1.2.jar") - ) - ) { - EssentialAPI.getNotifications() - .push( - Chattils.NAME, - "The ingame updater has successfully installed the newest version." - ) - Updater.addShutdownHook() - Updater.shouldUpdate = false - } else { - EssentialAPI.getNotifications().push( - Chattils.NAME, - "The ingame updater has NOT installed the newest version as something went wrong." - ) - } - } - } - this.onDeny = { - restorePreviousScreen() - } - } childOf this.window - } -}
\ No newline at end of file diff --git a/src/main/kotlin/cc/woverflow/chattils/updater/Updater.kt b/src/main/kotlin/cc/woverflow/chattils/updater/Updater.kt deleted file mode 100644 index 35b6e79..0000000 --- a/src/main/kotlin/cc/woverflow/chattils/updater/Updater.kt +++ /dev/null @@ -1,103 +0,0 @@ -package cc.woverflow.chattils.updater - -import cc.woverflow.chattils.Chattils -import cc.woverflow.chattils.config.ChattilsConfig -import gg.essential.api.EssentialAPI -import gg.essential.api.utils.Multithreading -import gg.essential.api.utils.WebUtil.downloadToFile -import gg.essential.api.utils.WebUtil.fetchJSON -import gg.essential.universal.UDesktop.open -import net.minecraft.client.Minecraft -import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion -import java.io.File -import java.io.IOException - -object Updater { - var updateUrl = "" - var latestTag: String? = null - var shouldUpdate = false - - fun update() { - Multithreading.runAsync { - try { - val latestRelease = - fetchJSON("https://api.github.com/repos/W-OVERFLOW/${Chattils.ID}/releases/latest").getObject() - latestTag = latestRelease["tag_name"].asString - val currentVersion = - DefaultArtifactVersion(Chattils.VER.substringBefore("-")) - val latestVersion = DefaultArtifactVersion(latestTag!!.substringAfter("v").substringBefore("-")) - if (currentVersion >= latestVersion) { - if (currentVersion != latestVersion || !Chattils.VER.contains("-")) { - return@runAsync - } - } - updateUrl = - latestRelease["assets"].asJsonArray[0].asJsonObject["browser_download_url"] - .asString - if (updateUrl.isNotEmpty()) { - if (ChattilsConfig.showUpdate) { - EssentialAPI.getNotifications().push( - Chattils.NAME, - "${Chattils.NAME} has a new update ($latestTag)! Click here to download it automatically!" - ) { EssentialAPI.getGuiUtil().openScreen(DownloadGui()) } - } - shouldUpdate = true - } - } catch (e: Exception) { - e.printStackTrace() - } - } - } - - fun download(url: String, file: File): Boolean { - var url = url - if (file.exists()) return true - url = url.replace(" ", "%20") - try { - downloadToFile(url, file, "${Chattils.NAME}/${Chattils.VER}") - } catch (e: Exception) { - e.printStackTrace() - return false - } - return file.exists() - } - - /** - * Adapted from RequisiteLaunchwrapper under LGPLv3 - * https://github.com/Qalcyo/RequisiteLaunchwrapper/blob/main/LICENSE - */ - fun addShutdownHook() { - Runtime.getRuntime().addShutdownHook(Thread { - println("Opening Deleter task...") - try { - val runtime = javaRuntime - if (Minecraft.isRunningOnMac) { - open(Chattils.jarFile.parentFile) - } - val file = File(Chattils.modDir.parentFile, "Deleter-1.2.jar") - Runtime.getRuntime() - .exec("\"" + runtime + "\" -jar \"" + file.absolutePath + "\" \"" + Chattils.jarFile.absolutePath + "\"") - } catch (e: Exception) { - e.printStackTrace() - } - Thread.currentThread().interrupt() - }) - } - - /** - * Gets the current Java runtime being used. - * - * @link https://stackoverflow.com/a/47925649 - */ - @get:Throws(IOException::class) - val javaRuntime: String - get() { - val os = System.getProperty("os.name") - val java = System.getProperty("java.home") + File.separator + "bin" + File.separator + - if (os != null && os.lowercase().startsWith("windows")) "java.exe" else "java" - if (!File(java).isFile) { - throw IOException("Unable to find suitable java runtime at $java") - } - return java - } -}
\ No newline at end of file |
