diff --git a/reactos/lib/userenv/directory.c b/reactos/lib/userenv/directory.c index c02285a7459..26d981b7cd0 100644 --- a/reactos/lib/userenv/directory.c +++ b/reactos/lib/userenv/directory.c @@ -1,4 +1,4 @@ -/* $Id: directory.c,v 1.1 2004/01/15 14:59:06 ekohl Exp $ +/* $Id: directory.c,v 1.2 2004/01/16 15:31:53 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -11,8 +11,6 @@ #include #include -//#include - #include "internal.h" @@ -22,6 +20,99 @@ BOOL CopyDirectory (LPCWSTR lpDestinationPath, LPCWSTR lpSourcePath) { + WCHAR szFileName[MAX_PATH]; + WCHAR szFullSrcName[MAX_PATH]; + WCHAR szFullDstName[MAX_PATH]; + WIN32_FIND_DATAW FindFileData; + LPWSTR lpSrcPtr; + LPWSTR lpDstPtr; + HANDLE hFind; + + DPRINT ("CopyDirectory (%S, %S) called\n", + lpDestinationPath, lpSourcePath); + + wcscpy (szFileName, lpSourcePath); + wcscat (szFileName, L"\\*.*"); + + hFind = FindFirstFileW (szFileName, + &FindFileData); + if (hFind == INVALID_HANDLE_VALUE) + { + DPRINT1 ("Error: %lu\n", GetLastError()); + return FALSE; + } + + wcscpy (szFullSrcName, lpSourcePath); + lpSrcPtr = AppendBackslash (szFullSrcName); + + wcscpy (szFullDstName, lpDestinationPath); + lpDstPtr = AppendBackslash (szFullDstName); + + for (;;) + { + if (wcscmp (FindFileData.cFileName, L".") && + wcscmp (FindFileData.cFileName, L"..")) + { + wcscpy (lpSrcPtr, FindFileData.cFileName); + wcscpy (lpDstPtr, FindFileData.cFileName); + + if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { + DPRINT ("Create directory: %S\n", szFullDstName); + if (!CreateDirectoryW (szFullDstName, NULL)) + { + if (GetLastError () != ERROR_ALREADY_EXISTS) + { + DPRINT1 ("Error: %lu\n", GetLastError()); + + FindClose (hFind); + return FALSE; + } + } + + if (!CopyDirectory (szFullDstName, szFullSrcName)) + { + DPRINT1 ("Error: %lu\n", GetLastError()); + + FindClose (hFind); + return FALSE; + } + } + else + { + DPRINT1 ("Copy file: %S -> %S\n", szFullSrcName, szFullDstName); + if (!CopyFileW (szFullSrcName, szFullDstName, FALSE)) + { + DPRINT1 ("Error: %lu\n", GetLastError()); + + FindClose (hFind); + return FALSE; + } + } + + /* Copy file attributes */ + if (FindFileData.dwFileAttributes & ~FILE_ATTRIBUTE_DIRECTORY) + { + SetFileAttributesW (szFullDstName, + FindFileData.dwFileAttributes); + } + } + + if (!FindNextFileW (hFind, &FindFileData)) + { + if (GetLastError () != ERROR_NO_MORE_FILES) + { + DPRINT1 ("Error: %lu\n", GetLastError()); + } + + break; + } + } + + FindClose (hFind); + + DPRINT ("Copy Directory() done\n"); + return TRUE; } diff --git a/reactos/lib/userenv/internal.h b/reactos/lib/userenv/internal.h index a0506f54444..fe53f8990d2 100644 --- a/reactos/lib/userenv/internal.h +++ b/reactos/lib/userenv/internal.h @@ -1,4 +1,4 @@ -/* $Id: internal.h,v 1.3 2004/01/15 14:59:06 ekohl Exp $ +/* $Id: internal.h,v 1.4 2004/01/16 15:31:53 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -17,11 +17,31 @@ DebugPrint (char* fmt,...); #define DPRINT1 DebugPrint("(%s:%d) ",__FILE__,__LINE__), DebugPrint #define CHECKPOINT1 do { DebugPrint("%s:%d\n",__FILE__,__LINE__); } while(0); +#ifdef __GNUC__ +#define DPRINT(args...) +#else +#define DPRINT +#endif /* __GNUC__ */ +#define CHECKPOINT + /* directory.h */ BOOL CopyDirectory (LPCWSTR lpDestinationPath, LPCWSTR lpSourcePath); +/* misc.h */ +LPWSTR +AppendBackslash (LPWSTR String); + +BOOL +AppendSystemPostfix (LPWSTR lpName, + DWORD dwMaxLength); + + +/* registry.h */ +BOOL +CreateUserHive (LPCWSTR lpKeyName); + #endif /* _INTERNAL_H */ /* EOF */ diff --git a/reactos/lib/userenv/makefile b/reactos/lib/userenv/makefile index a817441151b..0f3a083dd59 100644 --- a/reactos/lib/userenv/makefile +++ b/reactos/lib/userenv/makefile @@ -15,7 +15,7 @@ TARGET_LFLAGS = -nostdlib -nostartfiles TARGET_SDKLIBS = ntdll.a kernel32.a advapi32.a -TARGET_OBJECTS = directory.o profile.o setup.o userenv.o +TARGET_OBJECTS = directory.o profile.o misc.o registry.o setup.o userenv.o DEP_OBJECTS = $(TARGET_OBJECTS) diff --git a/reactos/lib/userenv/misc.c b/reactos/lib/userenv/misc.c new file mode 100644 index 00000000000..ca0861ea1ac --- /dev/null +++ b/reactos/lib/userenv/misc.c @@ -0,0 +1,35 @@ +/* $Id: misc.c,v 1.1 2004/01/16 15:31:53 ekohl Exp $ + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/userenv/misc.c + * PURPOSE: User profile code + * PROGRAMMER: Eric Kohl + */ + +#include +#include +#include + +#include "internal.h" + + +/* FUNCTIONS ***************************************************************/ + +LPWSTR +AppendBackslash (LPWSTR String) +{ + ULONG Length; + + Length = lstrlenW (String); + if (String[Length - 1] != L'\\') + { + String[Length] = L'\\'; + Length++; + String[Length] = (WCHAR)0; + } + + return &String[Length]; +} + +/* EOF */ diff --git a/reactos/lib/userenv/profile.c b/reactos/lib/userenv/profile.c index 16827899586..951ddc62003 100644 --- a/reactos/lib/userenv/profile.c +++ b/reactos/lib/userenv/profile.c @@ -1,4 +1,4 @@ -/* $Id: profile.c,v 1.2 2004/01/15 14:59:06 ekohl Exp $ +/* $Id: profile.c,v 1.3 2004/01/16 15:31:53 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -18,6 +18,63 @@ /* FUNCTIONS ***************************************************************/ +BOOL +AppendSystemPostfix (LPWSTR lpName, + DWORD dwMaxLength) +{ + WCHAR szSystemRoot[MAX_PATH]; + WCHAR szDrivePostfix[3]; + LPWSTR lpszPostfix; + LPWSTR lpszPtr; + DWORD dwPostfixLength; + + /* Build profile name postfix */ + if (!ExpandEnvironmentStringsW (L"%SystemRoot%", + szSystemRoot, + MAX_PATH)) + { + DPRINT1("Error: %lu\n", GetLastError()); + return FALSE; + } + + _wcsupr (szSystemRoot); + + /* Get name postfix */ + szSystemRoot[2] = L'.'; + lpszPostfix = &szSystemRoot[2]; + lpszPtr = lpszPostfix; + while (*lpszPtr != (WCHAR)0) + { + if (*lpszPtr == L'\\') + *lpszPtr = '_'; + lpszPtr++; + } + + dwPostfixLength = wcslen (lpszPostfix); + if (szSystemRoot[0] != L'C') + { + dwPostfixLength += 2; + szDrivePostfix[0] = L'_'; + szDrivePostfix[1] = szSystemRoot[0]; + szDrivePostfix[2] = (WCHAR)0; + } + + if (wcslen (lpName) + dwPostfixLength >= dwMaxLength) + { + DPRINT1("Error: buffer overflow\n"); + return FALSE; + } + + wcscat (lpName, lpszPostfix); + if (szSystemRoot[0] != L'C') + { + wcscat (lpName, szDrivePostfix); + } + + return TRUE; +} + + BOOL WINAPI CreateUserProfileW (PSID Sid, LPCWSTR lpUserName) @@ -87,6 +144,13 @@ CreateUserProfileW (PSID Sid, wcscpy (szUserProfilePath, szProfilesPath); wcscat (szUserProfilePath, L"\\"); wcscat (szUserProfilePath, lpUserName); + if (!AppendSystemPostfix (szUserProfilePath, MAX_PATH)) + { + DPRINT1("AppendSystemPostfix() failed\n", GetLastError()); + RtlFreeUnicodeString (&SidString); + RegCloseKey (hKey); + return FALSE; + } wcscpy (szDefaultUserPath, szProfilesPath); wcscat (szDefaultUserPath, L"\\"); @@ -121,9 +185,6 @@ CreateUserProfileW (PSID Sid, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\"); wcscat (szBuffer, SidString.Buffer); -// DebugPrint ("User SID: %wZ\n", &SidString); -// RtlFreeUnicodeString (&SidString); - /* Create user profile key */ if (RegCreateKeyExW (HKEY_LOCAL_MACHINE, szBuffer, @@ -144,6 +205,13 @@ CreateUserProfileW (PSID Sid, wcscpy (szBuffer, szRawProfilesPath); wcscat (szBuffer, L"\\"); wcscat (szBuffer, lpUserName); + if (!AppendSystemPostfix (szBuffer, MAX_PATH)) + { + DPRINT1("AppendSystemPostfix() failed\n", GetLastError()); + RtlFreeUnicodeString (&SidString); + RegCloseKey (hKey); + return FALSE; + } /* Set 'ProfileImagePath' value (non-expanded) */ if (RegSetValueExW (hKey, @@ -178,6 +246,7 @@ CreateUserProfileW (PSID Sid, /* Create user hive name */ wcscat (szUserProfilePath, L"\\ntuser.dat"); +#if 0 /* Create new user hive */ if (RegLoadKeyW (HKEY_USERS, SidString.Buffer, @@ -188,10 +257,17 @@ CreateUserProfileW (PSID Sid, return FALSE; } - /* FIXME: Copy default user hive */ + /* Create user hive */ + if (!CreateUserHive (SidString.Buffer)) + { + DPRINT1("Error: %lu\n", GetLastError()); + RtlFreeUnicodeString (&SidString); + return FALSE; + } RegUnLoadKeyW (HKEY_USERS, SidString.Buffer); +#endif RtlFreeUnicodeString (&SidString); diff --git a/reactos/lib/userenv/registry.c b/reactos/lib/userenv/registry.c new file mode 100644 index 00000000000..814d8bb2e91 --- /dev/null +++ b/reactos/lib/userenv/registry.c @@ -0,0 +1,26 @@ +/* $Id: registry.c,v 1.1 2004/01/16 15:31:53 ekohl Exp $ + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/userenv/registry.c + * PURPOSE: User profile code + * PROGRAMMER: Eric Kohl + */ + +#include +#include +#include + +#include "internal.h" + + +/* FUNCTIONS ***************************************************************/ + +BOOL +CreateUserHive (LPCWSTR lpKeyName) +{ + + return TRUE; +} + +/* EOF */ diff --git a/reactos/lib/userenv/setup.c b/reactos/lib/userenv/setup.c index 43fa1e917ac..bd72482574f 100644 --- a/reactos/lib/userenv/setup.c +++ b/reactos/lib/userenv/setup.c @@ -1,4 +1,4 @@ -/* $Id: setup.c,v 1.2 2004/01/13 12:34:09 ekohl Exp $ +/* $Id: setup.c,v 1.3 2004/01/16 15:31:53 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -56,23 +56,6 @@ AllUsersDirectories[] = }; -static LPWSTR -AppendBackslash(LPWSTR String) -{ - ULONG Length; - - Length = lstrlenW (String); - if (String[Length - 1] != L'\\') - { - String[Length] = L'\\'; - Length++; - String[Length] = (WCHAR)0; - } - - return &String[Length]; -} - - void DebugPrint(char* fmt,...) { @@ -92,9 +75,7 @@ InitializeProfiles (VOID) { WCHAR szProfilesPath[MAX_PATH]; WCHAR szProfilePath[MAX_PATH]; - WCHAR szSystemRoot[MAX_PATH]; WCHAR szBuffer[MAX_PATH]; - LPWSTR lpszPostfix; LPWSTR lpszPtr; DWORD dwLength; PDIRDATA lpDirData; @@ -146,32 +127,15 @@ InitializeProfiles (VOID) } } - /* Build profile name postfix */ - if (!ExpandEnvironmentStringsW (L"%SystemRoot%", - szSystemRoot, - MAX_PATH)) + /* Set 'DefaultUserProfile' value */ + wcscpy (szBuffer, L"Default User"); + if (!AppendSystemPostfix (szBuffer, MAX_PATH)) { - DPRINT1("Error: %lu\n", GetLastError()); + DPRINT1("AppendSystemPostfix() failed\n", GetLastError()); RegCloseKey (hKey); return FALSE; } - /* Get name postfix */ - szSystemRoot[2] = L'.'; - lpszPostfix = &szSystemRoot[2]; - lpszPtr = lpszPostfix; - while (*lpszPtr != (WCHAR)0) - { - if (*lpszPtr == L'\\') - *lpszPtr = '_'; - lpszPtr++; - } - _wcsupr (lpszPostfix); - - /* Set 'DefaultUserProfile' value */ - wcscpy (szBuffer, L"Default User"); - wcscat (szBuffer, lpszPostfix); - dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR); if (RegSetValueExW (hKey, L"DefaultUserProfile", @@ -231,7 +195,12 @@ InitializeProfiles (VOID) /* Set 'AllUsersProfile' value */ wcscpy (szBuffer, L"All Users"); - wcscat (szBuffer, lpszPostfix); + if (!AppendSystemPostfix (szBuffer, MAX_PATH)) + { + DPRINT1("AppendSystemPostfix() failed\n", GetLastError()); + RegCloseKey (hKey); + return FALSE; + } dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR); if (RegSetValueExW (hKey,