--- /dev/null
+/* $Id: profile.c,v 1.1 2004/01/13 12:34:09 ekohl Exp $
+ *
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS system libraries
+ * FILE: lib/userenv/profile.c
+ * PURPOSE: User profile code
+ * PROGRAMMER: Eric Kohl
+ */
+
+#include <windows.h>
+#include <string.h>
+
+#include <userenv.h>
+
+#include "internal.h"
+
+
+/* FUNCTIONS ***************************************************************/
+
+BOOL WINAPI
+CreateUserProfileW (PSID Sid,
+ LPCWSTR lpUserName)
+{
+ return TRUE;
+}
+
+
+BOOL WINAPI
+GetAllUsersProfileDirectoryW (LPWSTR lpProfileDir,
+ LPDWORD lpcchSize)
+{
+ WCHAR szProfilePath[MAX_PATH];
+ WCHAR szBuffer[MAX_PATH];
+ DWORD dwLength;
+ HKEY hKey;
+
+ if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
+ L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
+ 0,
+ KEY_READ,
+ &hKey))
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ return FALSE;
+ }
+
+ /* Get profiles path */
+ dwLength = MAX_PATH * sizeof(WCHAR);
+ if (RegQueryValueExW (hKey,
+ L"ProfilesDirectory",
+ NULL,
+ NULL,
+ (LPBYTE)szBuffer,
+ &dwLength))
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
+
+ /* Expand it */
+ if (!ExpandEnvironmentStringsW (szBuffer,
+ szProfilePath,
+ MAX_PATH))
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
+
+ /* Get 'AllUsersProfile' name */
+ dwLength = MAX_PATH * sizeof(WCHAR);
+ if (RegQueryValueExW (hKey,
+ L"AllUsersProfile",
+ NULL,
+ NULL,
+ (LPBYTE)szBuffer,
+ &dwLength))
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
+
+ RegCloseKey (hKey);
+
+ wcscat (szProfilePath, L"\\");
+ wcscat (szProfilePath, szBuffer);
+
+ dwLength = wcslen (szProfilePath);
+ if (lpProfileDir != NULL)
+ {
+ if (*lpcchSize < dwLength)
+ {
+ *lpcchSize = dwLength;
+ SetLastError (ERROR_INSUFFICIENT_BUFFER);
+ return FALSE;
+ }
+
+ wcscpy (lpProfileDir, szProfilePath);
+ }
+
+ *lpcchSize = dwLength;
+
+ return TRUE;
+}
+
+
+BOOL WINAPI
+GetDefaultUserProfileDirectoryW (LPWSTR lpProfileDir,
+ LPDWORD lpcchSize)
+{
+ WCHAR szProfilePath[MAX_PATH];
+ WCHAR szBuffer[MAX_PATH];
+ DWORD dwLength;
+ HKEY hKey;
+
+ if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
+ L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
+ 0,
+ KEY_READ,
+ &hKey))
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ return FALSE;
+ }
+
+ /* Get profiles path */
+ dwLength = MAX_PATH * sizeof(WCHAR);
+ if (RegQueryValueExW (hKey,
+ L"ProfilesDirectory",
+ NULL,
+ NULL,
+ (LPBYTE)szBuffer,
+ &dwLength))
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
+
+ /* Expand it */
+ if (!ExpandEnvironmentStringsW (szBuffer,
+ szProfilePath,
+ MAX_PATH))
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
+
+ /* Get 'DefaultUserProfile' name */
+ dwLength = MAX_PATH * sizeof(WCHAR);
+ if (RegQueryValueExW (hKey,
+ L"DefaultUserProfile",
+ NULL,
+ NULL,
+ (LPBYTE)szBuffer,
+ &dwLength))
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
+
+ RegCloseKey (hKey);
+
+ wcscat (szProfilePath, L"\\");
+ wcscat (szProfilePath, szBuffer);
+
+ dwLength = wcslen (szProfilePath);
+ if (lpProfileDir != NULL)
+ {
+ if (*lpcchSize < dwLength)
+ {
+ *lpcchSize = dwLength;
+ SetLastError (ERROR_INSUFFICIENT_BUFFER);
+ return FALSE;
+ }
+
+ wcscpy (lpProfileDir, szProfilePath);
+ }
+
+ *lpcchSize = dwLength;
+
+ return TRUE;
+}
+
+
+BOOL WINAPI
+GetProfilesDirectoryW (LPWSTR lpProfilesDir,
+ LPDWORD lpcchSize)
+{
+ WCHAR szProfilesPath[MAX_PATH];
+ WCHAR szBuffer[MAX_PATH];
+ DWORD dwLength;
+ HKEY hKey;
+
+ if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
+ L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
+ 0,
+ KEY_READ,
+ &hKey))
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ return FALSE;
+ }
+
+ dwLength = MAX_PATH * sizeof(WCHAR);
+ if (RegQueryValueExW (hKey,
+ L"ProfilesDirectory",
+ NULL,
+ NULL,
+ (LPBYTE)szBuffer,
+ &dwLength))
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
+
+ RegCloseKey (hKey);
+
+ if (!ExpandEnvironmentStringsW (szBuffer,
+ szProfilesPath,
+ MAX_PATH))
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ return FALSE;
+ }
+
+ dwLength = wcslen (szProfilesPath);
+ if (lpProfilesDir != NULL)
+ {
+ if (*lpcchSize < dwLength)
+ {
+ *lpcchSize = dwLength;
+ SetLastError (ERROR_INSUFFICIENT_BUFFER);
+ return FALSE;
+ }
+
+ wcscpy (lpProfilesDir, szProfilesPath);
+ }
+
+ *lpcchSize = dwLength;
+
+ return TRUE;
+}
+
+
+BOOL WINAPI
+GetUserProfileDirectoryW (HANDLE hToken,
+ LPWSTR lpProfileDir,
+ LPDWORD lpcchSize)
+{
+ /* FIXME */
+ return GetDefaultUserProfileDirectoryW (lpProfileDir, lpcchSize);
+}
+
+/* EOF */
-/* $Id: setup.c,v 1.1 2004/01/09 19:52:01 ekohl Exp $
+/* $Id: setup.c,v 1.2 2004/01/13 12:34:09 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
#include <windows.h>
#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
#include <userenv.h>
#include "internal.h"
-
typedef struct _DIRDATA
{
BOOL Hidden;
{TRUE, L"Recent"},
{FALSE, L"Start Menu"},
{FALSE, L"Start Menu\\Programs"},
+ {FALSE, L"Start Menu\\Programs\\Startup"},
{FALSE, NULL}
};
{FALSE, L"My Documents"},
{FALSE, L"Start Menu"},
{FALSE, L"Start Menu\\Programs"},
-
+ {FALSE, L"Start Menu\\Programs\\Startup"},
+ {FALSE, L"Start Menu\\Programs\\Administrative Tools"},
+ {TRUE, L"Templates"},
{FALSE, NULL}
};
}
+void
+DebugPrint(char* fmt,...)
+{
+ char buffer[512];
+ va_list ap;
+
+ va_start(ap, fmt);
+ vsprintf(buffer, fmt, ap);
+ va_end(ap);
+
+ OutputDebugStringA(buffer);
+}
+
+
BOOL WINAPI
InitializeProfiles (VOID)
{
- WCHAR SystemRoot[MAX_PATH];
- WCHAR Path[MAX_PATH];
- LPWSTR Postfix;
- LPWSTR Ptr;
- PDIRDATA DirData;
-
- /* Build profile name postfix */
- if (!ExpandEnvironmentStringsW (L"%SystemRoot%",
- SystemRoot,
- MAX_PATH))
- return FALSE;
+ WCHAR szProfilesPath[MAX_PATH];
+ WCHAR szProfilePath[MAX_PATH];
+ WCHAR szSystemRoot[MAX_PATH];
+ WCHAR szBuffer[MAX_PATH];
+ LPWSTR lpszPostfix;
+ LPWSTR lpszPtr;
+ DWORD dwLength;
+ PDIRDATA lpDirData;
+
+ HKEY hKey;
+
+ if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
+ L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
+ 0,
+ KEY_ALL_ACCESS,
+ &hKey))
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ return FALSE;
+ }
- SystemRoot[2] = L'.';
- Postfix = &SystemRoot[2];
- Ptr = Postfix;
- while (*Ptr != (WCHAR)0)
+ /* Get profiles path */
+ dwLength = MAX_PATH * sizeof(WCHAR);
+ if (RegQueryValueExW (hKey,
+ L"ProfilesDirectory",
+ NULL,
+ NULL,
+ (LPBYTE)szBuffer,
+ &dwLength))
{
- if (*Ptr == L'\\')
- *Ptr = '_';
- Ptr++;
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
}
- _wcsupr (Postfix);
- /* Create 'Documents and Settings' directory */
- if (!ExpandEnvironmentStringsW (L"%SystemDrive%\\Documents and Settings",
- Path,
+ /* Expand it */
+ if (!ExpandEnvironmentStringsW (szBuffer,
+ szProfilesPath,
MAX_PATH))
- return FALSE;
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
- if (!CreateDirectoryW (Path, NULL))
- return FALSE;
+ /* Create profiles directory */
+ if (!CreateDirectoryW (szProfilesPath, NULL))
+ {
+ if (GetLastError () != ERROR_ALREADY_EXISTS)
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
+ }
- /* Create 'Default User' directory */
- if (!ExpandEnvironmentStringsW (L"%SystemDrive%\\Documents and Settings\\Default User",
- Path,
+ /* Build profile name postfix */
+ if (!ExpandEnvironmentStringsW (L"%SystemRoot%",
+ szSystemRoot,
MAX_PATH))
- return FALSE;
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
- wcscat (Path, Postfix);
+ /* 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",
+ 0,
+ REG_SZ,
+ (LPBYTE)szBuffer,
+ dwLength))
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
- if (!CreateDirectoryW (Path, NULL))
- return FALSE;
+ /* Create 'Default User' profile directory */
+ wcscpy (szProfilePath, szProfilesPath);
+ wcscat (szProfilePath, L"\\");
+ wcscat (szProfilePath, szBuffer);
+ if (!CreateDirectoryW (szProfilePath, NULL))
+ {
+ if (GetLastError () != ERROR_ALREADY_EXISTS)
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
+ }
/* Set current user profile */
- SetEnvironmentVariableW (L"USERPROFILE", Path);
+ SetEnvironmentVariableW (L"USERPROFILE", szProfilePath);
- /* Create default user subdirectories */
- Ptr = AppendBackslash (Path);
- DirData = &DefaultUserDirectories[0];
- while (DirData->DirName != NULL)
+ /* Create 'Default User' subdirectories */
+ /* FIXME: Get these paths from the registry */
+ lpszPtr = AppendBackslash (szProfilePath);
+ lpDirData = &DefaultUserDirectories[0];
+ while (lpDirData->DirName != NULL)
{
- wcscpy (Ptr, DirData->DirName);
+ wcscpy (lpszPtr, lpDirData->DirName);
- if (!CreateDirectoryW (Path, NULL))
- return FALSE;
+ if (!CreateDirectoryW (szProfilePath, NULL))
+ {
+ if (GetLastError () != ERROR_ALREADY_EXISTS)
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
+ }
- if (DirData->Hidden == TRUE)
+ if (lpDirData->Hidden == TRUE)
{
- SetFileAttributesW (Path, FILE_ATTRIBUTE_HIDDEN);
+ SetFileAttributesW (szProfilePath,
+ FILE_ATTRIBUTE_HIDDEN);
}
- DirData++;
+ lpDirData++;
}
- /* Create 'All Users' directory */
- if (!ExpandEnvironmentStringsW (L"%SystemDrive%\\Documents and Settings\\All Users",
- Path,
- MAX_PATH))
- return FALSE;
+ /* Set 'AllUsersProfile' value */
+ wcscpy (szBuffer, L"All Users");
+ wcscat (szBuffer, lpszPostfix);
+
+ dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR);
+ if (RegSetValueExW (hKey,
+ L"AllUsersProfile",
+ 0,
+ REG_SZ,
+ (LPBYTE)szBuffer,
+ dwLength))
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
- wcscat (Path, Postfix);
+ /* Create 'All Users' profile directory */
+ wcscpy (szProfilePath, szProfilesPath);
+ wcscat (szProfilePath, L"\\");
+ wcscat (szProfilePath, szBuffer);
+ if (!CreateDirectoryW (szProfilePath, NULL))
+ {
+ if (GetLastError () != ERROR_ALREADY_EXISTS)
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
+ }
- if (!CreateDirectoryW (Path, NULL))
- return FALSE;
+ /* Set 'All Users' profile */
+ SetEnvironmentVariableW (L"ALLUSERSPROFILE", szProfilePath);
- /* Create all users subdirectories */
- Ptr = AppendBackslash (Path);
- DirData = &AllUsersDirectories[0];
- while (DirData->DirName != NULL)
+ /* Create 'All Users' subdirectories */
+ /* FIXME: Take these paths from the registry */
+ lpszPtr = AppendBackslash (szProfilePath);
+ lpDirData = &AllUsersDirectories[0];
+ while (lpDirData->DirName != NULL)
{
- wcscpy (Ptr, DirData->DirName);
+ wcscpy (lpszPtr, lpDirData->DirName);
- if (!CreateDirectoryW (Path, NULL))
- return FALSE;
+ if (!CreateDirectoryW (szProfilePath, NULL))
+ {
+ if (GetLastError () != ERROR_ALREADY_EXISTS)
+ {
+ DPRINT1("Error: %lu\n", GetLastError());
+ RegCloseKey (hKey);
+ return FALSE;
+ }
+ }
- if (DirData->Hidden == TRUE)
+ if (lpDirData->Hidden == TRUE)
{
- SetFileAttributesW (Path, FILE_ATTRIBUTE_HIDDEN);
+ SetFileAttributesW (szProfilePath,
+ FILE_ATTRIBUTE_HIDDEN);
}
- DirData++;
+ lpDirData++;
}
+ RegCloseKey (hKey);
+
+ DPRINT1("Success\n");
+
return TRUE;
}