From 7e07fc5893baf40093a44c1cee71feea88555f71 Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 30 Sep 2017 15:37:36 +0200 Subject: finish.nim tool: make path environment creation more robust --- tools/finish.nim | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'tools/finish.nim') 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 & -- cgit 1.4.1-2-gfad0