2004-09-30 20:23:00 +00:00
|
|
|
/*
|
|
|
|
* ReactOS kernel
|
|
|
|
* Copyright (C) 2004 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-09-30 20:23:00 +00:00
|
|
|
*/
|
2013-03-16 20:41:13 +00:00
|
|
|
/*
|
2004-01-15 14:59:06 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
2013-10-24 20:16:20 +00:00
|
|
|
* FILE: dll/win32/userenv/directory.c
|
2004-01-15 14:59:06 +00:00
|
|
|
* PURPOSE: User profile code
|
|
|
|
* PROGRAMMER: Eric Kohl
|
|
|
|
*/
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include "precomp.h"
|
2004-01-15 14:59:06 +00:00
|
|
|
|
2006-01-11 22:40:31 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2004-01-15 14:59:06 +00:00
|
|
|
/* FUNCTIONS ***************************************************************/
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2004-12-28 13:30:18 +00:00
|
|
|
CopyProfileDirectoryA(LPCSTR lpSourcePath,
|
2012-12-08 22:11:41 +00:00
|
|
|
LPCSTR lpDestinationPath,
|
|
|
|
DWORD dwFlags)
|
2004-12-28 13:30:18 +00:00
|
|
|
{
|
2012-12-08 22:11:41 +00:00
|
|
|
UNICODE_STRING SrcPath;
|
|
|
|
UNICODE_STRING DstPath;
|
|
|
|
BOOL bResult;
|
|
|
|
|
2013-09-10 21:26:37 +00:00
|
|
|
if (!RtlCreateUnicodeStringFromAsciiz(&SrcPath,
|
|
|
|
(LPSTR)lpSourcePath))
|
2004-12-28 13:30:18 +00:00
|
|
|
{
|
2013-09-10 21:26:37 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2012-12-08 22:11:41 +00:00
|
|
|
return FALSE;
|
2004-12-28 13:30:18 +00:00
|
|
|
}
|
|
|
|
|
2013-09-10 21:26:37 +00:00
|
|
|
if (!RtlCreateUnicodeStringFromAsciiz(&DstPath,
|
|
|
|
(LPSTR)lpDestinationPath))
|
2004-12-28 13:30:18 +00:00
|
|
|
{
|
2012-12-08 22:11:41 +00:00
|
|
|
RtlFreeUnicodeString(&SrcPath);
|
2013-09-10 21:26:37 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2012-12-08 22:11:41 +00:00
|
|
|
return FALSE;
|
2004-12-28 13:30:18 +00:00
|
|
|
}
|
|
|
|
|
2012-12-08 22:11:41 +00:00
|
|
|
bResult = CopyProfileDirectoryW(SrcPath.Buffer,
|
|
|
|
DstPath.Buffer,
|
|
|
|
dwFlags);
|
2004-12-28 13:30:18 +00:00
|
|
|
|
2012-12-08 22:11:41 +00:00
|
|
|
RtlFreeUnicodeString(&DstPath);
|
|
|
|
RtlFreeUnicodeString(&SrcPath);
|
2004-12-28 13:30:18 +00:00
|
|
|
|
2012-12-08 22:11:41 +00:00
|
|
|
return bResult;
|
2004-12-28 13:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2004-12-28 13:30:18 +00:00
|
|
|
CopyProfileDirectoryW(LPCWSTR lpSourcePath,
|
2012-12-08 22:11:41 +00:00
|
|
|
LPCWSTR lpDestinationPath,
|
|
|
|
DWORD dwFlags)
|
2004-12-28 13:30:18 +00:00
|
|
|
{
|
2012-12-08 22:11:41 +00:00
|
|
|
/* FIXME: dwFlags are ignored! */
|
|
|
|
return CopyDirectory(lpDestinationPath, lpSourcePath);
|
2004-12-28 13:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-15 14:59:06 +00:00
|
|
|
BOOL
|
2013-10-24 20:16:20 +00:00
|
|
|
CopyDirectory(LPCWSTR lpDestinationPath,
|
|
|
|
LPCWSTR lpSourcePath)
|
2004-01-15 14:59:06 +00:00
|
|
|
{
|
2012-12-08 22:11:41 +00:00
|
|
|
WCHAR szFileName[MAX_PATH];
|
|
|
|
WCHAR szFullSrcName[MAX_PATH];
|
|
|
|
WCHAR szFullDstName[MAX_PATH];
|
|
|
|
WIN32_FIND_DATAW FindFileData;
|
|
|
|
LPWSTR lpSrcPtr;
|
|
|
|
LPWSTR lpDstPtr;
|
|
|
|
HANDLE hFind;
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT("CopyDirectory (%S, %S) called\n",
|
2012-12-08 22:11:41 +00:00
|
|
|
lpDestinationPath, lpSourcePath);
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
wcscpy(szFileName, lpSourcePath);
|
|
|
|
wcscat(szFileName, L"\\*.*");
|
2012-12-08 22:11:41 +00:00
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
hFind = FindFirstFileW(szFileName,
|
|
|
|
&FindFileData);
|
2012-12-08 22:11:41 +00:00
|
|
|
if (hFind == INVALID_HANDLE_VALUE)
|
2004-01-16 15:31:53 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
2012-12-08 22:11:41 +00:00
|
|
|
return FALSE;
|
2004-01-16 15:31:53 +00:00
|
|
|
}
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
wcscpy(szFullSrcName, lpSourcePath);
|
|
|
|
lpSrcPtr = AppendBackslash(szFullSrcName);
|
2004-01-16 15:31:53 +00:00
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
wcscpy(szFullDstName, lpDestinationPath);
|
|
|
|
lpDstPtr = AppendBackslash(szFullDstName);
|
2004-01-16 15:31:53 +00:00
|
|
|
|
2012-12-08 22:11:41 +00:00
|
|
|
for (;;)
|
2004-01-16 15:31:53 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
if (wcscmp(FindFileData.cFileName, L".") &&
|
|
|
|
wcscmp(FindFileData.cFileName, L".."))
|
2012-12-08 22:11:41 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
wcscpy(lpSrcPtr, FindFileData.cFileName);
|
|
|
|
wcscpy(lpDstPtr, FindFileData.cFileName);
|
2012-12-08 22:11:41 +00:00
|
|
|
|
|
|
|
if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT("Create directory: %S\n", szFullDstName);
|
|
|
|
if (!CreateDirectoryExW(szFullSrcName, szFullDstName, NULL))
|
2012-12-08 22:11:41 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
if (GetLastError() != ERROR_ALREADY_EXISTS)
|
2012-12-08 22:11:41 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
2012-12-08 22:11:41 +00:00
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
FindClose(hFind);
|
2012-12-08 22:11:41 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
if (!CopyDirectory(szFullDstName, szFullSrcName))
|
2012-12-08 22:11:41 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
2012-12-08 22:11:41 +00:00
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
FindClose(hFind);
|
2012-12-08 22:11:41 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT("Copy file: %S -> %S\n", szFullSrcName, szFullDstName);
|
|
|
|
if (!CopyFileW(szFullSrcName, szFullDstName, FALSE))
|
2012-12-08 22:11:41 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
2012-12-08 22:11:41 +00:00
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
FindClose(hFind);
|
2012-12-08 22:11:41 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
if (!FindNextFileW(hFind, &FindFileData))
|
2012-12-08 22:11:41 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
if (GetLastError() != ERROR_NO_MORE_FILES)
|
2012-12-08 22:11:41 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
2012-12-08 22:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2004-01-16 15:31:53 +00:00
|
|
|
}
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
FindClose(hFind);
|
2004-01-16 15:31:53 +00:00
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT("CopyDirectory() done\n");
|
2004-01-16 15:31:53 +00:00
|
|
|
|
2012-12-08 22:11:41 +00:00
|
|
|
return TRUE;
|
2004-01-15 14:59:06 +00:00
|
|
|
}
|
|
|
|
|
2004-05-07 11:18:53 +00:00
|
|
|
|
|
|
|
BOOL
|
2013-10-24 20:16:20 +00:00
|
|
|
CreateDirectoryPath(LPCWSTR lpPathName,
|
|
|
|
LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
2004-05-07 11:18:53 +00:00
|
|
|
{
|
2012-12-08 22:11:41 +00:00
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
LPWSTR Ptr;
|
|
|
|
DWORD dwError;
|
2004-05-07 11:18:53 +00:00
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT("CreateDirectoryPath() called\n");
|
2004-05-07 11:18:53 +00:00
|
|
|
|
2012-12-08 22:11:41 +00:00
|
|
|
if (lpPathName == NULL || *lpPathName == 0)
|
|
|
|
return TRUE;
|
2004-05-07 11:18:53 +00:00
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
if (CreateDirectoryW(lpPathName,
|
|
|
|
lpSecurityAttributes))
|
2012-12-08 22:11:41 +00:00
|
|
|
return TRUE;
|
2004-05-07 11:18:53 +00:00
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
dwError = GetLastError();
|
2012-12-08 22:11:41 +00:00
|
|
|
if (dwError == ERROR_ALREADY_EXISTS)
|
|
|
|
return TRUE;
|
2004-05-07 11:18:53 +00:00
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
wcscpy(szPath, lpPathName);
|
2004-05-07 11:18:53 +00:00
|
|
|
|
2012-12-08 22:11:41 +00:00
|
|
|
if (wcslen(szPath) > 3 && szPath[1] == ':' && szPath[2] == '\\')
|
2004-05-07 11:18:53 +00:00
|
|
|
{
|
2012-12-08 22:11:41 +00:00
|
|
|
Ptr = &szPath[3];
|
2004-05-07 11:18:53 +00:00
|
|
|
}
|
2012-12-08 22:11:41 +00:00
|
|
|
else
|
2004-05-07 11:18:53 +00:00
|
|
|
{
|
2012-12-08 22:11:41 +00:00
|
|
|
Ptr = szPath;
|
2004-05-07 11:18:53 +00:00
|
|
|
}
|
|
|
|
|
2012-12-08 22:11:41 +00:00
|
|
|
while (Ptr != NULL)
|
2004-05-07 11:18:53 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
Ptr = wcschr(Ptr, L'\\');
|
2012-12-08 22:11:41 +00:00
|
|
|
if (Ptr != NULL)
|
|
|
|
*Ptr = 0;
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT("CreateDirectory(%S)\n", szPath);
|
|
|
|
if (!CreateDirectoryW(szPath,
|
|
|
|
lpSecurityAttributes))
|
2012-12-08 22:11:41 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
dwError = GetLastError();
|
2012-12-08 22:11:41 +00:00
|
|
|
if (dwError != ERROR_ALREADY_EXISTS)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Ptr != NULL)
|
|
|
|
{
|
|
|
|
*Ptr = L'\\';
|
|
|
|
Ptr++;
|
|
|
|
}
|
2004-05-07 11:18:53 +00:00
|
|
|
}
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT("CreateDirectoryPath() done\n");
|
2004-05-07 11:18:53 +00:00
|
|
|
|
2012-12-08 22:11:41 +00:00
|
|
|
return TRUE;
|
2004-05-07 11:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
static
|
|
|
|
BOOL
|
|
|
|
RecursiveRemoveDir(LPCWSTR lpPath)
|
2004-05-08 13:11:07 +00:00
|
|
|
{
|
2012-12-08 22:11:41 +00:00
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
WIN32_FIND_DATAW FindData;
|
|
|
|
HANDLE hFind;
|
|
|
|
BOOL bResult;
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
wcscpy(szPath, lpPath);
|
|
|
|
wcscat(szPath, L"\\*.*");
|
|
|
|
DPRINT("Search path: '%S'\n", szPath);
|
2012-12-08 22:11:41 +00:00
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
hFind = FindFirstFileW(szPath,
|
|
|
|
&FindData);
|
2012-12-08 22:11:41 +00:00
|
|
|
if (hFind == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
bResult = TRUE;
|
|
|
|
while (TRUE)
|
2004-05-08 13:11:07 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
if (wcscmp(FindData.cFileName, L".") &&
|
|
|
|
wcscmp(FindData.cFileName, L".."))
|
2012-12-08 22:11:41 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
wcscpy(szPath, lpPath);
|
|
|
|
wcscat(szPath, L"\\");
|
|
|
|
wcscat(szPath, FindData.cFileName);
|
|
|
|
DPRINT("File name: '%S'\n", szPath);
|
2012-12-08 22:11:41 +00:00
|
|
|
|
|
|
|
if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT("Delete directory: '%S'\n", szPath);
|
2012-12-08 22:11:41 +00:00
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
if (!RecursiveRemoveDir(szPath))
|
2012-12-08 22:11:41 +00:00
|
|
|
{
|
|
|
|
bResult = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FindData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
|
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
SetFileAttributesW(szPath,
|
|
|
|
FindData.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY);
|
2012-12-08 22:11:41 +00:00
|
|
|
}
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
if (!RemoveDirectoryW(szPath))
|
2012-12-08 22:11:41 +00:00
|
|
|
{
|
|
|
|
bResult = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT("Delete file: '%S'\n", szPath);
|
2012-12-08 22:11:41 +00:00
|
|
|
|
|
|
|
if (FindData.dwFileAttributes & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM))
|
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
SetFileAttributesW(szPath,
|
|
|
|
FILE_ATTRIBUTE_NORMAL);
|
2012-12-08 22:11:41 +00:00
|
|
|
}
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
if (!DeleteFileW(szPath))
|
2012-12-08 22:11:41 +00:00
|
|
|
{
|
|
|
|
bResult = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
if (!FindNextFileW(hFind, &FindData))
|
2012-12-08 22:11:41 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
if (GetLastError() != ERROR_NO_MORE_FILES)
|
2012-12-08 22:11:41 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
2012-12-08 22:11:41 +00:00
|
|
|
bResult = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2004-05-08 13:11:07 +00:00
|
|
|
}
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
FindClose(hFind);
|
2004-05-08 13:11:07 +00:00
|
|
|
|
2012-12-08 22:11:41 +00:00
|
|
|
return bResult;
|
2004-05-08 13:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-07 11:18:53 +00:00
|
|
|
BOOL
|
2013-10-24 20:16:20 +00:00
|
|
|
RemoveDirectoryPath(LPCWSTR lpPathName)
|
2004-05-07 11:18:53 +00:00
|
|
|
{
|
2013-10-24 20:16:20 +00:00
|
|
|
if (!RecursiveRemoveDir(lpPathName))
|
2012-12-08 22:11:41 +00:00
|
|
|
return FALSE;
|
2004-05-08 13:11:07 +00:00
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
DPRINT("Delete directory: '%S'\n", lpPathName);
|
|
|
|
return RemoveDirectoryW(lpPathName);
|
2004-05-07 11:18:53 +00:00
|
|
|
}
|
|
|
|
|
2004-01-15 14:59:06 +00:00
|
|
|
/* EOF */
|