mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 19:52:36 +00:00
finish.nim tool: make path environment creation more robust
This commit is contained in:
@@ -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 &
|
||||
|
||||
Reference in New Issue
Block a user