mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
[SHELL32] Refactor CShellLink::DoOpen (#7149)
Reduce code. Modernize code. JIRA issue: N/A Use CStringW and CComHeapPtr<WCHAR> for dynamic allocation.
This commit is contained in:
parent
894ad4f17d
commit
b6b82fee3f
1 changed files with 20 additions and 35 deletions
|
@ -6,7 +6,7 @@
|
|||
* Copyright 2009 Andrew Hill
|
||||
* Copyright 2013 Dominik Hornung
|
||||
* Copyright 2017 Hermes Belusca-Maito
|
||||
* Copyright 2018-2021 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
|
||||
* Copyright 2018-2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -2592,40 +2592,33 @@ HRESULT STDMETHODCALLTYPE CShellLink::InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
|
|||
|
||||
HRESULT CShellLink::DoOpen(LPCMINVOKECOMMANDINFO lpici)
|
||||
{
|
||||
HRESULT hr;
|
||||
LPWSTR args = NULL;
|
||||
LPWSTR path = strdupW(m_sPath);
|
||||
BOOL unicode = lpici->cbSize >= FIELD_OFFSET(CMINVOKECOMMANDINFOEX, ptInvoke) &&
|
||||
(lpici->fMask & CMIC_MASK_UNICODE);
|
||||
|
||||
CStringW args;
|
||||
if (m_sArgs)
|
||||
args = m_sArgs;
|
||||
|
||||
if (unicode)
|
||||
{
|
||||
LPCMINVOKECOMMANDINFOEX iciex = (LPCMINVOKECOMMANDINFOEX)lpici;
|
||||
SIZE_T len = 2;
|
||||
|
||||
if (m_sArgs)
|
||||
len += wcslen(m_sArgs);
|
||||
if (iciex->lpParametersW)
|
||||
len += wcslen(iciex->lpParametersW);
|
||||
|
||||
args = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
||||
*args = 0;
|
||||
if (m_sArgs)
|
||||
wcscat(args, m_sArgs);
|
||||
if (iciex->lpParametersW)
|
||||
if (iciex->lpParametersW && iciex->lpParametersW[0])
|
||||
{
|
||||
wcscat(args, L" ");
|
||||
wcscat(args, iciex->lpParametersW);
|
||||
args += L' ';
|
||||
args += iciex->lpParametersW;
|
||||
}
|
||||
}
|
||||
else if (m_sArgs != NULL)
|
||||
else
|
||||
{
|
||||
args = strdupW(m_sArgs);
|
||||
CComHeapPtr<WCHAR> pszParams;
|
||||
if (lpici->lpParameters && lpici->lpParameters[0] && __SHCloneStrAtoW(&pszParams, lpici->lpParameters))
|
||||
{
|
||||
args += L' ';
|
||||
args += pszParams;
|
||||
}
|
||||
}
|
||||
|
||||
SHELLEXECUTEINFOW sei;
|
||||
ZeroMemory(&sei, sizeof(sei));
|
||||
sei.cbSize = sizeof(sei);
|
||||
SHELLEXECUTEINFOW sei = { sizeof(sei) };
|
||||
sei.fMask = SEE_MASK_HASLINKNAME | SEE_MASK_UNICODE |
|
||||
(lpici->fMask & (SEE_MASK_NOASYNC | SEE_MASK_ASYNCOK | SEE_MASK_FLAG_NO_UI));
|
||||
if (m_pPidl)
|
||||
|
@ -2635,7 +2628,7 @@ HRESULT CShellLink::DoOpen(LPCMINVOKECOMMANDINFO lpici)
|
|||
}
|
||||
else
|
||||
{
|
||||
sei.lpFile = path;
|
||||
sei.lpFile = m_sPath;
|
||||
}
|
||||
sei.lpParameters = args;
|
||||
sei.lpClass = m_sLinkPath;
|
||||
|
@ -2643,19 +2636,11 @@ HRESULT CShellLink::DoOpen(LPCMINVOKECOMMANDINFO lpici)
|
|||
sei.lpDirectory = m_sWorkDir;
|
||||
sei.lpVerb = L"open";
|
||||
|
||||
// HACK for ShellExecuteExW
|
||||
if (m_sPath && wcsstr(m_sPath, L".cpl"))
|
||||
// HACK for ShellExecuteExW: Change the default verb if this is a Control Panel applet
|
||||
if (m_sPath && lstrcmpiW(PathFindExtensionW(m_sPath), L".cpl") == 0)
|
||||
sei.lpVerb = L"cplopen";
|
||||
|
||||
if (ShellExecuteExW(&sei))
|
||||
hr = S_OK;
|
||||
else
|
||||
hr = E_FAIL;
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, args);
|
||||
HeapFree(GetProcessHeap(), 0, path);
|
||||
|
||||
return hr;
|
||||
return (ShellExecuteExW(&sei) ? S_OK : E_FAIL);
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CShellLink::GetCommandString(UINT_PTR idCmd, UINT uType, UINT* pwReserved, LPSTR pszName, UINT cchMax)
|
||||
|
|
Loading…
Reference in a new issue