downloader improvements
This commit is contained in:
parent
0535b6b6bf
commit
63f28b3650
1 changed files with 9 additions and 9 deletions
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
|
|
||||||
import
|
import
|
||||||
ui, asyncdispatch, httpclient, os, finish, registry, strutils
|
ui, asyncdispatch, httpclient, os, finish, registry, strutils, osproc
|
||||||
|
|
||||||
type
|
type
|
||||||
Actions = object
|
Actions = object
|
||||||
|
|
@ -25,6 +25,10 @@ type
|
||||||
const arch = $(sizeof(int)*8)
|
const arch = $(sizeof(int)*8)
|
||||||
|
|
||||||
proc download(pkg: string; c: Controls) {.async.} =
|
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
|
c.bar.value = 0
|
||||||
var client = newAsyncHttpClient()
|
var client = newAsyncHttpClient()
|
||||||
proc onProgressChanged(total, progress, speed: BiggestInt) {.async.} =
|
proc onProgressChanged(total, progress, speed: BiggestInt) {.async.} =
|
||||||
|
|
@ -34,17 +38,13 @@ proc download(pkg: string; c: Controls) {.async.} =
|
||||||
client.onProgressChanged = onProgressChanged
|
client.onProgressChanged = onProgressChanged
|
||||||
# XXX give a destination filename instead
|
# XXX give a destination filename instead
|
||||||
let contents = await client.getContent("https://nim-lang.org/download/" & pkg & ".7z")
|
let contents = await client.getContent("https://nim-lang.org/download/" & pkg & ".7z")
|
||||||
let z = r"..\dist" / pkg & ".7z"
|
|
||||||
# XXX make this async somehow:
|
# XXX make this async somehow:
|
||||||
writeFile(z, contents)
|
writeFile(z, contents)
|
||||||
c.bar.value = 100
|
c.bar.value = 100
|
||||||
let olddir = getCurrentDir()
|
let p = osproc.startProcess("7zG.exe", getCurrentDir() / r"..\dist",
|
||||||
try:
|
["x", pkg & ".7z"])
|
||||||
setCurrentDir(olddir / "dist")
|
if p.waitForExit != 0:
|
||||||
if os.execShellCmd("7zG.exe x " & pkg & ".7z") != 0:
|
|
||||||
c.lab.text = "Unpacking failed: " & z
|
c.lab.text = "Unpacking failed: " & z
|
||||||
finally:
|
|
||||||
setCurrentdir(olddir)
|
|
||||||
|
|
||||||
proc apply(a: Actions; c: Controls) {.async.} =
|
proc apply(a: Actions; c: Controls) {.async.} =
|
||||||
if a.mingw:
|
if a.mingw:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue