finish.nim tool: use global path environment variable if local does not exist

This commit is contained in:
Araq
2017-05-17 21:48:36 +02:00
parent b2e649c093
commit 6857363034

View File

@@ -92,7 +92,13 @@ when defined(windows):
echo "Could not access 'config/nim.cfg' [Error]"
proc addToPathEnv*(e: string) =
let p = getUnicodeValue(r"Environment", "Path", HKEY_CURRENT_USER)
var p: string
try:
p = getUnicodeValue(r"Environment", "Path", HKEY_CURRENT_USER)
except OSError:
p = getUnicodeValue(
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)