Compare commits

..

1 commit

Author SHA1 Message Date
092fe6bceb make a bit more resilient 2025-04-09 17:47:28 -07:00
2 changed files with 51 additions and 32 deletions

View file

@ -1 +1,5 @@
setCommand "cpp"
when defined(windows):
switch("passL", "-static")
switch("define", "ssl")
switch("app", "gui")

View file

@ -1,5 +1,3 @@
# Copyright 2018, NimGL contributors.
import nimgl/imgui, nimgl/imgui/[impl_opengl, impl_glfw]
import nimgl/[opengl, glfw]
import std/[times, os, math, asyncdispatch, httpclient, strformat, strutils, paths, dirs, osproc]
@ -67,11 +65,32 @@ proc mergeDirectory(source, dest: string) =
for file in walkDirRec(source, {PathComponent.pcFile}, relative=true):
copyFile($(source.Path / file.Path), $(dest.Path / file.Path))
proc getClient() {.async.} =
proc extractClient(zipPath: string, version: string) {.async.} =
removeDir("client")
# clean up versioned files
removeDir(unixToNativePath("client") / "lib")
superUnsafeSet(clientStatus, "Client: extracting...", 255)
await sleepAsync(10)
ziparchives.extractAll(zipPath, cache / "client")
ziparchives.extractAll(cache / "client" / "mage-client.zip", clientDir)
superUnsafeSet(clientStatus, "Client: good to go", 255)
mergeDirectory(clientDir / "sounds", userDir / "sounds")
mergeDirectory(clientDir / "sample-decks", userDir / "sample-decks")
mergeDirectory(clientDir / "backgrounds", userDir / "backgrounds")
clientExists = true
writeFile("version", version)
clientVersion = readFile("version")
removeFile(zipPath)
mergeDirectory(clientDir / "sounds", userDir / "sounds")
mergeDirectory(clientDir / "sample-decks", userDir / "sample-decks")
mergeDirectory(clientDir / "backgrounds", userDir / "backgrounds")
proc getClient() {.async.} =
downloadingClient = true
var client = newAsyncHttpClient(headers=headers, maxRedirects=0)
var baseUrl = await getFoulUrl()
@ -83,27 +102,13 @@ proc getClient() {.async.} =
try:
await client.downloadFile(url, path)
except CatchableError as e:
echo e.msg
finally:
client.close()
await extractClient(path, baseUrl.split("/")[^1])
superUnsafeSet(clientStatus, "Client: extracting...", 255)
ziparchives.extractAll(path, cache / "client")
ziparchives.extractAll(cache / "client" / "mage-client.zip", clientDir)
superUnsafeSet(clientStatus, "Client: good to go", 255)
mergeDirectory(clientDir / "sounds", userDir / "sounds")
mergeDirectory(clientDir / "sample-decks", userDir / "sample-decks")
mergeDirectory(clientDir / "backgrounds", userDir / "backgrounds")
clientExists = true
writeFile("version", baseUrl.split("/")[^1])
mergeDirectory(clientDir / "sounds", userDir / "sounds")
mergeDirectory(clientDir / "sample-decks", userDir / "sample-decks")
mergeDirectory(clientDir / "backgrounds", userDir / "backgrounds")
proc onJavaChange(total, progress, speed: BiggestInt) {.async.} =
{.cast(gcsafe).}:
var status = &"{(progress / 1000).int}K/{(total / 1000).int}k ({speed div 1000} kbps)"
@ -148,13 +153,19 @@ proc checkForUpdates() {.async.} =
defer:
checkingForUpdate = false
if fileExists("version"):
clientVersion = await getFoulVersion()
clientVersion = readFile("version")
try:
var version = await getFoulVersion()
if clientVersion == version:
superUnsafeSet(clientStatus, "Client: good to go", 255)
else:
superUnsafeSet(clientStatus, "Client: needs update", 255)
clientExists = false
except:
superUnsafeSet(clientStatus, "Client: no internet?", 255)
clientExists = true
if readFile("version") == clientVersion:
superUnsafeSet(clientStatus, "Client: good to go", 255)
else:
superUnsafeSet(clientStatus, "Client: needs update", 255)
clientExists = false
else:
superUnsafeSet(clientStatus, "Client: needs download", 255)
clientExists = false
@ -197,6 +208,7 @@ proc main() =
superUnsafeSet(javaBuf, readFile("javaArgs"), 2048)
else:
superUnsafeSet(javaBuf, "-Xmx1024m -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true", 2048)
writeFile("javaArgs", "-Xmx1024m -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true")
while not w.windowShouldClose:
frameTimer = cpuTime() + 0.016
@ -235,19 +247,22 @@ proc main() =
igText("Client version:")
igSameLine()
igText(clientVersion)
igText(clientVersion.cstring)
if clientExists and javaExists:
if javaExists:
igText("Java args:")
igSameLine()
igPushItemWidth(211)
igInputText("", javaBuf, 2048)
igInputText("", javaBuf.cstring, 2048)
if igButton("Run", ImVec2(x: 288, y: 0)):
if igButton(if clientExists: "Run" else: "Force Run", ImVec2(x: 288, y: 0)):
w.hideWindow()
var command = absolutePath(javaDir / "bin" / "java") & " " & (javaBuf.strip(chars={'\x00'}).split(" ") & @["-jar", absolutePath(getJarPath())]).join(" ")
var process = execCmdEx(command, workingDir=userDir)
writeFile("javaArgs", javaBuf)
w.showWindow()
if os.fileExists("client.zip") and igButton("Manual Update", ImVec2(x: 288, y: 0)):
asyncCheck extractClient("client.zip", "[manual install]")
igEnd()
# End simple window