ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

folders.cpp
Go to the documentation of this file.
00001 /*
00002  *    Copyright 1997    Marcus Meissner
00003  *    Copyright 1998    Juergen Schmied
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00018  */
00019 
00020 #include <precomp.h>
00021 
00022 WINE_DEFAULT_DEBUG_CHANNEL(shell);
00023 
00024 WCHAR swShell32Name[MAX_PATH];
00025 
00026 DWORD NumIconOverlayHandlers = 0;
00027 IShellIconOverlayIdentifier ** Handlers = NULL;
00028 
00029 static HRESULT getIconLocationForFolder(LPCITEMIDLIST pidl, UINT uFlags,
00030                                         LPWSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
00031 {
00032     int icon_idx;
00033     WCHAR wszPath[MAX_PATH];
00034     WCHAR wszCLSIDValue[CHARS_IN_GUID];
00035     static const WCHAR shellClassInfo[] = { '.', 'S', 'h', 'e', 'l', 'l', 'C', 'l', 'a', 's', 's', 'I', 'n', 'f', 'o', 0 };
00036     static const WCHAR iconFile[] = { 'I', 'c', 'o', 'n', 'F', 'i', 'l', 'e', 0 };
00037     static const WCHAR clsid[] = { 'C', 'L', 'S', 'I', 'D', 0 };
00038     static const WCHAR clsid2[] = { 'C', 'L', 'S', 'I', 'D', '2', 0 };
00039     static const WCHAR iconIndex[] = { 'I', 'c', 'o', 'n', 'I', 'n', 'd', 'e', 'x', 0 };
00040 
00041     if (SHELL32_GetCustomFolderAttribute(pidl, shellClassInfo, iconFile,
00042                                          wszPath, MAX_PATH))
00043     {
00044         WCHAR wszIconIndex[10];
00045         SHELL32_GetCustomFolderAttribute(pidl, shellClassInfo, iconIndex,
00046                                          wszIconIndex, 10);
00047         *piIndex = _wtoi(wszIconIndex);
00048     }
00049     else if (SHELL32_GetCustomFolderAttribute(pidl, shellClassInfo, clsid,
00050              wszCLSIDValue, CHARS_IN_GUID) &&
00051              HCR_GetDefaultIconW(wszCLSIDValue, szIconFile, cchMax, &icon_idx))
00052     {
00053         *piIndex = icon_idx;
00054     }
00055     else if (SHELL32_GetCustomFolderAttribute(pidl, shellClassInfo, clsid2,
00056              wszCLSIDValue, CHARS_IN_GUID) &&
00057              HCR_GetDefaultIconW(wszCLSIDValue, szIconFile, cchMax, &icon_idx))
00058     {
00059         *piIndex = icon_idx;
00060     }
00061     else
00062     {
00063         static const WCHAR folder[] = { 'F', 'o', 'l', 'd', 'e', 'r', 0 };
00064 
00065         if (!HCR_GetDefaultIconW(folder, szIconFile, cchMax, &icon_idx))
00066         {
00067             lstrcpynW(szIconFile, swShell32Name, cchMax);
00068             icon_idx = -IDI_SHELL_FOLDER;
00069         }
00070 
00071         if (uFlags & GIL_OPENICON)
00072             *piIndex = icon_idx < 0 ? icon_idx - 1 : icon_idx + 1;
00073         else
00074             *piIndex = icon_idx;
00075     }
00076 
00077     return S_OK;
00078 }
00079 
00080 void InitIconOverlays(void)
00081 {
00082     HKEY hKey;
00083     DWORD dwIndex, dwResult, dwSize;
00084     WCHAR szName[MAX_PATH];
00085     WCHAR szValue[100];
00086     CLSID clsid;
00087     IShellIconOverlayIdentifier * Overlay;
00088 
00089     if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellIconOverlayIdentifiers", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
00090         return;
00091 
00092     if (RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &dwResult, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
00093     {
00094         RegCloseKey(hKey);
00095         return;
00096     }
00097 
00098     Handlers = (IShellIconOverlayIdentifier **)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwResult * sizeof(IShellIconOverlayIdentifier*));
00099     if (!Handlers)
00100     {
00101         RegCloseKey(hKey);
00102         return;
00103     }
00104 
00105     dwIndex = 0;
00106 
00107     CoInitialize(0);
00108 
00109     do
00110     {
00111         dwSize = sizeof(szName) / sizeof(WCHAR);
00112         dwResult = RegEnumKeyExW(hKey, dwIndex, szName, &dwSize, NULL, NULL, NULL, NULL);
00113 
00114         if (dwResult == ERROR_NO_MORE_ITEMS)
00115             break;
00116 
00117         if (dwResult == ERROR_SUCCESS)
00118         {
00119             dwSize = sizeof(szValue) / sizeof(WCHAR);
00120             if (RegGetValueW(hKey, szName, NULL, RRF_RT_REG_SZ, NULL, szValue, &dwSize) == ERROR_SUCCESS)
00121             {
00122 
00123                 CLSIDFromString(szValue, &clsid);
00124                 dwResult = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (LPVOID*)&Overlay);
00125                 if (dwResult == S_OK)
00126                 {
00127                     Handlers[NumIconOverlayHandlers] = Overlay;
00128                     NumIconOverlayHandlers++;
00129                 }
00130             }
00131         }
00132 
00133         dwIndex++;
00134 
00135     } while(1);
00136 
00137     RegCloseKey(hKey);
00138 }
00139 
00140 BOOL
00141 GetIconOverlay(LPCITEMIDLIST pidl, WCHAR * wTemp, int* pIndex)
00142 {
00143     DWORD Index;
00144     HRESULT hResult;
00145     int Priority;
00146     int HighestPriority;
00147     ULONG IconIndex;
00148     ULONG Flags;
00149     WCHAR szPath[MAX_PATH];
00150 
00151     if(!SHGetPathFromIDListW(pidl, szPath))
00152         return FALSE;
00153 
00154 
00155     HighestPriority = 101;
00156     IconIndex = NumIconOverlayHandlers;
00157     for(Index = 0; Index < NumIconOverlayHandlers; Index++)
00158     {
00159         hResult = Handlers[Index]->IsMemberOf(szPath, SFGAO_FILESYSTEM);
00160         if (hResult == S_OK)
00161         {
00162             hResult = Handlers[Index]->GetPriority(&Priority);
00163             if (hResult == S_OK)
00164             {
00165                 if (Priority < HighestPriority)
00166                 {
00167                     HighestPriority = Priority;
00168                     IconIndex = Index;
00169                 }
00170             }
00171         }
00172     }
00173 
00174     if (IconIndex == NumIconOverlayHandlers)
00175         return FALSE;
00176 
00177     hResult = Handlers[IconIndex]->GetOverlayInfo(wTemp, MAX_PATH, pIndex, &Flags);
00178 
00179     if (hResult == S_OK)
00180         return TRUE;
00181     else
00182         return FALSE;
00183 }
00184 
00185 /**************************************************************************
00186 *  IExtractIconW_Constructor
00187 */
00188 IExtractIconW* IExtractIconW_Constructor(LPCITEMIDLIST pidl)
00189 {
00190     CComPtr<IDefaultExtractIconInit>    initIcon;
00191     IExtractIconW *extractIcon;
00192     GUID const * riid;
00193     int icon_idx;
00194     UINT flags;
00195     CHAR sTemp[MAX_PATH];
00196     WCHAR wTemp[MAX_PATH];
00197     LPITEMIDLIST pSimplePidl = ILFindLastID(pidl);
00198     HRESULT hr;
00199 
00200     hr = SHCreateDefaultExtractIcon(IID_IDefaultExtractIconInit, (void **)&initIcon);
00201     if (FAILED(hr))
00202         return NULL;
00203 
00204     hr = initIcon->QueryInterface(IID_IExtractIconW, (void **)&extractIcon);
00205     if (FAILED(hr))
00206         return NULL;
00207 
00208     if (_ILIsDesktop(pSimplePidl))
00209     {
00210         initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_DESKTOP);
00211     }
00212     else if ((riid = _ILGetGUIDPointer(pSimplePidl)))
00213     {
00214         /* my computer and other shell extensions */
00215         static const WCHAR fmt[] = { 'C', 'L', 'S', 'I', 'D', '\\',
00216                                      '{', '%', '0', '8', 'l', 'x', '-', '%', '0', '4', 'x', '-', '%', '0', '4', 'x', '-',
00217                                      '%', '0', '2', 'x', '%', '0', '2', 'x', '-', '%', '0', '2', 'x', '%', '0', '2', 'x',
00218                                      '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '}', 0
00219                                    };
00220         WCHAR xriid[50];
00221 
00222         swprintf(xriid, fmt,
00223                  riid->Data1, riid->Data2, riid->Data3,
00224                  riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
00225                  riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]);
00226 
00227         if (HCR_GetDefaultIconW(xriid, wTemp, MAX_PATH, &icon_idx))
00228         {
00229             initIcon->SetNormalIcon(wTemp, icon_idx);
00230         }
00231         else
00232         {
00233             if (IsEqualGUID(*riid, CLSID_MyComputer))
00234                 initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_COMPUTER);
00235             else if (IsEqualGUID(*riid, CLSID_MyDocuments))
00236                 initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_DOCUMENTS);
00237             else if (IsEqualGUID(*riid, CLSID_NetworkPlaces))
00238                 initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_NETWORK_PLACES);
00239             else
00240                 initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_FOLDER);
00241         }
00242     }
00243 
00244     else if (_ILIsDrive (pSimplePidl))
00245     {
00246         static const WCHAR drive[] = { 'D', 'r', 'i', 'v', 'e', 0 };
00247         int icon_idx = -1;
00248 
00249         if (_ILGetDrive(pSimplePidl, sTemp, MAX_PATH))
00250         {
00251             switch(GetDriveTypeA(sTemp))
00252             {
00253                 case DRIVE_REMOVABLE:
00254                     icon_idx = IDI_SHELL_FLOPPY;
00255                     break;
00256                 case DRIVE_CDROM:
00257                     icon_idx = IDI_SHELL_CDROM;
00258                     break;
00259                 case DRIVE_REMOTE:
00260                     icon_idx = IDI_SHELL_NETDRIVE;
00261                     break;
00262                 case DRIVE_RAMDISK:
00263                     icon_idx = IDI_SHELL_RAMDISK;
00264                     break;
00265                 case DRIVE_NO_ROOT_DIR:
00266                     icon_idx = IDI_SHELL_CDROM;
00267                     break;
00268             }
00269         }
00270 
00271         if (icon_idx != -1)
00272         {
00273             initIcon->SetNormalIcon(swShell32Name, -icon_idx);
00274         }
00275         else
00276         {
00277             if (HCR_GetDefaultIconW(drive, wTemp, MAX_PATH, &icon_idx))
00278                 initIcon->SetNormalIcon(wTemp, icon_idx);
00279             else
00280                 initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_DRIVE);
00281         }
00282     }
00283 
00284     else if (_ILIsFolder (pSimplePidl))
00285     {
00286         if (SUCCEEDED(getIconLocationForFolder(
00287                           pidl, 0, wTemp, MAX_PATH,
00288                           &icon_idx,
00289                           &flags)))
00290         {
00291             initIcon->SetNormalIcon(wTemp, icon_idx);
00292         }
00293         if (SUCCEEDED(getIconLocationForFolder(
00294                           pidl, GIL_DEFAULTICON, wTemp, MAX_PATH,
00295                           &icon_idx,
00296                           &flags)))
00297         {
00298             initIcon->SetDefaultIcon(wTemp, icon_idx);
00299         }
00300         if (SUCCEEDED(getIconLocationForFolder(
00301                           pidl, GIL_FORSHORTCUT, wTemp, MAX_PATH,
00302                           &icon_idx,
00303                           &flags)))
00304         {
00305             initIcon->SetShortcutIcon(wTemp, icon_idx);
00306         }
00307         if (SUCCEEDED(getIconLocationForFolder(
00308                           pidl, GIL_OPENICON, wTemp, MAX_PATH,
00309                           &icon_idx,
00310                           &flags)))
00311         {
00312             initIcon->SetOpenIcon(wTemp, icon_idx);
00313         }
00314     }
00315     else
00316     {
00317         BOOL found = FALSE;
00318 
00319         if (_ILIsCPanelStruct(pSimplePidl))
00320         {
00321             if (SUCCEEDED(CPanel_GetIconLocationW(pSimplePidl, wTemp, MAX_PATH, &icon_idx)))
00322                 found = TRUE;
00323         }
00324         else if (_ILGetExtension(pSimplePidl, sTemp, MAX_PATH))
00325         {
00326             if (HCR_MapTypeToValueA(sTemp, sTemp, MAX_PATH, TRUE)
00327                     && HCR_GetDefaultIconA(sTemp, sTemp, MAX_PATH, &icon_idx))
00328             {
00329                 if (!lstrcmpA("%1", sTemp)) /* icon is in the file */
00330                 {
00331                     SHGetPathFromIDListW(pidl, wTemp);
00332                     icon_idx = 0;
00333                 }
00334                 else
00335                 {
00336                     MultiByteToWideChar(CP_ACP, 0, sTemp, -1, wTemp, MAX_PATH);
00337                 }
00338 
00339                 found = TRUE;
00340             }
00341             else if (!lstrcmpiA(sTemp, "lnkfile"))
00342             {
00343                 /* extract icon from shell shortcut */
00344                 CComPtr<IShellFolder>        dsf;
00345                 CComPtr<IShellLinkW>        psl;
00346 
00347                 if (SUCCEEDED(SHGetDesktopFolder(&dsf)))
00348                 {
00349                     HRESULT hr = dsf->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST*)&pidl, IID_IShellLinkW, NULL, (LPVOID *)&psl);
00350 
00351                     if (SUCCEEDED(hr))
00352                     {
00353                         hr = psl->GetIconLocation(wTemp, MAX_PATH, &icon_idx);
00354 
00355                         if (SUCCEEDED(hr) && *sTemp)
00356                             found = TRUE;
00357 
00358                     }
00359                 }
00360             }
00361         }
00362 
00363         if (!found)
00364             /* default icon */
00365             initIcon->SetNormalIcon(swShell32Name, 0);
00366         else
00367             initIcon->SetNormalIcon(wTemp, icon_idx);
00368     }
00369 
00370     return extractIcon;
00371 }
00372 
00373 /**************************************************************************
00374 *  IExtractIconA_Constructor
00375 */
00376 IExtractIconA* IExtractIconA_Constructor(LPCITEMIDLIST pidl)
00377 {
00378     IExtractIconW *extractIconW;
00379     IExtractIconA *extractIconA;
00380     HRESULT hr;
00381 
00382     extractIconW = IExtractIconW_Constructor(pidl);
00383     if (!extractIconW)
00384         return NULL;
00385 
00386     hr = extractIconW->QueryInterface(IID_IExtractIconA, (void **)&extractIconA);
00387     extractIconW->Release();
00388     if (FAILED(hr))
00389         return NULL;
00390     return extractIconA;
00391 }

Generated on Sat May 26 2012 04:24:55 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.