finish.nim tool: make path environment creation more robust

This commit is contained in:
Araq
2017-09-30 15:37:36 +02:00
parent 7b63ee85b9
commit 7e07fc5893

View File

@@ -91,16 +91,25 @@ when defined(windows):
except IOError:
echo "Could not access 'config/nim.cfg' [Error]"
proc addToPathEnv*(e: string) =
var p: string
proc tryGetUnicodeValue(path, key: string; handle: HKEY): string =
try:
p = getUnicodeValue(r"Environment", "Path", HKEY_CURRENT_USER)
except OSError:
p = getUnicodeValue(
result = getUnicodeValue(path, key, handle)
except:
result = ""
proc addToPathEnv*(e: string) =
var p = tryGetUnicodeValue(r"Environment", "Path", HKEY_CURRENT_USER)
if p.len == 0:
p = tryGetUnicodeValue(
r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment",
"Path", HKEY_LOCAL_MACHINE)
let x = if e.contains(Whitespace): "\"" & e & "\"" else: e
setUnicodeValue(r"Environment", "Path", p & ";" & x, HKEY_CURRENT_USER)
if p.len > 0:
p.add ";"
p.add x
else:
p = x
setUnicodeValue(r"Environment", "Path", p, HKEY_CURRENT_USER)
proc createShortcut(src, dest: string; icon = "") =
var cmd = "bin\\makelink.exe \"" & src & "\" \"\" \"" & dest &