3 * Copyright (C) 2004 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: setup.c,v 1.10 2004/10/08 11:52:30 ekohl Exp $
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS system libraries
23 * FILE: lib/userenv/setup.c
24 * PURPOSE: Profile setup functions
25 * PROGRAMMER: Eric Kohl
30 typedef struct _FOLDERDATA
37 BOOL bUserShellFolder
;
38 } FOLDERDATA
, *PFOLDERDATA
;
44 {L
"AppData", L
"Application Data", IDS_APPDATA
, TRUE
, TRUE
, TRUE
},
45 {L
"Desktop", L
"Desktop", IDS_DESKTOP
, FALSE
, TRUE
, TRUE
},
46 {L
"Favorites", L
"Favorites", IDS_FAVORITES
, FALSE
, TRUE
, TRUE
},
47 {L
"Personal", L
"My Documents", IDS_MYDOCUMENTS
, FALSE
, TRUE
, TRUE
},
48 {L
"My Pictures", L
"My Documents\\My Pictures", IDS_MYPICTURES
, FALSE
, TRUE
, TRUE
},
49 {L
"My Music", L
"My Documents\\My Music", IDS_MYMUSIC
, FALSE
, TRUE
, TRUE
},
50 {L
"My Video", L
"My Documents\\My Videos", IDS_MYVIDEOS
, FALSE
, TRUE
, TRUE
},
51 {L
"NetHood", L
"NetHood", IDS_NETHOOD
, TRUE
, TRUE
, TRUE
}, /* hidden ??*/
52 {L
"PrintHood", L
"PrintHood", IDS_PRINTHOOD
, TRUE
, TRUE
, TRUE
},
53 {L
"Recent", L
"Recent", IDS_RECENT
, TRUE
, TRUE
, TRUE
},
54 {L
"SendTo", L
"SendTo", IDS_SENDTO
, FALSE
, TRUE
, TRUE
},
55 {L
"Templates", L
"Templates", IDS_TEMPLATES
, FALSE
, TRUE
, TRUE
},
56 {L
"Start Menu", L
"Start Menu", IDS_STARTMENU
, FALSE
, TRUE
, TRUE
},
57 {L
"Programs", L
"Start Menu\\Programs", IDS_PROGRAMS
, FALSE
, TRUE
, TRUE
},
58 {L
"Startup", L
"Start Menu\\Programs\\Startup", IDS_STARTUP
, FALSE
, TRUE
, TRUE
},
59 {L
"Local Settings", L
"Local Settings", IDS_LOCALSETTINGS
, TRUE
, TRUE
, TRUE
},
60 {L
"Local AppData", L
"Local Settings\\Application Data", IDS_LOCALAPPDATA
, TRUE
, TRUE
, TRUE
},
61 {L
"Temp", L
"Local Settings\\Temp", IDS_TEMP
, FALSE
, FALSE
, FALSE
},
62 {L
"Cache", L
"Local Settings\\Temporary Internet Files", IDS_CACHE
, FALSE
, TRUE
, TRUE
}, /* hidden ??*/
63 {L
"History", L
"Local Settings\\History", IDS_HISTORY
, FALSE
, TRUE
, TRUE
}, /* hidden ??*/
64 {L
"Cookies", L
"Cookies", IDS_COOKIES
, FALSE
, TRUE
, TRUE
}, /* hidden ??*/
65 {NULL
, NULL
, -1, FALSE
, FALSE
, FALSE
}
70 CommonShellFolders
[] =
72 {L
"Common AppData", L
"Application Data", IDS_APPDATA
, TRUE
, TRUE
, TRUE
},
73 {L
"Common Desktop", L
"Desktop", IDS_DESKTOP
, FALSE
, TRUE
, TRUE
},
74 {L
"Common Favorites", L
"Favorites", IDS_FAVORITES
, FALSE
, TRUE
, TRUE
},
75 {L
"Common Start Menu", L
"Start Menu", IDS_STARTMENU
, FALSE
, TRUE
, TRUE
},
76 {L
"Common Programs", L
"Start Menu\\Programs", IDS_PROGRAMS
, FALSE
, TRUE
, TRUE
},
77 {L
"Common Administrative Tools", L
"Start Menu\\Programs\\Administrative Tools", IDS_ADMINTOOLS
, FALSE
, TRUE
, FALSE
},
78 {L
"Common Startup", L
"Start Menu\\Programs\\Startup", IDS_STARTUP
, FALSE
, TRUE
, TRUE
},
79 {L
"Common Templates", L
"Templates", IDS_TEMPLATES
, TRUE
, TRUE
, TRUE
},
80 {L
"Common Documents", L
"My Documents", IDS_MYDOCUMENTS
, FALSE
, TRUE
, TRUE
},
81 {L
"CommonPictures", L
"My Documents\\My Pictures", IDS_MYPICTURES
, FALSE
, TRUE
, TRUE
},
82 {L
"CommonMusic", L
"My Documents\\My Music", IDS_MYMUSIC
, FALSE
, TRUE
, TRUE
},
83 {L
"CommonVideo", L
"My Documents\\My Videos", IDS_MYVIDEOS
, FALSE
, TRUE
, TRUE
},
84 {NULL
, NULL
, -1, FALSE
, FALSE
, FALSE
}
89 DebugPrint(char* fmt
,...)
95 vsprintf(buffer
, fmt
, ap
);
98 OutputDebugStringA(buffer
);
103 InitializeProfiles (VOID
)
105 WCHAR szProfilesPath
[MAX_PATH
];
106 WCHAR szProfilePath
[MAX_PATH
];
107 WCHAR szBuffer
[MAX_PATH
];
109 PFOLDERDATA lpFolderData
;
112 /* Load profiles directory path */
113 if (!LoadString(hInstance
,
118 DPRINT1("Error: %lu\n", GetLastError());
122 if (RegOpenKeyExW (HKEY_LOCAL_MACHINE
,
123 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
128 DPRINT1("Error: %lu\n", GetLastError());
132 /* Store profiles directory path */
133 dwLength
= (wcslen (szBuffer
) + 1) * sizeof(WCHAR
);
134 if (RegSetValueExW (hKey
,
135 L
"ProfilesDirectory",
141 DPRINT1("Error: %lu\n", GetLastError());
147 if (!ExpandEnvironmentStringsW (szBuffer
,
151 DPRINT1("Error: %lu\n", GetLastError());
156 /* Create profiles directory */
157 if (!CreateDirectoryW (szProfilesPath
, NULL
))
159 if (GetLastError () != ERROR_ALREADY_EXISTS
)
161 DPRINT1("Error: %lu\n", GetLastError());
167 /* Set 'DefaultUserProfile' value */
168 wcscpy (szBuffer
, L
"Default User");
169 if (!AppendSystemPostfix (szBuffer
, MAX_PATH
))
171 DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
176 dwLength
= (wcslen (szBuffer
) + 1) * sizeof(WCHAR
);
177 if (RegSetValueExW (hKey
,
178 L
"DefaultUserProfile",
184 DPRINT1("Error: %lu\n", GetLastError());
191 /* Create 'Default User' profile directory */
192 wcscpy (szProfilePath
, szProfilesPath
);
193 wcscat (szProfilePath
, L
"\\");
194 wcscat (szProfilePath
, szBuffer
);
195 if (!CreateDirectoryW (szProfilePath
, NULL
))
197 if (GetLastError () != ERROR_ALREADY_EXISTS
)
199 DPRINT1("Error: %lu\n", GetLastError());
204 /* Set current user profile */
205 SetEnvironmentVariableW(L
"USERPROFILE", szProfilePath
);
207 /* Create 'Default User' subdirectories */
208 /* FIXME: Get these paths from the registry */
209 lpFolderData
= &UserShellFolders
[0];
210 while (lpFolderData
->lpValueName
!= NULL
)
212 wcscpy(szBuffer
, szProfilePath
);
213 wcscat(szBuffer
, L
"\\");
215 /* Append the folder name */
216 dwLength
= wcslen(szBuffer
);
217 if (!LoadStringW(hInstance
,
220 MAX_PATH
- dwLength
))
222 /* Use the default name instead */
223 wcscat(szBuffer
, lpFolderData
->lpPath
);
226 if (!CreateDirectoryW(szBuffer
, NULL
))
228 if (GetLastError() != ERROR_ALREADY_EXISTS
)
230 DPRINT1("Error: %lu\n", GetLastError());
235 if (lpFolderData
->bHidden
== TRUE
)
237 SetFileAttributesW(szBuffer
,
238 FILE_ATTRIBUTE_HIDDEN
);
244 /* Set default 'Shell Folders' values */
245 if (RegOpenKeyExW(HKEY_USERS
,
246 L
".Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
251 DPRINT1("Error: %lu\n", GetLastError());
255 lpFolderData
= &UserShellFolders
[0];
256 while (lpFolderData
->lpValueName
!= NULL
)
258 if (lpFolderData
->bShellFolder
)
260 wcscpy(szBuffer
, szProfilePath
);
261 wcscat(szBuffer
, L
"\\");
263 /* Append the folder name */
264 dwLength
= wcslen(szBuffer
);
265 if (!LoadStringW(hInstance
,
268 MAX_PATH
- dwLength
))
270 /* Use the default name instead */
271 wcscat(szBuffer
, lpFolderData
->lpPath
);
274 dwLength
= (wcslen(szBuffer
) + 1) * sizeof(WCHAR
);
275 if (RegSetValueExW(hKey
,
276 lpFolderData
->lpValueName
,
282 DPRINT1("Error: %lu\n", GetLastError());
291 /* Set 'Fonts' folder path */
292 GetWindowsDirectory(szBuffer
, MAX_PATH
);
293 wcscat(szBuffer
, L
"\\media\\fonts");
295 dwLength
= (wcslen(szBuffer
) + 1) * sizeof(WCHAR
);
296 if (RegSetValueExW(hKey
,
303 DPRINT1("Error: %lu\n", GetLastError());
310 /* Set default 'User Shell Folders' values */
311 if (RegOpenKeyExW(HKEY_USERS
,
312 L
".Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
317 DPRINT1("Error: %lu\n", GetLastError());
321 lpFolderData
= &UserShellFolders
[0];
322 while (lpFolderData
->lpValueName
!= NULL
)
324 if (lpFolderData
->bUserShellFolder
)
326 wcscpy(szBuffer
, L
"%USERPROFILE%\\");
328 /* Append the folder name */
329 dwLength
= wcslen(szBuffer
);
330 if (!LoadStringW(hInstance
,
333 MAX_PATH
- dwLength
))
335 /* Use the default name instead */
336 wcscat(szBuffer
, lpFolderData
->lpPath
);
339 dwLength
= (wcslen(szBuffer
) + 1) * sizeof(WCHAR
);
340 if (RegSetValueExW(hKey
,
341 lpFolderData
->lpValueName
,
347 DPRINT1("Error: %lu\n", GetLastError());
359 /* Set 'AllUsersProfile' value */
360 wcscpy(szBuffer
, L
"All Users");
361 if (!AppendSystemPostfix(szBuffer
, MAX_PATH
))
363 DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
367 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
368 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
373 DPRINT1("Error: %lu\n", GetLastError());
377 dwLength
= (wcslen(szBuffer
) + 1) * sizeof(WCHAR
);
378 if (RegSetValueExW(hKey
,
385 DPRINT1("Error: %lu\n", GetLastError());
393 /* Create 'All Users' profile directory */
394 wcscpy(szProfilePath
, szProfilesPath
);
395 wcscat(szProfilePath
, L
"\\");
396 wcscat(szProfilePath
, szBuffer
);
397 if (!CreateDirectoryW(szProfilePath
, NULL
))
399 if (GetLastError() != ERROR_ALREADY_EXISTS
)
401 DPRINT1("Error: %lu\n", GetLastError());
406 /* Set 'All Users' profile */
407 SetEnvironmentVariableW(L
"ALLUSERSPROFILE", szProfilePath
);
409 /* Create 'All Users' subdirectories */
410 /* FIXME: Take these paths from the registry */
411 lpFolderData
= &CommonShellFolders
[0];
412 while (lpFolderData
->lpValueName
!= NULL
)
414 wcscpy(szBuffer
, szProfilePath
);
415 wcscat(szBuffer
, L
"\\");
417 /* Append the folder name */
418 dwLength
= wcslen(szBuffer
);
419 if (!LoadStringW(hInstance
,
422 MAX_PATH
- dwLength
))
424 /* Use the default name instead */
425 wcscat(szBuffer
, lpFolderData
->lpPath
);
428 if (!CreateDirectoryW(szBuffer
, NULL
))
430 if (GetLastError() != ERROR_ALREADY_EXISTS
)
432 DPRINT1("Error: %lu\n", GetLastError());
437 if (lpFolderData
->bHidden
)
439 SetFileAttributesW(szBuffer
,
440 FILE_ATTRIBUTE_HIDDEN
);
446 /* Set common 'Shell Folders' values */
447 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
448 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
453 DPRINT1("Error: %lu\n", GetLastError());
457 lpFolderData
= &CommonShellFolders
[0];
458 while (lpFolderData
->lpValueName
!= NULL
)
460 if (lpFolderData
->bShellFolder
)
462 wcscpy(szBuffer
, szProfilePath
);
463 wcscat(szBuffer
, L
"\\");
465 /* Append the folder name */
466 dwLength
= wcslen(szBuffer
);
467 if (!LoadStringW(hInstance
,
470 MAX_PATH
- dwLength
))
472 /* Use the default name instead */
473 wcscat(szBuffer
, lpFolderData
->lpPath
);
476 dwLength
= (wcslen(szBuffer
) + 1) * sizeof(WCHAR
);
477 if (RegSetValueExW(hKey
,
478 lpFolderData
->lpValueName
,
484 DPRINT1("Error: %lu\n", GetLastError());
495 /* Set common 'User Shell Folders' values */
496 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
497 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
502 DPRINT1("Error: %lu\n", GetLastError());
506 lpFolderData
= &CommonShellFolders
[0];
507 while (lpFolderData
->lpValueName
!= NULL
)
509 if (lpFolderData
->bUserShellFolder
)
511 wcscpy(szBuffer
, L
"%ALLUSERSPROFILE%\\");
513 /* Append the folder name */
514 dwLength
= wcslen(szBuffer
);
515 if (!LoadStringW(hInstance
,
518 MAX_PATH
- dwLength
))
520 /* Use the default name instead */
521 wcscat(szBuffer
, lpFolderData
->lpPath
);
524 dwLength
= (wcslen(szBuffer
) + 1) * sizeof(WCHAR
);
525 if (RegSetValueExW(hKey
,
526 lpFolderData
->lpValueName
,
532 DPRINT1("Error: %lu\n", GetLastError());
551 UpdateUsersShellFolderSettings(LPCWSTR lpUserProfilePath
,
554 WCHAR szBuffer
[MAX_PATH
];
556 PFOLDERDATA lpFolderData
;
559 DPRINT("UpdateUsersShellFolderSettings() called\n");
561 DPRINT("User profile path: %S\n", lpUserProfilePath
);
563 if (RegOpenKeyExW(hUserKey
,
564 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
569 DPRINT1("Error: %lu\n", GetLastError());
573 lpFolderData
= &UserShellFolders
[0];
574 while (lpFolderData
->lpValueName
!= NULL
)
576 if (lpFolderData
->bShellFolder
)
578 wcscpy(szBuffer
, lpUserProfilePath
);
579 wcscat(szBuffer
, L
"\\");
581 /* Append the folder name */
582 dwLength
= wcslen(szBuffer
);
583 if (!LoadStringW(hInstance
,
586 MAX_PATH
- dwLength
))
588 /* Use the default name instead */
589 wcscat(szBuffer
, lpFolderData
->lpPath
);
592 DPRINT("%S: %S\n", lpFolderData
->lpValueName
, szBuffer
);
594 dwLength
= (wcslen(szBuffer
) + 1) * sizeof(WCHAR
);
595 if (RegSetValueExW(hFoldersKey
,
596 lpFolderData
->lpValueName
,
602 DPRINT1("Error: %lu\n", GetLastError());
603 RegCloseKey(hFoldersKey
);
611 RegCloseKey(hFoldersKey
);
613 DPRINT("UpdateUsersShellFolderSettings() done\n");