ReactOS 0.4.16-dev-334-g4d9f67c
directory.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for directory.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOL WINAPI CopyProfileDirectoryA (LPCSTR lpSourcePath, LPCSTR lpDestinationPath, DWORD dwFlags)
 
BOOL WINAPI CopyProfileDirectoryW (LPCWSTR lpSourcePath, LPCWSTR lpDestinationPath, DWORD dwFlags)
 
BOOL CopyDirectory (LPCWSTR lpDestinationPath, LPCWSTR lpSourcePath)
 
BOOL CreateDirectoryPath (LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
 
static BOOL RecursiveRemoveDir (LPCWSTR lpPath)
 
BOOL RemoveDirectoryPath (LPCWSTR lpPathName)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 29 of file directory.c.

Function Documentation

◆ CopyDirectory()

BOOL CopyDirectory ( LPCWSTR  lpDestinationPath,
LPCWSTR  lpSourcePath 
)

Definition at line 82 of file directory.c.

84{
85 WCHAR szFileName[MAX_PATH];
86 WCHAR szFullSrcName[MAX_PATH];
87 WCHAR szFullDstName[MAX_PATH];
88 WIN32_FIND_DATAW FindFileData;
89 LPWSTR lpSrcPtr;
90 LPWSTR lpDstPtr;
91 HANDLE hFind;
92
93 DPRINT("CopyDirectory (%S, %S) called\n",
94 lpDestinationPath, lpSourcePath);
95
96 wcscpy(szFileName, lpSourcePath);
97 wcscat(szFileName, L"\\*.*");
98
99 hFind = FindFirstFileW(szFileName,
100 &FindFileData);
101 if (hFind == INVALID_HANDLE_VALUE)
102 {
103 DPRINT1("Error: %lu\n", GetLastError());
104 return FALSE;
105 }
106
107 wcscpy(szFullSrcName, lpSourcePath);
108 lpSrcPtr = AppendBackslash(szFullSrcName);
109
110 wcscpy(szFullDstName, lpDestinationPath);
111 lpDstPtr = AppendBackslash(szFullDstName);
112
113 for (;;)
114 {
115 if (wcscmp(FindFileData.cFileName, L".") &&
116 wcscmp(FindFileData.cFileName, L".."))
117 {
118 wcscpy(lpSrcPtr, FindFileData.cFileName);
119 wcscpy(lpDstPtr, FindFileData.cFileName);
120
121 if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
122 {
123 DPRINT("Create directory: %S\n", szFullDstName);
124 if (!CreateDirectoryExW(szFullSrcName, szFullDstName, NULL))
125 {
127 {
128 DPRINT1("Error: %lu\n", GetLastError());
129
130 FindClose(hFind);
131 return FALSE;
132 }
133 }
134
135 if (!CopyDirectory(szFullDstName, szFullSrcName))
136 {
137 DPRINT1("Error: %lu\n", GetLastError());
138
139 FindClose(hFind);
140 return FALSE;
141 }
142 }
143 else
144 {
145 DPRINT("Copy file: %S -> %S\n", szFullSrcName, szFullDstName);
146 if (!CopyFileW(szFullSrcName, szFullDstName, FALSE))
147 {
148 DPRINT1("Error: %lu\n", GetLastError());
149
150 FindClose(hFind);
151 return FALSE;
152 }
153 }
154 }
155
156 if (!FindNextFileW(hFind, &FindFileData))
157 {
159 {
160 DPRINT1("Error: %lu\n", GetLastError());
161 }
162
163 break;
164 }
165 }
166
167 FindClose(hFind);
168
169 DPRINT("CopyDirectory() done\n");
170
171 return TRUE;
172}
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI CopyFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copy.c:439
BOOL WINAPI CreateDirectoryExW(IN LPCWSTR lpTemplateDirectory, IN LPCWSTR lpNewDirectory, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:193
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
BOOL CopyDirectory(LPCWSTR lpDestinationPath, LPCWSTR lpSourcePath)
Definition: directory.c:82
LPWSTR AppendBackslash(LPWSTR String)
Definition: misc.c:40
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define DPRINT
Definition: sndvol32.h:73
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_NO_MORE_FILES
Definition: winerror.h:121
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by CopyDirectory(), CopyProfileDirectoryW(), CopySystemProfile(), and CreateUserProfileExW().

◆ CopyProfileDirectoryA()

BOOL WINAPI CopyProfileDirectoryA ( LPCSTR  lpSourcePath,
LPCSTR  lpDestinationPath,
DWORD  dwFlags 
)

Definition at line 36 of file directory.c.

39{
40 UNICODE_STRING SrcPath;
42 BOOL bResult;
43
45 (LPSTR)lpSourcePath))
46 {
48 return FALSE;
49 }
50
52 (LPSTR)lpDestinationPath))
53 {
54 RtlFreeUnicodeString(&SrcPath);
56 return FALSE;
57 }
58
59 bResult = CopyProfileDirectoryW(SrcPath.Buffer,
60 DstPath.Buffer,
61 dwFlags);
62
64 RtlFreeUnicodeString(&SrcPath);
65
66 return bResult;
67}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define SetLastError(x)
Definition: compat.h:752
BOOL WINAPI CopyProfileDirectoryW(LPCWSTR lpSourcePath, LPCWSTR lpDestinationPath, DWORD dwFlags)
Definition: directory.c:72
unsigned int BOOL
Definition: ntddk_ex.h:94
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeStringFromAsciiz(_Out_ PUNICODE_STRING Destination, _In_ PCSZ Source)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
IN HANDLE DstPath
Definition: fsutil.h:81
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
char * LPSTR
Definition: xmlstorage.h:182

◆ CopyProfileDirectoryW()

BOOL WINAPI CopyProfileDirectoryW ( LPCWSTR  lpSourcePath,
LPCWSTR  lpDestinationPath,
DWORD  dwFlags 
)

Definition at line 72 of file directory.c.

75{
76 /* FIXME: dwFlags are ignored! */
77 return CopyDirectory(lpDestinationPath, lpSourcePath);
78}

Referenced by CopyProfileDirectoryA().

◆ CreateDirectoryPath()

BOOL CreateDirectoryPath ( LPCWSTR  lpPathName,
LPSECURITY_ATTRIBUTES  lpSecurityAttributes 
)

Definition at line 176 of file directory.c.

178{
180 LPWSTR Ptr;
181 DWORD dwError;
182
183 DPRINT("CreateDirectoryPath() called\n");
184
185 if (lpPathName == NULL || *lpPathName == 0)
186 return TRUE;
187
188 if (CreateDirectoryW(lpPathName,
189 lpSecurityAttributes))
190 return TRUE;
191
192 dwError = GetLastError();
193 if (dwError == ERROR_ALREADY_EXISTS)
194 return TRUE;
195
196 wcscpy(szPath, lpPathName);
197
198 if (wcslen(szPath) > 3 && szPath[1] == ':' && szPath[2] == '\\')
199 {
200 Ptr = &szPath[3];
201 }
202 else
203 {
204 Ptr = szPath;
205 }
206
207 while (Ptr != NULL)
208 {
209 Ptr = wcschr(Ptr, L'\\');
210 if (Ptr != NULL)
211 *Ptr = 0;
212
213 DPRINT("CreateDirectory(%S)\n", szPath);
215 lpSecurityAttributes))
216 {
217 dwError = GetLastError();
218 if (dwError != ERROR_ALREADY_EXISTS)
219 return FALSE;
220 }
221
222 if (Ptr != NULL)
223 {
224 *Ptr = L'\\';
225 Ptr++;
226 }
227 }
228
229 DPRINT("CreateDirectoryPath() done\n");
230
231 return TRUE;
232}
#define wcschr
Definition: compat.h:17
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
LPCWSTR szPath
Definition: env.c:37

Referenced by AddDesktopItemW(), and CreateGroupW().

◆ RecursiveRemoveDir()

static BOOL RecursiveRemoveDir ( LPCWSTR  lpPath)
static

Definition at line 237 of file directory.c.

238{
240 WIN32_FIND_DATAW FindData;
241 HANDLE hFind;
242 BOOL bResult;
243
244 wcscpy(szPath, lpPath);
245 wcscat(szPath, L"\\*.*");
246 DPRINT("Search path: '%S'\n", szPath);
247
248 hFind = FindFirstFileW(szPath,
249 &FindData);
250 if (hFind == INVALID_HANDLE_VALUE)
251 return FALSE;
252
253 bResult = TRUE;
254 while (TRUE)
255 {
256 if (wcscmp(FindData.cFileName, L".") &&
257 wcscmp(FindData.cFileName, L".."))
258 {
259 wcscpy(szPath, lpPath);
260 wcscat(szPath, L"\\");
261 wcscat(szPath, FindData.cFileName);
262 DPRINT("File name: '%S'\n", szPath);
263
264 if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
265 {
266 DPRINT("Delete directory: '%S'\n", szPath);
267
269 {
270 bResult = FALSE;
271 break;
272 }
273
274 if (FindData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
275 {
277 FindData.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY);
278 }
279
281 {
282 bResult = FALSE;
283 break;
284 }
285 }
286 else
287 {
288 DPRINT("Delete file: '%S'\n", szPath);
289
290 if (FindData.dwFileAttributes & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM))
291 {
294 }
295
296 if (!DeleteFileW(szPath))
297 {
298 bResult = FALSE;
299 break;
300 }
301 }
302 }
303
304 if (!FindNextFileW(hFind, &FindData))
305 {
307 {
308 DPRINT1("Error: %lu\n", GetLastError());
309 bResult = FALSE;
310 break;
311 }
312
313 break;
314 }
315 }
316
317 FindClose(hFind);
318
319 return bResult;
320}
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:794
static BOOL RecursiveRemoveDir(LPCWSTR lpPath)
Definition: directory.c:237
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704

Referenced by RecursiveRemoveDir(), and RemoveDirectoryPath().

◆ RemoveDirectoryPath()

BOOL RemoveDirectoryPath ( LPCWSTR  lpPathName)

Definition at line 324 of file directory.c.

325{
326 if (!RecursiveRemoveDir(lpPathName))
327 return FALSE;
328
329 DPRINT("Delete directory: '%S'\n", lpPathName);
330 return RemoveDirectoryW(lpPathName);
331}

Referenced by DeleteGroupW(), and DeleteProfileW().