shlwapi: Refactor get executable code in IQueryAssociations_fnGetString.

This commit is contained in:
Lei Zhang 2008-10-13 18:07:15 -07:00 committed by Alexandre Julliard
parent 48ad706c08
commit 4e0c0ec157

View File

@ -590,41 +590,16 @@ static HRESULT ASSOC_GetValue(HKEY hkey, WCHAR ** pszText)
return S_OK; return S_OK;
} }
/************************************************************************** static HRESULT ASSOC_GetExecutable(IQueryAssociationsImpl *This,
* IQueryAssociations_GetString {SHLWAPI} LPCWSTR pszExtra, LPWSTR path,
* DWORD pathlen, DWORD *len)
* 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;
HKEY hkeyCommand; HKEY hkeyCommand;
HKEY hkeyFile; HKEY hkeyFile;
HKEY hkeyShell; HKEY hkeyShell;
HKEY hkeyVerb; HKEY hkeyVerb;
HRESULT hr; HRESULT hr;
LONG ret; LONG ret;
WCHAR path[MAX_PATH];
WCHAR * pszCommand; WCHAR * pszCommand;
WCHAR * pszEnd; WCHAR * pszEnd;
WCHAR * pszExtraFromReg; 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 commandW[] = { 'c','o','m','m','a','n','d',0 };
static const WCHAR shellW[] = { 's','h','e','l','l',0 }; static const WCHAR shellW[] = { 's','h','e','l','l',0 };
TRACE("(%p,0x%8x,0x%8x,%s,%p,%p)\n", This, cfFlags, str, assert(len);
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_GetValue(This->hkeySource, &pszFileType); hr = ASSOC_GetValue(This->hkeySource, &pszFileType);
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ, ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ, &hkeyFile);
&hkeyFile);
HeapFree(GetProcessHeap(), 0, pszFileType); HeapFree(GetProcessHeap(), 0, pszFileType);
if (ret != ERROR_SUCCESS) if (ret != ERROR_SUCCESS)
return HRESULT_FROM_WIN32(ret); return HRESULT_FROM_WIN32(ret);
@ -670,8 +633,8 @@ static HRESULT WINAPI IQueryAssociations_fnGetString(
} }
} }
ret = RegOpenKeyExW(hkeyShell, pszExtra ? pszExtra : pszExtraFromReg, ret = RegOpenKeyExW(hkeyShell, pszExtra ? pszExtra : pszExtraFromReg, 0,
0, KEY_READ, &hkeyVerb); KEY_READ, &hkeyVerb);
HeapFree(GetProcessHeap(), 0, pszExtraFromReg); HeapFree(GetProcessHeap(), 0, pszExtraFromReg);
RegCloseKey(hkeyShell); RegCloseKey(hkeyShell);
if (ret != ERROR_SUCCESS) if (ret != ERROR_SUCCESS)
@ -700,11 +663,60 @@ static HRESULT WINAPI IQueryAssociations_fnGetString(
if (pszEnd) if (pszEnd)
*pszEnd = 0; *pszEnd = 0;
len = SearchPathW(NULL, pszStart, NULL, MAX_PATH, path, NULL); *len = SearchPathW(NULL, pszStart, NULL, pathlen, path, NULL);
HeapFree(GetProcessHeap(), 0, pszCommand); HeapFree(GetProcessHeap(), 0, pszCommand);
if (!len) if (!*len)
return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); 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++; len++;
if (pszOut) if (pszOut)
{ {