mirror of
https://github.com/reactos/reactos.git
synced 2024-09-28 13:34:53 +00:00
[SHELL32] COpenWithMenu: Use ShellExecuteExW to open the file
CORE-15353
This commit is contained in:
parent
40288a7032
commit
9baf05f164
|
@ -221,50 +221,30 @@ HICON COpenWithList::GetIcon(SApp *pApp)
|
||||||
|
|
||||||
BOOL COpenWithList::Execute(COpenWithList::SApp *pApp, LPCWSTR pwszFilePath)
|
BOOL COpenWithList::Execute(COpenWithList::SApp *pApp, LPCWSTR pwszFilePath)
|
||||||
{
|
{
|
||||||
STARTUPINFOW si;
|
WCHAR wszBuf[256];
|
||||||
PROCESS_INFORMATION pi;
|
HKEY hKey;
|
||||||
WCHAR wszBuf[MAX_PATH * 2 + 8], *pszEnd = wszBuf;
|
|
||||||
size_t cchRemaining = _countof(wszBuf);
|
|
||||||
|
|
||||||
/* setup path with argument */
|
|
||||||
ZeroMemory(&si, sizeof(STARTUPINFOW));
|
|
||||||
si.cb = sizeof(STARTUPINFOW);
|
|
||||||
|
|
||||||
/* Build the command line */
|
|
||||||
for (UINT i = 0; pApp->wszCmd[i] && cchRemaining > 1; ++i)
|
|
||||||
{
|
|
||||||
if (pApp->wszCmd[i] != '%')
|
|
||||||
{
|
|
||||||
*(pszEnd++) = pApp->wszCmd[i];
|
|
||||||
--cchRemaining;
|
|
||||||
}
|
|
||||||
else if (pApp->wszCmd[++i] == '1')
|
|
||||||
{
|
|
||||||
if (StrChrW(pwszFilePath, L' ') && cchRemaining > 3)
|
|
||||||
StringCchPrintfExW(pszEnd, cchRemaining, &pszEnd, &cchRemaining, 0, L"\"%ls\"", pwszFilePath);
|
|
||||||
else
|
|
||||||
StringCchCopyExW(pszEnd, cchRemaining, pwszFilePath, &pszEnd, &cchRemaining, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* NULL-terminate the command string */
|
|
||||||
if (cchRemaining > 0)
|
|
||||||
*pszEnd = L'\0';
|
|
||||||
|
|
||||||
/* Start the application now */
|
|
||||||
TRACE("Starting process %ls\n", wszBuf);
|
|
||||||
if (!CreateProcessW(NULL, wszBuf, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
|
|
||||||
{
|
|
||||||
ERR("CreateProcessW %ls failed\n", wszBuf);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add app to registry if it wasnt there before */
|
/* Add app to registry if it wasnt there before */
|
||||||
SaveApp(pApp);
|
SaveApp(pApp);
|
||||||
if (!pApp->bMRUList)
|
if (!pApp->bMRUList)
|
||||||
AddAppToMRUList(pApp, pwszFilePath);
|
AddAppToMRUList(pApp, pwszFilePath);
|
||||||
|
|
||||||
CloseHandle(pi.hThread);
|
/* Get a handle to the reg key */
|
||||||
CloseHandle(pi.hProcess);
|
StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s", pApp->wszFilename);
|
||||||
|
if (RegCreateKeyEx(HKEY_CLASSES_ROOT, wszBuf, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
ERR("RegOpenKeyEx failed\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Let ShellExecuteExW do the work */
|
||||||
|
SHELLEXECUTEINFOW sei = {sizeof(SHELLEXECUTEINFOW), SEE_MASK_CLASSKEY};
|
||||||
|
sei.nShow = SW_SHOWNORMAL;
|
||||||
|
sei.hkeyClass = hKey;
|
||||||
|
sei.lpFile = pwszFilePath;
|
||||||
|
|
||||||
|
ShellExecuteExW(&sei);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue