3 * Copyright (C) 2004 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS system libraries
22 * FILE: dll/win32/userenv/directory.c
23 * PURPOSE: User profile code
24 * PROGRAMMER: Eric Kohl
32 /* FUNCTIONS ***************************************************************/
36 CopyProfileDirectoryA(LPCSTR lpSourcePath
,
37 LPCSTR lpDestinationPath
,
40 UNICODE_STRING SrcPath
;
41 UNICODE_STRING DstPath
;
44 if (!RtlCreateUnicodeStringFromAsciiz(&SrcPath
,
47 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
51 if (!RtlCreateUnicodeStringFromAsciiz(&DstPath
,
52 (LPSTR
)lpDestinationPath
))
54 RtlFreeUnicodeString(&SrcPath
);
55 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
59 bResult
= CopyProfileDirectoryW(SrcPath
.Buffer
,
63 RtlFreeUnicodeString(&DstPath
);
64 RtlFreeUnicodeString(&SrcPath
);
72 CopyProfileDirectoryW(LPCWSTR lpSourcePath
,
73 LPCWSTR lpDestinationPath
,
76 /* FIXME: dwFlags are ignored! */
77 return CopyDirectory(lpDestinationPath
, lpSourcePath
);
82 CopyDirectory(LPCWSTR lpDestinationPath
,
85 WCHAR szFileName
[MAX_PATH
];
86 WCHAR szFullSrcName
[MAX_PATH
];
87 WCHAR szFullDstName
[MAX_PATH
];
88 WIN32_FIND_DATAW FindFileData
;
93 DPRINT("CopyDirectory (%S, %S) called\n",
94 lpDestinationPath
, lpSourcePath
);
96 wcscpy(szFileName
, lpSourcePath
);
97 wcscat(szFileName
, L
"\\*.*");
99 hFind
= FindFirstFileW(szFileName
,
101 if (hFind
== INVALID_HANDLE_VALUE
)
103 DPRINT1("Error: %lu\n", GetLastError());
107 wcscpy(szFullSrcName
, lpSourcePath
);
108 lpSrcPtr
= AppendBackslash(szFullSrcName
);
110 wcscpy(szFullDstName
, lpDestinationPath
);
111 lpDstPtr
= AppendBackslash(szFullDstName
);
115 if (wcscmp(FindFileData
.cFileName
, L
".") &&
116 wcscmp(FindFileData
.cFileName
, L
".."))
118 wcscpy(lpSrcPtr
, FindFileData
.cFileName
);
119 wcscpy(lpDstPtr
, FindFileData
.cFileName
);
121 if (FindFileData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
123 DPRINT("Create directory: %S\n", szFullDstName
);
124 if (!CreateDirectoryExW(szFullSrcName
, szFullDstName
, NULL
))
126 if (GetLastError() != ERROR_ALREADY_EXISTS
)
128 DPRINT1("Error: %lu\n", GetLastError());
135 if (!CopyDirectory(szFullDstName
, szFullSrcName
))
137 DPRINT1("Error: %lu\n", GetLastError());
145 DPRINT("Copy file: %S -> %S\n", szFullSrcName
, szFullDstName
);
146 if (!CopyFileW(szFullSrcName
, szFullDstName
, FALSE
))
148 DPRINT1("Error: %lu\n", GetLastError());
156 if (!FindNextFileW(hFind
, &FindFileData
))
158 if (GetLastError() != ERROR_NO_MORE_FILES
)
160 DPRINT1("Error: %lu\n", GetLastError());
169 DPRINT("CopyDirectory() done\n");
176 CreateDirectoryPath(LPCWSTR lpPathName
,
177 LPSECURITY_ATTRIBUTES lpSecurityAttributes
)
179 WCHAR szPath
[MAX_PATH
];
183 DPRINT("CreateDirectoryPath() called\n");
185 if (lpPathName
== NULL
|| *lpPathName
== 0)
188 if (CreateDirectoryW(lpPathName
,
189 lpSecurityAttributes
))
192 dwError
= GetLastError();
193 if (dwError
== ERROR_ALREADY_EXISTS
)
196 wcscpy(szPath
, lpPathName
);
198 if (wcslen(szPath
) > 3 && szPath
[1] == ':' && szPath
[2] == '\\')
209 Ptr
= wcschr(Ptr
, L
'\\');
213 DPRINT("CreateDirectory(%S)\n", szPath
);
214 if (!CreateDirectoryW(szPath
,
215 lpSecurityAttributes
))
217 dwError
= GetLastError();
218 if (dwError
!= ERROR_ALREADY_EXISTS
)
229 DPRINT("CreateDirectoryPath() done\n");
237 RecursiveRemoveDir(LPCWSTR lpPath
)
239 WCHAR szPath
[MAX_PATH
];
240 WIN32_FIND_DATAW FindData
;
244 wcscpy(szPath
, lpPath
);
245 wcscat(szPath
, L
"\\*.*");
246 DPRINT("Search path: '%S'\n", szPath
);
248 hFind
= FindFirstFileW(szPath
,
250 if (hFind
== INVALID_HANDLE_VALUE
)
256 if (wcscmp(FindData
.cFileName
, L
".") &&
257 wcscmp(FindData
.cFileName
, L
".."))
259 wcscpy(szPath
, lpPath
);
260 wcscat(szPath
, L
"\\");
261 wcscat(szPath
, FindData
.cFileName
);
262 DPRINT("File name: '%S'\n", szPath
);
264 if (FindData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
266 DPRINT("Delete directory: '%S'\n", szPath
);
268 if (!RecursiveRemoveDir(szPath
))
274 if (FindData
.dwFileAttributes
& FILE_ATTRIBUTE_READONLY
)
276 SetFileAttributesW(szPath
,
277 FindData
.dwFileAttributes
& ~FILE_ATTRIBUTE_READONLY
);
280 if (!RemoveDirectoryW(szPath
))
288 DPRINT("Delete file: '%S'\n", szPath
);
290 if (FindData
.dwFileAttributes
& (FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_SYSTEM
))
292 SetFileAttributesW(szPath
,
293 FILE_ATTRIBUTE_NORMAL
);
296 if (!DeleteFileW(szPath
))
304 if (!FindNextFileW(hFind
, &FindData
))
306 if (GetLastError() != ERROR_NO_MORE_FILES
)
308 DPRINT1("Error: %lu\n", GetLastError());
324 RemoveDirectoryPath(LPCWSTR lpPathName
)
326 if (!RecursiveRemoveDir(lpPathName
))
329 DPRINT("Delete directory: '%S'\n", lpPathName
);
330 return RemoveDirectoryW(lpPathName
);