Changeset 4607 for trunk/src/shell32


Ignore:
Timestamp:
Nov 17, 2000, 10:57:35 AM (25 years ago)
Author:
sandervl
Message:

KS: ICO_ExtractIconEx fix for LX images

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/shell32/iconcache.c

    r4121 r4607  
    1 /* $Id: iconcache.c,v 1.1 2000-08-30 13:52:51 sandervl Exp $ */
     1/* $Id: iconcache.c,v 1.2 2000-11-17 09:57:35 sandervl Exp $ */
    22/*
    33 *      shell icon cache (SIC)
     
    6363        TRACE("width = 0x%08x height = 0x%08x\n", entry->bWidth, entry->bHeight);
    6464        TRACE("colors = 0x%08x planes = 0x%08x\n", entry->bColorCount, entry->wPlanes);
    65         TRACE("bitcount = 0x%08x bytesinres = 0x%08lx offset = 0x%08lx\n", 
     65        TRACE("bitcount = 0x%08x bytesinres = 0x%08lx offset = 0x%08lx\n",
    6666        entry->wBitCount, entry->dwBytesInRes, entry->dwImageOffset);
    6767}
     
    8383        int                     size;
    8484
    85         TRACE("0x%08x %p\n", hFile, retptr); 
     85        TRACE("0x%08x %p\n", hFile, retptr);
    8686
    8787        *retptr = NULL;
     
    119119          if( size > sizeof(NE_TYPEINFO) )
    120120          { pTypeInfo = (BYTE*)HeapAlloc( GetProcessHeap(), 0, size);
    121             if( pTypeInfo ) 
     121            if( pTypeInfo )
    122122            { _llseek(hFile, mz_header.e_lfanew+ne_header.ne_rsrctab, SEEK_SET);
    123123              if( _lread( hFile, (char*)pTypeInfo, size) != size )
    124               { HeapFree( GetProcessHeap(), 0, pTypeInfo); 
     124              { HeapFree( GetProcessHeap(), 0, pTypeInfo);
    125125                pTypeInfo = NULL;
    126126              }
     
    176176#define HEADER_SIZE_FILE        (sizeof(icoICONDIR) - sizeof (icoICONDIRENTRY))
    177177
    178 static BYTE * ICO_GetIconDirectory( HFILE hFile, LPicoICONDIR* lplpiID, ULONG *uSize ) 
     178static BYTE * ICO_GetIconDirectory( HFILE hFile, LPicoICONDIR* lplpiID, ULONG *uSize )
    179179{       CURSORICONDIR   lpcid;  /* icon resource in resource-dir format */
    180180        LPicoICONDIR    lpiID;  /* icon resource in file format */
    181181        int             i;
    182182
    183         TRACE("0x%08x %p\n", hFile, lplpiID); 
     183        TRACE("0x%08x %p\n", hFile, lplpiID);
    184184       
    185185        _llseek( hFile, 0, SEEK_SET );
     
    254254          if( pData == (BYTE*)-1 )
    255255          { pCIDir = ICO_GetIconDirectory(hFile, &lpiID, &uSize);       /* check for .ICO file */
    256             if( pCIDir ) 
     256            if( pCIDir )
    257257            { iconDirCount = 1; iconCount = lpiID->idCount;
    258258              TRACE("-- icon found %p 0x%08lx 0x%08x 0x%08x\n", pCIDir, uSize, iconDirCount, iconCount);
     
    265265              TRACE("\tfound directory - %i icon families\n", iconDirCount);
    266266            }
    267             if( pTInfo->type_id == NE_RSCTYPE_ICON ) 
     267            if( pTInfo->type_id == NE_RSCTYPE_ICON )
    268268            { iconCount = pTInfo->count;
    269269              pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
     
    279279            else if( nIconIndex < iconDirCount )
    280280            { UINT16   i, icon;
    281               if( n > iconDirCount - nIconIndex ) 
     281              if( n > iconDirCount - nIconIndex )
    282282                n = iconDirCount - nIconIndex;
    283283
    284               for( i = nIconIndex; i < nIconIndex + n; i++ ) 
     284              for( i = nIconIndex; i < nIconIndex + n; i++ )
    285285              { /* .ICO files have only one icon directory */
    286286
     
    288288                  pCIDir = SHELL_LoadResource( hFile, pIconDir + i, *(WORD*)pData, &uSize );
    289289                RetPtr[i-nIconIndex] = pLookupIconIdFromDirectoryEx( pCIDir, TRUE,  GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0);
    290                 HeapFree(GetProcessHeap(), 0, pCIDir); 
     290                HeapFree(GetProcessHeap(), 0, pCIDir);
    291291              }
    292292
     
    312312            }
    313313          }
    314           if( lpiID ) 
     314          if( lpiID )
    315315            HeapFree( GetProcessHeap(), 0, lpiID);
    316           else 
     316          else
    317317            HeapFree( GetProcessHeap(), 0, pData);
    318         } 
     318        }
    319319/* end ico file */
    320320
     
    329329          PIMAGE_RESOURCE_DIRECTORY_ENTRY       xresent;
    330330          int                   i,j;
    331                  
    332           if ( !(fmapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL))) 
     331               
     332          if ( !(fmapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL)))
    333333          { WARN("failed to create filemap.\n");        /* FIXME, INVALID_HANDLE_VALUE? */
    334334            goto end_2;         /* failure */
    335335          }
    336336
    337           if ( !(peimage = MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0))) 
     337          if ( !(peimage = MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0)))
    338338          { WARN("failed to mmap filemap.\n");
    339339            goto end_2;         /* failure */
     
    345345          rootresdir = NULL;
    346346
    347           for (i=0;i<pe_header->FileHeader.NumberOfSections;i++) 
     347          for (i=0;i<pe_header->FileHeader.NumberOfSections;i++)
    348348          { if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
    349349              continue;
    350350            /* FIXME: doesn't work when the resources are not in a seperate section */
    351             if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress) 
     351            if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress)
    352352            { rootresdir = (PIMAGE_RESOURCE_DIRECTORY)((char*)peimage+pe_sections[i].PointerToRawData);
    353353              break;
     
    355355          }
    356356
    357           if (!rootresdir) 
     357          if (!rootresdir)
    358358          { WARN("haven't found section for resource directory.\n");
    359359            goto end_3;         /* failure */
    360360          }
    361361  /* search the group icon dir*/
    362           if (!(icongroupresdir = GetResDirEntryW(rootresdir,RT_GROUP_ICONW, (DWORD)rootresdir,FALSE))) 
     362          if (!(icongroupresdir = GetResDirEntryW(rootresdir,RT_GROUP_ICONW, (DWORD)rootresdir,FALSE)))
    363363          { WARN("No Icongroupresourcedirectory!\n");
    364364            goto end_3;         /* failure */
     
    380380
    381381            while(n<iconDirCount && xprdeTmp)
    382             {             
     382            {
    383383              if(xprdeTmp->u1.Id ==  iId)
    384384              {
     
    387387              }
    388388              n++;
    389               xprdeTmp++;                 
     389              xprdeTmp++;
    390390            }
    391391            if (nIconIndex < 0)
     
    397397
    398398  /* check nIconIndex to be in range */
    399           if (nIconIndex >= iconDirCount) 
     399          if (nIconIndex >= iconDirCount)
    400400          {
    401401            WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
     
    411411          xresent = xresent+nIconIndex;         /* starting from specified index ... */
    412412
    413           for (i=0;i<n;i++,xresent++) 
     413          for (i=0;i<n;i++,xresent++)
    414414          { PIMAGE_RESOURCE_DIRECTORY   resdir;
    415415
     
    424424            igdata = NULL;
    425425
    426             for (j=0;j<pe_header->FileHeader.NumberOfSections;j++) 
     426            for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
    427427            { if (igdataent->OffsetToData < pe_sections[j].VirtualAddress)
    428428                continue;
     
    432432            }
    433433
    434             if (!igdata) 
     434            if (!igdata)
    435435            { WARN("no matching real address for icongroup!\n");
    436436              goto end_3;       /* failure */
     
    439439          }
    440440
    441           if (!(iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,(DWORD)rootresdir,FALSE))) 
     441          if (!(iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,(DWORD)rootresdir,FALSE)))
    442442          { WARN("No Iconresourcedirectory!\n");
    443443            goto end_3;         /* failure */
    444444          }
    445445
    446           for (i=0;i<n;i++) 
     446          for (i=0;i<n;i++)
    447447          { PIMAGE_RESOURCE_DIRECTORY   xresdir;
    448448            xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],(DWORD)rootresdir,FALSE);
     
    452452
    453453            /* map virtual to address in image */
    454             for (j=0;j<pe_header->FileHeader.NumberOfSections;j++) 
     454            for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
    455455            { if (idataent->OffsetToData < pe_sections[j].VirtualAddress)
    456456                continue;
     
    459459              idata = peimage+(idataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
    460460            }
    461             if (!idata) 
     461            if (!idata)
    462462            { WARN("no matching real address found for icondata!\n");
    463463              RetPtr[i]=0;
     
    469469          goto end_3;           /* sucess */
    470470        }
     471#ifdef __WIN32OS2__
     472        else
     473    {
     474        if( nIconIndex == -1 )
     475            {
     476                TRACE( "ICO_ExtractIconEx : iconcount not implemented!\n" );
     477            }
     478        else
     479        {
     480            /* Try to get icon(s) using LoadImageA. This works for
     481               LX images, like Odin's shell32.dll! */
     482            HINSTANCE hInst = LoadLibraryA( lpszExeFileName );
     483            if ( hInst )
     484            {
     485                INT icon;
     486                    for( icon = nIconIndex; icon < nIconIndex + n; icon++ )
     487                    {
     488                        RetPtr[ icon - nIconIndex ]
     489                            = LoadImageA( hInst,
     490                                      MAKEINTRESOURCEA( icon ),
     491                                          IMAGE_ICON,
     492                                          cxDesired,
     493                                          cyDesired,
     494                                          LR_DEFAULTCOLOR );
     495                    }
     496                hRet = RetPtr[ 0 ];
     497                FreeLibrary( hInst );   
     498            }
     499        }
     500    }
     501#endif
    471502        goto end_1;             /* unknown filetype */
    472503
     
    508539          return 1;
    509540
    510         return 0; 
     541        return 0;
    511542}
    512543/*****************************************************************************
     
    639670 *
    640671 * NOTES
    641  *  hack to load the resources from the shell32.dll under a different dll name 
     672 *  hack to load the resources from the shell32.dll under a different dll name
    642673 *  will be removed when the resource-compiler is ready
    643674 */
     
    651682        if (sic_hdpa)   /* already initialized?*/
    652683          return TRUE;
    653          
     684       
    654685        sic_hdpa = pDPA_Create(16);
    655686       
     
    700731          for (i=0; i < pDPA_GetPtrCount(sic_hdpa); ++i)
    701732          {
    702             lpsice = pDPA_GetPtr(sic_hdpa, i); 
     733            lpsice = pDPA_GetPtr(sic_hdpa, i);
    703734            SHFree(lpsice);
    704735          }
     
    776807 *
    777808 * PARAMETERS
    778  *      sh      [IN]            pointer to an instance of IShellFolder 
     809 *      sh      [IN]            pointer to an instance of IShellFolder
    779810 *      pidl    [IN]
    780811 *      pIndex  [OUT][OPTIONAL] SIC index for big icon
     
    801832 *
    802833 */
    803 INT WINAPI Shell_GetCachedImageIndexA(LPCSTR szPath, INT nIndex, BOOL bSimulateDoc) 
     834INT WINAPI Shell_GetCachedImageIndexA(LPCSTR szPath, INT nIndex, BOOL bSimulateDoc)
    804835{
    805836        WARN("(%s,%08x,%08x) semi-stub.\n",debugstr_a(szPath), nIndex, bSimulateDoc);
     
    807838}
    808839
    809 INT WINAPI Shell_GetCachedImageIndexW(LPCWSTR szPath, INT nIndex, BOOL bSimulateDoc) 
     840INT WINAPI Shell_GetCachedImageIndexW(LPCWSTR szPath, INT nIndex, BOOL bSimulateDoc)
    810841{       INT ret;
    811842        LPSTR sTemp = HEAP_strdupWtoA (GetProcessHeap(),0,szPath);
     
    835866 * ExtractIconExA                       [shell32.190]
    836867 * RETURNS
    837  *  0 no icon found 
     868 *  0 no icon found
    838869 *  1 file is not valid
    839870 *  HICON handle of a icon (phiconLarge/Small == NULL)
     
    846877        if (nIconIndex==-1)     /* Number of icons requested */
    847878          return ICO_ExtractIconEx(lpszFile, NULL, -1, 0, 0, 0  );
    848          
     879       
    849880       
    850881        if (phiconLarge)
    851882        { ret = ICO_ExtractIconEx(lpszFile, phiconLarge, nIconIndex, nIcons, 32, 32  );
    852883          if ( nIcons==1)
    853           { ret = phiconLarge[0];          
     884          { ret = phiconLarge[0];       
    854885          }
    855886        }
Note: See TracChangeset for help on using the changeset viewer.