diff --git a/config.nims b/config.nims index 9e98732..feacfdf 100644 --- a/config.nims +++ b/config.nims @@ -1,5 +1 @@ -setCommand "cpp" -when defined(windows): - switch("passL", "-static") -switch("define", "ssl") -switch("app", "gui") \ No newline at end of file +setCommand "cpp" \ No newline at end of file diff --git a/src/magicmissile.nim b/src/magicmissile.nim index cbe07cf..42bb53a 100644 --- a/src/magicmissile.nim +++ b/src/magicmissile.nim @@ -1,3 +1,5 @@ +# 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] @@ -64,33 +66,12 @@ proc mergeDirectory(source, dest: string) = for file in walkDirRec(source, {PathComponent.pcFile}, relative=true): copyFile($(source.Path / file.Path), $(dest.Path / file.Path)) + -proc extractClient(zipPath: string, version: string) {.async.} = +proc getClient() {.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() @@ -102,12 +83,26 @@ 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).}: @@ -153,19 +148,13 @@ proc checkForUpdates() {.async.} = defer: checkingForUpdate = false if fileExists("version"): - 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 + clientVersion = await getFoulVersion() - + 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 @@ -208,7 +197,6 @@ 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 @@ -247,22 +235,19 @@ proc main() = igText("Client version:") igSameLine() - igText(clientVersion.cstring) + igText(clientVersion) - if javaExists: + if clientExists and javaExists: igText("Java args:") igSameLine() igPushItemWidth(211) - igInputText("", javaBuf.cstring, 2048) + igInputText("", javaBuf, 2048) - if igButton(if clientExists: "Run" else: "Force Run", ImVec2(x: 288, y: 0)): + if igButton("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