ReactOS 0.4.15-dev-6679-g945ee4b
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 skip("'%S' already exists. Exiting now\n", FileName);
31 return FALSE;
32 }
33
35 if (hRes == NULL)
36 {
37 skip("Could not locate resource (%d). Exiting now\n", i);
38 return FALSE;
39 }
40
41 iSize = SizeofResource(NULL, hRes);
42
43 hData = LoadResource(NULL, hRes);
44 if (hData == NULL)
45 {
46 skip("Could not load resource (%d). Exiting now\n", i);
47 return FALSE;
48 }
49
50 // Lock the resource into global memory.
51 pResLock = LockResource(hData);
52 if (pResLock == NULL)
53 {
54 skip("Could not lock resource (%d). Exiting now\n", i);
55 return FALSE;
56 }
57
58 fout = _wfopen(FileName, L"wb");
59 fwrite(pResLock, iSize, 1, fout);
60 fclose(fout);
61 return TRUE;
62}
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
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
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 105 of file PrivateExtractIcons.c.

106{
107 HICON ahIcon;
108 UINT i, aIconId, cIcons, cIcoTotal;
109 WCHAR PathBuffer[MAX_PATH];
110
111 /* Extract icons */
112 for (i = 0; i < _countof(IconFiles); ++i)
113 {
114 ExpandEnvironmentStringsW(IconFiles[i].FileName, PathBuffer, _countof(PathBuffer));
115
116 if (!ResourceToFile(IconFiles[i].ResourceId, PathBuffer))
117 goto Cleanup;
118 }
119
120 for (i = 0; i < _countof(IconTests); ++i)
121 {
122 /* Get total number of icon groups in file.
123 * None of the hard numbers in the function matter since we have
124 * two NULLs for the Icon Handle and Count to be set. */
125 cIcoTotal = PrivateExtractIconsW(IconTests[i].FilePath, 0, 16, 16, NULL, NULL, 0, 0);
126 ok((i == 3 ?
127 cIcoTotal > 232 && cIcoTotal < 240 : /* shell32 case: ROS has 233, W2K2SP2 has 239 icon groups. */
128 cIcoTotal == IconTests[i].cTotalIcons),
129 "PrivateExtractIconsW(%u): "
130 "got %u, expected %u\n", i, cIcoTotal, IconTests[i].cTotalIcons);
131
132 /* Always test extraction of the FIRST icon (index 0) */
133 ahIcon = (HICON)UlongToHandle(0xdeadbeef);
134 aIconId = 0xdeadbeef;
135 cIcons = PrivateExtractIconsW(IconTests[i].FilePath, 0, 16, 16, &ahIcon, &aIconId, 1, 0);
136 ok(cIcons == IconTests[i].cIcons, "PrivateExtractIconsW(%u): got %u, expected %u\n", i, cIcons, IconTests[i].cIcons);
137 ok(ahIcon != (HICON)UlongToHandle(0xdeadbeef), "PrivateExtractIconsW(%u): icon not set\n", i);
138 ok((IconTests[i].bhIconValid && ahIcon) || (!IconTests[i].bhIconValid && !ahIcon),
139 "PrivateExtractIconsW(%u): icon expected to be %s, but got 0x%p\n",
140 i, IconTests[i].bhIconValid ? "valid" : "not valid", ahIcon);
141 if (cIcons == 0xFFFFFFFF)
142 {
143 ok(aIconId == 0xdeadbeef,
144 "PrivateExtractIconsW(%u): id should not be set to 0x%x\n",
145 i, aIconId);
146 }
147 else
148 {
149 ok(aIconId != 0xdeadbeef, "PrivateExtractIconsW(%u): id not set\n", i);
150 }
151 if (ahIcon && ahIcon != (HICON)UlongToHandle(0xdeadbeef))
152 DestroyIcon(ahIcon);
153 }
154
155Cleanup:
156 for (i = 0; i < _countof(IconFiles); ++i)
157 {
158 ExpandEnvironmentStringsW(IconFiles[i].FileName, PathBuffer, _countof(PathBuffer));
159 DeleteFileW(PathBuffer);
160 }
161}
BOOL bhIconValid
UINT cTotalIcons
INT ResourceId
PCWSTR FilePath
BOOL ResourceToFile(INT i, PCWSTR FileName)
static struct @1580 IconFiles[]
UINT cIcons
static struct @1579 IconTests[]
#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
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
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:2022
__wchar_t WCHAR
Definition: xmlstorage.h:180

Variable Documentation

◆ bhIconValid

BOOL bhIconValid

Definition at line 69 of file PrivateExtractIcons.c.

Referenced by START_TEST().

◆ cIcons

UINT cIcons

Definition at line 67 of file PrivateExtractIcons.c.

Referenced by START_TEST(), and test_PrivateExtractIcons().

◆ cTotalIcons

UINT cTotalIcons

Definition at line 68 of file PrivateExtractIcons.c.

Referenced by START_TEST().

◆ FileName

Definition at line 97 of file PrivateExtractIcons.c.

◆ FilePath

◆ 

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

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},
}

Referenced by START_TEST().

◆ ResourceId