start: Try cycling through extensions if original path failed to execute.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2018-10-24 14:32:14 +03:00 committed by Alexandre Julliard
parent dd7230d1bc
commit 1c93654885
1 changed files with 49 additions and 1 deletions

View File

@ -403,7 +403,55 @@ int wmain (int argc, WCHAR *argv[])
} }
if (!ShellExecuteExW(&sei)) if (!ShellExecuteExW(&sei))
fatal_string_error(STRING_EXECFAIL, GetLastError(), sei.lpFile); {
static const WCHAR pathextW[] = {'P','A','T','H','E','X','T',0};
const WCHAR *filename = sei.lpFile;
DWORD size, filename_len;
WCHAR *name, *env;
size = GetEnvironmentVariableW(pathextW, NULL, 0);
if (size)
{
WCHAR *start, *ptr;
env = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
if (!env)
fatal_string_error(STRING_EXECFAIL, ERROR_OUTOFMEMORY, sei.lpFile);
GetEnvironmentVariableW(pathextW, env, size);
filename_len = strlenW(filename);
name = HeapAlloc(GetProcessHeap(), 0, (filename_len + size) * sizeof(WCHAR));
if (!name)
fatal_string_error(STRING_EXECFAIL, ERROR_OUTOFMEMORY, sei.lpFile);
sei.lpFile = name;
start = env;
while ((ptr = strchrW(start, ';')))
{
if (start == ptr)
{
start = ptr + 1;
continue;
}
strcpyW(name, filename);
memcpy(&name[filename_len], start, (ptr - start) * sizeof(WCHAR));
name[filename_len + (ptr - start)] = 0;
if (ShellExecuteExW(&sei))
{
HeapFree(GetProcessHeap(), 0, name);
HeapFree(GetProcessHeap(), 0, env);
goto done;
}
start = ptr + 1;
}
}
fatal_string_error(STRING_EXECFAIL, GetLastError(), filename);
}
done: done:
HeapFree( GetProcessHeap(), 0, args ); HeapFree( GetProcessHeap(), 0, args );