Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
| 092fe6bceb |
2 changed files with 51 additions and 32 deletions
|
|
@ -1 +1,5 @@
|
||||||
setCommand "cpp"
|
setCommand "cpp"
|
||||||
|
when defined(windows):
|
||||||
|
switch("passL", "-static")
|
||||||
|
switch("define", "ssl")
|
||||||
|
switch("app", "gui")
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
# Copyright 2018, NimGL contributors.
|
|
||||||
|
|
||||||
import nimgl/imgui, nimgl/imgui/[impl_opengl, impl_glfw]
|
import nimgl/imgui, nimgl/imgui/[impl_opengl, impl_glfw]
|
||||||
import nimgl/[opengl, glfw]
|
import nimgl/[opengl, glfw]
|
||||||
import std/[times, os, math, asyncdispatch, httpclient, strformat, strutils, paths, dirs, osproc]
|
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):
|
for file in walkDirRec(source, {PathComponent.pcFile}, relative=true):
|
||||||
copyFile($(source.Path / file.Path), $(dest.Path / file.Path))
|
copyFile($(source.Path / file.Path), $(dest.Path / file.Path))
|
||||||
|
|
||||||
|
proc extractClient(zipPath: string, version: string) {.async.} =
|
||||||
proc getClient() {.async.} =
|
|
||||||
removeDir("client")
|
removeDir("client")
|
||||||
# clean up versioned files
|
# clean up versioned files
|
||||||
removeDir(unixToNativePath("client") / "lib")
|
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
|
downloadingClient = true
|
||||||
var client = newAsyncHttpClient(headers=headers, maxRedirects=0)
|
var client = newAsyncHttpClient(headers=headers, maxRedirects=0)
|
||||||
var baseUrl = await getFoulUrl()
|
var baseUrl = await getFoulUrl()
|
||||||
|
|
@ -83,27 +102,13 @@ proc getClient() {.async.} =
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await client.downloadFile(url, path)
|
await client.downloadFile(url, path)
|
||||||
|
except CatchableError as e:
|
||||||
|
echo e.msg
|
||||||
finally:
|
finally:
|
||||||
client.close()
|
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.} =
|
proc onJavaChange(total, progress, speed: BiggestInt) {.async.} =
|
||||||
{.cast(gcsafe).}:
|
{.cast(gcsafe).}:
|
||||||
var status = &"{(progress / 1000).int}K/{(total / 1000).int}k ({speed div 1000} kbps)"
|
var status = &"{(progress / 1000).int}K/{(total / 1000).int}k ({speed div 1000} kbps)"
|
||||||
|
|
@ -148,13 +153,19 @@ proc checkForUpdates() {.async.} =
|
||||||
defer:
|
defer:
|
||||||
checkingForUpdate = false
|
checkingForUpdate = false
|
||||||
if fileExists("version"):
|
if fileExists("version"):
|
||||||
clientVersion = await getFoulVersion()
|
clientVersion = readFile("version")
|
||||||
|
try:
|
||||||
if readFile("version") == clientVersion:
|
var version = await getFoulVersion()
|
||||||
|
if clientVersion == version:
|
||||||
superUnsafeSet(clientStatus, "Client: good to go", 255)
|
superUnsafeSet(clientStatus, "Client: good to go", 255)
|
||||||
else:
|
else:
|
||||||
superUnsafeSet(clientStatus, "Client: needs update", 255)
|
superUnsafeSet(clientStatus, "Client: needs update", 255)
|
||||||
clientExists = false
|
clientExists = false
|
||||||
|
except:
|
||||||
|
superUnsafeSet(clientStatus, "Client: no internet?", 255)
|
||||||
|
clientExists = true
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
superUnsafeSet(clientStatus, "Client: needs download", 255)
|
superUnsafeSet(clientStatus, "Client: needs download", 255)
|
||||||
clientExists = false
|
clientExists = false
|
||||||
|
|
@ -197,6 +208,7 @@ proc main() =
|
||||||
superUnsafeSet(javaBuf, readFile("javaArgs"), 2048)
|
superUnsafeSet(javaBuf, readFile("javaArgs"), 2048)
|
||||||
else:
|
else:
|
||||||
superUnsafeSet(javaBuf, "-Xmx1024m -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true", 2048)
|
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:
|
while not w.windowShouldClose:
|
||||||
frameTimer = cpuTime() + 0.016
|
frameTimer = cpuTime() + 0.016
|
||||||
|
|
@ -235,19 +247,22 @@ proc main() =
|
||||||
|
|
||||||
igText("Client version:")
|
igText("Client version:")
|
||||||
igSameLine()
|
igSameLine()
|
||||||
igText(clientVersion)
|
igText(clientVersion.cstring)
|
||||||
|
|
||||||
if clientExists and javaExists:
|
if javaExists:
|
||||||
igText("Java args:")
|
igText("Java args:")
|
||||||
igSameLine()
|
igSameLine()
|
||||||
igPushItemWidth(211)
|
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()
|
w.hideWindow()
|
||||||
var command = absolutePath(javaDir / "bin" / "java") & " " & (javaBuf.strip(chars={'\x00'}).split(" ") & @["-jar", absolutePath(getJarPath())]).join(" ")
|
var command = absolutePath(javaDir / "bin" / "java") & " " & (javaBuf.strip(chars={'\x00'}).split(" ") & @["-jar", absolutePath(getJarPath())]).join(" ")
|
||||||
var process = execCmdEx(command, workingDir=userDir)
|
var process = execCmdEx(command, workingDir=userDir)
|
||||||
|
writeFile("javaArgs", javaBuf)
|
||||||
w.showWindow()
|
w.showWindow()
|
||||||
|
if os.fileExists("client.zip") and igButton("Manual Update", ImVec2(x: 288, y: 0)):
|
||||||
|
asyncCheck extractClient("client.zip", "[manual install]")
|
||||||
igEnd()
|
igEnd()
|
||||||
# End simple window
|
# End simple window
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue