[SETUPLIB][USETUP] Move the registry-update procedure into setuplib.
[reactos.git] / base / setup / lib / setuplib.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Setup Library
4 * FILE: base/setup/lib/setuplib.c
5 * PURPOSE: Setup Library - Main initialization helpers
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8 */
9
10 /* INCLUDES *****************************************************************/
11
12 #include "precomp.h"
13 #include "filesup.h"
14 #include "infsupp.h"
15 #include "inicache.h"
16
17 #include "setuplib.h"
18
19 #define NDEBUG
20 #include <debug.h>
21
22
23 /* GLOBALS ******************************************************************/
24
25 /* FUNCTIONS ****************************************************************/
26
27 VOID
28 CheckUnattendedSetup(
29 IN OUT PUSETUP_DATA pSetupData)
30 {
31 INFCONTEXT Context;
32 HINF UnattendInf;
33 UINT ErrorLine;
34 INT IntValue;
35 PWCHAR Value;
36 WCHAR UnattendInfPath[MAX_PATH];
37
38 CombinePaths(UnattendInfPath, ARRAYSIZE(UnattendInfPath), 2,
39 pSetupData->SourcePath.Buffer, L"unattend.inf");
40
41 DPRINT("UnattendInf path: '%S'\n", UnattendInfPath);
42
43 if (DoesFileExist(NULL, UnattendInfPath) == FALSE)
44 {
45 DPRINT("Does not exist: %S\n", UnattendInfPath);
46 return;
47 }
48
49 /* Load 'unattend.inf' from installation media */
50 UnattendInf = SetupOpenInfFileExW(UnattendInfPath,
51 NULL,
52 INF_STYLE_OLDNT,
53 pSetupData->LanguageId,
54 &ErrorLine);
55
56 if (UnattendInf == INVALID_HANDLE_VALUE)
57 {
58 DPRINT("SetupOpenInfFileExW() failed\n");
59 return;
60 }
61
62 /* Open 'Unattend' section */
63 if (!SetupFindFirstLineW(UnattendInf, L"Unattend", L"Signature", &Context))
64 {
65 DPRINT("SetupFindFirstLineW() failed for section 'Unattend'\n");
66 goto Quit;
67 }
68
69 /* Get pointer 'Signature' key */
70 if (!INF_GetData(&Context, NULL, &Value))
71 {
72 DPRINT("INF_GetData() failed for key 'Signature'\n");
73 goto Quit;
74 }
75
76 /* Check 'Signature' string */
77 if (_wcsicmp(Value, L"$ReactOS$") != 0)
78 {
79 DPRINT("Signature not $ReactOS$\n");
80 INF_FreeData(Value);
81 goto Quit;
82 }
83
84 INF_FreeData(Value);
85
86 /* Check if Unattend setup is enabled */
87 if (!SetupFindFirstLineW(UnattendInf, L"Unattend", L"UnattendSetupEnabled", &Context))
88 {
89 DPRINT("Can't find key 'UnattendSetupEnabled'\n");
90 goto Quit;
91 }
92
93 if (!INF_GetData(&Context, NULL, &Value))
94 {
95 DPRINT("Can't read key 'UnattendSetupEnabled'\n");
96 goto Quit;
97 }
98
99 if (_wcsicmp(Value, L"yes") != 0)
100 {
101 DPRINT("Unattend setup is disabled by 'UnattendSetupEnabled' key!\n");
102 INF_FreeData(Value);
103 goto Quit;
104 }
105
106 INF_FreeData(Value);
107
108 /* Search for 'DestinationDiskNumber' in the 'Unattend' section */
109 if (!SetupFindFirstLineW(UnattendInf, L"Unattend", L"DestinationDiskNumber", &Context))
110 {
111 DPRINT("SetupFindFirstLine() failed for key 'DestinationDiskNumber'\n");
112 goto Quit;
113 }
114
115 if (!SetupGetIntField(&Context, 1, &IntValue))
116 {
117 DPRINT("SetupGetIntField() failed for key 'DestinationDiskNumber'\n");
118 goto Quit;
119 }
120
121 pSetupData->DestinationDiskNumber = (LONG)IntValue;
122
123 /* Search for 'DestinationPartitionNumber' in the 'Unattend' section */
124 if (!SetupFindFirstLineW(UnattendInf, L"Unattend", L"DestinationPartitionNumber", &Context))
125 {
126 DPRINT("SetupFindFirstLine() failed for key 'DestinationPartitionNumber'\n");
127 goto Quit;
128 }
129
130 if (!SetupGetIntField(&Context, 1, &IntValue))
131 {
132 DPRINT("SetupGetIntField() failed for key 'DestinationPartitionNumber'\n");
133 goto Quit;
134 }
135
136 pSetupData->DestinationPartitionNumber = (LONG)IntValue;
137
138 /* Search for 'InstallationDirectory' in the 'Unattend' section (optional) */
139 if (SetupFindFirstLineW(UnattendInf, L"Unattend", L"InstallationDirectory", &Context))
140 {
141 /* Get pointer 'InstallationDirectory' key */
142 if (!INF_GetData(&Context, NULL, &Value))
143 {
144 DPRINT("INF_GetData() failed for key 'InstallationDirectory'\n");
145 goto Quit;
146 }
147
148 RtlStringCchCopyW(pSetupData->InstallationDirectory,
149 ARRAYSIZE(pSetupData->InstallationDirectory),
150 Value);
151
152 INF_FreeData(Value);
153 }
154
155 IsUnattendedSetup = TRUE;
156 DPRINT("Running unattended setup\n");
157
158 /* Search for 'MBRInstallType' in the 'Unattend' section */
159 pSetupData->MBRInstallType = -1;
160 if (SetupFindFirstLineW(UnattendInf, L"Unattend", L"MBRInstallType", &Context))
161 {
162 if (SetupGetIntField(&Context, 1, &IntValue))
163 {
164 pSetupData->MBRInstallType = IntValue;
165 }
166 }
167
168 /* Search for 'FormatPartition' in the 'Unattend' section */
169 pSetupData->FormatPartition = 0;
170 if (SetupFindFirstLineW(UnattendInf, L"Unattend", L"FormatPartition", &Context))
171 {
172 if (SetupGetIntField(&Context, 1, &IntValue))
173 {
174 pSetupData->FormatPartition = IntValue;
175 }
176 }
177
178 pSetupData->AutoPartition = 0;
179 if (SetupFindFirstLineW(UnattendInf, L"Unattend", L"AutoPartition", &Context))
180 {
181 if (SetupGetIntField(&Context, 1, &IntValue))
182 {
183 pSetupData->AutoPartition = IntValue;
184 }
185 }
186
187 /* Search for LocaleID in the 'Unattend' section */
188 if (SetupFindFirstLineW(UnattendInf, L"Unattend", L"LocaleID", &Context))
189 {
190 if (INF_GetData(&Context, NULL, &Value))
191 {
192 LONG Id = wcstol(Value, NULL, 16);
193 RtlStringCchPrintfW(pSetupData->LocaleID,
194 ARRAYSIZE(pSetupData->LocaleID),
195 L"%08lx", Id);
196 INF_FreeData(Value);
197 }
198 }
199
200 Quit:
201 SetupCloseInfFile(UnattendInf);
202 }
203
204 VOID
205 InstallSetupInfFile(
206 IN OUT PUSETUP_DATA pSetupData)
207 {
208 NTSTATUS Status;
209 PINICACHE IniCache;
210
211 #if 0 // HACK FIXME!
212 PINICACHE UnattendCache;
213 PINICACHEITERATOR Iterator;
214 #else
215 // WCHAR CrLf[] = {L'\r', L'\n'};
216 CHAR CrLf[] = {'\r', '\n'};
217 HANDLE FileHandle, UnattendFileHandle, SectionHandle;
218 FILE_STANDARD_INFORMATION FileInfo;
219 ULONG FileSize;
220 PVOID ViewBase;
221 UNICODE_STRING FileName;
222 OBJECT_ATTRIBUTES ObjectAttributes;
223 IO_STATUS_BLOCK IoStatusBlock;
224 #endif
225
226 PINICACHESECTION IniSection;
227 WCHAR PathBuffer[MAX_PATH];
228 WCHAR UnattendInfPath[MAX_PATH];
229
230 /* Create a $winnt$.inf file with default entries */
231 IniCache = IniCacheCreate();
232 if (!IniCache)
233 return;
234
235 IniSection = IniCacheAppendSection(IniCache, L"SetupParams");
236 if (IniSection)
237 {
238 /* Key "skipmissingfiles" */
239 // RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
240 // L"\"%s\"", L"WinNt5.2");
241 // IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
242 // L"Version", PathBuffer);
243 }
244
245 IniSection = IniCacheAppendSection(IniCache, L"Data");
246 if (IniSection)
247 {
248 RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
249 L"\"%s\"", IsUnattendedSetup ? L"yes" : L"no");
250 IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
251 L"UnattendedInstall", PathBuffer);
252
253 // "floppylessbootpath" (yes/no)
254
255 RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
256 L"\"%s\"", L"winnt");
257 IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
258 L"ProductType", PathBuffer);
259
260 RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
261 L"\"%s\\\"", pSetupData->SourceRootPath.Buffer);
262 IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
263 L"SourcePath", PathBuffer);
264
265 // "floppyless" ("0")
266 }
267
268 #if 0
269
270 /* TODO: Append the standard unattend.inf file */
271 CombinePaths(UnattendInfPath, ARRAYSIZE(UnattendInfPath), 2,
272 pSetupData->SourcePath.Buffer, L"unattend.inf");
273 if (DoesFileExist(NULL, UnattendInfPath) == FALSE)
274 {
275 DPRINT("Does not exist: %S\n", UnattendInfPath);
276 goto Quit;
277 }
278
279 Status = IniCacheLoad(&UnattendCache, UnattendInfPath, FALSE);
280 if (!NT_SUCCESS(Status))
281 {
282 DPRINT1("Cannot load %S as an INI file!\n", UnattendInfPath);
283 goto Quit;
284 }
285
286 IniCacheDestroy(UnattendCache);
287
288 Quit:
289 CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2,
290 pSetupData->DestinationPath.Buffer, L"System32\\$winnt$.inf");
291 IniCacheSave(IniCache, PathBuffer);
292 IniCacheDestroy(IniCache);
293
294 #else
295
296 CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2,
297 pSetupData->DestinationPath.Buffer, L"System32\\$winnt$.inf");
298 IniCacheSave(IniCache, PathBuffer);
299 IniCacheDestroy(IniCache);
300
301 /* TODO: Append the standard unattend.inf file */
302 CombinePaths(UnattendInfPath, ARRAYSIZE(UnattendInfPath), 2,
303 pSetupData->SourcePath.Buffer, L"unattend.inf");
304 if (DoesFileExist(NULL, UnattendInfPath) == FALSE)
305 {
306 DPRINT("Does not exist: %S\n", UnattendInfPath);
307 return;
308 }
309
310 RtlInitUnicodeString(&FileName, PathBuffer);
311 InitializeObjectAttributes(&ObjectAttributes,
312 &FileName,
313 OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
314 NULL,
315 NULL);
316 Status = NtOpenFile(&FileHandle,
317 FILE_APPEND_DATA | SYNCHRONIZE,
318 &ObjectAttributes,
319 &IoStatusBlock,
320 FILE_SHARE_READ,
321 FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);
322 if (!NT_SUCCESS(Status))
323 {
324 DPRINT1("Cannot load %S as an INI file!\n", PathBuffer);
325 return;
326 }
327
328 /* Query the file size */
329 Status = NtQueryInformationFile(FileHandle,
330 &IoStatusBlock,
331 &FileInfo,
332 sizeof(FileInfo),
333 FileStandardInformation);
334 if (!NT_SUCCESS(Status))
335 {
336 DPRINT("NtQueryInformationFile() failed (Status %lx)\n", Status);
337 FileInfo.EndOfFile.QuadPart = 0ULL;
338 }
339
340 Status = OpenAndMapFile(NULL,
341 UnattendInfPath,
342 &UnattendFileHandle,
343 &SectionHandle,
344 &ViewBase,
345 &FileSize,
346 FALSE);
347 if (!NT_SUCCESS(Status))
348 {
349 DPRINT1("Cannot load %S !\n", UnattendInfPath);
350 NtClose(FileHandle);
351 return;
352 }
353
354 /* Write to the INI file */
355
356 /* "\r\n" */
357 Status = NtWriteFile(FileHandle,
358 NULL,
359 NULL,
360 NULL,
361 &IoStatusBlock,
362 (PVOID)CrLf,
363 sizeof(CrLf),
364 &FileInfo.EndOfFile,
365 NULL);
366
367 Status = NtWriteFile(FileHandle,
368 NULL,
369 NULL,
370 NULL,
371 &IoStatusBlock,
372 ViewBase,
373 FileSize,
374 NULL,
375 NULL);
376 if (!NT_SUCCESS(Status))
377 {
378 DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
379 }
380
381 /* Finally, unmap and close the file */
382 UnMapAndCloseFile(UnattendFileHandle, SectionHandle, ViewBase);
383
384 NtClose(FileHandle);
385 #endif
386 }
387
388 NTSTATUS
389 GetSourcePaths(
390 OUT PUNICODE_STRING SourcePath,
391 OUT PUNICODE_STRING SourceRootPath,
392 OUT PUNICODE_STRING SourceRootDir)
393 {
394 NTSTATUS Status;
395 HANDLE Handle;
396 OBJECT_ATTRIBUTES ObjectAttributes;
397 UCHAR ImageFileBuffer[sizeof(UNICODE_STRING) + MAX_PATH * sizeof(WCHAR)];
398 PUNICODE_STRING InstallSourcePath = (PUNICODE_STRING)&ImageFileBuffer;
399 WCHAR SystemRootBuffer[MAX_PATH] = L"";
400 UNICODE_STRING SystemRootPath = RTL_CONSTANT_STRING(L"\\SystemRoot");
401 ULONG BufferSize;
402 PWCHAR Ptr;
403
404 /* Determine the installation source path via the full path of the installer */
405 RtlInitEmptyUnicodeString(InstallSourcePath,
406 (PWSTR)((ULONG_PTR)ImageFileBuffer + sizeof(UNICODE_STRING)),
407 sizeof(ImageFileBuffer) - sizeof(UNICODE_STRING)
408 /* Reserve space for a NULL terminator */ - sizeof(UNICODE_NULL));
409 BufferSize = sizeof(ImageFileBuffer);
410 Status = NtQueryInformationProcess(NtCurrentProcess(),
411 ProcessImageFileName,
412 InstallSourcePath,
413 BufferSize,
414 NULL);
415 // STATUS_INFO_LENGTH_MISMATCH or STATUS_BUFFER_TOO_SMALL ?
416 if (!NT_SUCCESS(Status))
417 return Status;
418
419 /* Manually NULL-terminate */
420 InstallSourcePath->Buffer[InstallSourcePath->Length / sizeof(WCHAR)] = UNICODE_NULL;
421
422 /* Strip the trailing file name */
423 Ptr = wcsrchr(InstallSourcePath->Buffer, OBJ_NAME_PATH_SEPARATOR);
424 if (Ptr)
425 *Ptr = UNICODE_NULL;
426 InstallSourcePath->Length = wcslen(InstallSourcePath->Buffer) * sizeof(WCHAR);
427
428
429 /*
430 * Now resolve the full path to \SystemRoot. In case it prefixes
431 * the installation source path determined from the full path of
432 * the installer, we use instead the resolved \SystemRoot as the
433 * installation source path.
434 * Otherwise, we use instead the path from the full installer path.
435 */
436
437 InitializeObjectAttributes(&ObjectAttributes,
438 &SystemRootPath,
439 OBJ_CASE_INSENSITIVE,
440 NULL,
441 NULL);
442
443 Status = NtOpenSymbolicLinkObject(&Handle,
444 SYMBOLIC_LINK_QUERY,
445 &ObjectAttributes);
446 if (!NT_SUCCESS(Status))
447 {
448 /*
449 * We failed at opening the \SystemRoot link (usually due to wrong
450 * access rights). Do not consider this as a fatal error, but use
451 * instead the image file path as the installation source path.
452 */
453 DPRINT1("NtOpenSymbolicLinkObject(%wZ) failed with Status 0x%08lx\n",
454 &SystemRootPath, Status);
455 goto InitPaths;
456 }
457
458 RtlInitEmptyUnicodeString(&SystemRootPath,
459 SystemRootBuffer,
460 sizeof(SystemRootBuffer));
461
462 Status = NtQuerySymbolicLinkObject(Handle,
463 &SystemRootPath,
464 &BufferSize);
465 NtClose(Handle);
466
467 if (!NT_SUCCESS(Status))
468 return Status; // Unexpected error
469
470 /* Check whether the resolved \SystemRoot is a prefix of the image file path */
471 if (RtlPrefixUnicodeString(&SystemRootPath, InstallSourcePath, TRUE))
472 {
473 /* Yes it is, so we use instead SystemRoot as the installation source path */
474 InstallSourcePath = &SystemRootPath;
475 }
476
477
478 InitPaths:
479 /*
480 * Retrieve the different source path components
481 */
482 RtlCreateUnicodeString(SourcePath, InstallSourcePath->Buffer);
483
484 /* Strip trailing directory */
485 Ptr = wcsrchr(InstallSourcePath->Buffer, OBJ_NAME_PATH_SEPARATOR);
486 if (Ptr)
487 {
488 RtlCreateUnicodeString(SourceRootDir, Ptr);
489 *Ptr = UNICODE_NULL;
490 }
491 else
492 {
493 RtlCreateUnicodeString(SourceRootDir, L"");
494 }
495
496 RtlCreateUnicodeString(SourceRootPath, InstallSourcePath->Buffer);
497
498 return STATUS_SUCCESS;
499 }
500
501 ERROR_NUMBER
502 LoadSetupInf(
503 OUT HINF* SetupInf,
504 IN OUT PUSETUP_DATA pSetupData)
505 {
506 INFCONTEXT Context;
507 UINT ErrorLine;
508 INT IntValue;
509 PWCHAR Value;
510 WCHAR FileNameBuffer[MAX_PATH];
511
512 CombinePaths(FileNameBuffer, ARRAYSIZE(FileNameBuffer), 2,
513 pSetupData->SourcePath.Buffer, L"txtsetup.sif");
514
515 DPRINT("SetupInf path: '%S'\n", FileNameBuffer);
516
517 *SetupInf = SetupOpenInfFileExW(FileNameBuffer,
518 NULL,
519 /* INF_STYLE_WIN4 | */ INF_STYLE_OLDNT,
520 pSetupData->LanguageId,
521 &ErrorLine);
522
523 if (*SetupInf == INVALID_HANDLE_VALUE)
524 return ERROR_LOAD_TXTSETUPSIF;
525
526 /* Open 'Version' section */
527 if (!SetupFindFirstLineW(*SetupInf, L"Version", L"Signature", &Context))
528 return ERROR_CORRUPT_TXTSETUPSIF;
529
530 /* Get pointer 'Signature' key */
531 if (!INF_GetData(&Context, NULL, &Value))
532 return ERROR_CORRUPT_TXTSETUPSIF;
533
534 /* Check 'Signature' string */
535 if (_wcsicmp(Value, L"$ReactOS$") != 0)
536 {
537 INF_FreeData(Value);
538 return ERROR_SIGNATURE_TXTSETUPSIF;
539 }
540
541 INF_FreeData(Value);
542
543 /* Open 'DiskSpaceRequirements' section */
544 if (!SetupFindFirstLineW(*SetupInf, L"DiskSpaceRequirements", L"FreeSysPartDiskSpace", &Context))
545 return ERROR_CORRUPT_TXTSETUPSIF;
546
547 pSetupData->RequiredPartitionDiskSpace = ~0;
548
549 /* Get the 'FreeSysPartDiskSpace' value */
550 if (!SetupGetIntField(&Context, 1, &IntValue))
551 return ERROR_CORRUPT_TXTSETUPSIF;
552
553 pSetupData->RequiredPartitionDiskSpace = (ULONG)IntValue;
554
555 //
556 // TODO: Support "SetupSourceDevice" and "SetupSourcePath" in txtsetup.sif
557 // See CORE-9023
558 //
559
560 /* Search for 'DefaultPath' in the 'SetupData' section */
561 if (SetupFindFirstLineW(*SetupInf, L"SetupData", L"DefaultPath", &Context))
562 {
563 /* Get pointer 'DefaultPath' key */
564 if (!INF_GetData(&Context, NULL, &Value))
565 return ERROR_CORRUPT_TXTSETUPSIF;
566
567 RtlStringCchCopyW(pSetupData->InstallationDirectory,
568 ARRAYSIZE(pSetupData->InstallationDirectory),
569 Value);
570
571 INF_FreeData(Value);
572 }
573
574 return ERROR_SUCCESS;
575 }
576
577 /*
578 * SIDEEFFECTS
579 * Calls RegInitializeRegistry
580 * Calls ImportRegistryFile
581 * Calls SetDefaultPagefile
582 * Calls SetMountedDeviceValues
583 */
584 ERROR_NUMBER
585 UpdateRegistry(
586 IN HINF SetupInf,
587 IN OUT PUSETUP_DATA pSetupData,
588 /**/IN BOOLEAN RepairUpdateFlag, /* HACK HACK! */
589 /**/IN PPARTLIST PartitionList, /* HACK HACK! */
590 /**/IN WCHAR DestinationDriveLetter, /* HACK HACK! */
591 /**/IN PCWSTR SelectedLanguageId, /* HACK HACK! */
592 IN PGENERIC_LIST DisplayList,
593 IN PGENERIC_LIST LayoutList,
594 IN PGENERIC_LIST LanguageList,
595 IN PREGISTRY_STATUS_ROUTINE StatusRoutine OPTIONAL)
596 {
597 ERROR_NUMBER ErrorNumber;
598 NTSTATUS Status;
599 INFCONTEXT InfContext;
600 PWSTR Action;
601 PWSTR File;
602 PWSTR Section;
603 BOOLEAN Success;
604 BOOLEAN ShouldRepairRegistry = FALSE;
605 BOOLEAN Delete;
606
607 if (RepairUpdateFlag)
608 {
609 DPRINT1("TODO: Updating / repairing the registry is not completely implemented yet!\n");
610
611 /* Verify the registry hives and check whether we need to update or repair any of them */
612 Status = VerifyRegistryHives(&pSetupData->DestinationPath, &ShouldRepairRegistry);
613 if (!NT_SUCCESS(Status))
614 {
615 DPRINT1("VerifyRegistryHives failed, Status 0x%08lx\n", Status);
616 ShouldRepairRegistry = FALSE;
617 }
618 if (!ShouldRepairRegistry)
619 DPRINT1("No need to repair the registry\n");
620 }
621
622 DoUpdate:
623 ErrorNumber = ERROR_SUCCESS;
624
625 /* Update the registry */
626 if (StatusRoutine) StatusRoutine(RegHiveUpdate);
627
628 /* Initialize the registry and setup the registry hives */
629 Status = RegInitializeRegistry(&pSetupData->DestinationPath);
630 if (!NT_SUCCESS(Status))
631 {
632 DPRINT1("RegInitializeRegistry() failed\n");
633 /********** HACK!!!!!!!!!!! **********/
634 if (Status == STATUS_NOT_IMPLEMENTED)
635 {
636 /* The hack was called, return its corresponding error */
637 return ERROR_INITIALIZE_REGISTRY;
638 }
639 else
640 /*************************************/
641 {
642 /* Something else failed */
643 return ERROR_CREATE_HIVE;
644 }
645 }
646
647 if (!RepairUpdateFlag || ShouldRepairRegistry)
648 {
649 /*
650 * We fully setup the hives, in case we are doing a fresh installation
651 * (RepairUpdateFlag == FALSE), or in case we are doing an update
652 * (RepairUpdateFlag == TRUE) BUT we have some registry hives to
653 * "repair" (aka. recreate: ShouldRepairRegistry == TRUE).
654 */
655
656 Success = SetupFindFirstLineW(SetupInf, L"HiveInfs.Fresh", NULL, &InfContext); // Windows-compatible
657 if (!Success)
658 Success = SetupFindFirstLineW(SetupInf, L"HiveInfs.Install", NULL, &InfContext); // ReactOS-specific
659
660 if (!Success)
661 {
662 DPRINT1("SetupFindFirstLine() failed\n");
663 ErrorNumber = ERROR_FIND_REGISTRY;
664 goto Cleanup;
665 }
666 }
667 else // if (RepairUpdateFlag && !ShouldRepairRegistry)
668 {
669 /*
670 * In case we are doing an update (RepairUpdateFlag == TRUE) and
671 * NO registry hives need a repair (ShouldRepairRegistry == FALSE),
672 * we only update the hives.
673 */
674
675 Success = SetupFindFirstLineW(SetupInf, L"HiveInfs.Upgrade", NULL, &InfContext);
676 if (!Success)
677 {
678 /* Nothing to do for update! */
679 DPRINT1("No update needed for the registry!\n");
680 goto Cleanup;
681 }
682 }
683
684 do
685 {
686 INF_GetDataField(&InfContext, 0, &Action);
687 INF_GetDataField(&InfContext, 1, &File);
688 INF_GetDataField(&InfContext, 2, &Section);
689
690 DPRINT("Action: %S File: %S Section %S\n", Action, File, Section);
691
692 if (Action == NULL)
693 {
694 INF_FreeData(Action);
695 INF_FreeData(File);
696 INF_FreeData(Section);
697 break; // Hackfix
698 }
699
700 if (!_wcsicmp(Action, L"AddReg"))
701 Delete = FALSE;
702 else if (!_wcsicmp(Action, L"DelReg"))
703 Delete = TRUE;
704 else
705 {
706 DPRINT1("Unrecognized registry INF action '%S'\n", Action);
707 INF_FreeData(Action);
708 INF_FreeData(File);
709 INF_FreeData(Section);
710 continue;
711 }
712
713 INF_FreeData(Action);
714
715 if (StatusRoutine) StatusRoutine(ImportRegHive, File);
716
717 if (!ImportRegistryFile(pSetupData->SourcePath.Buffer,
718 File, Section,
719 pSetupData->LanguageId, Delete))
720 {
721 DPRINT1("Importing %S failed\n", File);
722 INF_FreeData(File);
723 INF_FreeData(Section);
724 ErrorNumber = ERROR_IMPORT_HIVE;
725 goto Cleanup;
726 }
727 } while (SetupFindNextLine(&InfContext, &InfContext));
728
729 if (!RepairUpdateFlag || ShouldRepairRegistry)
730 {
731 /* See the explanation for this test above */
732
733 /* Update display registry settings */
734 if (StatusRoutine) StatusRoutine(DisplaySettingsUpdate);
735 if (!ProcessDisplayRegistry(SetupInf, DisplayList))
736 {
737 ErrorNumber = ERROR_UPDATE_DISPLAY_SETTINGS;
738 goto Cleanup;
739 }
740
741 /* Set the locale */
742 if (StatusRoutine) StatusRoutine(LocaleSettingsUpdate);
743 if (!ProcessLocaleRegistry(LanguageList))
744 {
745 ErrorNumber = ERROR_UPDATE_LOCALESETTINGS;
746 goto Cleanup;
747 }
748
749 /* Add keyboard layouts */
750 if (StatusRoutine) StatusRoutine(KeybLayouts);
751 if (!AddKeyboardLayouts(SelectedLanguageId))
752 {
753 ErrorNumber = ERROR_ADDING_KBLAYOUTS;
754 goto Cleanup;
755 }
756
757 /* Set GeoID */
758 if (!SetGeoID(MUIGetGeoID(SelectedLanguageId)))
759 {
760 ErrorNumber = ERROR_UPDATE_GEOID;
761 goto Cleanup;
762 }
763
764 if (!IsUnattendedSetup)
765 {
766 /* Update keyboard layout settings */
767 if (StatusRoutine) StatusRoutine(KeybSettingsUpdate);
768 if (!ProcessKeyboardLayoutRegistry(LayoutList, SelectedLanguageId))
769 {
770 ErrorNumber = ERROR_UPDATE_KBSETTINGS;
771 goto Cleanup;
772 }
773 }
774
775 /* Add codepage information to registry */
776 if (StatusRoutine) StatusRoutine(CodePageInfoUpdate);
777 if (!AddCodePage(SelectedLanguageId))
778 {
779 ErrorNumber = ERROR_ADDING_CODEPAGE;
780 goto Cleanup;
781 }
782
783 /* Set the default pagefile entry */
784 SetDefaultPagefile(DestinationDriveLetter);
785
786 /* Update the mounted devices list */
787 // FIXME: This should technically be done by mountmgr (if AutoMount is enabled)!
788 SetMountedDeviceValues(PartitionList);
789 }
790
791 Cleanup:
792 //
793 // TODO: Unload all the registry stuff, perform cleanup,
794 // and copy the created hive files into .sav files.
795 //
796 RegCleanupRegistry(&pSetupData->DestinationPath);
797
798 /*
799 * Check whether we were in update/repair mode but we were actually
800 * repairing the registry hives. If so, we have finished repairing them,
801 * and we now reset the flag and run the proper registry update.
802 * Otherwise we have finished the registry update!
803 */
804 if (RepairUpdateFlag && ShouldRepairRegistry)
805 {
806 ShouldRepairRegistry = FALSE;
807 goto DoUpdate;
808 }
809
810 return ErrorNumber;
811 }
812
813 /* EOF */