f9b1b324426d318d2d3c55f50a6cdcdfc218dde6
[reactos.git] / reactos / dll / win32 / userenv / setup.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2004 ReactOS Team
4 *
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.
9 *
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.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS system libraries
22 * FILE: dll/win32/userenv/setup.c
23 * PURPOSE: Profile setup functions
24 * PROGRAMMER: Eric Kohl
25 */
26
27 #include "precomp.h"
28
29 #define NDEBUG
30 #include <debug.h>
31
32 #include "resources.h"
33
34 typedef struct _FOLDERDATA
35 {
36 LPWSTR lpValueName;
37 LPWSTR lpPath;
38 UINT uId;
39 BOOL bHidden;
40 BOOL bShellFolder;
41 BOOL bUserShellFolder;
42 } FOLDERDATA, *PFOLDERDATA;
43
44
45 static FOLDERDATA
46 UserShellFolders[] =
47 {
48 {L"AppData", L"Application Data", IDS_APPDATA, TRUE, TRUE, TRUE},
49 {L"Desktop", L"Desktop", IDS_DESKTOP, FALSE, TRUE, TRUE},
50 {L"Favorites", L"Favorites", IDS_FAVORITES, FALSE, TRUE, TRUE},
51 {L"Personal", L"My Documents", IDS_MYDOCUMENTS, FALSE, TRUE, TRUE},
52 {L"My Pictures", L"My Documents\\My Pictures", IDS_MYPICTURES, FALSE, TRUE, TRUE},
53 {L"My Music", L"My Documents\\My Music", IDS_MYMUSIC, FALSE, TRUE, TRUE},
54 {L"My Video", L"My Documents\\My Videos", IDS_MYVIDEOS, FALSE, TRUE, TRUE},
55 {L"NetHood", L"NetHood", IDS_NETHOOD, TRUE, TRUE, TRUE},
56 {L"PrintHood", L"PrintHood", IDS_PRINTHOOD, TRUE, TRUE, TRUE},
57 {L"Recent", L"Recent", IDS_RECENT, TRUE, TRUE, TRUE},
58 {L"SendTo", L"SendTo", IDS_SENDTO, FALSE, TRUE, TRUE},
59 {L"Templates", L"Templates", IDS_TEMPLATES, FALSE, TRUE, TRUE},
60 {L"Start Menu", L"Start Menu", IDS_STARTMENU, FALSE, TRUE, TRUE},
61 {L"Programs", L"Start Menu\\Programs", IDS_PROGRAMS, FALSE, TRUE, TRUE},
62 {L"Startup", L"Start Menu\\Programs\\Startup", IDS_STARTUP, FALSE, TRUE, TRUE},
63 {L"Local Settings", L"Local Settings", IDS_LOCALSETTINGS, TRUE, TRUE, TRUE},
64 {L"Local AppData", L"Local Settings\\Application Data", IDS_LOCALAPPDATA, TRUE, TRUE, TRUE},
65 {L"Temp", L"Local Settings\\Temp", IDS_TEMP, FALSE, FALSE, FALSE},
66 {L"Cache", L"Local Settings\\Temporary Internet Files", IDS_CACHE, FALSE, TRUE, TRUE},
67 {L"History", L"Local Settings\\History", IDS_HISTORY, FALSE, TRUE, TRUE},
68 {L"Cookies", L"Cookies", IDS_COOKIES, FALSE, TRUE, TRUE},
69 {NULL, NULL, -1, FALSE, FALSE, FALSE}
70 };
71
72
73 static FOLDERDATA
74 CommonShellFolders[] =
75 {
76 {L"Common AppData", L"Application Data", IDS_APPDATA, TRUE, TRUE, TRUE},
77 {L"Common Desktop", L"Desktop", IDS_DESKTOP, FALSE, TRUE, TRUE},
78 {L"Common Favorites", L"Favorites", IDS_FAVORITES, FALSE, TRUE, TRUE},
79 {L"Common Start Menu", L"Start Menu", IDS_STARTMENU, FALSE, TRUE, TRUE},
80 {L"Common Programs", L"Start Menu\\Programs", IDS_PROGRAMS, FALSE, TRUE, TRUE},
81 {L"Common Administrative Tools", L"Start Menu\\Programs\\Administrative Tools", IDS_ADMINTOOLS, FALSE, TRUE, FALSE},
82 {L"Common Startup", L"Start Menu\\Programs\\Startup", IDS_STARTUP, FALSE, TRUE, TRUE},
83 {L"Common Templates", L"Templates", IDS_TEMPLATES, TRUE, TRUE, TRUE},
84 {L"Common Documents", L"My Documents", IDS_MYDOCUMENTS, FALSE, TRUE, TRUE},
85 {L"CommonPictures", L"My Documents\\My Pictures", IDS_MYPICTURES, FALSE, TRUE, TRUE},
86 {L"CommonMusic", L"My Documents\\My Music", IDS_MYMUSIC, FALSE, TRUE, TRUE},
87 {L"CommonVideo", L"My Documents\\My Videos", IDS_MYVIDEOS, FALSE, TRUE, TRUE},
88 {NULL, NULL, -1, FALSE, FALSE, FALSE}
89 };
90
91
92 void
93 DebugPrint(char* fmt,...)
94 {
95 char buffer[512];
96 va_list ap;
97
98 va_start(ap, fmt);
99 vsprintf(buffer, fmt, ap);
100 va_end(ap);
101
102 OutputDebugStringA(buffer);
103 }
104
105
106 BOOL
107 WINAPI
108 InitializeProfiles(VOID)
109 {
110 WCHAR szProfilesPath[MAX_PATH];
111 WCHAR szProfilePath[MAX_PATH];
112 WCHAR szCommonFilesDirPath[MAX_PATH];
113 WCHAR szBuffer[MAX_PATH];
114 DWORD dwLength;
115 PFOLDERDATA lpFolderData;
116 HKEY hKey;
117 LONG Error;
118
119 DPRINT("InitializeProfiles()\n");
120
121 /* Load profiles directory path */
122 if (!LoadStringW(hInstance,
123 IDS_PROFILEPATH,
124 szBuffer,
125 ARRAYSIZE(szBuffer)))
126 {
127 DPRINT1("Error: %lu\n", GetLastError());
128 return FALSE;
129 }
130
131 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
132 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
133 0,
134 KEY_SET_VALUE,
135 &hKey);
136 if (Error != ERROR_SUCCESS)
137 {
138 DPRINT1("Error: %lu\n", Error);
139 SetLastError((DWORD)Error);
140 return FALSE;
141 }
142
143 /* Expand it */
144 if (!ExpandEnvironmentStringsW(szBuffer,
145 szProfilesPath,
146 ARRAYSIZE(szProfilesPath)))
147 {
148 DPRINT1("Error: %lu\n", GetLastError());
149 RegCloseKey(hKey);
150 return FALSE;
151 }
152
153 /* Create profiles directory */
154 if (!CreateDirectoryW(szProfilesPath, NULL))
155 {
156 if (GetLastError() != ERROR_ALREADY_EXISTS)
157 {
158 DPRINT1("Error: %lu\n", GetLastError());
159 RegCloseKey(hKey);
160 return FALSE;
161 }
162 }
163
164 /* Store the profiles directory path in the registry */
165 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
166 Error = RegSetValueExW(hKey,
167 L"ProfilesDirectory",
168 0,
169 REG_EXPAND_SZ,
170 (LPBYTE)szBuffer,
171 dwLength);
172 if (Error != ERROR_SUCCESS)
173 {
174 DPRINT1("Error: %lu\n", Error);
175 RegCloseKey(hKey);
176 SetLastError((DWORD)Error);
177 return FALSE;
178 }
179
180 /* Set 'DefaultUserProfile' value */
181 wcscpy(szBuffer, L"Default User");
182
183 /* Create Default User profile directory path */
184 wcscpy(szProfilePath, szProfilesPath);
185 wcscat(szProfilePath, L"\\");
186 wcscat(szProfilePath, szBuffer);
187
188 /* Attempt default user directory creation */
189 if (!CreateDirectoryW(szProfilePath, NULL))
190 {
191 if (GetLastError() != ERROR_ALREADY_EXISTS)
192 {
193 DPRINT1("Error: %lu\n", GetLastError());
194 RegCloseKey(hKey);
195 return FALSE;
196 }
197
198 /* Directory existed, let's try to append the postfix */
199 if (!AppendSystemPostfix(szBuffer, ARRAYSIZE(szBuffer)))
200 {
201 DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
202 RegCloseKey(hKey);
203 return FALSE;
204 }
205
206 /* Create Default User profile directory path again */
207 wcscpy(szProfilePath, szProfilesPath);
208 wcscat(szProfilePath, L"\\");
209 wcscat(szProfilePath, szBuffer);
210
211 /* Attempt creation again with appended postfix */
212 if (!CreateDirectoryW(szProfilePath, NULL))
213 {
214 if (GetLastError() != ERROR_ALREADY_EXISTS)
215 {
216 DPRINT1("Error: %lu\n", GetLastError());
217 RegCloseKey(hKey);
218 return FALSE;
219 }
220 }
221 }
222
223 /* Store the default user profile path in the registry */
224 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
225 Error = RegSetValueExW(hKey,
226 L"DefaultUserProfile",
227 0,
228 REG_SZ,
229 (LPBYTE)szBuffer,
230 dwLength);
231 if (Error != ERROR_SUCCESS)
232 {
233 DPRINT1("Error: %lu\n", Error);
234 RegCloseKey(hKey);
235 SetLastError((DWORD)Error);
236 return FALSE;
237 }
238
239 RegCloseKey(hKey);
240
241 /* Set current user profile */
242 SetEnvironmentVariableW(L"USERPROFILE", szProfilePath);
243
244 /* Create 'Default User' subdirectories */
245 /* FIXME: Get these paths from the registry */
246 lpFolderData = &UserShellFolders[0];
247 while (lpFolderData->lpValueName != NULL)
248 {
249 wcscpy(szBuffer, szProfilePath);
250 wcscat(szBuffer, L"\\");
251
252 /* Append the folder name */
253 dwLength = wcslen(szBuffer);
254 if (!LoadStringW(hInstance,
255 lpFolderData->uId,
256 &szBuffer[dwLength],
257 ARRAYSIZE(szBuffer) - dwLength))
258 {
259 /* Use the default name instead */
260 wcscat(szBuffer, lpFolderData->lpPath);
261 }
262
263 if (!CreateDirectoryW(szBuffer, NULL))
264 {
265 if (GetLastError() != ERROR_ALREADY_EXISTS)
266 {
267 DPRINT1("Error: %lu\n", GetLastError());
268 return FALSE;
269 }
270 }
271
272 if (lpFolderData->bHidden == TRUE)
273 {
274 SetFileAttributesW(szBuffer,
275 FILE_ATTRIBUTE_HIDDEN);
276 }
277
278 lpFolderData++;
279 }
280
281 /* Set default 'Shell Folders' values */
282 Error = RegOpenKeyExW(HKEY_USERS,
283 L".Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
284 0,
285 KEY_SET_VALUE,
286 &hKey);
287 if (Error != ERROR_SUCCESS)
288 {
289 DPRINT1("Error: %lu\n", Error);
290 SetLastError((DWORD)Error);
291 return FALSE;
292 }
293
294 lpFolderData = &UserShellFolders[0];
295 while (lpFolderData->lpValueName != NULL)
296 {
297 if (lpFolderData->bShellFolder)
298 {
299 wcscpy(szBuffer, szProfilePath);
300 wcscat(szBuffer, L"\\");
301
302 /* Append the folder name */
303 dwLength = wcslen(szBuffer);
304 if (!LoadStringW(hInstance,
305 lpFolderData->uId,
306 &szBuffer[dwLength],
307 ARRAYSIZE(szBuffer) - dwLength))
308 {
309 /* Use the default name instead */
310 wcscat(szBuffer, lpFolderData->lpPath);
311 }
312
313 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
314 Error = RegSetValueExW(hKey,
315 lpFolderData->lpValueName,
316 0,
317 REG_SZ,
318 (LPBYTE)szBuffer,
319 dwLength);
320 if (Error != ERROR_SUCCESS)
321 {
322 DPRINT1("Error: %lu\n", Error);
323 RegCloseKey(hKey);
324 SetLastError((DWORD)Error);
325 return FALSE;
326 }
327 }
328
329 lpFolderData++;
330 }
331
332 /* Set 'Fonts' folder path */
333 GetWindowsDirectoryW(szBuffer, ARRAYSIZE(szBuffer));
334 wcscat(szBuffer, L"\\Fonts");
335
336 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
337 Error = RegSetValueExW(hKey,
338 L"Fonts",
339 0,
340 REG_SZ,
341 (LPBYTE)szBuffer,
342 dwLength);
343 if (Error != ERROR_SUCCESS)
344 {
345 DPRINT1("Error: %lu\n", Error);
346 RegCloseKey(hKey);
347 SetLastError((DWORD)Error);
348 return FALSE;
349 }
350
351 RegCloseKey(hKey);
352
353 /* Set default 'User Shell Folders' values */
354 Error = RegOpenKeyExW(HKEY_USERS,
355 L".Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
356 0,
357 KEY_SET_VALUE,
358 &hKey);
359 if (Error != ERROR_SUCCESS)
360 {
361 DPRINT1("Error: %lu\n", Error);
362 SetLastError((DWORD)Error);
363 return FALSE;
364 }
365
366 lpFolderData = &UserShellFolders[0];
367 while (lpFolderData->lpValueName != NULL)
368 {
369 if (lpFolderData->bUserShellFolder)
370 {
371 wcscpy(szBuffer, L"%USERPROFILE%\\");
372
373 /* Append the folder name */
374 dwLength = wcslen(szBuffer);
375 if (!LoadStringW(hInstance,
376 lpFolderData->uId,
377 &szBuffer[dwLength],
378 ARRAYSIZE(szBuffer) - dwLength))
379 {
380 /* Use the default name instead */
381 wcscat(szBuffer, lpFolderData->lpPath);
382 }
383
384 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
385 Error = RegSetValueExW(hKey,
386 lpFolderData->lpValueName,
387 0,
388 REG_EXPAND_SZ,
389 (LPBYTE)szBuffer,
390 dwLength);
391 if (Error != ERROR_SUCCESS)
392 {
393 DPRINT1("Error: %lu\n", Error);
394 RegCloseKey(hKey);
395 SetLastError((DWORD)Error);
396 return FALSE;
397 }
398 }
399
400 lpFolderData++;
401 }
402
403 RegCloseKey(hKey);
404
405 /* Set 'AllUsersProfile' value */
406 wcscpy(szBuffer, L"All Users");
407
408 /* Create 'All Users' profile directory path */
409 wcscpy(szProfilePath, szProfilesPath);
410 wcscat(szProfilePath, L"\\");
411 wcscat(szProfilePath, szBuffer);
412
413 /* Attempt 'All Users' directory creation */
414 if (!CreateDirectoryW(szProfilePath, NULL))
415 {
416 if (GetLastError() != ERROR_ALREADY_EXISTS)
417 {
418 DPRINT1("Error: %lu\n", GetLastError());
419 return FALSE;
420 }
421
422 /* Directory existed, let's try to append the postfix */
423 if (!AppendSystemPostfix(szBuffer, ARRAYSIZE(szBuffer)))
424 {
425 DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
426 return FALSE;
427 }
428
429 /* Attempt again creation with appended postfix */
430 wcscpy(szProfilePath, szProfilesPath);
431 wcscat(szProfilePath, L"\\");
432 wcscat(szProfilePath, szBuffer);
433
434 if (!CreateDirectoryW(szProfilePath, NULL))
435 {
436 if (GetLastError() != ERROR_ALREADY_EXISTS)
437 {
438 DPRINT1("Error: %lu\n", GetLastError());
439 return FALSE;
440 }
441 }
442 }
443
444 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
445 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
446 0,
447 KEY_SET_VALUE,
448 &hKey);
449 if (Error != ERROR_SUCCESS)
450 {
451 DPRINT1("Error: %lu\n", Error);
452 SetLastError((DWORD)Error);
453 return FALSE;
454 }
455
456 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
457 Error = RegSetValueExW(hKey,
458 L"AllUsersProfile",
459 0,
460 REG_SZ,
461 (LPBYTE)szBuffer,
462 dwLength);
463
464 RegCloseKey(hKey);
465
466 if (Error != ERROR_SUCCESS)
467 {
468 DPRINT1("Error: %lu\n", Error);
469 SetLastError((DWORD)Error);
470 return FALSE;
471 }
472
473 /* Set 'All Users' profile */
474 SetEnvironmentVariableW(L"ALLUSERSPROFILE", szProfilePath);
475
476 /* Create 'All Users' subdirectories */
477 /* FIXME: Take these paths from the registry */
478 lpFolderData = &CommonShellFolders[0];
479 while (lpFolderData->lpValueName != NULL)
480 {
481 wcscpy(szBuffer, szProfilePath);
482 wcscat(szBuffer, L"\\");
483
484 /* Append the folder name */
485 dwLength = wcslen(szBuffer);
486 if (!LoadStringW(hInstance,
487 lpFolderData->uId,
488 &szBuffer[dwLength],
489 ARRAYSIZE(szBuffer) - dwLength))
490 {
491 /* Use the default name instead */
492 wcscat(szBuffer, lpFolderData->lpPath);
493 }
494
495 if (!CreateDirectoryW(szBuffer, NULL))
496 {
497 if (GetLastError() != ERROR_ALREADY_EXISTS)
498 {
499 DPRINT1("Error: %lu\n", GetLastError());
500 return FALSE;
501 }
502 }
503
504 if (lpFolderData->bHidden)
505 {
506 SetFileAttributesW(szBuffer,
507 FILE_ATTRIBUTE_HIDDEN);
508 }
509
510 lpFolderData++;
511 }
512
513 /* Set common 'Shell Folders' values */
514 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
515 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
516 0,
517 KEY_SET_VALUE,
518 &hKey);
519 if (Error != ERROR_SUCCESS)
520 {
521 DPRINT1("Error: %lu\n", Error);
522 SetLastError((DWORD)Error);
523 return FALSE;
524 }
525
526 lpFolderData = &CommonShellFolders[0];
527 while (lpFolderData->lpValueName != NULL)
528 {
529 if (lpFolderData->bShellFolder)
530 {
531 wcscpy(szBuffer, szProfilePath);
532 wcscat(szBuffer, L"\\");
533
534 /* Append the folder name */
535 dwLength = wcslen(szBuffer);
536 if (!LoadStringW(hInstance,
537 lpFolderData->uId,
538 &szBuffer[dwLength],
539 ARRAYSIZE(szBuffer) - dwLength))
540 {
541 /* Use the default name instead */
542 wcscat(szBuffer, lpFolderData->lpPath);
543 }
544
545 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
546 Error = RegSetValueExW(hKey,
547 lpFolderData->lpValueName,
548 0,
549 REG_SZ,
550 (LPBYTE)szBuffer,
551 dwLength);
552 if (Error != ERROR_SUCCESS)
553 {
554 DPRINT1("Error: %lu\n", Error);
555 RegCloseKey(hKey);
556 SetLastError((DWORD)Error);
557 return FALSE;
558 }
559 }
560
561 lpFolderData++;
562 }
563
564 RegCloseKey(hKey);
565
566 /* Set common 'User Shell Folders' values */
567 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
568 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
569 0,
570 KEY_SET_VALUE,
571 &hKey);
572 if (Error != ERROR_SUCCESS)
573 {
574 DPRINT1("Error: %lu\n", Error);
575 SetLastError((DWORD)Error);
576 return FALSE;
577 }
578
579 lpFolderData = &CommonShellFolders[0];
580 while (lpFolderData->lpValueName != NULL)
581 {
582 if (lpFolderData->bUserShellFolder)
583 {
584 wcscpy(szBuffer, L"%ALLUSERSPROFILE%\\");
585
586 /* Append the folder name */
587 dwLength = wcslen(szBuffer);
588 if (!LoadStringW(hInstance,
589 lpFolderData->uId,
590 &szBuffer[dwLength],
591 ARRAYSIZE(szBuffer) - dwLength))
592 {
593 /* Use the default name instead */
594 wcscat(szBuffer, lpFolderData->lpPath);
595 }
596
597 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
598 Error = RegSetValueExW(hKey,
599 lpFolderData->lpValueName,
600 0,
601 REG_EXPAND_SZ,
602 (LPBYTE)szBuffer,
603 dwLength);
604 if (Error != ERROR_SUCCESS)
605 {
606 DPRINT1("Error: %lu\n", Error);
607 RegCloseKey(hKey);
608 SetLastError((DWORD)Error);
609 return FALSE;
610 }
611 }
612
613 lpFolderData++;
614 }
615
616 RegCloseKey(hKey);
617
618 /* Load 'Program Files' location */
619 if (!LoadStringW(hInstance,
620 IDS_PROGRAMFILES,
621 szBuffer,
622 ARRAYSIZE(szBuffer)))
623 {
624 DPRINT1("Error: %lu\n", GetLastError());
625 return FALSE;
626 }
627
628 if (!LoadStringW(hInstance,
629 IDS_COMMONFILES,
630 szCommonFilesDirPath,
631 ARRAYSIZE(szCommonFilesDirPath)))
632 {
633 DPRINT1("Warning: %lu\n", GetLastError());
634 }
635
636 /* Expand it */
637 if (!ExpandEnvironmentStringsW(szBuffer,
638 szProfilesPath,
639 ARRAYSIZE(szProfilesPath)))
640 {
641 DPRINT1("Error: %lu\n", GetLastError());
642 return FALSE;
643 }
644
645 wcscpy(szBuffer, szProfilesPath);
646 wcscat(szBuffer, L"\\");
647 wcscat(szBuffer, szCommonFilesDirPath);
648
649 if (!ExpandEnvironmentStringsW(szBuffer,
650 szCommonFilesDirPath,
651 ARRAYSIZE(szCommonFilesDirPath)))
652 {
653 DPRINT1("Warning: %lu\n", GetLastError());
654 }
655
656 /* Store it */
657 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
658 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
659 0,
660 KEY_SET_VALUE,
661 &hKey);
662 if (Error != ERROR_SUCCESS)
663 {
664 DPRINT1("Error: %lu\n", Error);
665 SetLastError((DWORD)Error);
666 return FALSE;
667 }
668
669 dwLength = (wcslen(szProfilesPath) + 1) * sizeof(WCHAR);
670 Error = RegSetValueExW(hKey,
671 L"ProgramFilesDir",
672 0,
673 REG_SZ,
674 (LPBYTE)szProfilesPath,
675 dwLength);
676 if (Error != ERROR_SUCCESS)
677 {
678 DPRINT1("Error: %lu\n", Error);
679 RegCloseKey(hKey);
680 SetLastError((DWORD)Error);
681 return FALSE;
682 }
683
684 dwLength = (wcslen(szCommonFilesDirPath) + 1) * sizeof(WCHAR);
685 Error = RegSetValueExW(hKey,
686 L"CommonFilesDir",
687 0,
688 REG_SZ,
689 (LPBYTE)szCommonFilesDirPath,
690 dwLength);
691 if (Error != ERROR_SUCCESS)
692 {
693 DPRINT1("Warning: %lu\n", Error);
694 }
695
696 RegCloseKey(hKey);
697
698 /* Create directory */
699 if (!CreateDirectoryW(szProfilesPath, NULL))
700 {
701 if (GetLastError() != ERROR_ALREADY_EXISTS)
702 {
703 DPRINT1("Error: %lu\n", GetLastError());
704 return FALSE;
705 }
706 }
707
708 /* Create directory */
709 if (!CreateDirectoryW(szCommonFilesDirPath, NULL))
710 {
711 if (GetLastError() != ERROR_ALREADY_EXISTS)
712 {
713 DPRINT1("Warning: %lu\n", GetLastError());
714 }
715 }
716
717 DPRINT("Success\n");
718
719 return TRUE;
720 }
721
722
723 BOOL
724 UpdateUsersShellFolderSettings(LPCWSTR lpUserProfilePath,
725 HKEY hUserKey)
726 {
727 WCHAR szBuffer[MAX_PATH];
728 DWORD dwLength;
729 PFOLDERDATA lpFolderData;
730 HKEY hFoldersKey;
731 LONG Error;
732
733 DPRINT("UpdateUsersShellFolderSettings() called\n");
734
735 DPRINT("User profile path: %S\n", lpUserProfilePath);
736
737 Error = RegOpenKeyExW(hUserKey,
738 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
739 0,
740 KEY_SET_VALUE,
741 &hFoldersKey);
742 if (Error != ERROR_SUCCESS)
743 {
744 DPRINT1("Error: %lu\n", Error);
745 SetLastError((DWORD)Error);
746 return FALSE;
747 }
748
749 lpFolderData = &UserShellFolders[0];
750 while (lpFolderData->lpValueName != NULL)
751 {
752 if (lpFolderData->bShellFolder)
753 {
754 wcscpy(szBuffer, lpUserProfilePath);
755 wcscat(szBuffer, L"\\");
756
757 /* Append the folder name */
758 dwLength = wcslen(szBuffer);
759 if (!LoadStringW(hInstance,
760 lpFolderData->uId,
761 &szBuffer[dwLength],
762 ARRAYSIZE(szBuffer) - dwLength))
763 {
764 /* Use the default name instead */
765 wcscat(szBuffer, lpFolderData->lpPath);
766 }
767
768 DPRINT("%S: %S\n", lpFolderData->lpValueName, szBuffer);
769
770 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
771 Error = RegSetValueExW(hFoldersKey,
772 lpFolderData->lpValueName,
773 0,
774 REG_SZ,
775 (LPBYTE)szBuffer,
776 dwLength);
777 if (Error != ERROR_SUCCESS)
778 {
779 DPRINT1("Error: %lu\n", Error);
780 RegCloseKey(hFoldersKey);
781 SetLastError((DWORD)Error);
782 return FALSE;
783 }
784 }
785
786 lpFolderData++;
787 }
788
789 RegCloseKey(hFoldersKey);
790
791 DPRINT("UpdateUsersShellFolderSettings() done\n");
792
793 return TRUE;
794 }
795
796 /* EOF */