Improve creation of shell folder settings.

Todo:
 - Store folder names in resource strings.
 - Update current users shell folder paths when a new profile is created.

svn path=/trunk/; revision=11151
This commit is contained in:
Eric Kohl 2004-10-02 12:31:28 +00:00
parent acb1dd91c6
commit 19c3f3e06e

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: setup.c,v 1.7 2004/09/30 20:23:00 ekohl Exp $ /* $Id: setup.c,v 1.8 2004/10/02 12:31:28 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -27,74 +27,53 @@
#include "precomp.h" #include "precomp.h"
typedef struct _FOLDERDATA
typedef struct _DIRDATA
{
BOOL Hidden;
LPWSTR DirName;
} DIRDATA, *PDIRDATA;
typedef struct _REGDATA
{ {
LPWSTR ValueName; LPWSTR ValueName;
LPWSTR ValueData; LPWSTR Path;
} REGDATA, *PREGDATA; BOOL Hidden;
BOOL bShellFolder;
BOOL bUserShellFolder;
} FOLDERDATA, *PFOLDERDATA;
static FOLDERDATA
static DIRDATA UserShellFolders[] =
DefaultUserDirectories[] =
{ {
{TRUE, L"Application Data"}, {L"AppData", L"Application Data", TRUE, TRUE, TRUE},
{FALSE, L"Desktop"}, {L"Desktop", L"Desktop", FALSE, TRUE, TRUE},
{FALSE, L"Favorites"}, {L"Favorites", L"Favorites", FALSE, TRUE, TRUE},
{FALSE, L"My Documents"}, {L"Personal", L"My Documents", FALSE, TRUE, TRUE},
{TRUE, L"PrintHood"}, {L"PrintHood", L"PrintHood", TRUE, TRUE, TRUE},
{TRUE, L"Recent"}, {L"Recent", L"Recent", TRUE, TRUE, TRUE},
{FALSE, L"Start Menu"}, {L"SendTo", L"SendTo", FALSE, TRUE, TRUE},
{FALSE, L"Start Menu\\Programs"}, {L"Templates", L"Templates", FALSE, TRUE, TRUE},
{FALSE, L"Start Menu\\Programs\\Startup"}, {L"Start Menu", L"Start Menu", FALSE, TRUE, TRUE},
{TRUE, L"Local Settings"}, {L"Programs", L"Start Menu\\Programs", FALSE, TRUE, TRUE},
{TRUE, L"Local Settings\\Application Data"}, {L"Startup", L"Start Menu\\Programs\\Startup", FALSE, TRUE, TRUE},
{FALSE, L"Local Settings\\Temp"}, {L"Local Settings", L"Local Settings", TRUE, TRUE, TRUE},
{FALSE, NULL} {L"Local AppData", L"Local Settings\\Application Data", TRUE, TRUE, TRUE},
{L"Temp", L"Local Settings\\Temp", FALSE, FALSE, FALSE},
{NULL, NULL, FALSE, FALSE, FALSE}
}; };
static DIRDATA static FOLDERDATA
AllUsersDirectories[] =
{
{TRUE, L"Application Data"},
{FALSE, L"Desktop"},
{FALSE, L"Favorites"},
{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}
};
static REGDATA
CommonShellFolders[] = CommonShellFolders[] =
{ {
{L"Desktop", L"%ALLUSERSPROFILE%\\Desktop"}, {L"Common AppData", L"Application Data", TRUE, TRUE, TRUE},
{L"Common AppData", L"%ALLUSERSPROFILE%\\Application Data"}, {L"Common Desktop", L"Desktop", FALSE, TRUE, TRUE},
{L"Common Programs", L"%ALLUSERSPROFILE%\\Start Menu\\Programs"}, {L"Common Favorites", L"Favorites", FALSE, TRUE, TRUE},
{L"Common Documents", L"%ALLUSERSPROFILE%\\Documents"}, {L"Common Start Menu", L"Start Menu", FALSE, TRUE, TRUE},
{L"Common Desktop", L"%ALLUSERSPROFILE%\\Desktop"}, {L"Common Programs", L"Start Menu\\Programs", FALSE, TRUE, TRUE},
{L"Common Start Menu", L"%ALLUSERSPROFILE%\\Start Menu"}, {L"Common Administrative Tools", L"Start Menu\\Programs\\Administrative Tools", FALSE, TRUE, FALSE},
{L"CommonPictures", L"%ALLUSERSPROFILE%\\Documents\\My Pictures"}, {L"Common Startup", L"Start Menu\\Programs\\Startup", FALSE, TRUE, TRUE},
{L"CommonMusic", L"%ALLUSERSPROFILE%\\Documents\\My Music"}, {L"Common Templates", L"Templates", TRUE, TRUE, TRUE},
{L"CommonVideo", L"%ALLUSERSPROFILE%\\Documents\\My Videos"}, {L"Common Documents", L"My Documents", FALSE, TRUE, TRUE},
{L"Common Favorites", L"%ALLUSERSPROFILE%\\Favorites"}, {L"CommonPictures", L"My Documents\\My Pictures", FALSE, TRUE, TRUE},
{L"Common Startup", L"%ALLUSERSPROFILE%\\Start Menu\\Programs\\Startup"}, {L"CommonMusic", L"My Documents\\My Music", FALSE, TRUE, TRUE},
{L"Common Administrative Tools", L"%ALLUSERSPROFILE%\\Start Menu\\Programs\\Administrative Tools"}, {L"CommonVideo", L"My Documents\\My Videos", FALSE, TRUE, TRUE},
{L"Common Templates", L"%ALLUSERSPROFILE%\\Templates"}, {NULL, NULL, FALSE, FALSE, FALSE}
{L"Personal", L"%ALLUSERSPROFILE%\\My Documents"},
{NULL, NULL}
}; };
@ -118,11 +97,8 @@ InitializeProfiles (VOID)
WCHAR szProfilesPath[MAX_PATH]; WCHAR szProfilesPath[MAX_PATH];
WCHAR szProfilePath[MAX_PATH]; WCHAR szProfilePath[MAX_PATH];
WCHAR szBuffer[MAX_PATH]; WCHAR szBuffer[MAX_PATH];
LPWSTR lpszPtr;
DWORD dwLength; DWORD dwLength;
PDIRDATA lpDirData; PFOLDERDATA lpFolderData;
PREGDATA lpRegData;
HKEY hKey; HKEY hKey;
if (RegOpenKeyExW (HKEY_LOCAL_MACHINE, if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
@ -192,6 +168,8 @@ InitializeProfiles (VOID)
return FALSE; return FALSE;
} }
RegCloseKey (hKey);
/* Create 'Default User' profile directory */ /* Create 'Default User' profile directory */
wcscpy (szProfilePath, szProfilesPath); wcscpy (szProfilePath, szProfilesPath);
wcscat (szProfilePath, L"\\"); wcscat (szProfilePath, L"\\");
@ -201,7 +179,6 @@ InitializeProfiles (VOID)
if (GetLastError () != ERROR_ALREADY_EXISTS) if (GetLastError () != ERROR_ALREADY_EXISTS)
{ {
DPRINT1("Error: %lu\n", GetLastError()); DPRINT1("Error: %lu\n", GetLastError());
RegCloseKey (hKey);
return FALSE; return FALSE;
} }
} }
@ -211,37 +188,141 @@ InitializeProfiles (VOID)
/* Create 'Default User' subdirectories */ /* Create 'Default User' subdirectories */
/* FIXME: Get these paths from the registry */ /* FIXME: Get these paths from the registry */
lpszPtr = AppendBackslash (szProfilePath); lpFolderData = &UserShellFolders[0];
lpDirData = &DefaultUserDirectories[0]; while (lpFolderData->ValueName != NULL)
while (lpDirData->DirName != NULL)
{ {
wcscpy (lpszPtr, lpDirData->DirName); wcscpy(szBuffer, szProfilePath);
wcscat(szBuffer, L"\\");
wcscat(szBuffer, lpFolderData->Path);
if (!CreateDirectoryW (szProfilePath, NULL)) if (!CreateDirectoryW(szBuffer, NULL))
{ {
if (GetLastError () != ERROR_ALREADY_EXISTS) if (GetLastError () != ERROR_ALREADY_EXISTS)
{ {
DPRINT1("Error: %lu\n", GetLastError()); DPRINT1("Error: %lu\n", GetLastError());
RegCloseKey (hKey);
return FALSE; return FALSE;
} }
} }
if (lpDirData->Hidden == TRUE) if (lpFolderData->Hidden == TRUE)
{ {
SetFileAttributesW (szProfilePath, SetFileAttributesW (szBuffer,
FILE_ATTRIBUTE_HIDDEN); FILE_ATTRIBUTE_HIDDEN);
} }
lpDirData++; lpFolderData++;
} }
/* Set default 'Shell Folders' values */
if (RegOpenKeyExW(HKEY_USERS,
L".Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
0,
KEY_ALL_ACCESS,
&hKey))
{
DPRINT1("Error: %lu\n", GetLastError());
return FALSE;
}
lpFolderData = &UserShellFolders[0];
while (lpFolderData->ValueName != NULL)
{
if (lpFolderData->bShellFolder)
{
wcscpy(szBuffer, szProfilePath);
wcscat(szBuffer, L"\\");
wcscat(szBuffer, lpFolderData->Path);
dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR);
if (RegSetValueExW(hKey,
lpFolderData->ValueName,
0,
REG_SZ,
(LPBYTE)szBuffer,
dwLength))
{
DPRINT1("Error: %lu\n", GetLastError());
RegCloseKey(hKey);
return FALSE;
}
}
lpFolderData++;
}
/* Set 'Fonts' folder path */
GetWindowsDirectory(szBuffer, MAX_PATH);
wcscat(szBuffer, L"\\media\\fonts");
dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR);
if (RegSetValueExW(hKey,
L"Fonts",
0,
REG_SZ,
(LPBYTE)szBuffer,
dwLength))
{
DPRINT1("Error: %lu\n", GetLastError());
RegCloseKey(hKey);
return FALSE;
}
RegCloseKey(hKey);
/* Set default 'User Shell Folders' values */
if (RegOpenKeyExW(HKEY_USERS,
L".Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
0,
KEY_ALL_ACCESS,
&hKey))
{
DPRINT1("Error: %lu\n", GetLastError());
return FALSE;
}
lpFolderData = &UserShellFolders[0];
while (lpFolderData->ValueName != NULL)
{
if (lpFolderData->bUserShellFolder)
{
wcscpy(szBuffer, L"%USERPROFILE%\\");
wcscat(szBuffer, lpFolderData->Path);
dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR);
if (RegSetValueExW(hKey,
lpFolderData->ValueName,
0,
REG_EXPAND_SZ,
(LPBYTE)szBuffer,
dwLength))
{
DPRINT1("Error: %lu\n", GetLastError());
RegCloseKey(hKey);
return FALSE;
}
}
lpFolderData++;
}
RegCloseKey(hKey);
/* Set 'AllUsersProfile' value */ /* Set 'AllUsersProfile' value */
wcscpy (szBuffer, L"All Users"); wcscpy (szBuffer, L"All Users");
if (!AppendSystemPostfix (szBuffer, MAX_PATH)) if (!AppendSystemPostfix (szBuffer, MAX_PATH))
{ {
DPRINT1("AppendSystemPostfix() failed\n", GetLastError()); DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
RegCloseKey (hKey); return FALSE;
}
if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
0,
KEY_ALL_ACCESS,
&hKey))
{
DPRINT1("Error: %lu\n", GetLastError());
return FALSE; return FALSE;
} }
@ -270,7 +351,6 @@ InitializeProfiles (VOID)
if (GetLastError () != ERROR_ALREADY_EXISTS) if (GetLastError () != ERROR_ALREADY_EXISTS)
{ {
DPRINT1("Error: %lu\n", GetLastError()); DPRINT1("Error: %lu\n", GetLastError());
RegCloseKey (hKey);
return FALSE; return FALSE;
} }
} }
@ -280,32 +360,32 @@ InitializeProfiles (VOID)
/* Create 'All Users' subdirectories */ /* Create 'All Users' subdirectories */
/* FIXME: Take these paths from the registry */ /* FIXME: Take these paths from the registry */
lpszPtr = AppendBackslash (szProfilePath); lpFolderData = &CommonShellFolders[0];
lpDirData = &AllUsersDirectories[0]; while (lpFolderData->ValueName != NULL)
while (lpDirData->DirName != NULL)
{ {
wcscpy (lpszPtr, lpDirData->DirName); wcscpy(szBuffer, szProfilePath);
wcscat(szBuffer, L"\\");
wcscat(szBuffer, lpFolderData->Path);
if (!CreateDirectoryW (szProfilePath, NULL)) if (!CreateDirectoryW(szBuffer, NULL))
{ {
if (GetLastError () != ERROR_ALREADY_EXISTS) if (GetLastError () != ERROR_ALREADY_EXISTS)
{ {
DPRINT1("Error: %lu\n", GetLastError()); DPRINT1("Error: %lu\n", GetLastError());
RegCloseKey (hKey);
return FALSE; return FALSE;
} }
} }
if (lpDirData->Hidden == TRUE) if (lpFolderData->Hidden)
{ {
SetFileAttributesW (szProfilePath, SetFileAttributesW(szBuffer,
FILE_ATTRIBUTE_HIDDEN); FILE_ATTRIBUTE_HIDDEN);
} }
lpDirData++; lpFolderData++;
} }
/* Create common shell folder registry values */ /* Set common 'Shell Folders' values */
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
0, 0,
@ -316,37 +396,76 @@ InitializeProfiles (VOID)
return FALSE; return FALSE;
} }
lpRegData = &CommonShellFolders[0]; lpFolderData = &CommonShellFolders[0];
while (lpRegData->ValueName != NULL) while (lpFolderData->ValueName != NULL)
{ {
if (!ExpandEnvironmentStringsW(lpRegData->ValueData, if (lpFolderData->bShellFolder)
szBuffer,
MAX_PATH))
{ {
DPRINT1("Error: %lu\n", GetLastError()); wcscpy(szBuffer, szProfilePath);
RegCloseKey(hKey); wcscat(szBuffer, L"\\");
return FALSE; wcscat(szBuffer, lpFolderData->Path);
dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR);
if (RegSetValueExW(hKey,
lpFolderData->ValueName,
0,
REG_SZ,
(LPBYTE)szBuffer,
dwLength))
{
DPRINT1("Error: %lu\n", GetLastError());
RegCloseKey(hKey);
return FALSE;
}
} }
dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR); lpFolderData++;
if (RegSetValueExW(hKey,
lpRegData->ValueName,
0,
REG_SZ,
(LPBYTE)szBuffer,
dwLength))
{
DPRINT1("Error: %lu\n", GetLastError());
RegCloseKey(hKey);
return FALSE;
}
lpRegData++;
} }
RegCloseKey(hKey); RegCloseKey(hKey);
/* Set common 'User Shell Folders' values */
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
0,
KEY_ALL_ACCESS,
&hKey))
{
DPRINT1("Error: %lu\n", GetLastError());
return FALSE;
}
lpFolderData = &CommonShellFolders[0];
while (lpFolderData->ValueName != NULL)
{
if (lpFolderData->bUserShellFolder)
{
wcscpy(szBuffer, L"%ALLUSERSPROFILE%\\");
wcscat(szBuffer, lpFolderData->Path);
dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR);
if (RegSetValueExW(hKey,
lpFolderData->ValueName,
0,
REG_EXPAND_SZ,
(LPBYTE)szBuffer,
dwLength))
{
DPRINT1("Error: %lu\n", GetLastError());
RegCloseKey(hKey);
return FALSE;
}
}
lpFolderData++;
}
RegCloseKey(hKey);
DPRINT1("Success\n"); DPRINT1("Success\n");
return TRUE; return TRUE;
} }
/* EOF */