Juergen Schmied | a9a4f4e | 1998-11-22 18:26:23 +0000 | [diff] [blame] | 1 | /* |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 2 | * file type mapping |
Juergen Schmied | a9a4f4e | 1998-11-22 18:26:23 +0000 | [diff] [blame] | 3 | * (HKEY_CLASSES_ROOT - Stuff) |
| 4 | * |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * Copyright 1998, 1999, 2000 Juergen Schmied |
Juergen Schmied | a9a4f4e | 1998-11-22 18:26:23 +0000 | [diff] [blame] | 6 | * |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Juergen Schmied | a9a4f4e | 1998-11-22 18:26:23 +0000 | [diff] [blame] | 20 | */ |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 21 | |
Steven Edwards | 9f573fa | 2002-07-29 23:28:29 +0000 | [diff] [blame] | 22 | #include "config.h" |
| 23 | #include "wine/port.h" |
| 24 | |
Juergen Schmied | a9a4f4e | 1998-11-22 18:26:23 +0000 | [diff] [blame] | 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 27 | #include <stdarg.h> |
Alexandre Julliard | 383da68 | 2000-02-10 22:15:21 +0000 | [diff] [blame] | 28 | #include <stdio.h> |
Michael Jung | 11cadc3 | 2005-06-25 17:55:53 +0000 | [diff] [blame] | 29 | |
| 30 | #define COBJMACROS |
| 31 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 32 | #include "wine/debug.h" |
Juergen Schmied | a9a4f4e | 1998-11-22 18:26:23 +0000 | [diff] [blame] | 33 | #include "winerror.h" |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 34 | #include "windef.h" |
| 35 | #include "winbase.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 36 | #include "winreg.h" |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 37 | #include "wingdi.h" |
| 38 | #include "winuser.h" |
Juergen Schmied | a9a4f4e | 1998-11-22 18:26:23 +0000 | [diff] [blame] | 39 | |
Juergen Schmied | ba28ba1 | 1999-01-23 14:12:48 +0000 | [diff] [blame] | 40 | #include "shlobj.h" |
Juergen Schmied | a9a4f4e | 1998-11-22 18:26:23 +0000 | [diff] [blame] | 41 | #include "shell32_main.h" |
Juergen Schmied | d72ace4 | 1999-08-15 14:24:49 +0000 | [diff] [blame] | 42 | #include "shlguid.h" |
| 43 | #include "shresdef.h" |
Juergen Schmied | 1e5ec88 | 2002-07-24 01:56:03 +0000 | [diff] [blame] | 44 | #include "shlwapi.h" |
Michael Jung | 11cadc3 | 2005-06-25 17:55:53 +0000 | [diff] [blame] | 45 | #include "pidl.h" |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 46 | #include "wine/unicode.h" |
Juergen Schmied | a9a4f4e | 1998-11-22 18:26:23 +0000 | [diff] [blame] | 47 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 48 | WINE_DEFAULT_DEBUG_CHANNEL(shell); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 49 | |
Juergen Schmied | 166cfd5 | 1999-07-25 12:19:12 +0000 | [diff] [blame] | 50 | #define MAX_EXTENSION_LENGTH 20 |
| 51 | |
Mike McCormack | e28c014 | 2005-07-03 12:03:35 +0000 | [diff] [blame] | 52 | BOOL HCR_MapTypeToValueW(LPCWSTR szExtension, LPWSTR szFileType, LONG len, BOOL bPrependDot) |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 53 | { |
| 54 | HKEY hkey; |
| 55 | WCHAR szTemp[MAX_EXTENSION_LENGTH + 2]; |
Juergen Schmied | a9a4f4e | 1998-11-22 18:26:23 +0000 | [diff] [blame] | 56 | |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 57 | TRACE("%s %p\n", debugstr_w(szExtension), debugstr_w(szFileType)); |
Juergen Schmied | 98f6cf0 | 1998-12-11 10:58:48 +0000 | [diff] [blame] | 58 | |
Aric Stewart | 3ae80eb | 2001-10-23 00:25:15 +0000 | [diff] [blame] | 59 | /* added because we do not want to have double dots */ |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 60 | if (szExtension[0] == '.') |
| 61 | bPrependDot = 0; |
Aric Stewart | 3ae80eb | 2001-10-23 00:25:15 +0000 | [diff] [blame] | 62 | |
Juergen Schmied | d72ace4 | 1999-08-15 14:24:49 +0000 | [diff] [blame] | 63 | if (bPrependDot) |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 64 | szTemp[0] = '.'; |
Juergen Schmied | d72ace4 | 1999-08-15 14:24:49 +0000 | [diff] [blame] | 65 | |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 66 | lstrcpynW(szTemp + (bPrependDot?1:0), szExtension, MAX_EXTENSION_LENGTH); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 67 | |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 68 | if (RegOpenKeyExW(HKEY_CLASSES_ROOT, szTemp, 0, 0x02000000, &hkey)) |
| 69 | { |
| 70 | return FALSE; |
Juergen Schmied | a9a4f4e | 1998-11-22 18:26:23 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 73 | if (RegQueryValueW(hkey, NULL, szFileType, &len)) |
| 74 | { |
| 75 | RegCloseKey(hkey); |
Juergen Schmied | a9a4f4e | 1998-11-22 18:26:23 +0000 | [diff] [blame] | 76 | return FALSE; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 77 | } |
Juergen Schmied | a9a4f4e | 1998-11-22 18:26:23 +0000 | [diff] [blame] | 78 | |
| 79 | RegCloseKey(hkey); |
| 80 | |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 81 | TRACE("--UE;\n} %s\n", debugstr_w(szFileType)); |
Juergen Schmied | a9a4f4e | 1998-11-22 18:26:23 +0000 | [diff] [blame] | 82 | |
| 83 | return TRUE; |
| 84 | } |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 85 | |
Mike McCormack | e28c014 | 2005-07-03 12:03:35 +0000 | [diff] [blame] | 86 | BOOL HCR_MapTypeToValueA(LPCSTR szExtension, LPSTR szFileType, LONG len, BOOL bPrependDot) |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 87 | { |
| 88 | HKEY hkey; |
| 89 | char szTemp[MAX_EXTENSION_LENGTH + 2]; |
| 90 | |
| 91 | TRACE("%s %p\n", szExtension, szFileType); |
| 92 | |
| 93 | /* added because we do not want to have double dots */ |
| 94 | if (szExtension[0] == '.') |
| 95 | bPrependDot = 0; |
| 96 | |
| 97 | if (bPrependDot) |
| 98 | szTemp[0] = '.'; |
| 99 | |
| 100 | lstrcpynA(szTemp + (bPrependDot?1:0), szExtension, MAX_EXTENSION_LENGTH); |
| 101 | |
| 102 | if (RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, 0x02000000, &hkey)) |
| 103 | { |
| 104 | return FALSE; |
| 105 | } |
| 106 | |
| 107 | if (RegQueryValueA(hkey, NULL, szFileType, &len)) |
| 108 | { |
| 109 | RegCloseKey(hkey); |
| 110 | return FALSE; |
| 111 | } |
| 112 | |
| 113 | RegCloseKey(hkey); |
| 114 | |
| 115 | TRACE("--UE;\n} %s\n", szFileType); |
| 116 | |
| 117 | return TRUE; |
| 118 | } |
| 119 | |
Francois Gouget | 9607151 | 2006-06-23 18:32:38 +0200 | [diff] [blame] | 120 | static const WCHAR swShell[] = {'s','h','e','l','l','\\',0}; |
| 121 | static const WCHAR swOpen[] = {'o','p','e','n',0}; |
| 122 | static const WCHAR swCommand[] = {'\\','c','o','m','m','a','n','d',0}; |
| 123 | |
| 124 | BOOL HCR_GetDefaultVerbW( HKEY hkeyClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len ) |
| 125 | { |
| 126 | WCHAR sTemp[MAX_PATH]; |
| 127 | LONG size; |
| 128 | HKEY hkey; |
| 129 | |
| 130 | TRACE("%p %s %p\n", hkeyClass, debugstr_w(szVerb), szDest); |
| 131 | |
| 132 | if (szVerb) |
| 133 | { |
| 134 | lstrcpynW(szDest, szVerb, len); |
| 135 | return TRUE; |
| 136 | } |
| 137 | |
| 138 | size=len; |
| 139 | *szDest='\0'; |
| 140 | if (!RegQueryValueW(hkeyClass, swShell, szDest, &size) && *szDest) |
| 141 | { |
| 142 | /* The MSDN says to first try the default verb */ |
| 143 | lstrcpyW(sTemp, swShell); |
| 144 | lstrcatW(sTemp, szDest); |
| 145 | lstrcatW(sTemp, swCommand); |
| 146 | if (!RegOpenKeyExW(hkeyClass, sTemp, 0, 0, &hkey)) |
| 147 | { |
| 148 | RegCloseKey(hkey); |
| 149 | TRACE("default verb=%s\n", debugstr_w(szDest)); |
| 150 | return TRUE; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /* then fallback to 'open' */ |
| 155 | lstrcpyW(sTemp, swShell); |
| 156 | lstrcatW(sTemp, swOpen); |
| 157 | lstrcatW(sTemp, swCommand); |
| 158 | if (!RegOpenKeyExW(hkeyClass, sTemp, 0, 0, &hkey)) |
| 159 | { |
| 160 | RegCloseKey(hkey); |
| 161 | lstrcpynW(szDest, swOpen, len); |
| 162 | TRACE("default verb=open\n"); |
| 163 | return TRUE; |
| 164 | } |
| 165 | |
| 166 | /* and then just use the first verb on Windows >= 2000 */ |
| 167 | if (!RegEnumKeyW(hkeyClass, 0, szDest, len) && *szDest) |
| 168 | { |
| 169 | TRACE("default verb=first verb=%s\n", debugstr_w(szDest)); |
| 170 | return TRUE; |
| 171 | } |
| 172 | |
| 173 | TRACE("no default verb!\n"); |
| 174 | return FALSE; |
| 175 | } |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 176 | |
Alexandre Julliard | e025c59 | 2004-01-16 23:06:25 +0000 | [diff] [blame] | 177 | BOOL HCR_GetExecuteCommandW( HKEY hkeyClass, LPCWSTR szClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len ) |
Marcelo Duarte | 3600273 | 2003-12-10 00:39:31 +0000 | [diff] [blame] | 178 | { |
Francois Gouget | 9607151 | 2006-06-23 18:32:38 +0200 | [diff] [blame] | 179 | WCHAR sTempVerb[MAX_PATH]; |
| 180 | BOOL ret; |
Marcelo Duarte | 3600273 | 2003-12-10 00:39:31 +0000 | [diff] [blame] | 181 | |
| 182 | TRACE("%p %s %s %p\n", hkeyClass, debugstr_w(szClass), debugstr_w(szVerb), szDest); |
| 183 | |
| 184 | if (szClass) |
Alexandre Julliard | e025c59 | 2004-01-16 23:06:25 +0000 | [diff] [blame] | 185 | RegOpenKeyExW(HKEY_CLASSES_ROOT, szClass, 0, 0x02000000, &hkeyClass); |
Francois Gouget | 9607151 | 2006-06-23 18:32:38 +0200 | [diff] [blame] | 186 | if (!hkeyClass) |
| 187 | return FALSE; |
| 188 | ret = FALSE; |
Marcelo Duarte | 3600273 | 2003-12-10 00:39:31 +0000 | [diff] [blame] | 189 | |
Francois Gouget | 9607151 | 2006-06-23 18:32:38 +0200 | [diff] [blame] | 190 | if (HCR_GetDefaultVerbW(hkeyClass, szVerb, sTempVerb, sizeof(sTempVerb))) |
| 191 | { |
| 192 | WCHAR sTemp[MAX_PATH]; |
| 193 | lstrcpyW(sTemp, swShell); |
| 194 | lstrcatW(sTemp, sTempVerb); |
| 195 | lstrcatW(sTemp, swCommand); |
| 196 | ret = (ERROR_SUCCESS == SHGetValueW(hkeyClass, sTemp, NULL, NULL, szDest, &len)); |
| 197 | } |
| 198 | if (szClass) |
| 199 | RegCloseKey(hkeyClass); |
Marcelo Duarte | 3600273 | 2003-12-10 00:39:31 +0000 | [diff] [blame] | 200 | |
| 201 | TRACE("-- %s\n", debugstr_w(szDest) ); |
| 202 | return ret; |
| 203 | } |
| 204 | |
Juergen Schmied | 01fc2ba | 1998-12-14 17:33:00 +0000 | [diff] [blame] | 205 | /*************************************************************************************** |
| 206 | * HCR_GetDefaultIcon [internal] |
| 207 | * |
| 208 | * Gets the icon for a filetype |
| 209 | */ |
Juergen Schmied | 799e6ce | 2003-01-10 01:45:57 +0000 | [diff] [blame] | 210 | static BOOL HCR_RegOpenClassIDKey(REFIID riid, HKEY *hkey) |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 211 | { |
| 212 | char xriid[50]; |
Michael Stefaniuc | 15765dd | 2006-10-15 12:27:34 +0200 | [diff] [blame] | 213 | sprintf( xriid, "CLSID\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 214 | riid->Data1, riid->Data2, riid->Data3, |
| 215 | riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3], |
| 216 | riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] ); |
| 217 | |
| 218 | TRACE("%s\n",xriid ); |
| 219 | |
Juergen Schmied | 799e6ce | 2003-01-10 01:45:57 +0000 | [diff] [blame] | 220 | return !RegOpenKeyExA(HKEY_CLASSES_ROOT, xriid, 0, KEY_READ, hkey); |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 223 | static BOOL HCR_RegGetDefaultIconW(HKEY hkey, LPWSTR szDest, DWORD len, int* picon_idx) |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 224 | { |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 225 | DWORD dwType; |
| 226 | WCHAR sTemp[MAX_PATH]; |
| 227 | WCHAR sNum[5]; |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 228 | |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 229 | if (!RegQueryValueExW(hkey, NULL, 0, &dwType, (LPBYTE)szDest, &len)) |
| 230 | { |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 231 | if (dwType == REG_EXPAND_SZ) |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 232 | { |
| 233 | ExpandEnvironmentStringsW(szDest, sTemp, MAX_PATH); |
| 234 | lstrcpynW(szDest, sTemp, len); |
| 235 | } |
| 236 | if (ParseFieldW (szDest, 2, sNum, 5)) |
| 237 | *picon_idx = atoiW(sNum); |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 238 | else |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 239 | *picon_idx=0; /* sometimes the icon number is missing */ |
| 240 | ParseFieldW (szDest, 1, szDest, len); |
Huw Davies | 47db6bc | 2005-06-15 18:07:43 +0000 | [diff] [blame] | 241 | PathUnquoteSpacesW(szDest); |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 242 | return TRUE; |
| 243 | } |
| 244 | return FALSE; |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 247 | static BOOL HCR_RegGetDefaultIconA(HKEY hkey, LPSTR szDest, DWORD len, int* picon_idx) |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 248 | { |
| 249 | DWORD dwType; |
| 250 | char sTemp[MAX_PATH]; |
| 251 | char sNum[5]; |
| 252 | |
Mike McCormack | d7b9a23 | 2005-07-06 19:08:05 +0000 | [diff] [blame] | 253 | if (!RegQueryValueExA(hkey, NULL, 0, &dwType, (LPBYTE)szDest, &len)) |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 254 | { |
| 255 | if (dwType == REG_EXPAND_SZ) |
| 256 | { |
| 257 | ExpandEnvironmentStringsA(szDest, sTemp, MAX_PATH); |
| 258 | lstrcpynA(szDest, sTemp, len); |
| 259 | } |
| 260 | if (ParseFieldA (szDest, 2, sNum, 5)) |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 261 | *picon_idx=atoi(sNum); |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 262 | else |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 263 | *picon_idx=0; /* sometimes the icon number is missing */ |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 264 | ParseFieldA (szDest, 1, szDest, len); |
Huw Davies | 47db6bc | 2005-06-15 18:07:43 +0000 | [diff] [blame] | 265 | PathUnquoteSpacesA(szDest); |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 266 | return TRUE; |
| 267 | } |
| 268 | return FALSE; |
| 269 | } |
| 270 | |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 271 | BOOL HCR_GetDefaultIconW(LPCWSTR szClass, LPWSTR szDest, DWORD len, int* picon_idx) |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 272 | { |
| 273 | static const WCHAR swDefaultIcon[] = {'\\','D','e','f','a','u','l','t','I','c','o','n',0}; |
| 274 | HKEY hkey; |
| 275 | WCHAR sTemp[MAX_PATH]; |
| 276 | BOOL ret = FALSE; |
| 277 | |
| 278 | TRACE("%s\n",debugstr_w(szClass) ); |
| 279 | |
| 280 | lstrcpynW(sTemp, szClass, MAX_PATH); |
| 281 | lstrcatW(sTemp, swDefaultIcon); |
| 282 | |
| 283 | if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, sTemp, 0, 0x02000000, &hkey)) |
| 284 | { |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 285 | ret = HCR_RegGetDefaultIconW(hkey, szDest, len, picon_idx); |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 286 | RegCloseKey(hkey); |
| 287 | } |
Huw Davies | 861282b | 2005-04-11 13:04:41 +0000 | [diff] [blame] | 288 | |
| 289 | if(ret) |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 290 | TRACE("-- %s %i\n", debugstr_w(szDest), *picon_idx); |
Huw Davies | 861282b | 2005-04-11 13:04:41 +0000 | [diff] [blame] | 291 | else |
| 292 | TRACE("-- not found\n"); |
| 293 | |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 294 | return ret; |
| 295 | } |
| 296 | |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 297 | BOOL HCR_GetDefaultIconA(LPCSTR szClass, LPSTR szDest, DWORD len, int* picon_idx) |
Juergen Schmied | 1dbf403d | 2000-06-24 12:56:08 +0000 | [diff] [blame] | 298 | { |
| 299 | HKEY hkey; |
| 300 | char sTemp[MAX_PATH]; |
Juergen Schmied | 1dbf403d | 2000-06-24 12:56:08 +0000 | [diff] [blame] | 301 | BOOL ret = FALSE; |
Juergen Schmied | 01fc2ba | 1998-12-14 17:33:00 +0000 | [diff] [blame] | 302 | |
Alexandre Julliard | a099a55 | 1999-06-12 15:45:58 +0000 | [diff] [blame] | 303 | TRACE("%s\n",szClass ); |
Juergen Schmied | 01fc2ba | 1998-12-14 17:33:00 +0000 | [diff] [blame] | 304 | |
| 305 | sprintf(sTemp, "%s\\DefaultIcon",szClass); |
| 306 | |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 307 | if (!RegOpenKeyExA(HKEY_CLASSES_ROOT, sTemp, 0, 0x02000000, &hkey)) |
Juergen Schmied | 1dbf403d | 2000-06-24 12:56:08 +0000 | [diff] [blame] | 308 | { |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 309 | ret = HCR_RegGetDefaultIconA(hkey, szDest, len, picon_idx); |
Juergen Schmied | 1dbf403d | 2000-06-24 12:56:08 +0000 | [diff] [blame] | 310 | RegCloseKey(hkey); |
Juergen Schmied | 01fc2ba | 1998-12-14 17:33:00 +0000 | [diff] [blame] | 311 | } |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 312 | TRACE("-- %s %i\n", szDest, *picon_idx); |
Juergen Schmied | 1dbf403d | 2000-06-24 12:56:08 +0000 | [diff] [blame] | 313 | return ret; |
Juergen Schmied | 166cfd5 | 1999-07-25 12:19:12 +0000 | [diff] [blame] | 314 | } |
Juergen Schmied | 01fc2ba | 1998-12-14 17:33:00 +0000 | [diff] [blame] | 315 | |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 316 | BOOL HCR_GetDefaultIconFromGUIDW(REFIID riid, LPWSTR szDest, DWORD len, int* picon_idx) |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 317 | { |
| 318 | HKEY hkey; |
| 319 | BOOL ret = FALSE; |
| 320 | |
Juergen Schmied | 799e6ce | 2003-01-10 01:45:57 +0000 | [diff] [blame] | 321 | if (HCR_RegOpenClassIDKey(riid, &hkey)) |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 322 | { |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 323 | ret = HCR_RegGetDefaultIconW(hkey, szDest, len, picon_idx); |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 324 | RegCloseKey(hkey); |
| 325 | } |
Martin Fuchs | 7114f8c | 2006-01-11 12:33:24 +0100 | [diff] [blame] | 326 | TRACE("-- %s %i\n", debugstr_w(szDest), *picon_idx); |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 327 | return ret; |
| 328 | } |
| 329 | |
Juergen Schmied | 166cfd5 | 1999-07-25 12:19:12 +0000 | [diff] [blame] | 330 | /*************************************************************************************** |
| 331 | * HCR_GetClassName [internal] |
| 332 | * |
Francois Gouget | f8e01ef | 2004-07-23 23:02:09 +0000 | [diff] [blame] | 333 | * Gets the name of a registered class |
Juergen Schmied | 166cfd5 | 1999-07-25 12:19:12 +0000 | [diff] [blame] | 334 | */ |
Francois Gouget | 6a6c85c | 2004-04-19 20:12:14 +0000 | [diff] [blame] | 335 | static const WCHAR swEmpty[] = {0}; |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 336 | |
| 337 | BOOL HCR_GetClassNameW(REFIID riid, LPWSTR szDest, DWORD len) |
| 338 | { |
| 339 | HKEY hkey; |
Juergen Schmied | d72ace4 | 1999-08-15 14:24:49 +0000 | [diff] [blame] | 340 | BOOL ret = FALSE; |
| 341 | DWORD buflen = len; |
Juergen Schmied | 166cfd5 | 1999-07-25 12:19:12 +0000 | [diff] [blame] | 342 | |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 343 | szDest[0] = 0; |
| 344 | if (HCR_RegOpenClassIDKey(riid, &hkey)) |
| 345 | { |
Michael Jung | bbeeb4b | 2006-02-14 10:41:29 +0100 | [diff] [blame] | 346 | static const WCHAR wszLocalizedString[] = |
| 347 | { 'L','o','c','a','l','i','z','e','d','S','t','r','i','n','g', 0 }; |
| 348 | if (!RegLoadMUIStringW(hkey, wszLocalizedString, szDest, len, NULL, 0, NULL) || |
| 349 | !RegQueryValueExW(hkey, swEmpty, 0, NULL, (LPBYTE)szDest, &len)) |
| 350 | { |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 351 | ret = TRUE; |
| 352 | } |
| 353 | RegCloseKey(hkey); |
| 354 | } |
Juergen Schmied | 166cfd5 | 1999-07-25 12:19:12 +0000 | [diff] [blame] | 355 | |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 356 | if (!ret || !szDest[0]) |
| 357 | { |
| 358 | if(IsEqualIID(riid, &CLSID_ShellDesktop)) |
| 359 | { |
| 360 | if (LoadStringW(shell32_hInstance, IDS_DESKTOP, szDest, buflen)) |
| 361 | ret = TRUE; |
| 362 | } |
| 363 | else if (IsEqualIID(riid, &CLSID_MyComputer)) |
| 364 | { |
| 365 | if(LoadStringW(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen)) |
| 366 | ret = TRUE; |
| 367 | } |
| 368 | } |
| 369 | TRACE("-- %s\n", debugstr_w(szDest)); |
| 370 | return ret; |
| 371 | } |
| 372 | |
| 373 | BOOL HCR_GetClassNameA(REFIID riid, LPSTR szDest, DWORD len) |
| 374 | { HKEY hkey; |
| 375 | BOOL ret = FALSE; |
| 376 | DWORD buflen = len; |
Juergen Schmied | 166cfd5 | 1999-07-25 12:19:12 +0000 | [diff] [blame] | 377 | |
Juergen Schmied | ed93b63 | 2000-02-20 18:38:19 +0000 | [diff] [blame] | 378 | szDest[0] = 0; |
Rolf Kalbermatter | caf31ce | 2002-12-13 23:45:36 +0000 | [diff] [blame] | 379 | if (HCR_RegOpenClassIDKey(riid, &hkey)) |
Juergen Schmied | d72ace4 | 1999-08-15 14:24:49 +0000 | [diff] [blame] | 380 | { |
Michael Jung | bbeeb4b | 2006-02-14 10:41:29 +0100 | [diff] [blame] | 381 | if (!RegLoadMUIStringA(hkey,"LocalizedString",szDest,len,NULL,0,NULL) || |
| 382 | !RegQueryValueExA(hkey,"",0,NULL,(LPBYTE)szDest,&len)) |
| 383 | { |
Juergen Schmied | d72ace4 | 1999-08-15 14:24:49 +0000 | [diff] [blame] | 384 | ret = TRUE; |
| 385 | } |
| 386 | RegCloseKey(hkey); |
Juergen Schmied | 166cfd5 | 1999-07-25 12:19:12 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Juergen Schmied | d72ace4 | 1999-08-15 14:24:49 +0000 | [diff] [blame] | 389 | if (!ret || !szDest[0]) |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 390 | { |
Juergen Schmied | d72ace4 | 1999-08-15 14:24:49 +0000 | [diff] [blame] | 391 | if(IsEqualIID(riid, &CLSID_ShellDesktop)) |
| 392 | { |
Juergen Schmied | ed93b63 | 2000-02-20 18:38:19 +0000 | [diff] [blame] | 393 | if (LoadStringA(shell32_hInstance, IDS_DESKTOP, szDest, buflen)) |
| 394 | ret = TRUE; |
Juergen Schmied | d72ace4 | 1999-08-15 14:24:49 +0000 | [diff] [blame] | 395 | } |
Juergen Schmied | afe53ed | 1999-11-23 22:31:18 +0000 | [diff] [blame] | 396 | else if (IsEqualIID(riid, &CLSID_MyComputer)) |
Juergen Schmied | d72ace4 | 1999-08-15 14:24:49 +0000 | [diff] [blame] | 397 | { |
Juergen Schmied | ed93b63 | 2000-02-20 18:38:19 +0000 | [diff] [blame] | 398 | if(LoadStringA(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen)) |
| 399 | ret = TRUE; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 400 | } |
Juergen Schmied | d72ace4 | 1999-08-15 14:24:49 +0000 | [diff] [blame] | 401 | } |
Juergen Schmied | 166cfd5 | 1999-07-25 12:19:12 +0000 | [diff] [blame] | 402 | |
| 403 | TRACE("-- %s\n", szDest); |
| 404 | |
Juergen Schmied | d72ace4 | 1999-08-15 14:24:49 +0000 | [diff] [blame] | 405 | return ret; |
Juergen Schmied | 166cfd5 | 1999-07-25 12:19:12 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Michael Jung | 11cadc3 | 2005-06-25 17:55:53 +0000 | [diff] [blame] | 408 | /****************************************************************************** |
| 409 | * HCR_GetFolderAttributes [Internal] |
| 410 | * |
| 411 | * Query the registry for a shell folders' attributes |
| 412 | * |
| 413 | * PARAMS |
| 414 | * pidlFolder [I] A simple pidl of type PT_GUID. |
| 415 | * pdwAttributes [IO] In: Attributes to be queried, OUT: Resulting attributes. |
| 416 | * |
| 417 | * RETURNS |
| 418 | * TRUE: Found information for the attributes in the registry |
| 419 | * FALSE: No attribute information found |
| 420 | * |
| 421 | * NOTES |
| 422 | * If queried for an attribute, which is set in the CallForAttributes registry |
| 423 | * value, the function binds to the shellfolder objects and queries it. |
| 424 | */ |
| 425 | BOOL HCR_GetFolderAttributes(LPCITEMIDLIST pidlFolder, LPDWORD pdwAttributes) |
| 426 | { |
| 427 | HKEY hSFKey; |
| 428 | LPOLESTR pwszCLSID; |
| 429 | LONG lResult; |
| 430 | DWORD dwTemp, dwLen; |
| 431 | static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 }; |
| 432 | static const WCHAR wszCallForAttributes[] = { |
| 433 | 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 }; |
| 434 | WCHAR wszShellFolderKey[] = { 'C','L','S','I','D','\\','{','0','0','0','2','1','4','0','0','-', |
| 435 | '0','0','0','0','-','0','0','0','0','-','C','0','0','0','-','0','0','0','0','0','0','0', |
| 436 | '0','0','0','4','6','}','\\','S','h','e','l','l','F','o','l','d','e','r',0 }; |
Juergen Schmied | 166cfd5 | 1999-07-25 12:19:12 +0000 | [diff] [blame] | 437 | |
Michael Jung | 11cadc3 | 2005-06-25 17:55:53 +0000 | [diff] [blame] | 438 | TRACE("(pidlFolder=%p, pdwAttributes=%p)\n", pidlFolder, pdwAttributes); |
| 439 | |
| 440 | if (!_ILIsPidlSimple(pidlFolder)) { |
| 441 | ERR("HCR_GetFolderAttributes should be called for simple PIDL's only!\n"); |
| 442 | return FALSE; |
| 443 | } |
| 444 | |
| 445 | if (!_ILIsDesktop(pidlFolder)) { |
| 446 | if (FAILED(StringFromCLSID(_ILGetGUIDPointer(pidlFolder), &pwszCLSID))) return FALSE; |
| 447 | memcpy(&wszShellFolderKey[6], pwszCLSID, 38 * sizeof(WCHAR)); |
| 448 | CoTaskMemFree(pwszCLSID); |
| 449 | } |
| 450 | |
| 451 | lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszShellFolderKey, 0, KEY_READ, &hSFKey); |
| 452 | if (lResult != ERROR_SUCCESS) return FALSE; |
| 453 | |
| 454 | dwLen = sizeof(DWORD); |
| 455 | lResult = RegQueryValueExW(hSFKey, wszCallForAttributes, 0, NULL, (LPBYTE)&dwTemp, &dwLen); |
| 456 | if ((lResult == ERROR_SUCCESS) && (dwTemp & *pdwAttributes)) { |
| 457 | LPSHELLFOLDER psfDesktop, psfFolder; |
| 458 | HRESULT hr; |
Juergen Schmied | 166cfd5 | 1999-07-25 12:19:12 +0000 | [diff] [blame] | 459 | |
Michael Jung | 11cadc3 | 2005-06-25 17:55:53 +0000 | [diff] [blame] | 460 | RegCloseKey(hSFKey); |
| 461 | hr = SHGetDesktopFolder(&psfDesktop); |
| 462 | if (SUCCEEDED(hr)) { |
| 463 | hr = IShellFolder_BindToObject(psfDesktop, pidlFolder, NULL, &IID_IShellFolder, |
| 464 | (LPVOID*)&psfFolder); |
| 465 | if (SUCCEEDED(hr)) { |
| 466 | hr = IShellFolder_GetAttributesOf(psfFolder, 0, NULL, pdwAttributes); |
Michael Jung | ff23dd2 | 2005-07-18 13:13:05 +0000 | [diff] [blame] | 467 | IShellFolder_Release(psfFolder); |
Michael Jung | 11cadc3 | 2005-06-25 17:55:53 +0000 | [diff] [blame] | 468 | } |
Michael Jung | ff23dd2 | 2005-07-18 13:13:05 +0000 | [diff] [blame] | 469 | IShellFolder_Release(psfDesktop); |
Michael Jung | 11cadc3 | 2005-06-25 17:55:53 +0000 | [diff] [blame] | 470 | } |
Michael Jung | 11cadc3 | 2005-06-25 17:55:53 +0000 | [diff] [blame] | 471 | if (FAILED(hr)) return FALSE; |
| 472 | } else { |
| 473 | lResult = RegQueryValueExW(hSFKey, wszAttributes, 0, NULL, (LPBYTE)&dwTemp, &dwLen); |
| 474 | RegCloseKey(hSFKey); |
| 475 | if (lResult == ERROR_SUCCESS) { |
| 476 | *pdwAttributes &= dwTemp; |
| 477 | } else { |
| 478 | return FALSE; |
| 479 | } |
| 480 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 481 | |
Hans Leidekker | 89e1d29 | 2006-10-07 20:18:14 +0200 | [diff] [blame] | 482 | TRACE("-- *pdwAttributes == 0x%08x\n", *pdwAttributes); |
Juergen Schmied | 166cfd5 | 1999-07-25 12:19:12 +0000 | [diff] [blame] | 483 | |
Michael Jung | 11cadc3 | 2005-06-25 17:55:53 +0000 | [diff] [blame] | 484 | return TRUE; |
Juergen Schmied | 01fc2ba | 1998-12-14 17:33:00 +0000 | [diff] [blame] | 485 | } |