diff options
author | Araq <rumpf_a@web.de> | 2017-02-08 00:34:36 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2017-02-08 00:34:36 +0100 |
commit | 63f28b3650aee952b851875c6c687aaca23855fd (patch) | |
tree | db056251b57912093968d6be820c2db54624f504 | |
parent | 0535b6b6bf5b533f1238832e5f92cdd50e3fa1de (diff) | |
download | Nim-63f28b3650aee952b851875c6c687aaca23855fd.tar.gz |
downloader improvements
-rw-r--r-- | tools/downloader.nim | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/tools/downloader.nim b/tools/downloader.nim index da79cde8d..48331e97a 100644 --- a/tools/downloader.nim +++ b/tools/downloader.nim @@ -12,7 +12,7 @@ import - ui, asyncdispatch, httpclient, os, finish, registry, strutils + ui, asyncdispatch, httpclient, os, finish, registry, strutils, osproc type Actions = object @@ -25,6 +25,10 @@ type const arch = $(sizeof(int)*8) proc download(pkg: string; c: Controls) {.async.} = + let z = r"..\dist" / pkg & ".7z" + if fileExists(z): + c.lab.text = z & " already exists" + return c.bar.value = 0 var client = newAsyncHttpClient() proc onProgressChanged(total, progress, speed: BiggestInt) {.async.} = @@ -34,17 +38,13 @@ proc download(pkg: string; c: Controls) {.async.} = client.onProgressChanged = onProgressChanged # XXX give a destination filename instead let contents = await client.getContent("https://nim-lang.org/download/" & pkg & ".7z") - let z = r"..\dist" / pkg & ".7z" # XXX make this async somehow: writeFile(z, contents) c.bar.value = 100 - let olddir = getCurrentDir() - try: - setCurrentDir(olddir / "dist") - if os.execShellCmd("7zG.exe x " & pkg & ".7z") != 0: - c.lab.text = "Unpacking failed: " & z - finally: - setCurrentdir(olddir) + let p = osproc.startProcess("7zG.exe", getCurrentDir() / r"..\dist", + ["x", pkg & ".7z"]) + if p.waitForExit != 0: + c.lab.text = "Unpacking failed: " & z proc apply(a: Actions; c: Controls) {.async.} = if a.mingw: |