[USERENV]

- Formatting, no code change

svn path=/trunk/; revision=57830
This commit is contained in:
Jérôme Gardou 2012-12-08 22:11:41 +00:00
parent 3a812eaed0
commit 2f7f2bfb3c

View file

@ -35,301 +35,301 @@
BOOL WINAPI BOOL WINAPI
CopyProfileDirectoryA(LPCSTR lpSourcePath, CopyProfileDirectoryA(LPCSTR lpSourcePath,
LPCSTR lpDestinationPath, LPCSTR lpDestinationPath,
DWORD dwFlags) DWORD dwFlags)
{ {
UNICODE_STRING SrcPath; UNICODE_STRING SrcPath;
UNICODE_STRING DstPath; UNICODE_STRING DstPath;
NTSTATUS Status; NTSTATUS Status;
BOOL bResult; BOOL bResult;
Status = RtlCreateUnicodeStringFromAsciiz(&SrcPath, Status = RtlCreateUnicodeStringFromAsciiz(&SrcPath,
(LPSTR)lpSourcePath); (LPSTR)lpSourcePath);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
SetLastError (RtlNtStatusToDosError (Status)); SetLastError (RtlNtStatusToDosError (Status));
return FALSE; return FALSE;
} }
Status = RtlCreateUnicodeStringFromAsciiz(&DstPath, Status = RtlCreateUnicodeStringFromAsciiz(&DstPath,
(LPSTR)lpDestinationPath); (LPSTR)lpDestinationPath);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
RtlFreeUnicodeString(&SrcPath); RtlFreeUnicodeString(&SrcPath);
SetLastError (RtlNtStatusToDosError (Status)); SetLastError (RtlNtStatusToDosError (Status));
return FALSE; return FALSE;
} }
bResult = CopyProfileDirectoryW(SrcPath.Buffer, bResult = CopyProfileDirectoryW(SrcPath.Buffer,
DstPath.Buffer, DstPath.Buffer,
dwFlags); dwFlags);
RtlFreeUnicodeString(&DstPath); RtlFreeUnicodeString(&DstPath);
RtlFreeUnicodeString(&SrcPath); RtlFreeUnicodeString(&SrcPath);
return bResult; return bResult;
} }
BOOL WINAPI BOOL WINAPI
CopyProfileDirectoryW(LPCWSTR lpSourcePath, CopyProfileDirectoryW(LPCWSTR lpSourcePath,
LPCWSTR lpDestinationPath, LPCWSTR lpDestinationPath,
DWORD dwFlags) DWORD dwFlags)
{ {
/* FIXME: dwFlags are ignored! */ /* FIXME: dwFlags are ignored! */
return CopyDirectory(lpDestinationPath, lpSourcePath); return CopyDirectory(lpDestinationPath, lpSourcePath);
} }
BOOL BOOL
CopyDirectory (LPCWSTR lpDestinationPath, CopyDirectory (LPCWSTR lpDestinationPath,
LPCWSTR lpSourcePath) LPCWSTR lpSourcePath)
{ {
WCHAR szFileName[MAX_PATH]; WCHAR szFileName[MAX_PATH];
WCHAR szFullSrcName[MAX_PATH]; WCHAR szFullSrcName[MAX_PATH];
WCHAR szFullDstName[MAX_PATH]; WCHAR szFullDstName[MAX_PATH];
WIN32_FIND_DATAW FindFileData; WIN32_FIND_DATAW FindFileData;
LPWSTR lpSrcPtr; LPWSTR lpSrcPtr;
LPWSTR lpDstPtr; LPWSTR lpDstPtr;
HANDLE hFind; HANDLE hFind;
DPRINT ("CopyDirectory (%S, %S) called\n", DPRINT ("CopyDirectory (%S, %S) called\n",
lpDestinationPath, lpSourcePath); lpDestinationPath, lpSourcePath);
wcscpy (szFileName, lpSourcePath); wcscpy (szFileName, lpSourcePath);
wcscat (szFileName, L"\\*.*"); wcscat (szFileName, L"\\*.*");
hFind = FindFirstFileW (szFileName, hFind = FindFirstFileW (szFileName,
&FindFileData); &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) if (hFind == INVALID_HANDLE_VALUE)
{ {
DPRINT1 ("Error: %lu\n", GetLastError()); DPRINT1 ("Error: %lu\n", GetLastError());
return FALSE; return FALSE;
} }
wcscpy (szFullSrcName, lpSourcePath); wcscpy (szFullSrcName, lpSourcePath);
lpSrcPtr = AppendBackslash (szFullSrcName); lpSrcPtr = AppendBackslash (szFullSrcName);
wcscpy (szFullDstName, lpDestinationPath); wcscpy (szFullDstName, lpDestinationPath);
lpDstPtr = AppendBackslash (szFullDstName); lpDstPtr = AppendBackslash (szFullDstName);
for (;;) for (;;)
{ {
if (wcscmp (FindFileData.cFileName, L".") && if (wcscmp (FindFileData.cFileName, L".") &&
wcscmp (FindFileData.cFileName, L"..")) wcscmp (FindFileData.cFileName, L".."))
{ {
wcscpy (lpSrcPtr, FindFileData.cFileName); wcscpy (lpSrcPtr, FindFileData.cFileName);
wcscpy (lpDstPtr, FindFileData.cFileName); wcscpy (lpDstPtr, FindFileData.cFileName);
if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{ {
DPRINT ("Create directory: %S\n", szFullDstName); DPRINT ("Create directory: %S\n", szFullDstName);
if (!CreateDirectoryExW (szFullSrcName, szFullDstName, NULL)) if (!CreateDirectoryExW (szFullSrcName, szFullDstName, NULL))
{ {
if (GetLastError () != ERROR_ALREADY_EXISTS) if (GetLastError () != ERROR_ALREADY_EXISTS)
{ {
DPRINT1 ("Error: %lu\n", GetLastError()); DPRINT1 ("Error: %lu\n", GetLastError());
FindClose (hFind); FindClose (hFind);
return FALSE; return FALSE;
} }
} }
if (!CopyDirectory (szFullDstName, szFullSrcName)) if (!CopyDirectory (szFullDstName, szFullSrcName))
{ {
DPRINT1 ("Error: %lu\n", GetLastError()); DPRINT1 ("Error: %lu\n", GetLastError());
FindClose (hFind); FindClose (hFind);
return FALSE; return FALSE;
} }
} }
else else
{ {
DPRINT ("Copy file: %S -> %S\n", szFullSrcName, szFullDstName); DPRINT ("Copy file: %S -> %S\n", szFullSrcName, szFullDstName);
if (!CopyFileW (szFullSrcName, szFullDstName, FALSE)) if (!CopyFileW (szFullSrcName, szFullDstName, FALSE))
{ {
DPRINT1 ("Error: %lu\n", GetLastError()); DPRINT1 ("Error: %lu\n", GetLastError());
FindClose (hFind); FindClose (hFind);
return FALSE; return FALSE;
} }
} }
} }
if (!FindNextFileW (hFind, &FindFileData)) if (!FindNextFileW (hFind, &FindFileData))
{ {
if (GetLastError () != ERROR_NO_MORE_FILES) if (GetLastError () != ERROR_NO_MORE_FILES)
{ {
DPRINT1 ("Error: %lu\n", GetLastError()); DPRINT1 ("Error: %lu\n", GetLastError());
} }
break; break;
} }
} }
FindClose (hFind); FindClose (hFind);
DPRINT ("CopyDirectory() done\n"); DPRINT ("CopyDirectory() done\n");
return TRUE; return TRUE;
} }
BOOL BOOL
CreateDirectoryPath (LPCWSTR lpPathName, CreateDirectoryPath (LPCWSTR lpPathName,
LPSECURITY_ATTRIBUTES lpSecurityAttributes) LPSECURITY_ATTRIBUTES lpSecurityAttributes)
{ {
WCHAR szPath[MAX_PATH]; WCHAR szPath[MAX_PATH];
LPWSTR Ptr; LPWSTR Ptr;
DWORD dwError; DWORD dwError;
DPRINT ("CreateDirectoryPath() called\n"); DPRINT ("CreateDirectoryPath() called\n");
if (lpPathName == NULL || *lpPathName == 0) if (lpPathName == NULL || *lpPathName == 0)
return TRUE; return TRUE;
if (CreateDirectoryW (lpPathName, if (CreateDirectoryW (lpPathName,
lpSecurityAttributes)) lpSecurityAttributes))
return TRUE; return TRUE;
dwError = GetLastError (); dwError = GetLastError ();
if (dwError == ERROR_ALREADY_EXISTS) if (dwError == ERROR_ALREADY_EXISTS)
return TRUE; return TRUE;
wcscpy (szPath, lpPathName); wcscpy (szPath, lpPathName);
if (wcslen(szPath) > 3 && szPath[1] == ':' && szPath[2] == '\\') if (wcslen(szPath) > 3 && szPath[1] == ':' && szPath[2] == '\\')
{ {
Ptr = &szPath[3]; Ptr = &szPath[3];
} }
else else
{ {
Ptr = szPath; Ptr = szPath;
} }
while (Ptr != NULL) while (Ptr != NULL)
{ {
Ptr = wcschr (Ptr, L'\\'); Ptr = wcschr (Ptr, L'\\');
if (Ptr != NULL) if (Ptr != NULL)
*Ptr = 0; *Ptr = 0;
DPRINT ("CreateDirectory(%S)\n", szPath); DPRINT ("CreateDirectory(%S)\n", szPath);
if (!CreateDirectoryW (szPath, if (!CreateDirectoryW (szPath,
lpSecurityAttributes)) lpSecurityAttributes))
{ {
dwError = GetLastError (); dwError = GetLastError ();
if (dwError != ERROR_ALREADY_EXISTS) if (dwError != ERROR_ALREADY_EXISTS)
return FALSE; return FALSE;
} }
if (Ptr != NULL) if (Ptr != NULL)
{ {
*Ptr = L'\\'; *Ptr = L'\\';
Ptr++; Ptr++;
} }
} }
DPRINT ("CreateDirectoryPath() done\n"); DPRINT ("CreateDirectoryPath() done\n");
return TRUE; return TRUE;
} }
static BOOL static BOOL
RecursiveRemoveDir (LPCWSTR lpPath) RecursiveRemoveDir (LPCWSTR lpPath)
{ {
WCHAR szPath[MAX_PATH]; WCHAR szPath[MAX_PATH];
WIN32_FIND_DATAW FindData; WIN32_FIND_DATAW FindData;
HANDLE hFind; HANDLE hFind;
BOOL bResult; BOOL bResult;
wcscpy (szPath, lpPath); wcscpy (szPath, lpPath);
wcscat (szPath, L"\\*.*"); wcscat (szPath, L"\\*.*");
DPRINT ("Search path: '%S'\n", szPath); DPRINT ("Search path: '%S'\n", szPath);
hFind = FindFirstFileW (szPath, hFind = FindFirstFileW (szPath,
&FindData); &FindData);
if (hFind == INVALID_HANDLE_VALUE) if (hFind == INVALID_HANDLE_VALUE)
return FALSE; return FALSE;
bResult = TRUE; bResult = TRUE;
while (TRUE) while (TRUE)
{ {
if (wcscmp (FindData.cFileName, L".") && if (wcscmp (FindData.cFileName, L".") &&
wcscmp (FindData.cFileName, L"..")) wcscmp (FindData.cFileName, L".."))
{ {
wcscpy (szPath, lpPath); wcscpy (szPath, lpPath);
wcscat (szPath, L"\\"); wcscat (szPath, L"\\");
wcscat (szPath, FindData.cFileName); wcscat (szPath, FindData.cFileName);
DPRINT ("File name: '%S'\n", szPath); DPRINT ("File name: '%S'\n", szPath);
if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{ {
DPRINT ("Delete directory: '%S'\n", szPath); DPRINT ("Delete directory: '%S'\n", szPath);
if (!RecursiveRemoveDir (szPath)) if (!RecursiveRemoveDir (szPath))
{ {
bResult = FALSE; bResult = FALSE;
break; break;
} }
if (FindData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) if (FindData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
{ {
SetFileAttributesW (szPath, SetFileAttributesW (szPath,
FindData.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY); FindData.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY);
} }
if (!RemoveDirectoryW (szPath)) if (!RemoveDirectoryW (szPath))
{ {
bResult = FALSE; bResult = FALSE;
break; break;
} }
} }
else else
{ {
DPRINT ("Delete file: '%S'\n", szPath); DPRINT ("Delete file: '%S'\n", szPath);
if (FindData.dwFileAttributes & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)) if (FindData.dwFileAttributes & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM))
{ {
SetFileAttributesW (szPath, SetFileAttributesW (szPath,
FILE_ATTRIBUTE_NORMAL); FILE_ATTRIBUTE_NORMAL);
} }
if (!DeleteFileW (szPath)) if (!DeleteFileW (szPath))
{ {
bResult = FALSE; bResult = FALSE;
break; break;
} }
} }
} }
if (!FindNextFileW (hFind, &FindData)) if (!FindNextFileW (hFind, &FindData))
{ {
if (GetLastError () != ERROR_NO_MORE_FILES) if (GetLastError () != ERROR_NO_MORE_FILES)
{ {
DPRINT1 ("Error: %lu\n", GetLastError()); DPRINT1 ("Error: %lu\n", GetLastError());
bResult = FALSE; bResult = FALSE;
break; break;
} }
break; break;
} }
} }
FindClose (hFind); FindClose (hFind);
return bResult; return bResult;
} }
BOOL BOOL
RemoveDirectoryPath (LPCWSTR lpPathName) RemoveDirectoryPath (LPCWSTR lpPathName)
{ {
if (!RecursiveRemoveDir (lpPathName)) if (!RecursiveRemoveDir (lpPathName))
return FALSE; return FALSE;
DPRINT ("Delete directory: '%S'\n", lpPathName); DPRINT ("Delete directory: '%S'\n", lpPathName);
return RemoveDirectoryW (lpPathName); return RemoveDirectoryW (lpPathName);
} }
/* EOF */ /* EOF */