downloader tool works
This commit is contained in:
parent
7652d15ed2
commit
26a8364ed7
2 changed files with 26 additions and 9 deletions
|
|
@ -1,8 +1,7 @@
|
||||||
|
# Helper that is run after Nim's installation.
|
||||||
# Test & show the new high level wrapper
|
|
||||||
|
|
||||||
import
|
import
|
||||||
"../ui", asyncdispatch, httpclient, zip/zipfiles, os
|
ui, asyncdispatch, httpclient, os, finish, registry, strutils
|
||||||
|
|
||||||
type
|
type
|
||||||
Actions = object
|
Actions = object
|
||||||
|
|
@ -28,6 +27,9 @@ proc download(pkg: string; c: Controls) {.async.} =
|
||||||
# XXX make this async somehow:
|
# XXX make this async somehow:
|
||||||
writeFile(z, contents)
|
writeFile(z, contents)
|
||||||
c.bar.value = 100
|
c.bar.value = 100
|
||||||
|
if os.execShellCmd("7zG x " & z) != 0:
|
||||||
|
c.lab.text = "Unpacking failed: " & z
|
||||||
|
|
||||||
when false:
|
when false:
|
||||||
var a: ZipArchive
|
var a: ZipArchive
|
||||||
if open(a, z, fmRead):
|
if open(a, z, fmRead):
|
||||||
|
|
@ -41,13 +43,28 @@ proc apply(a: Actions; c: Controls) {.async.} =
|
||||||
await download("mingw" & arch, c)
|
await download("mingw" & arch, c)
|
||||||
if a.aporia:
|
if a.aporia:
|
||||||
await download("aporia-0.4.0", c)
|
await download("aporia-0.4.0", c)
|
||||||
if a.startMenu:
|
|
||||||
discard "add start menu entry"
|
if a.addToPath:
|
||||||
|
let desiredPath = expandFilename(getCurrentDir() / "bin")
|
||||||
|
let p = getUnicodeValue(r"Environment", "Path",
|
||||||
|
HKEY_CURRENT_USER)
|
||||||
|
var alreadyInPath = false
|
||||||
|
for x in p.split(';'):
|
||||||
|
if x.len == 0: continue
|
||||||
|
let y = try: expandFilename(if x[0] == '"' and x[^1] == '"':
|
||||||
|
substr(x, 1, x.len-2) else: x)
|
||||||
|
except: ""
|
||||||
|
if y == desiredPath: alreadyInPath = true
|
||||||
|
if not alreadyInPath:
|
||||||
|
addToPathEnv(desiredPath)
|
||||||
|
|
||||||
|
if a.startMenu:
|
||||||
|
createStartMenuEntry()
|
||||||
|
|
||||||
c.apply.text = "Quit"
|
c.apply.text = "Quit"
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
var mainwin = newWindow("Nim installer", 640, 480, true)
|
var mainwin = newWindow("Nim installer", 640, 280, true)
|
||||||
mainwin.margined = true
|
mainwin.margined = true
|
||||||
mainwin.onClosing = (proc (): bool = return true)
|
mainwin.onClosing = (proc (): bool = return true)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ when defined(windows):
|
||||||
except IOError:
|
except IOError:
|
||||||
echo "Could not access 'config/nim.cfg' [Error]"
|
echo "Could not access 'config/nim.cfg' [Error]"
|
||||||
|
|
||||||
proc addToPathEnv(e: string) =
|
proc addToPathEnv*(e: string) =
|
||||||
let p = getUnicodeValue(r"Environment", "Path", HKEY_CURRENT_USER)
|
let p = getUnicodeValue(r"Environment", "Path", HKEY_CURRENT_USER)
|
||||||
let x = if e.contains(Whitespace): "\"" & e & "\"" else: e
|
let x = if e.contains(Whitespace): "\"" & e & "\"" else: e
|
||||||
setUnicodeValue(r"Environment", "Path", p & ";" & x, HKEY_CURRENT_USER)
|
setUnicodeValue(r"Environment", "Path", p & ";" & x, HKEY_CURRENT_USER)
|
||||||
|
|
@ -65,13 +65,13 @@ when defined(windows):
|
||||||
cmd.add " \"" & icon & "\" 0"
|
cmd.add " \"" & icon & "\" 0"
|
||||||
discard execShellCmd(cmd)
|
discard execShellCmd(cmd)
|
||||||
|
|
||||||
proc createStartMenuEntry() =
|
proc createStartMenuEntry*(override = false) =
|
||||||
let appdata = getEnv("APPDATA")
|
let appdata = getEnv("APPDATA")
|
||||||
if appdata.len == 0: return
|
if appdata.len == 0: return
|
||||||
let dest = appdata & r"\Microsoft\Windows\Start Menu\Programs\Nim-" &
|
let dest = appdata & r"\Microsoft\Windows\Start Menu\Programs\Nim-" &
|
||||||
NimVersion
|
NimVersion
|
||||||
if dirExists(dest): return
|
if dirExists(dest): return
|
||||||
if askBool("Would like to add Nim-" & NimVersion &
|
if override or askBool("Would like to add Nim-" & NimVersion &
|
||||||
" to your start menu? (y/n) "):
|
" to your start menu? (y/n) "):
|
||||||
createDir(dest)
|
createDir(dest)
|
||||||
createShortcut(getCurrentDir() / "tools" / "start.bat", dest / "Nim",
|
createShortcut(getCurrentDir() / "tools" / "start.bat", dest / "Nim",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue