diff options
author | Leon Bottou <leon@bottou.org> | 2013-08-26 23:44:32 +0400 |
---|---|---|
committer | Leon Bottou <leon@bottou.org> | 2013-08-26 23:44:32 +0400 |
commit | 6da1c72df173e2c45e512ebaabe25edad7f8ec45 (patch) | |
tree | fcb4a24273ac7230db06201eaaf07cff4293c0ff | |
parent | bcc2b133e88081692a5d2bd5be3727ddeec0e8bf (diff) |
more aggressive program search (win)
-rw-r--r-- | init.lua.in | 23 | ||||
-rw-r--r-- | paths.c | 51 |
2 files changed, 55 insertions, 19 deletions
diff --git a/init.lua.in b/init.lua.in index 197ca42..d72a482 100644 --- a/init.lua.in +++ b/init.lua.in @@ -120,18 +120,23 @@ end function findprogram(exe) if is_win() then - local k = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\' .. exe; - local x = getregistryvalue('HKEY_LOCAL_MACHINE', k, '') - if type(x) == 'string' then return x end - x = getregistryvalue('HKEY_LOCAL_MACHINE', k .. '.exe', '') - if type(x) == 'string' then return x end - local path = os.getenv("PATH") or "." + if not exe:match('[.]exe$') then + exe = exe .. '.exe' + end + local path, k, x = os.getenv("PATH") or "." for dir in path:gmatch('[^;]+') do x = concat(dir, exe) if filep(x) then return x end - x = x .. '.exe' - if filep(x) then return x end end + k = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\' .. exe + x = getregistryvalue('HKEY_CURRENT_USER', k, '') + if type(x) == 'string' then return x end + x = getregistryvalue('HKEY_LOCAL_MACHINE', k, '') + if type(x) == 'string' then return x end + k = 'Applications\\' .. exe .. '\\shell\\open\\command' + x = getregistryvalue('HKEY_CLASSES_ROOT', k, '') + if type(x) == 'string' and x:match('"') then x = x:match('"[^"]+"') end + if type(x) == 'string' then return x end else local path = os.getenv("PATH") or "." for dir in path:gmatch('[^:]+') do @@ -140,4 +145,4 @@ function findprogram(exe) end end return nil -end
\ No newline at end of file +end @@ -862,7 +862,7 @@ lua_getregistryvalue(lua_State *L) HKEY skey; DWORD type; DWORD len = 0; - char *data = ""; + char *data = NULL; LONG res; res = RegOpenKeyExA(rkey, subkey, 0, KEY_READ, &skey); if (res != ERROR_SUCCESS) @@ -878,15 +878,19 @@ lua_getregistryvalue(lua_State *L) return 3; } res = RegQueryValueExA(skey, value, NULL, &type, (LPBYTE)data, &len); - if (res == ERROR_MORE_DATA) + if (len > 0) { len += 8; - if ((data = (char*)malloc(len))) - res = RegQueryValueExA(skey, value, NULL, &type, (LPBYTE)data, &len); + data = (char*)malloc(len); + if (! data) + luaL_error(L, "out of memory"); + res = RegQueryValueExA(skey, value, NULL, &type, (LPBYTE)data, &len); } + RegCloseKey(skey); if (res != ERROR_SUCCESS) { - RegCloseKey(skey); + if (data) + free(data); lua_pushnil(L); lua_pushinteger(L, res); if (res == ERROR_FILE_NOT_FOUND) @@ -899,14 +903,41 @@ lua_getregistryvalue(lua_State *L) } switch(type) { - case REG_SZ: - if (((const char*)data)[len-1] == 0) len -= 1; - case REG_BINARY: - lua_pushlstring(L, (const char*)data, (int)len); - return 1; case REG_DWORD: lua_pushinteger(L, (lua_Integer)*(const DWORD*)data); + if (data) + free(data); + return 1; + case REG_EXPAND_SZ: + if (data && len > 0) + { + if ((len = ExpandEnvironmentStrings(data, NULL, 0)) > 0) + { + char *buf = (char*)malloc(len + 8); + if (!buf) + luaL_error(L, "out of memory"); + len = ExpandEnvironmentStrings(data, buf, len+8); + free(data); + data = buf; + } + } + // fall thru + case REG_SZ: + if (data && len > 0) + if (((const char*)data)[len-1] == 0) + len -= 1; + // fall thru + case REG_BINARY: + if (data && len > 0) + lua_pushlstring(L, (const char*)data, (int)len); + else + lua_pushliteral(L, ""); + if (data) + free(data); return 1; + // unimplemented + case REG_QWORD: + case REG_MULTI_SZ: default: lua_pushnil(L); lua_pushinteger(L, res); |