Added Unicode versions of the HCR_ internal functions.

This commit is contained in:
Rolf Kalbermatter 2002-12-13 23:45:36 +00:00 committed by Alexandre Julliard
parent 887b2d9780
commit caf31cee32
8 changed files with 238 additions and 63 deletions

View File

@ -34,42 +34,102 @@
#include "shlguid.h"
#include "shresdef.h"
#include "shlwapi.h"
#include "wine/unicode.h"
WINE_DEFAULT_DEBUG_CHANNEL(shell);
#define MAX_EXTENSION_LENGTH 20
BOOL HCR_MapTypeToValue ( LPCSTR szExtension, LPSTR szFileType, DWORD len, BOOL bPrependDot)
{ HKEY hkey;
char szTemp[MAX_EXTENSION_LENGTH + 2];
BOOL HCR_MapTypeToValueW(LPCWSTR szExtension, LPWSTR szFileType, DWORD len, BOOL bPrependDot)
{
HKEY hkey;
WCHAR szTemp[MAX_EXTENSION_LENGTH + 2];
TRACE("%s %p\n",szExtension, szFileType );
TRACE("%s %p\n", debugstr_w(szExtension), debugstr_w(szFileType));
/* added because we do not want to have double dots */
if (szExtension[0]=='.')
bPrependDot=0;
if (szExtension[0] == '.')
bPrependDot = 0;
if (bPrependDot)
strcpy(szTemp, ".");
szTemp[0] = '.';
lstrcpynA(szTemp+((bPrependDot)?1:0), szExtension, MAX_EXTENSION_LENGTH);
lstrcpynW(szTemp + (bPrependDot?1:0), szExtension, MAX_EXTENSION_LENGTH);
if (RegOpenKeyExA(HKEY_CLASSES_ROOT,szTemp,0,0x02000000,&hkey))
{ return FALSE;
if (RegOpenKeyExW(HKEY_CLASSES_ROOT, szTemp, 0, 0x02000000, &hkey))
{
return FALSE;
}
if (RegQueryValueA(hkey,NULL,szFileType,&len))
{ RegCloseKey(hkey);
if (RegQueryValueW(hkey, NULL, szFileType, &len))
{
RegCloseKey(hkey);
return FALSE;
}
RegCloseKey(hkey);
TRACE("--UE;\n} %s\n", szFileType );
TRACE("--UE;\n} %s\n", debugstr_w(szFileType));
return TRUE;
}
BOOL HCR_GetExecuteCommand ( LPCSTR szClass, LPCSTR szVerb, LPSTR szDest, DWORD len )
BOOL HCR_MapTypeToValueA(LPCSTR szExtension, LPSTR szFileType, DWORD len, BOOL bPrependDot)
{
HKEY hkey;
char szTemp[MAX_EXTENSION_LENGTH + 2];
TRACE("%s %p\n", szExtension, szFileType);
/* added because we do not want to have double dots */
if (szExtension[0] == '.')
bPrependDot = 0;
if (bPrependDot)
szTemp[0] = '.';
lstrcpynA(szTemp + (bPrependDot?1:0), szExtension, MAX_EXTENSION_LENGTH);
if (RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, 0x02000000, &hkey))
{
return FALSE;
}
if (RegQueryValueA(hkey, NULL, szFileType, &len))
{
RegCloseKey(hkey);
return FALSE;
}
RegCloseKey(hkey);
TRACE("--UE;\n} %s\n", szFileType);
return TRUE;
}
BOOL HCR_GetExecuteCommandW(LPCWSTR szClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len)
{
static const WCHAR swShell[] = {'\\','s','h','e','l','l','\\',0};
static const WCHAR swCommand[] = {'\\','c','o','m','m','a','n','d',0};
WCHAR sTemp[MAX_PATH];
TRACE("%s %s %p\n",debugstr_w(szClass), debugstr_w(szVerb), szDest);
lstrcpyW(sTemp, szClass);
lstrcatW(sTemp, swShell);
lstrcatW(sTemp, szVerb);
lstrcatW(sTemp, swCommand);
if (ERROR_SUCCESS == SHGetValueW(HKEY_CLASSES_ROOT, sTemp, NULL, NULL, szDest, &len)) {
TRACE("-- %s\n", debugstr_w(szDest) );
return TRUE;
}
return FALSE;
}
BOOL HCR_GetExecuteCommandA(LPCSTR szClass, LPCSTR szVerb, LPSTR szDest, DWORD len)
{
char sTemp[MAX_PATH];
@ -83,65 +143,172 @@ BOOL HCR_GetExecuteCommand ( LPCSTR szClass, LPCSTR szVerb, LPSTR szDest, DWORD
}
return FALSE;
}
/***************************************************************************************
* HCR_GetDefaultIcon [internal]
*
* Gets the icon for a filetype
*/
BOOL HCR_GetDefaultIcon (LPCSTR szClass, LPSTR szDest, DWORD len, LPDWORD dwNr)
static HRESULT HCR_RegOpenClassIDKey(REFIID riid, HKEY *hkey)
{
char xriid[50];
sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
riid->Data1, riid->Data2, riid->Data3,
riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
TRACE("%s\n",xriid );
return RegOpenKeyExA(HKEY_CLASSES_ROOT, xriid, 0, KEY_READ, hkey);
}
static BOOL HCR_RegGetDefaultIconW(HKEY hkey, LPWSTR szDest, DWORD len, LPDWORD dwNr)
{
DWORD dwType;
WCHAR sTemp[MAX_PATH];
WCHAR sNum[5];
if (!RegQueryValueExW(hkey, NULL, 0, &dwType, (LPBYTE)szDest, &len))
{
if (dwType == REG_EXPAND_SZ)
{
ExpandEnvironmentStringsW(szDest, sTemp, MAX_PATH);
lstrcpynW(szDest, sTemp, len);
}
if (ParseFieldW (szDest, 2, sNum, 5))
*dwNr = atoiW(sNum);
else
*dwNr=0; /* sometimes the icon number is missing */
ParseFieldW (szDest, 1, szDest, len);
return TRUE;
}
return FALSE;
}
static BOOL HCR_RegGetDefaultIconA(HKEY hkey, LPSTR szDest, DWORD len, LPDWORD dwNr)
{
DWORD dwType;
char sTemp[MAX_PATH];
char sNum[5];
if (!RegQueryValueExA(hkey, NULL, 0, &dwType, szDest, &len))
{
if (dwType == REG_EXPAND_SZ)
{
ExpandEnvironmentStringsA(szDest, sTemp, MAX_PATH);
lstrcpynA(szDest, sTemp, len);
}
if (ParseFieldA (szDest, 2, sNum, 5))
*dwNr=atoi(sNum);
else
*dwNr=0; /* sometimes the icon number is missing */
ParseFieldA (szDest, 1, szDest, len);
return TRUE;
}
return FALSE;
}
BOOL HCR_GetDefaultIconW(LPCWSTR szClass, LPWSTR szDest, DWORD len, LPDWORD dwNr)
{
static const WCHAR swDefaultIcon[] = {'\\','D','e','f','a','u','l','t','I','c','o','n',0};
HKEY hkey;
WCHAR sTemp[MAX_PATH];
BOOL ret = FALSE;
TRACE("%s\n",debugstr_w(szClass) );
lstrcpynW(sTemp, szClass, MAX_PATH);
lstrcatW(sTemp, swDefaultIcon);
if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, sTemp, 0, 0x02000000, &hkey))
{
ret = HCR_RegGetDefaultIconW(hkey, szDest, len, dwNr);
RegCloseKey(hkey);
}
TRACE("-- %s %li\n", debugstr_w(szDest), *dwNr );
return ret;
}
BOOL HCR_GetDefaultIconA(LPCSTR szClass, LPSTR szDest, DWORD len, LPDWORD dwNr)
{
HKEY hkey;
char sTemp[MAX_PATH];
char sNum[5];
DWORD dwType;
BOOL ret = FALSE;
TRACE("%s\n",szClass );
sprintf(sTemp, "%s\\DefaultIcon",szClass);
if (!RegOpenKeyExA(HKEY_CLASSES_ROOT,sTemp,0,0x02000000,&hkey))
if (!RegOpenKeyExA(HKEY_CLASSES_ROOT, sTemp, 0, 0x02000000, &hkey))
{
if (!RegQueryValueExA(hkey, NULL, 0, &dwType, szDest, &len))
{
if (dwType == REG_EXPAND_SZ)
{
ExpandEnvironmentStringsA(szDest, sTemp, MAX_PATH);
strcpy(szDest, sTemp);
}
if (ParseFieldA (szDest, 2, sNum, 5))
*dwNr=atoi(sNum);
else
*dwNr=0; /* sometimes the icon number is missing */
ParseFieldA (szDest, 1, szDest, len);
ret = TRUE;
}
ret = HCR_RegGetDefaultIconA(hkey, szDest, len, dwNr);
RegCloseKey(hkey);
}
TRACE("-- %s %li\n", szDest, *dwNr );
return ret;
}
BOOL HCR_GetDefaultIconFromGUIDW(REFIID riid, LPWSTR szDest, DWORD len, LPDWORD dwNr)
{
HKEY hkey;
BOOL ret = FALSE;
if (!HCR_RegOpenClassIDKey(riid, &hkey))
{
ret = HCR_RegGetDefaultIconW(hkey, szDest, len, dwNr);
RegCloseKey(hkey);
}
TRACE("-- %s %li\n", debugstr_w(szDest), *dwNr );
return ret;
}
/***************************************************************************************
* HCR_GetClassName [internal]
*
* Gets the name of a registred class
*/
BOOL HCR_GetClassName (REFIID riid, LPSTR szDest, DWORD len)
{ HKEY hkey;
char xriid[50];
static WCHAR swEmpty[] = {0};
BOOL HCR_GetClassNameW(REFIID riid, LPWSTR szDest, DWORD len)
{
HKEY hkey;
BOOL ret = FALSE;
DWORD buflen = len;
sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
riid->Data1, riid->Data2, riid->Data3,
riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
szDest[0] = 0;
if (HCR_RegOpenClassIDKey(riid, &hkey))
{
if (!RegQueryValueExW(hkey, swEmpty, 0, NULL, (LPBYTE)szDest, &len))
{
ret = TRUE;
}
RegCloseKey(hkey);
}
TRACE("%s\n",xriid );
if (!ret || !szDest[0])
{
if(IsEqualIID(riid, &CLSID_ShellDesktop))
{
if (LoadStringW(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
ret = TRUE;
}
else if (IsEqualIID(riid, &CLSID_MyComputer))
{
if(LoadStringW(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
ret = TRUE;
}
}
TRACE("-- %s\n", debugstr_w(szDest));
return ret;
}
BOOL HCR_GetClassNameA(REFIID riid, LPSTR szDest, DWORD len)
{ HKEY hkey;
BOOL ret = FALSE;
DWORD buflen = len;
szDest[0] = 0;
if (!RegOpenKeyExA(HKEY_CLASSES_ROOT,xriid,0,KEY_READ,&hkey))
if (HCR_RegOpenClassIDKey(riid, &hkey))
{
if (!RegQueryValueExA(hkey,"",0,NULL,szDest,&len))
{

View File

@ -312,7 +312,7 @@ const char * shdebugstr_guid( const struct _GUID *id )
if (IsEqualIID(InterfaceDesc[i].riid, id)) name = InterfaceDesc[i].name;
}
if (!name) {
if (HCR_GetClassName(id, clsidbuf, 100))
if (HCR_GetClassNameA(id, clsidbuf, 100))
name = clsidbuf;
}

View File

@ -186,7 +186,7 @@ static HRESULT WINAPI IExtractIconW_fnGetIconLocation(
riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]);
if (HCR_GetDefaultIcon(xriid, sTemp, MAX_PATH, &dwNr))
if (HCR_GetDefaultIconA(xriid, sTemp, MAX_PATH, &dwNr))
{
MultiByteToWideChar(CP_ACP, 0, sTemp, MAX_PATH, szIconFile, cchMax);
*piIndex = dwNr;
@ -200,7 +200,7 @@ static HRESULT WINAPI IExtractIconW_fnGetIconLocation(
else if (_ILIsDrive (pSimplePidl))
{
if (HCR_GetDefaultIcon("Drive", sTemp, MAX_PATH, &dwNr))
if (HCR_GetDefaultIconA("Drive", sTemp, MAX_PATH, &dwNr))
{
MultiByteToWideChar(CP_ACP, 0, sTemp, MAX_PATH, szIconFile, cchMax);
*piIndex = dwNr;
@ -213,7 +213,7 @@ static HRESULT WINAPI IExtractIconW_fnGetIconLocation(
}
else if (_ILIsFolder (pSimplePidl))
{
if (HCR_GetDefaultIcon("Folder", sTemp, MAX_PATH, &dwNr))
if (HCR_GetDefaultIconA("Folder", sTemp, MAX_PATH, &dwNr))
{
MultiByteToWideChar(CP_ACP, 0, sTemp, MAX_PATH, szIconFile, cchMax);
}
@ -227,8 +227,8 @@ static HRESULT WINAPI IExtractIconW_fnGetIconLocation(
else /* object is file */
{
if (_ILGetExtension(pSimplePidl, sTemp, MAX_PATH)
&& HCR_MapTypeToValue(sTemp, sTemp, MAX_PATH, TRUE)
&& HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
&& HCR_MapTypeToValueA(sTemp, sTemp, MAX_PATH, TRUE)
&& HCR_GetDefaultIconA(sTemp, sTemp, MAX_PATH, &dwNr))
{
if (!lstrcmpA("%1", sTemp)) /* icon is in the file */
{

View File

@ -1384,7 +1384,7 @@ DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
if (_ILIsDesktop(pidl))
{
/* desktop */
if (HCR_GetClassName(&CLSID_ShellDesktop, szTemp, MAX_PATH))
if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
{
if (szOut)
lstrcpynA(szOut, szTemp, uOutSize);
@ -1403,7 +1403,7 @@ DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
else if (( riid = _ILGetGUIDPointer(pidl) ))
{
/* special folder */
if ( HCR_GetClassName(riid, szTemp, MAX_PATH) )
if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
{
if (szOut)
lstrcpynA(szOut, szTemp, uOutSize);
@ -1669,8 +1669,8 @@ void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
}
if (_ILGetExtension (pidl, sTemp, 64))
{
if (!( HCR_MapTypeToValue(sTemp, sTemp, 64, TRUE)
&& HCR_MapTypeToValue(sTemp, pOut, uOutSize, FALSE )))
if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
&& HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE )))
{
lstrcpynA (pOut, sTemp, uOutSize - 6);
strcat (pOut, "-file");

View File

@ -347,8 +347,8 @@ DWORD WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
{
char sTemp[64];
strcpy(sTemp,PathFindExtensionA(path));
if (!( HCR_MapTypeToValue(sTemp, sTemp, 64, TRUE)
&& HCR_MapTypeToValue(sTemp, psfi->szTypeName, 80, FALSE )))
if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
&& HCR_MapTypeToValueA(sTemp, psfi->szTypeName, 80, FALSE )))
{
lstrcpynA (psfi->szTypeName, sTemp, 64);
strcat (psfi->szTypeName, "-file");
@ -405,8 +405,8 @@ DWORD WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
{
psfi->iIcon = 0;
szExt = (LPSTR) PathFindExtensionA(sTemp);
if ( szExt && HCR_MapTypeToValue(szExt, sTemp, MAX_PATH, TRUE)
&& HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
if ( szExt && HCR_MapTypeToValueA(szExt, sTemp, MAX_PATH, TRUE)
&& HCR_GetDefaultIconA(sTemp, sTemp, MAX_PATH, &dwNr))
{
if (!strcmp("%1",sTemp)) /* icon is in the file */
strcpy(sTemp, path);

View File

@ -57,11 +57,19 @@ BOOL PidlToSicIndex (IShellFolder * sh, LPITEMIDLIST pidl, BOOL bBigIcon, UINT u
INT SIC_GetIconIndex (LPCSTR sSourceFile, INT dwSourceIndex );
/* Classes Root */
BOOL HCR_MapTypeToValue ( LPCSTR szExtension, LPSTR szFileType, DWORD len, BOOL bPrependDot);
BOOL HCR_GetExecuteCommand ( LPCSTR szClass, LPCSTR szVerb, LPSTR szDest, DWORD len );
BOOL HCR_GetDefaultIcon (LPCSTR szClass, LPSTR szDest, DWORD len, LPDWORD dwNr);
BOOL HCR_GetClassName (REFIID riid, LPSTR szDest, DWORD len);
BOOL HCR_GetFolderAttributes (REFIID riid, LPDWORD szDest);
BOOL HCR_MapTypeToValueW(LPCWSTR szExtension, LPWSTR szFileType, DWORD len, BOOL bPrependDot);
BOOL HCR_GetExecuteCommandW(LPCWSTR szClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len);
BOOL HCR_GetDefaultIconW(LPCWSTR szClass, LPWSTR szDest, DWORD len, LPDWORD dwNr);
BOOL HCR_GetDefaultIconFromGUIDW(REFIID riid, LPWSTR szDest, DWORD len, LPDWORD dwNr);
BOOL HCR_GetClassNameW(REFIID riid, LPWSTR szDest, DWORD len);
/* ANSI versions of above functions, supposed to go away as soon as they are not used anymore */
BOOL HCR_MapTypeToValueA(LPCSTR szExtension, LPSTR szFileType, DWORD len, BOOL bPrependDot);
BOOL HCR_GetExecuteCommandA(LPCSTR szClass, LPCSTR szVerb, LPSTR szDest, DWORD len);
BOOL HCR_GetDefaultIconA(LPCSTR szClass, LPSTR szDest, DWORD len, LPDWORD dwNr);
BOOL HCR_GetClassNameA(REFIID riid, LPSTR szDest, DWORD len);
BOOL HCR_GetFolderAttributes(REFIID riid, LPDWORD szDest);
INT_PTR CALLBACK AboutDlgProc(HWND,UINT,WPARAM,LPARAM);
DWORD WINAPI ParseFieldA(LPCSTR src, DWORD nField, LPSTR dst, DWORD len);

View File

@ -459,7 +459,7 @@ static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING)) {
lstrcpyA (szPath, This->sPathTarget);
} else {
HCR_GetClassName (&CLSID_ShellDesktop, szPath, MAX_PATH);
HCR_GetClassNameA(&CLSID_ShellDesktop, szPath, MAX_PATH);
}
} else if (_ILIsPidlSimple (pidl)) {
if ((clsid = _ILGetGUIDPointer (pidl))) {
@ -496,7 +496,7 @@ static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
}
} else {
/* user friendly name */
HCR_GetClassName (clsid, szPath, MAX_PATH);
HCR_GetClassNameA (clsid, szPath, MAX_PATH);
}
} else {
/* file system folder */

View File

@ -569,7 +569,7 @@ BOOL WINAPI ShellExecuteExA32 (LPSHELLEXECUTEINFOA sei, SHELL_ExecuteA1632 execf
/* launch a document by fileclass like 'WordPad.Document.1' */
/* the Commandline contains 'c:\Path\wordpad.exe "%1"' */
/* FIXME: szCommandline should not be of a fixed size. Plus MAX_PATH is way too short! */
HCR_GetExecuteCommand(sei->lpClass, (sei->lpVerb) ? sei->lpVerb : "open", szCommandline, sizeof(szCommandline));
HCR_GetExecuteCommandA(sei->lpClass, (sei->lpVerb) ? sei->lpVerb : "open", szCommandline, sizeof(szCommandline));
/* FIXME: get the extension of lpFile, check if it fits to the lpClass */
TRACE("SEE_MASK_CLASSNAME->'%s', doc->'%s'\n", szCommandline, szApplicationName);