diff options
author | Araq <rumpf_a@web.de> | 2017-09-30 15:37:36 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2017-09-30 15:37:36 +0200 |
commit | 7e07fc5893baf40093a44c1cee71feea88555f71 (patch) | |
tree | 2a0a69120c70fb28b0c877168f4af4981e2d6e73 /tools/finish.nim | |
parent | 7b63ee85b93caff1a992171cf4ae5a04c330d726 (diff) | |
download | Nim-7e07fc5893baf40093a44c1cee71feea88555f71.tar.gz |
finish.nim tool: make path environment creation more robust
Diffstat (limited to 'tools/finish.nim')
-rw-r--r-- | tools/finish.nim | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/tools/finish.nim b/tools/finish.nim index a6f689eac..45d7dd3a8 100644 --- a/tools/finish.nim +++ b/tools/finish.nim @@ -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 & |