ReactOS 0.4.15-dev-8413-gc1c91f2
dirid.c File Reference
#include "setupapi_private.h"
Include dependency graph for dirid.c:

Go to the source code of this file.

Classes

struct  user_dirid
 

Macros

#define MAX_SYSTEM_DIRID   DIRID_PRINTPROCESSOR
 
#define MIN_CSIDL_DIRID   0x4000
 
#define MAX_CSIDL_DIRID   0x403f
 

Functions

static const WCHARget_unknown_dirid (void)
 
static const WCHARget_csidl_dir (DWORD csidl)
 
static const WCHARcreate_system_dirid (int dirid)
 
const WCHARDIRID_get_string (int dirid)
 
static BOOL store_user_dirid (HINF hinf, int id, WCHAR *str)
 
BOOL WINAPI SetupSetDirectoryIdA (HINF hinf, DWORD id, PCSTR dir)
 
BOOL WINAPI SetupSetDirectoryIdW (HINF hinf, DWORD id, PCWSTR dir)
 

Variables

static int nb_user_dirids
 
static int alloc_user_dirids
 
static struct user_diriduser_dirids
 
static const WCHARsystem_dirids [MAX_SYSTEM_DIRID+1]
 
static const WCHARcsidl_dirids [MAX_CSIDL_DIRID-MIN_CSIDL_DIRID+1]
 

Macro Definition Documentation

◆ MAX_CSIDL_DIRID

#define MAX_CSIDL_DIRID   0x403f

Definition at line 25 of file dirid.c.

◆ MAX_SYSTEM_DIRID

#define MAX_SYSTEM_DIRID   DIRID_PRINTPROCESSOR

Definition at line 23 of file dirid.c.

◆ MIN_CSIDL_DIRID

#define MIN_CSIDL_DIRID   0x4000

Definition at line 24 of file dirid.c.

Function Documentation

◆ create_system_dirid()

static const WCHAR * create_system_dirid ( int  dirid)
static

Definition at line 58 of file dirid.c.

59{
60 static const WCHAR Null[] = {0};
61 static const WCHAR C_Root[] = {'C',':','\\',0};
62 static const WCHAR Drivers[] = {'\\','d','r','i','v','e','r','s',0};
63 static const WCHAR Inf[] = {'\\','i','n','f',0};
64 static const WCHAR Help[] = {'\\','h','e','l','p',0};
65 static const WCHAR Fonts[] = {'\\','f','o','n','t','s',0};
66 static const WCHAR Viewers[] = {'\\','v','i','e','w','e','r','s',0};
67 static const WCHAR System[] = {'\\','s','y','s','t','e','m',0};
68 static const WCHAR Spool[] = {'\\','s','p','o','o','l',0};
69 static const WCHAR UserProfile[] = {'U','S','E','R','P','R','O','F','I','L','E',0};
70
72 int len;
73 DWORD needed;
74
75 switch(dirid)
76 {
77 case DIRID_NULL:
78 return Null;
79 case DIRID_WINDOWS:
81 break;
82 case DIRID_SYSTEM:
84 break;
85 case DIRID_DRIVERS:
87 strcatW( buffer, Drivers );
88 break;
89 case DIRID_INF:
91 strcatW( buffer, Inf );
92 break;
93 case DIRID_HELP:
96 break;
97 case DIRID_FONTS:
99 strcatW( buffer, Fonts );
100 break;
101 case DIRID_VIEWERS:
103 strcatW( buffer, Viewers );
104 break;
105 case DIRID_APPS:
106 return C_Root; /* FIXME */
107 case DIRID_SHARED:
109 break;
110 case DIRID_BOOT:
111 return C_Root; /* FIXME */
112 case DIRID_SYSTEM16:
114 strcatW( buffer, System );
115 break;
116 case DIRID_SPOOL:
117 case DIRID_SPOOLDRIVERS: /* FIXME */
119 strcatW( buffer, Spool );
120 break;
122 if (GetEnvironmentVariableW( UserProfile, buffer, MAX_PATH )) break;
124 case DIRID_LOADER:
125 return C_Root; /* FIXME */
127 if (!GetPrintProcessorDirectoryW(NULL, NULL, 1, (LPBYTE)buffer, sizeof(buffer), &needed))
128 {
129 WARN( "cannot retrieve print processor directory\n" );
130 return get_unknown_dirid();
131 }
132 break;
133 case DIRID_COLOR: /* FIXME */
134 default:
135 FIXME( "unknown dirid %d\n", dirid );
136 return get_unknown_dirid();
137 }
138 len = (strlenW(buffer) + 1) * sizeof(WCHAR);
139 if ((str = HeapAlloc( GetProcessHeap(), 0, len ))) memcpy( str, buffer, len );
140 return str;
141}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
static const WCHAR * get_unknown_dirid(void)
Definition: dirid.c:40
static const WCHAR * get_csidl_dir(DWORD csidl)
Definition: dirid.c:143
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:755
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2352
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
GLenum GLsizei len
Definition: glext.h:6722
PCHAR Help
Definition: kdb_cli.c:344
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
@ System
Definition: scrrun.idl:72
#define strlenW(s)
Definition: unicode.h:34
#define strcatW(d, s)
Definition: unicode.h:36
const WCHAR * str
#define DIRID_SPOOL
Definition: setupapi.h:199
#define DIRID_SYSTEM16
Definition: setupapi.h:198
#define DIRID_COLOR
Definition: setupapi.h:194
#define DIRID_SYSTEM
Definition: setupapi.h:188
#define DIRID_USERPROFILE
Definition: setupapi.h:201
#define DIRID_SHARED
Definition: setupapi.h:196
#define DIRID_NULL
Definition: setupapi.h:185
#define DIRID_HELP
Definition: setupapi.h:191
#define DIRID_WINDOWS
Definition: setupapi.h:187
#define DIRID_SPOOLDRIVERS
Definition: setupapi.h:200
#define DIRID_LOADER
Definition: setupapi.h:202
#define DIRID_INF
Definition: setupapi.h:190
#define DIRID_APPS
Definition: setupapi.h:195
#define DIRID_FONTS
Definition: setupapi.h:192
#define DIRID_PRINTPROCESSOR
Definition: setupapi.h:203
#define DIRID_VIEWERS
Definition: setupapi.h:193
#define DIRID_BOOT
Definition: setupapi.h:197
#define DIRID_DRIVERS
Definition: setupapi.h:189
#define CSIDL_PROFILE
Definition: shlobj.h:2211
unsigned char * LPBYTE
Definition: typedefs.h:53
WINBOOL WINAPI GetPrintProcessorDirectoryW(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by DIRID_get_string().

◆ DIRID_get_string()

const WCHAR * DIRID_get_string ( int  dirid)

Definition at line 159 of file dirid.c.

160{
161 int i;
162
163 if (dirid == DIRID_ABSOLUTE || dirid == DIRID_ABSOLUTE_16BIT) dirid = DIRID_NULL;
164
165 if (dirid >= DIRID_USER)
166 {
167 for (i = 0; i < nb_user_dirids; i++)
168 if (user_dirids[i].id == dirid) return user_dirids[i].str;
169 WARN("user id %d not found\n", dirid );
170 return NULL;
171 }
172 else if (dirid >= MIN_CSIDL_DIRID)
173 {
174 if (dirid > MAX_CSIDL_DIRID) return get_unknown_dirid();
175 dirid -= MIN_CSIDL_DIRID;
176 if (!csidl_dirids[dirid]) csidl_dirids[dirid] = get_csidl_dir( dirid );
177 return csidl_dirids[dirid];
178 }
179 else
180 {
181 if (dirid > MAX_SYSTEM_DIRID) return get_unknown_dirid();
182 if (!system_dirids[dirid]) system_dirids[dirid] = create_system_dirid( dirid );
183 return system_dirids[dirid];
184 }
185}
static const WCHAR * create_system_dirid(int dirid)
Definition: dirid.c:58
static struct user_dirid * user_dirids
Definition: dirid.c:35
#define MAX_CSIDL_DIRID
Definition: dirid.c:25
static const WCHAR * csidl_dirids[MAX_CSIDL_DIRID-MIN_CSIDL_DIRID+1]
Definition: dirid.c:37
static int nb_user_dirids
Definition: dirid.c:33
#define MIN_CSIDL_DIRID
Definition: dirid.c:24
static const WCHAR * system_dirids[MAX_SYSTEM_DIRID+1]
Definition: dirid.c:36
#define MAX_SYSTEM_DIRID
Definition: dirid.c:23
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
#define DIRID_USER
Definition: setupapi.h:217
#define DIRID_ABSOLUTE
Definition: setupapi.h:184
#define DIRID_ABSOLUTE_16BIT
Definition: setupapi.h:218

Referenced by Concatenate(), and get_dirid_subst().

◆ get_csidl_dir()

static const WCHAR * get_csidl_dir ( DWORD  csidl)
static

Definition at line 143 of file dirid.c.

144{
146 int len;
147
148 if (!SHGetSpecialFolderPathW( NULL, buffer, csidl, TRUE ))
149 {
150 FIXME( "CSIDL %x not found\n", csidl );
151 return get_unknown_dirid();
152 }
153 len = (strlenW(buffer) + 1) * sizeof(WCHAR);
154 if ((str = HeapAlloc( GetProcessHeap(), 0, len ))) memcpy( str, buffer, len );
155 return str;
156}
#define TRUE
Definition: types.h:120
BOOL WINAPI SHGetSpecialFolderPathW(HWND hwndOwner, LPWSTR szPath, int nFolder, BOOL bCreate)
Definition: shellpath.c:3092

Referenced by create_system_dirid(), and DIRID_get_string().

◆ get_unknown_dirid()

static const WCHAR * get_unknown_dirid ( void  )
static

Definition at line 40 of file dirid.c.

41{
42 static WCHAR *unknown_dirid;
43 static const WCHAR unknown_str[] = {'\\','u','n','k','n','o','w','n',0};
44
45 if (!unknown_dirid)
46 {
47 UINT len = GetSystemDirectoryW( NULL, 0 ) + strlenW(unknown_str);
48 if (!(unknown_dirid = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return NULL;
49 GetSystemDirectoryW( unknown_dirid, len );
50 strcatW( unknown_dirid, unknown_str );
51 }
52 return unknown_dirid;
53}
unsigned int UINT
Definition: ndis.h:50

Referenced by create_system_dirid(), DIRID_get_string(), and get_csidl_dir().

◆ SetupSetDirectoryIdA()

BOOL WINAPI SetupSetDirectoryIdA ( HINF  hinf,
DWORD  id,
PCSTR  dir 
)

Definition at line 226 of file dirid.c.

227{
228 UNICODE_STRING dirW;
229 int i;
230
231 if (!id) /* clear everything */
232 {
233 for (i = 0; i < nb_user_dirids; i++) HeapFree( GetProcessHeap(), 0, user_dirids[i].str );
234 nb_user_dirids = 0;
235 return TRUE;
236 }
237 if (id < DIRID_USER)
238 {
240 return FALSE;
241 }
242
243 /* duplicate the string */
245 {
247 return FALSE;
248 }
249 return store_user_dirid( hinf, id, dirW.Buffer );
250}
unsigned int dir
Definition: maze.c:112
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
static BOOL store_user_dirid(HINF hinf, int id, WCHAR *str)
Definition: dirid.c:188
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define HeapFree(x, y, z)
Definition: compat.h:735
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeStringFromAsciiz(_Out_ PUNICODE_STRING Destination, _In_ PCSZ Source)

◆ SetupSetDirectoryIdW()

BOOL WINAPI SetupSetDirectoryIdW ( HINF  hinf,
DWORD  id,
PCWSTR  dir 
)

Definition at line 256 of file dirid.c.

257{
258 int i, len;
259 WCHAR *str;
260
261 if (!id) /* clear everything */
262 {
263 for (i = 0; i < nb_user_dirids; i++) HeapFree( GetProcessHeap(), 0, user_dirids[i].str );
264 nb_user_dirids = 0;
265 return TRUE;
266 }
267 if (id < DIRID_USER)
268 {
270 return FALSE;
271 }
272
273 /* duplicate the string */
274 len = (strlenW(dir)+1) * sizeof(WCHAR);
275 if (!(str = HeapAlloc( GetProcessHeap(), 0, len ))) return FALSE;
276 memcpy( str, dir, len );
277 return store_user_dirid( hinf, id, str );
278}

Referenced by set_ldids().

◆ store_user_dirid()

static BOOL store_user_dirid ( HINF  hinf,
int  id,
WCHAR str 
)
static

Definition at line 188 of file dirid.c.

189{
190 int i;
191
192 for (i = 0; i < nb_user_dirids; i++) if (user_dirids[i].id == id) break;
193
195 else
196 {
198 {
199 int new_size = max( 32, alloc_user_dirids * 2 );
200
201 struct user_dirid *new;
202
203 if (user_dirids)
205 new_size * sizeof(*new) );
206 else
207 new = HeapAlloc( GetProcessHeap(), 0,
208 new_size * sizeof(*new) );
209
210 if (!new) return FALSE;
211 user_dirids = new;
212 alloc_user_dirids = new_size;
213 }
215 }
216 user_dirids[i].id = id;
217 user_dirids[i].str = str;
218 TRACE("id %d -> %s\n", id, debugstr_w(str) );
219 return TRUE;
220}
static int alloc_user_dirids
Definition: dirid.c:34
#define HeapReAlloc
Definition: compat.h:734
GLuint id
Definition: glext.h:5910
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
#define max(a, b)
Definition: svc.c:63

Referenced by SetupSetDirectoryIdA(), and SetupSetDirectoryIdW().

Variable Documentation

◆ alloc_user_dirids

int alloc_user_dirids
static

Definition at line 34 of file dirid.c.

Referenced by store_user_dirid().

◆ csidl_dirids

const WCHAR* csidl_dirids[MAX_CSIDL_DIRID-MIN_CSIDL_DIRID+1]
static

Definition at line 37 of file dirid.c.

Referenced by DIRID_get_string().

◆ nb_user_dirids

int nb_user_dirids
static

◆ system_dirids

const WCHAR* system_dirids[MAX_SYSTEM_DIRID+1]
static

Definition at line 36 of file dirid.c.

Referenced by DIRID_get_string().

◆ user_dirids

struct user_dirid* user_dirids
static