@@ -6,14 +6,16 @@ import mynameisjeff.skyblockclientupdater.SkyClientUpdater
6
6
import mynameisjeff.skyblockclientupdater.SkyClientUpdater.mc
7
7
import mynameisjeff.skyblockclientupdater.gui.PromptUpdateScreen
8
8
import net.minecraft.client.gui.GuiMainMenu
9
+ import net.minecraft.util.Util
9
10
import net.minecraftforge.client.event.GuiOpenEvent
10
11
import net.minecraftforge.fml.common.eventhandler.EventPriority
11
12
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
12
13
import org.apache.commons.lang3.StringUtils
13
14
import org.apache.http.HttpVersion
14
15
import org.apache.http.client.methods.HttpGet
15
16
import java.awt.Desktop
16
- import java.io.*
17
+ import java.io.File
18
+ import java.io.IOException
17
19
import java.net.URL
18
20
import kotlin.concurrent.thread
19
21
@@ -47,14 +49,13 @@ object UpdateChecker {
47
49
}
48
50
49
51
fun getLatestCommitID () {
50
- try {
52
+ latestCommitID = try {
51
53
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 ) {
55
56
println (" Failed to load latest commit id" )
56
57
ex.printStackTrace()
57
- latestCommitID = " main"
58
+ " main"
58
59
}
59
60
}
60
61
@@ -72,17 +73,23 @@ object UpdateChecker {
72
73
println (" Copying ${item.second} to mod folder" )
73
74
val newLocation = File (modDir, item.second)
74
75
newLocation.createNewFile()
75
- copyFile( newJar, newLocation )
76
+ newJar.copyTo(newLocation, true )
76
77
newJar.delete()
77
78
}
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
+ }
78
84
println (" Running delete task" )
79
85
if (deleteTask.path == " invalid" ) {
80
86
println (" Task doesn't exist" )
87
+ Desktop .getDesktop().open(File (mc.mcDataDir, " mods" ))
81
88
return @Thread
82
89
}
83
90
val runtime = getJavaRuntime()
84
91
println (" Using runtime $runtime " )
85
- if (net.minecraft.util. Util .getOSType() == net.minecraft.util. Util .EnumOS .OSX ) {
92
+ if (os == Util .EnumOS .OSX ) {
86
93
val sipStatus = Runtime .getRuntime().exec(" csrutil status" )
87
94
sipStatus.waitFor()
88
95
if (! sipStatus.inputStream.readTextAndClose().contains(" System Integrity Protection status: disabled." )) {
@@ -121,7 +128,7 @@ object UpdateChecker {
121
128
fun getLatestMods () {
122
129
var mods = JsonArray ()
123
130
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
125
132
}
126
133
catch (ex: Throwable ) {
127
134
println (" Failed to load mod files" )
@@ -172,17 +179,15 @@ object UpdateChecker {
172
179
println (" Checking for SkyClientUpdater delete task..." )
173
180
val taskDir = File (File (mc.mcDataDir, " skyclientupdater" ), " files" )
174
181
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"
177
183
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() ) {
180
186
thread(name = " Download SkyclientUpdater delete task" ) {
181
187
println (" Downloading SkyClientUpdater delete task." )
182
188
WebUtils .builder.build().use {
183
189
val req = HttpGet (URL (url).toURI())
184
190
req.protocolVersion = HttpVersion .HTTP_1_1
185
- val taskFile = File (taskDir, taskFileName)
186
191
taskFile.createNewFile()
187
192
val res = it.execute(req)
188
193
if (res.statusLine.statusCode != 200 ) {
@@ -197,37 +202,11 @@ object UpdateChecker {
197
202
}
198
203
}
199
204
} else {
200
- deleteTask = existingTask
205
+ deleteTask = taskFile
201
206
println (" SkyClientUpdater delete task found" )
202
207
}
203
208
}
204
209
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
-
231
210
/* *
232
211
* @link https://stackoverflow.com/a/47925649
233
212
*/
0 commit comments