shlwapi: Refactor get executable code in IQueryAssociations_fnGetString.
This commit is contained in:
parent
48ad706c08
commit
4e0c0ec157
|
@ -590,41 +590,16 @@ static HRESULT ASSOC_GetValue(HKEY hkey, WCHAR ** pszText)
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* IQueryAssociations_GetString {SHLWAPI}
|
||||
*
|
||||
* Get a file association string from the registry.
|
||||
*
|
||||
* PARAMS
|
||||
* iface [I] IQueryAssociations interface to query
|
||||
* cfFlags [I] ASSOCF_ flags from "shlwapi.h"
|
||||
* str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
|
||||
* pszExtra [I] Extra information about the string location
|
||||
* pszOut [O] Destination for the association string
|
||||
* pcchOut [I/O] Length of pszOut
|
||||
*
|
||||
* RETURNS
|
||||
* Success: S_OK. pszOut contains the string, pcchOut contains its length.
|
||||
* Failure: An HRESULT error code indicating the error.
|
||||
*/
|
||||
static HRESULT WINAPI IQueryAssociations_fnGetString(
|
||||
IQueryAssociations *iface,
|
||||
ASSOCF cfFlags,
|
||||
ASSOCSTR str,
|
||||
LPCWSTR pszExtra,
|
||||
LPWSTR pszOut,
|
||||
DWORD *pcchOut)
|
||||
static HRESULT ASSOC_GetExecutable(IQueryAssociationsImpl *This,
|
||||
LPCWSTR pszExtra, LPWSTR path,
|
||||
DWORD pathlen, DWORD *len)
|
||||
{
|
||||
IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
|
||||
const ASSOCF cfUnimplemented = ~(0);
|
||||
DWORD len;
|
||||
HKEY hkeyCommand;
|
||||
HKEY hkeyFile;
|
||||
HKEY hkeyShell;
|
||||
HKEY hkeyVerb;
|
||||
HRESULT hr;
|
||||
LONG ret;
|
||||
WCHAR path[MAX_PATH];
|
||||
WCHAR * pszCommand;
|
||||
WCHAR * pszEnd;
|
||||
WCHAR * pszExtraFromReg;
|
||||
|
@ -633,24 +608,12 @@ static HRESULT WINAPI IQueryAssociations_fnGetString(
|
|||
static const WCHAR commandW[] = { 'c','o','m','m','a','n','d',0 };
|
||||
static const WCHAR shellW[] = { 's','h','e','l','l',0 };
|
||||
|
||||
TRACE("(%p,0x%8x,0x%8x,%s,%p,%p)\n", This, cfFlags, str,
|
||||
debugstr_w(pszExtra), pszOut, pcchOut);
|
||||
assert(len);
|
||||
|
||||
if (cfFlags & cfUnimplemented)
|
||||
FIXME("%08x: unimplemented flags!\n", cfFlags & cfUnimplemented);
|
||||
|
||||
if (!pcchOut)
|
||||
return E_UNEXPECTED;
|
||||
|
||||
switch (str)
|
||||
{
|
||||
case ASSOCSTR_EXECUTABLE:
|
||||
{
|
||||
hr = ASSOC_GetValue(This->hkeySource, &pszFileType);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ,
|
||||
&hkeyFile);
|
||||
ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ, &hkeyFile);
|
||||
HeapFree(GetProcessHeap(), 0, pszFileType);
|
||||
if (ret != ERROR_SUCCESS)
|
||||
return HRESULT_FROM_WIN32(ret);
|
||||
|
@ -670,8 +633,8 @@ static HRESULT WINAPI IQueryAssociations_fnGetString(
|
|||
}
|
||||
}
|
||||
|
||||
ret = RegOpenKeyExW(hkeyShell, pszExtra ? pszExtra : pszExtraFromReg,
|
||||
0, KEY_READ, &hkeyVerb);
|
||||
ret = RegOpenKeyExW(hkeyShell, pszExtra ? pszExtra : pszExtraFromReg, 0,
|
||||
KEY_READ, &hkeyVerb);
|
||||
HeapFree(GetProcessHeap(), 0, pszExtraFromReg);
|
||||
RegCloseKey(hkeyShell);
|
||||
if (ret != ERROR_SUCCESS)
|
||||
|
@ -700,11 +663,60 @@ static HRESULT WINAPI IQueryAssociations_fnGetString(
|
|||
if (pszEnd)
|
||||
*pszEnd = 0;
|
||||
|
||||
len = SearchPathW(NULL, pszStart, NULL, MAX_PATH, path, NULL);
|
||||
*len = SearchPathW(NULL, pszStart, NULL, pathlen, path, NULL);
|
||||
HeapFree(GetProcessHeap(), 0, pszCommand);
|
||||
if (!len)
|
||||
if (!*len)
|
||||
return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* IQueryAssociations_GetString {SHLWAPI}
|
||||
*
|
||||
* Get a file association string from the registry.
|
||||
*
|
||||
* PARAMS
|
||||
* iface [I] IQueryAssociations interface to query
|
||||
* cfFlags [I] ASSOCF_ flags from "shlwapi.h"
|
||||
* str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
|
||||
* pszExtra [I] Extra information about the string location
|
||||
* pszOut [O] Destination for the association string
|
||||
* pcchOut [I/O] Length of pszOut
|
||||
*
|
||||
* RETURNS
|
||||
* Success: S_OK. pszOut contains the string, pcchOut contains its length.
|
||||
* Failure: An HRESULT error code indicating the error.
|
||||
*/
|
||||
static HRESULT WINAPI IQueryAssociations_fnGetString(
|
||||
IQueryAssociations *iface,
|
||||
ASSOCF cfFlags,
|
||||
ASSOCSTR str,
|
||||
LPCWSTR pszExtra,
|
||||
LPWSTR pszOut,
|
||||
DWORD *pcchOut)
|
||||
{
|
||||
IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
|
||||
const ASSOCF cfUnimplemented = ~(0);
|
||||
DWORD len = 0;
|
||||
HRESULT hr;
|
||||
WCHAR path[MAX_PATH];
|
||||
|
||||
TRACE("(%p,0x%8x,0x%8x,%s,%p,%p)\n", This, cfFlags, str,
|
||||
debugstr_w(pszExtra), pszOut, pcchOut);
|
||||
|
||||
if (cfFlags & cfUnimplemented)
|
||||
FIXME("%08x: unimplemented flags!\n", cfFlags & cfUnimplemented);
|
||||
|
||||
if (!pcchOut)
|
||||
return E_UNEXPECTED;
|
||||
|
||||
switch (str)
|
||||
{
|
||||
case ASSOCSTR_EXECUTABLE:
|
||||
{
|
||||
hr = ASSOC_GetExecutable(This, pszExtra, path, MAX_PATH, &len);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
len++;
|
||||
if (pszOut)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue