ReactOS 0.4.15-dev-7958-gcd0bb1a
PrivateExtractIcons.c File Reference
#include "precomp.h"
#include <stdio.h>
Include dependency graph for PrivateExtractIcons.c:

Go to the source code of this file.

Functions

BOOL FileExists (PCWSTR FileName)
 
BOOL ResourceToFile (INT i, PCWSTR FileName)
 
 START_TEST (PrivateExtractIcons)
 

Variables

struct {
   PCWSTR   FilePath
 
   UINT   cIcons
 
   UINT   cTotalIcons
 
   BOOL   bhIconValid
 
IconTests []
 
struct {
   PCWSTR   FileName
 
   INT   ResourceId
 
IconFiles []
 

Function Documentation

◆ FileExists()

BOOL FileExists ( PCWSTR  FileName)

Definition at line 12 of file PrivateExtractIcons.c.

13{
15
16 return (Attribute != INVALID_FILE_ATTRIBUTES &&
17 !(Attribute & FILE_ATTRIBUTE_DIRECTORY));
18}
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23

Referenced by ResourceToFile().

◆ ResourceToFile()

BOOL ResourceToFile ( INT  i,
PCWSTR  FileName 
)

Definition at line 20 of file PrivateExtractIcons.c.

21{
22 FILE *fout;
23 HGLOBAL hData;
24 HRSRC hRes;
25 PVOID pResLock;
26 UINT iSize;
27
29 {
30 /* We should only be using %temp% paths, so deleting here should be OK */
31 printf("Deleting '%S' that already exists.\n", FileName);
33 }
34
36 if (hRes == NULL)
37 {
38 skip("Could not locate resource (%d). Exiting now\n", i);
39 return FALSE;
40 }
41
42 iSize = SizeofResource(NULL, hRes);
43
44 hData = LoadResource(NULL, hRes);
45 if (hData == NULL)
46 {
47 skip("Could not load resource (%d). Exiting now\n", i);
48 return FALSE;
49 }
50
51 // Lock the resource into global memory.
52 pResLock = LockResource(hData);
53 if (pResLock == NULL)
54 {
55 skip("Could not lock resource (%d). Exiting now\n", i);
56 return FALSE;
57 }
58
59 fout = _wfopen(FileName, L"wb");
60 fwrite(pResLock, iSize, 1, fout);
61 fclose(fout);
62 return TRUE;
63}
BOOL FileExists(PCWSTR FileName)
#define skip(...)
Definition: atltest.h:64
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
#define printf
Definition: freeldr.h:97
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define RT_RCDATA
Definition: pedump.c:372
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( PrivateExtractIcons  )

Definition at line 113 of file PrivateExtractIcons.c.

114{
115 HICON ahIcon;
116 UINT i, aIconId, cIcons, cIcoTotal;
117 WCHAR PathBuffer[MAX_PATH];
118
119 /* Extract icons */
120 for (i = 0; i < _countof(IconFiles); ++i)
121 {
122 ExpandEnvironmentStringsW(IconFiles[i].FileName, PathBuffer, _countof(PathBuffer));
123
124 if (!ResourceToFile(IconFiles[i].ResourceId, PathBuffer))
125 goto Cleanup;
126 }
127
128 for (i = 0; i < _countof(IconTests); ++i)
129 {
130 /* Get total number of icon groups in file.
131 * None of the hard numbers in the function matter since we have
132 * two NULLs for the Icon Handle and Count to be set. */
133 cIcoTotal = PrivateExtractIconsW(IconTests[i].FilePath, 0, 16, 16, NULL, NULL, 0, 0);
134 ok((i == 3 ?
135 cIcoTotal > 232 && cIcoTotal < 240 : /* shell32 case: ROS has 233, W2K2SP2 has 239 icon groups. */
136 cIcoTotal == IconTests[i].cTotalIcons),
137 "PrivateExtractIconsW(%u): "
138 "got %u, expected %u\n", i, cIcoTotal, IconTests[i].cTotalIcons);
139
140 /* Always test extraction of the FIRST icon (index 0) */
141 ahIcon = (HICON)UlongToHandle(0xdeadbeef);
142 aIconId = 0xdeadbeef;
143 cIcons = PrivateExtractIconsW(IconTests[i].FilePath, 0, 16, 16, &ahIcon, &aIconId, 1, 0);
144 ok(cIcons == IconTests[i].cIcons, "PrivateExtractIconsW(%u): got %u, expected %u\n", i, cIcons, IconTests[i].cIcons);
145 ok(ahIcon != (HICON)UlongToHandle(0xdeadbeef), "PrivateExtractIconsW(%u): icon not set\n", i);
146 ok((IconTests[i].bhIconValid && ahIcon) || (!IconTests[i].bhIconValid && !ahIcon),
147 "PrivateExtractIconsW(%u): icon expected to be %s, but got 0x%p\n",
148 i, IconTests[i].bhIconValid ? "valid" : "not valid", ahIcon);
149 if (cIcons == 0xFFFFFFFF)
150 {
151 ok(aIconId == 0xdeadbeef,
152 "PrivateExtractIconsW(%u): id should not be set to 0x%x\n",
153 i, aIconId);
154 }
155 else
156 {
157 ok(aIconId != 0xdeadbeef, "PrivateExtractIconsW(%u): id not set\n", i);
158 }
159 if (ahIcon && ahIcon != (HICON)UlongToHandle(0xdeadbeef))
160 DestroyIcon(ahIcon);
161 }
162
163Cleanup:
164 for (i = 0; i < _countof(IconFiles); ++i)
165 {
166 ExpandEnvironmentStringsW(IconFiles[i].FileName, PathBuffer, _countof(PathBuffer));
167 DeleteFileW(PathBuffer);
168 }
169}
BOOL bhIconValid
static struct @1601 IconFiles[]
UINT cTotalIcons
INT ResourceId
PCWSTR FilePath
BOOL ResourceToFile(INT i, PCWSTR FileName)
static struct @1600 IconTests[]
UINT cIcons
#define ok(value,...)
Definition: atltest.h:57
#define UlongToHandle(ul)
Definition: basetsd.h:97
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
static const WCHAR Cleanup[]
Definition: register.c:80
static HICON
Definition: imagelist.c:84
#define _countof(array)
Definition: sndvol32.h:68
UINT WINAPI PrivateExtractIconsW(_In_reads_(MAX_PATH) LPCWSTR szFileName, _In_ int nIconIndex, _In_ int cxIcon, _In_ int cyIcon, _Out_writes_opt_(nIcons) HICON *phicon, _Out_writes_opt_(nIcons) UINT *piconid, _In_ UINT nIcons, _In_ UINT flags)
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2053
__wchar_t WCHAR
Definition: xmlstorage.h:180

Variable Documentation

◆ bhIconValid

BOOL bhIconValid

Definition at line 70 of file PrivateExtractIcons.c.

Referenced by START_TEST().

◆ cIcons

UINT cIcons

Definition at line 68 of file PrivateExtractIcons.c.

Referenced by START_TEST(), and test_PrivateExtractIcons().

◆ cTotalIcons

UINT cTotalIcons

Definition at line 69 of file PrivateExtractIcons.c.

Referenced by START_TEST().

◆ FileName

Definition at line 104 of file PrivateExtractIcons.c.

◆ FilePath

◆ 

struct { ... } IconFiles[]
Initial value:
=
{
{L"%temp%\\ROS.ico", IDR_ICONS_PNG},
{L"%temp%\\sysicon.ico", IDR_ICONS_NORMAL},
{L"%temp%\\cpimg2e.exe", IDR_EXE_NORMAL}
}
#define IDR_ICONS_NORMAL
Definition: resource.h:5
#define IDR_ICONS_PNG
Definition: resource.h:4
#define IDR_EXE_NORMAL
Definition: resource.h:6

Referenced by START_TEST().

◆ 

struct { ... } IconTests[]
Initial value:
=
{
{L"notepad.exe", 1, 1, TRUE},
{L"%SystemRoot%\\System32\\cmd.exe", 1, 1, TRUE},
{L"%SystemRoot%\\System32\\autochk.exe", 0, 0, FALSE},
{L"%SystemRoot%\\System32\\shell32.dll", 1, 233, TRUE},
{L"%SystemRoot%\\non-existent-file.sdf", 0xFFFFFFFF, 0, FALSE},
{L"%SystemRoot%\\explorer.exe", 1, 18, TRUE},
{L"%temp%\\sysicon.ico", 1, 1, TRUE},
{L"%temp%\\ROS.ico", 1, 1, TRUE},
{L"%temp%\\cpimg2e.exe", 1, 1, TRUE},
}

Referenced by START_TEST().

◆ ResourceId