Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit 3f9a592

Browse files
1.0.9
1 parent 18e1640 commit 3f9a592

File tree

3 files changed

+23
-44
lines changed

3 files changed

+23
-44
lines changed

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77

88
ext.kotlin_version = "1.5.21"
99

10-
version = "1.0.8"
10+
version = "1.0.9"
1111
group = "mynameisjeff"
1212
archivesBaseName = "SkyblockClient-Updater"
1313

@@ -67,7 +67,7 @@ processResources {
6767
task moveResources {
6868
doLast {
6969
ant.move file: "${buildDir}/resources/main",
70-
todir: "${buildDir}/classes/java"
70+
todir: "${buildDir}/classes/kotlin"
7171
}
7272
}
7373

src/main/kotlin/mynameisjeff/skyblockclientupdater/SkyClientUpdater.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent
1313
@Mod(modid = "skyblockclientupdater", name = "SkyClient Updater", version = SkyClientUpdater.VERSION, clientSideOnly = true, modLanguage = "kotlin", modLanguageAdapter = "mynameisjeff.skyblockclientupdater.utils.kotlin.KotlinAdapter")
1414
object SkyClientUpdater {
1515

16-
const val VERSION = "1.0.8"
16+
const val VERSION = "1.0.9"
1717

1818
val mc: Minecraft
1919
get() = Minecraft.getMinecraft()

src/main/kotlin/mynameisjeff/skyblockclientupdater/utils/UpdateChecker.kt

+20-41
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import mynameisjeff.skyblockclientupdater.SkyClientUpdater
66
import mynameisjeff.skyblockclientupdater.SkyClientUpdater.mc
77
import mynameisjeff.skyblockclientupdater.gui.PromptUpdateScreen
88
import net.minecraft.client.gui.GuiMainMenu
9+
import net.minecraft.util.Util
910
import net.minecraftforge.client.event.GuiOpenEvent
1011
import net.minecraftforge.fml.common.eventhandler.EventPriority
1112
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
1213
import org.apache.commons.lang3.StringUtils
1314
import org.apache.http.HttpVersion
1415
import org.apache.http.client.methods.HttpGet
1516
import java.awt.Desktop
16-
import java.io.*
17+
import java.io.File
18+
import java.io.IOException
1719
import java.net.URL
1820
import kotlin.concurrent.thread
1921

@@ -47,14 +49,13 @@ object UpdateChecker {
4749
}
4850

4951
fun getLatestCommitID() {
50-
try {
52+
latestCommitID = try {
5153
val commits = JsonParser().parse(WebUtils.fetchResponse("https://api.github.com/repos/nacrt/SkyblockClient-REPO/commits")).asJsonArray
52-
latestCommitID = commits[0].asJsonObject["sha"].asString
53-
}
54-
catch (ex: Throwable) {
54+
commits[0].asJsonObject["sha"].asString
55+
} catch (ex: Throwable) {
5556
println("Failed to load latest commit id")
5657
ex.printStackTrace()
57-
latestCommitID = "main"
58+
"main"
5859
}
5960
}
6061

@@ -72,17 +73,23 @@ object UpdateChecker {
7273
println("Copying ${item.second} to mod folder")
7374
val newLocation = File(modDir, item.second)
7475
newLocation.createNewFile()
75-
copyFile(newJar, newLocation)
76+
newJar.copyTo(newLocation, true)
7677
newJar.delete()
7778
}
79+
val os = Util.getOSType()
80+
if ((os == Util.EnumOS.OSX || os == Util.EnumOS.LINUX) && needsDelete.removeAll { it.first.delete() } && needsDelete.isEmpty()) {
81+
println("Successfully deleted all files normally.")
82+
return@Thread
83+
}
7884
println("Running delete task")
7985
if (deleteTask.path == "invalid") {
8086
println("Task doesn't exist")
87+
Desktop.getDesktop().open(File(mc.mcDataDir, "mods"))
8188
return@Thread
8289
}
8390
val runtime = getJavaRuntime()
8491
println("Using runtime $runtime")
85-
if (net.minecraft.util.Util.getOSType() == net.minecraft.util.Util.EnumOS.OSX) {
92+
if (os == Util.EnumOS.OSX) {
8693
val sipStatus = Runtime.getRuntime().exec("csrutil status")
8794
sipStatus.waitFor()
8895
if (!sipStatus.inputStream.readTextAndClose().contains("System Integrity Protection status: disabled.")) {
@@ -121,7 +128,7 @@ object UpdateChecker {
121128
fun getLatestMods() {
122129
var mods = JsonArray()
123130
try {
124-
mods = JsonParser().parse(WebUtils.fetchResponse("https://rawcdn.githack.com/nacrt/SkyblockClient-REPO/$latestCommitID/files/mods.json")).asJsonArray
131+
mods = JsonParser().parse(WebUtils.fetchResponse("https://cdn.jsdelivr.net/gh/nacrt/SkyblockClient-REPO@$latestCommitID/files/mods.json")).asJsonArray
125132
}
126133
catch (ex: Throwable) {
127134
println("Failed to load mod files")
@@ -172,17 +179,15 @@ object UpdateChecker {
172179
println("Checking for SkyClientUpdater delete task...")
173180
val taskDir = File(File(mc.mcDataDir, "skyclientupdater"), "files")
174181
val url =
175-
"https://cdn.discordapp.com/attachments/807303259902705685/841080571731640401/SkytilsInstaller-1.0-SNAPSHOT.jar"
176-
val taskFileName = getJarNameFromUrl(url)
182+
"https://cdn.discordapp.com/attachments/807303259902705685/864882597342740511/SkytilsInstaller-1.1-SNAPSHOT.jar"
177183
taskDir.mkdirs()
178-
val existingTask = taskDir.listFiles()!!.find { it.name == taskFileName }
179-
if (existingTask == null) {
184+
val taskFile = File(taskDir, url.substringAfterLast("/"))
185+
if (!taskFile.exists()) {
180186
thread(name = "Download SkyclientUpdater delete task") {
181187
println("Downloading SkyClientUpdater delete task.")
182188
WebUtils.builder.build().use {
183189
val req = HttpGet(URL(url).toURI())
184190
req.protocolVersion = HttpVersion.HTTP_1_1
185-
val taskFile = File(taskDir, taskFileName)
186191
taskFile.createNewFile()
187192
val res = it.execute(req)
188193
if (res.statusLine.statusCode != 200) {
@@ -197,37 +202,11 @@ object UpdateChecker {
197202
}
198203
}
199204
} else {
200-
deleteTask = existingTask
205+
deleteTask = taskFile
201206
println("SkyClientUpdater delete task found")
202207
}
203208
}
204209

205-
fun getJarNameFromUrl(url: String): String {
206-
val sUrl = url.split("/".toRegex()).toTypedArray()
207-
return sUrl[sUrl.size - 1]
208-
}
209-
210-
private fun copyFile(sourceFile: File, destFile: File) {
211-
if (!destFile.exists()) {
212-
sourceFile.renameTo(destFile)
213-
return
214-
}
215-
var source: InputStream? = null
216-
var dest: OutputStream? = null
217-
try {
218-
source = FileInputStream(sourceFile)
219-
dest = FileOutputStream(destFile)
220-
val buffer = ByteArray(1024)
221-
var length: Int
222-
while (source.read(buffer).also { length = it } > 0) {
223-
dest.write(buffer, 0, length)
224-
}
225-
} finally {
226-
source!!.close()
227-
dest!!.close()
228-
}
229-
}
230-
231210
/**
232211
* @link https://stackoverflow.com/a/47925649
233212
*/

0 commit comments

Comments
 (0)