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)
10 /* INCLUDES *****************************************************************/
23 /* GLOBALS ******************************************************************/
25 /* FUNCTIONS ****************************************************************/
29 IN OUT PUSETUP_DATA pSetupData
)
36 WCHAR UnattendInfPath
[MAX_PATH
];
38 CombinePaths(UnattendInfPath
, ARRAYSIZE(UnattendInfPath
), 2,
39 pSetupData
->SourcePath
.Buffer
, L
"unattend.inf");
41 DPRINT("UnattendInf path: '%S'\n", UnattendInfPath
);
43 if (DoesFileExist(NULL
, UnattendInfPath
) == FALSE
)
45 DPRINT("Does not exist: %S\n", UnattendInfPath
);
49 /* Load 'unattend.inf' from installation media */
50 UnattendInf
= SpInfOpenInfFile(UnattendInfPath
,
53 pSetupData
->LanguageId
,
55 if (UnattendInf
== INVALID_HANDLE_VALUE
)
57 DPRINT("SpInfOpenInfFile() failed\n");
61 /* Open 'Unattend' section */
62 if (!SpInfFindFirstLine(UnattendInf
, L
"Unattend", L
"Signature", &Context
))
64 DPRINT("SpInfFindFirstLine() failed for section 'Unattend'\n");
68 /* Get pointer 'Signature' key */
69 if (!INF_GetData(&Context
, NULL
, &Value
))
71 DPRINT("INF_GetData() failed for key 'Signature'\n");
75 /* Check 'Signature' string */
76 if (_wcsicmp(Value
, L
"$ReactOS$") != 0)
78 DPRINT("Signature not $ReactOS$\n");
85 /* Check if Unattend setup is enabled */
86 if (!SpInfFindFirstLine(UnattendInf
, L
"Unattend", L
"UnattendSetupEnabled", &Context
))
88 DPRINT("Can't find key 'UnattendSetupEnabled'\n");
92 if (!INF_GetData(&Context
, NULL
, &Value
))
94 DPRINT("Can't read key 'UnattendSetupEnabled'\n");
98 if (_wcsicmp(Value
, L
"yes") != 0)
100 DPRINT("Unattend setup is disabled by 'UnattendSetupEnabled' key!\n");
107 /* Search for 'DestinationDiskNumber' in the 'Unattend' section */
108 if (!SpInfFindFirstLine(UnattendInf
, L
"Unattend", L
"DestinationDiskNumber", &Context
))
110 DPRINT("SpInfFindFirstLine() failed for key 'DestinationDiskNumber'\n");
114 if (!SpInfGetIntField(&Context
, 1, &IntValue
))
116 DPRINT("SpInfGetIntField() failed for key 'DestinationDiskNumber'\n");
120 pSetupData
->DestinationDiskNumber
= (LONG
)IntValue
;
122 /* Search for 'DestinationPartitionNumber' in the 'Unattend' section */
123 if (!SpInfFindFirstLine(UnattendInf
, L
"Unattend", L
"DestinationPartitionNumber", &Context
))
125 DPRINT("SpInfFindFirstLine() failed for key 'DestinationPartitionNumber'\n");
129 if (!SpInfGetIntField(&Context
, 1, &IntValue
))
131 DPRINT("SpInfGetIntField() failed for key 'DestinationPartitionNumber'\n");
135 pSetupData
->DestinationPartitionNumber
= (LONG
)IntValue
;
137 /* Search for 'InstallationDirectory' in the 'Unattend' section (optional) */
138 if (SpInfFindFirstLine(UnattendInf
, L
"Unattend", L
"InstallationDirectory", &Context
))
140 /* Get pointer 'InstallationDirectory' key */
141 if (!INF_GetData(&Context
, NULL
, &Value
))
143 DPRINT("INF_GetData() failed for key 'InstallationDirectory'\n");
147 RtlStringCchCopyW(pSetupData
->InstallationDirectory
,
148 ARRAYSIZE(pSetupData
->InstallationDirectory
),
154 IsUnattendedSetup
= TRUE
;
155 DPRINT("Running unattended setup\n");
157 /* Search for 'MBRInstallType' in the 'Unattend' section */
158 pSetupData
->MBRInstallType
= -1;
159 if (SpInfFindFirstLine(UnattendInf
, L
"Unattend", L
"MBRInstallType", &Context
))
161 if (SpInfGetIntField(&Context
, 1, &IntValue
))
163 pSetupData
->MBRInstallType
= IntValue
;
167 /* Search for 'FormatPartition' in the 'Unattend' section */
168 pSetupData
->FormatPartition
= 0;
169 if (SpInfFindFirstLine(UnattendInf
, L
"Unattend", L
"FormatPartition", &Context
))
171 if (SpInfGetIntField(&Context
, 1, &IntValue
))
173 pSetupData
->FormatPartition
= IntValue
;
177 pSetupData
->AutoPartition
= 0;
178 if (SpInfFindFirstLine(UnattendInf
, L
"Unattend", L
"AutoPartition", &Context
))
180 if (SpInfGetIntField(&Context
, 1, &IntValue
))
182 pSetupData
->AutoPartition
= IntValue
;
186 /* Search for LocaleID in the 'Unattend' section */
187 if (SpInfFindFirstLine(UnattendInf
, L
"Unattend", L
"LocaleID", &Context
))
189 if (INF_GetData(&Context
, NULL
, &Value
))
191 LONG Id
= wcstol(Value
, NULL
, 16);
192 RtlStringCchPrintfW(pSetupData
->LocaleID
,
193 ARRAYSIZE(pSetupData
->LocaleID
),
200 SpInfCloseInfFile(UnattendInf
);
205 IN OUT PUSETUP_DATA pSetupData
)
211 PINICACHE UnattendCache
;
212 PINICACHEITERATOR Iterator
;
214 // WCHAR CrLf[] = {L'\r', L'\n'};
215 CHAR CrLf
[] = {'\r', '\n'};
216 HANDLE FileHandle
, UnattendFileHandle
, SectionHandle
;
217 FILE_STANDARD_INFORMATION FileInfo
;
220 UNICODE_STRING FileName
;
221 OBJECT_ATTRIBUTES ObjectAttributes
;
222 IO_STATUS_BLOCK IoStatusBlock
;
225 PINICACHESECTION IniSection
;
226 WCHAR PathBuffer
[MAX_PATH
];
227 WCHAR UnattendInfPath
[MAX_PATH
];
229 /* Create a $winnt$.inf file with default entries */
230 IniCache
= IniCacheCreate();
234 IniSection
= IniCacheAppendSection(IniCache
, L
"SetupParams");
237 /* Key "skipmissingfiles" */
238 // RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
239 // L"\"%s\"", L"WinNt5.2");
240 // IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
241 // L"Version", PathBuffer);
244 IniSection
= IniCacheAppendSection(IniCache
, L
"Data");
247 RtlStringCchPrintfW(PathBuffer
, ARRAYSIZE(PathBuffer
),
248 L
"\"%s\"", IsUnattendedSetup
? L
"yes" : L
"no");
249 IniCacheInsertKey(IniSection
, NULL
, INSERT_LAST
,
250 L
"UnattendedInstall", PathBuffer
);
252 // "floppylessbootpath" (yes/no)
254 RtlStringCchPrintfW(PathBuffer
, ARRAYSIZE(PathBuffer
),
255 L
"\"%s\"", L
"winnt");
256 IniCacheInsertKey(IniSection
, NULL
, INSERT_LAST
,
257 L
"ProductType", PathBuffer
);
259 RtlStringCchPrintfW(PathBuffer
, ARRAYSIZE(PathBuffer
),
260 L
"\"%s\\\"", pSetupData
->SourceRootPath
.Buffer
);
261 IniCacheInsertKey(IniSection
, NULL
, INSERT_LAST
,
262 L
"SourcePath", PathBuffer
);
264 // "floppyless" ("0")
269 /* TODO: Append the standard unattend.inf file */
270 CombinePaths(UnattendInfPath
, ARRAYSIZE(UnattendInfPath
), 2,
271 pSetupData
->SourcePath
.Buffer
, L
"unattend.inf");
272 if (DoesFileExist(NULL
, UnattendInfPath
) == FALSE
)
274 DPRINT("Does not exist: %S\n", UnattendInfPath
);
278 Status
= IniCacheLoad(&UnattendCache
, UnattendInfPath
, FALSE
);
279 if (!NT_SUCCESS(Status
))
281 DPRINT1("Cannot load %S as an INI file!\n", UnattendInfPath
);
285 IniCacheDestroy(UnattendCache
);
288 CombinePaths(PathBuffer
, ARRAYSIZE(PathBuffer
), 2,
289 pSetupData
->DestinationPath
.Buffer
, L
"System32\\$winnt$.inf");
290 IniCacheSave(IniCache
, PathBuffer
);
291 IniCacheDestroy(IniCache
);
295 CombinePaths(PathBuffer
, ARRAYSIZE(PathBuffer
), 2,
296 pSetupData
->DestinationPath
.Buffer
, L
"System32\\$winnt$.inf");
297 IniCacheSave(IniCache
, PathBuffer
);
298 IniCacheDestroy(IniCache
);
300 /* TODO: Append the standard unattend.inf file */
301 CombinePaths(UnattendInfPath
, ARRAYSIZE(UnattendInfPath
), 2,
302 pSetupData
->SourcePath
.Buffer
, L
"unattend.inf");
303 if (DoesFileExist(NULL
, UnattendInfPath
) == FALSE
)
305 DPRINT("Does not exist: %S\n", UnattendInfPath
);
309 RtlInitUnicodeString(&FileName
, PathBuffer
);
310 InitializeObjectAttributes(&ObjectAttributes
,
312 OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
,
315 Status
= NtOpenFile(&FileHandle
,
316 FILE_APPEND_DATA
| SYNCHRONIZE
,
320 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_NON_DIRECTORY_FILE
);
321 if (!NT_SUCCESS(Status
))
323 DPRINT1("Cannot load %S as an INI file!\n", PathBuffer
);
327 /* Query the file size */
328 Status
= NtQueryInformationFile(FileHandle
,
332 FileStandardInformation
);
333 if (!NT_SUCCESS(Status
))
335 DPRINT("NtQueryInformationFile() failed (Status %lx)\n", Status
);
336 FileInfo
.EndOfFile
.QuadPart
= 0ULL;
339 Status
= OpenAndMapFile(NULL
,
346 if (!NT_SUCCESS(Status
))
348 DPRINT1("Cannot load %S !\n", UnattendInfPath
);
353 /* Write to the INI file */
356 Status
= NtWriteFile(FileHandle
,
366 Status
= NtWriteFile(FileHandle
,
375 if (!NT_SUCCESS(Status
))
377 DPRINT("NtWriteFile() failed (Status %lx)\n", Status
);
380 /* Finally, unmap and close the file */
381 UnMapAndCloseFile(UnattendFileHandle
, SectionHandle
, ViewBase
);
389 OUT PUNICODE_STRING SourcePath
,
390 OUT PUNICODE_STRING SourceRootPath
,
391 OUT PUNICODE_STRING SourceRootDir
)
395 OBJECT_ATTRIBUTES ObjectAttributes
;
396 UCHAR ImageFileBuffer
[sizeof(UNICODE_STRING
) + MAX_PATH
* sizeof(WCHAR
)];
397 PUNICODE_STRING InstallSourcePath
= (PUNICODE_STRING
)&ImageFileBuffer
;
398 WCHAR SystemRootBuffer
[MAX_PATH
] = L
"";
399 UNICODE_STRING SystemRootPath
= RTL_CONSTANT_STRING(L
"\\SystemRoot");
403 /* Determine the installation source path via the full path of the installer */
404 RtlInitEmptyUnicodeString(InstallSourcePath
,
405 (PWSTR
)((ULONG_PTR
)ImageFileBuffer
+ sizeof(UNICODE_STRING
)),
406 sizeof(ImageFileBuffer
) - sizeof(UNICODE_STRING
)
407 /* Reserve space for a NULL terminator */ - sizeof(UNICODE_NULL
));
408 BufferSize
= sizeof(ImageFileBuffer
);
409 Status
= NtQueryInformationProcess(NtCurrentProcess(),
410 ProcessImageFileName
,
414 // STATUS_INFO_LENGTH_MISMATCH or STATUS_BUFFER_TOO_SMALL ?
415 if (!NT_SUCCESS(Status
))
418 /* Manually NULL-terminate */
419 InstallSourcePath
->Buffer
[InstallSourcePath
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
421 /* Strip the trailing file name */
422 Ptr
= wcsrchr(InstallSourcePath
->Buffer
, OBJ_NAME_PATH_SEPARATOR
);
425 InstallSourcePath
->Length
= wcslen(InstallSourcePath
->Buffer
) * sizeof(WCHAR
);
429 * Now resolve the full path to \SystemRoot. In case it prefixes
430 * the installation source path determined from the full path of
431 * the installer, we use instead the resolved \SystemRoot as the
432 * installation source path.
433 * Otherwise, we use instead the path from the full installer path.
436 InitializeObjectAttributes(&ObjectAttributes
,
438 OBJ_CASE_INSENSITIVE
,
442 Status
= NtOpenSymbolicLinkObject(&LinkHandle
,
445 if (!NT_SUCCESS(Status
))
448 * We failed at opening the \SystemRoot link (usually due to wrong
449 * access rights). Do not consider this as a fatal error, but use
450 * instead the image file path as the installation source path.
452 DPRINT1("NtOpenSymbolicLinkObject(%wZ) failed with Status 0x%08lx\n",
453 &SystemRootPath
, Status
);
457 RtlInitEmptyUnicodeString(&SystemRootPath
,
459 sizeof(SystemRootBuffer
));
461 /* Resolve the link and close its handle */
462 Status
= NtQuerySymbolicLinkObject(LinkHandle
,
467 if (!NT_SUCCESS(Status
))
468 return Status
; // Unexpected error
470 /* Check whether the resolved \SystemRoot is a prefix of the image file path */
471 if (RtlPrefixUnicodeString(&SystemRootPath
, InstallSourcePath
, TRUE
))
473 /* Yes it is, so we use instead SystemRoot as the installation source path */
474 InstallSourcePath
= &SystemRootPath
;
480 * Retrieve the different source path components
482 RtlCreateUnicodeString(SourcePath
, InstallSourcePath
->Buffer
);
484 /* Strip trailing directory */
485 Ptr
= wcsrchr(InstallSourcePath
->Buffer
, OBJ_NAME_PATH_SEPARATOR
);
488 RtlCreateUnicodeString(SourceRootDir
, Ptr
);
493 RtlCreateUnicodeString(SourceRootDir
, L
"");
496 RtlCreateUnicodeString(SourceRootPath
, InstallSourcePath
->Buffer
);
498 return STATUS_SUCCESS
;
503 IN OUT PUSETUP_DATA pSetupData
)
509 WCHAR FileNameBuffer
[MAX_PATH
];
511 CombinePaths(FileNameBuffer
, ARRAYSIZE(FileNameBuffer
), 2,
512 pSetupData
->SourcePath
.Buffer
, L
"txtsetup.sif");
514 DPRINT("SetupInf path: '%S'\n", FileNameBuffer
);
516 pSetupData
->SetupInf
=
517 SpInfOpenInfFile(FileNameBuffer
,
519 /* INF_STYLE_WIN4 | */ INF_STYLE_OLDNT
,
520 pSetupData
->LanguageId
,
522 if (pSetupData
->SetupInf
== INVALID_HANDLE_VALUE
)
523 return ERROR_LOAD_TXTSETUPSIF
;
525 /* Open 'Version' section */
526 if (!SpInfFindFirstLine(pSetupData
->SetupInf
, L
"Version", L
"Signature", &Context
))
527 return ERROR_CORRUPT_TXTSETUPSIF
;
529 /* Get pointer 'Signature' key */
530 if (!INF_GetData(&Context
, NULL
, &Value
))
531 return ERROR_CORRUPT_TXTSETUPSIF
;
533 /* Check 'Signature' string */
534 if (_wcsicmp(Value
, L
"$ReactOS$") != 0)
537 return ERROR_SIGNATURE_TXTSETUPSIF
;
542 /* Open 'DiskSpaceRequirements' section */
543 if (!SpInfFindFirstLine(pSetupData
->SetupInf
, L
"DiskSpaceRequirements", L
"FreeSysPartDiskSpace", &Context
))
544 return ERROR_CORRUPT_TXTSETUPSIF
;
546 pSetupData
->RequiredPartitionDiskSpace
= ~0;
548 /* Get the 'FreeSysPartDiskSpace' value */
549 if (!SpInfGetIntField(&Context
, 1, &IntValue
))
550 return ERROR_CORRUPT_TXTSETUPSIF
;
552 pSetupData
->RequiredPartitionDiskSpace
= (ULONG
)IntValue
;
555 // Support "SetupSourceDevice" and "SetupSourcePath" in txtsetup.sif
557 // Support for that should also be added in setupldr.
560 /* Update the Setup Source paths */
561 if (SpInfFindFirstLine(pSetupData
->SetupInf
, L
"SetupData", L
"SetupSourceDevice", &Context
))
564 * Get optional pointer 'SetupSourceDevice' key, its presence
565 * will dictate whether we also need 'SetupSourcePath'.
567 if (INF_GetData(&Context
, NULL
, &Value
))
569 /* Free the old source root path string and create the new one */
570 RtlFreeUnicodeString(&pSetupData
->SourceRootPath
);
571 RtlCreateUnicodeString(&pSetupData
->SourceRootPath
, Value
);
574 if (!SpInfFindFirstLine(pSetupData
->SetupInf
, L
"SetupData", L
"SetupSourcePath", &Context
))
576 /* The 'SetupSourcePath' value is mandatory! */
577 return ERROR_CORRUPT_TXTSETUPSIF
;
580 /* Get pointer 'SetupSourcePath' key */
581 if (!INF_GetData(&Context
, NULL
, &Value
))
583 /* The 'SetupSourcePath' value is mandatory! */
584 return ERROR_CORRUPT_TXTSETUPSIF
;
587 /* Free the old source path string and create the new one */
588 RtlFreeUnicodeString(&pSetupData
->SourceRootDir
);
589 RtlCreateUnicodeString(&pSetupData
->SourceRootDir
, Value
);
594 /* Search for 'DefaultPath' in the 'SetupData' section */
595 pSetupData
->InstallationDirectory
[0] = 0;
596 if (SpInfFindFirstLine(pSetupData
->SetupInf
, L
"SetupData", L
"DefaultPath", &Context
))
598 /* Get pointer 'DefaultPath' key */
599 if (!INF_GetData(&Context
, NULL
, &Value
))
600 return ERROR_CORRUPT_TXTSETUPSIF
;
602 RtlStringCchCopyW(pSetupData
->InstallationDirectory
,
603 ARRAYSIZE(pSetupData
->InstallationDirectory
),
609 return ERROR_SUCCESS
;
613 InitDestinationPaths(
614 IN OUT PUSETUP_DATA pSetupData
,
615 IN PCWSTR InstallationDir
,
616 IN PDISKENTRY DiskEntry
, // FIXME: HACK!
617 IN PPARTENTRY PartEntry
) // FIXME: HACK!
619 WCHAR PathBuffer
[MAX_PATH
];
622 // TODO: Check return status values of the functions!
625 /* Create 'pSetupData->DestinationRootPath' string */
626 RtlFreeUnicodeString(&pSetupData
->DestinationRootPath
);
627 RtlStringCchPrintfW(PathBuffer
, ARRAYSIZE(PathBuffer
),
628 L
"\\Device\\Harddisk%lu\\Partition%lu\\",
629 DiskEntry
->DiskNumber
,
630 PartEntry
->PartitionNumber
);
631 RtlCreateUnicodeString(&pSetupData
->DestinationRootPath
, PathBuffer
);
632 DPRINT("DestinationRootPath: %wZ\n", &pSetupData
->DestinationRootPath
);
634 // FIXME! Which variable to choose?
635 if (!InstallationDir
)
636 InstallationDir
= pSetupData
->InstallationDirectory
;
638 /** Equivalent of 'NTOS_INSTALLATION::SystemArcPath' **/
639 /* Create 'pSetupData->DestinationArcPath' */
640 RtlFreeUnicodeString(&pSetupData
->DestinationArcPath
);
641 RtlStringCchPrintfW(PathBuffer
, ARRAYSIZE(PathBuffer
),
642 L
"multi(0)disk(0)rdisk(%lu)partition(%lu)\\",
643 DiskEntry
->BiosDiskNumber
,
644 PartEntry
->PartitionNumber
);
645 ConcatPaths(PathBuffer
, ARRAYSIZE(PathBuffer
), 1, InstallationDir
);
646 RtlCreateUnicodeString(&pSetupData
->DestinationArcPath
, PathBuffer
);
648 /** Equivalent of 'NTOS_INSTALLATION::SystemNtPath' **/
649 /* Create 'pSetupData->DestinationPath' string */
650 RtlFreeUnicodeString(&pSetupData
->DestinationPath
);
651 CombinePaths(PathBuffer
, ARRAYSIZE(PathBuffer
), 2,
652 pSetupData
->DestinationRootPath
.Buffer
, InstallationDir
);
653 RtlCreateUnicodeString(&pSetupData
->DestinationPath
, PathBuffer
);
655 /** Equivalent of 'NTOS_INSTALLATION::PathComponent' **/
656 // FIXME: This is only temporary!! Must be removed later!
657 /***/RtlCreateUnicodeString(&pSetupData
->InstallPath
, InstallationDir
);/***/
659 return STATUS_SUCCESS
;
665 IN OUT PUSETUP_DATA pSetupData
,
670 RtlZeroMemory(pSetupData
, sizeof(*pSetupData
));
672 // pSetupData->ComputerList = NULL;
673 // pSetupData->DisplayList = NULL;
674 // pSetupData->KeyboardList = NULL;
675 // pSetupData->LayoutList = NULL;
676 // pSetupData->LanguageList = NULL;
678 /* Initialize global unicode strings */
679 RtlInitUnicodeString(&pSetupData
->SourcePath
, NULL
);
680 RtlInitUnicodeString(&pSetupData
->SourceRootPath
, NULL
);
681 RtlInitUnicodeString(&pSetupData
->SourceRootDir
, NULL
);
682 RtlInitUnicodeString(&pSetupData
->DestinationArcPath
, NULL
);
683 RtlInitUnicodeString(&pSetupData
->DestinationPath
, NULL
);
684 RtlInitUnicodeString(&pSetupData
->DestinationRootPath
, NULL
);
685 RtlInitUnicodeString(&pSetupData
->SystemRootPath
, NULL
);
687 // FIXME: This is only temporary!! Must be removed later!
688 /***/RtlInitUnicodeString(&pSetupData
->InstallPath
, NULL
);/***/
691 // TODO: Load and start SetupDD, and ask it for the information
694 return ERROR_SUCCESS
;
702 /* Get the source path and source root path */
704 // NOTE: Sometimes the source path may not be in SystemRoot !!
705 // (and this is the case when using the 1st-stage GUI setup!)
707 Status
= GetSourcePaths(&pSetupData
->SourcePath
,
708 &pSetupData
->SourceRootPath
,
709 &pSetupData
->SourceRootDir
);
710 if (!NT_SUCCESS(Status
))
712 DPRINT1("GetSourcePaths() failed (Status 0x%08lx)", Status
);
713 return ERROR_NO_SOURCE_DRIVE
;
717 * SourcePath: '\Device\CdRom0\I386'
718 * SourceRootPath: '\Device\CdRom0'
719 * SourceRootDir: '\I386'
721 DPRINT1("SourcePath (1): '%wZ'\n", &pSetupData
->SourcePath
);
722 DPRINT1("SourceRootPath (1): '%wZ'\n", &pSetupData
->SourceRootPath
);
723 DPRINT1("SourceRootDir (1): '%wZ'\n", &pSetupData
->SourceRootDir
);
725 /* Load 'txtsetup.sif' from the installation media */
726 Error
= LoadSetupInf(pSetupData
);
727 if (Error
!= ERROR_SUCCESS
)
729 DPRINT1("LoadSetupInf() failed (Error 0x%lx)", Error
);
732 DPRINT1("SourcePath (2): '%wZ'\n", &pSetupData
->SourcePath
);
733 DPRINT1("SourceRootPath (2): '%wZ'\n", &pSetupData
->SourceRootPath
);
734 DPRINT1("SourceRootDir (2): '%wZ'\n", &pSetupData
->SourceRootDir
);
736 return ERROR_SUCCESS
;
739 return ERROR_SUCCESS
;
744 IN OUT PUSETUP_DATA pSetupData
)
746 /* Destroy the computer settings list */
747 if (pSetupData
->ComputerList
!= NULL
)
749 DestroyGenericList(pSetupData
->ComputerList
, TRUE
);
750 pSetupData
->ComputerList
= NULL
;
753 /* Destroy the display settings list */
754 if (pSetupData
->DisplayList
!= NULL
)
756 DestroyGenericList(pSetupData
->DisplayList
, TRUE
);
757 pSetupData
->DisplayList
= NULL
;
760 /* Destroy the keyboard settings list */
761 if (pSetupData
->KeyboardList
!= NULL
)
763 DestroyGenericList(pSetupData
->KeyboardList
, TRUE
);
764 pSetupData
->KeyboardList
= NULL
;
767 /* Destroy the keyboard layout list */
768 if (pSetupData
->LayoutList
!= NULL
)
770 DestroyGenericList(pSetupData
->LayoutList
, TRUE
);
771 pSetupData
->LayoutList
= NULL
;
774 /* Destroy the languages list */
775 if (pSetupData
->LanguageList
!= NULL
)
777 DestroyGenericList(pSetupData
->LanguageList
, FALSE
);
778 pSetupData
->LanguageList
= NULL
;
781 /* Close the Setup INF */
782 SpInfCloseInfFile(pSetupData
->SetupInf
);
787 * Calls RegInitializeRegistry
788 * Calls ImportRegistryFile
789 * Calls SetDefaultPagefile
790 * Calls SetMountedDeviceValues
794 IN OUT PUSETUP_DATA pSetupData
,
795 /**/IN BOOLEAN RepairUpdateFlag
, /* HACK HACK! */
796 /**/IN PPARTLIST PartitionList
, /* HACK HACK! */
797 /**/IN WCHAR DestinationDriveLetter
, /* HACK HACK! */
798 /**/IN PCWSTR SelectedLanguageId
, /* HACK HACK! */
799 IN PREGISTRY_STATUS_ROUTINE StatusRoutine OPTIONAL
)
801 ERROR_NUMBER ErrorNumber
;
803 INFCONTEXT InfContext
;
808 BOOLEAN ShouldRepairRegistry
= FALSE
;
811 if (RepairUpdateFlag
)
813 DPRINT1("TODO: Updating / repairing the registry is not completely implemented yet!\n");
815 /* Verify the registry hives and check whether we need to update or repair any of them */
816 Status
= VerifyRegistryHives(&pSetupData
->DestinationPath
, &ShouldRepairRegistry
);
817 if (!NT_SUCCESS(Status
))
819 DPRINT1("VerifyRegistryHives failed, Status 0x%08lx\n", Status
);
820 ShouldRepairRegistry
= FALSE
;
822 if (!ShouldRepairRegistry
)
823 DPRINT1("No need to repair the registry\n");
827 ErrorNumber
= ERROR_SUCCESS
;
829 /* Update the registry */
830 if (StatusRoutine
) StatusRoutine(RegHiveUpdate
);
832 /* Initialize the registry and setup the registry hives */
833 Status
= RegInitializeRegistry(&pSetupData
->DestinationPath
);
834 if (!NT_SUCCESS(Status
))
836 DPRINT1("RegInitializeRegistry() failed\n");
837 /********** HACK!!!!!!!!!!! **********/
838 if (Status
== STATUS_NOT_IMPLEMENTED
)
840 /* The hack was called, return its corresponding error */
841 return ERROR_INITIALIZE_REGISTRY
;
844 /*************************************/
846 /* Something else failed */
847 return ERROR_CREATE_HIVE
;
851 if (!RepairUpdateFlag
|| ShouldRepairRegistry
)
854 * We fully setup the hives, in case we are doing a fresh installation
855 * (RepairUpdateFlag == FALSE), or in case we are doing an update
856 * (RepairUpdateFlag == TRUE) BUT we have some registry hives to
857 * "repair" (aka. recreate: ShouldRepairRegistry == TRUE).
860 Success
= SpInfFindFirstLine(pSetupData
->SetupInf
, L
"HiveInfs.Fresh", NULL
, &InfContext
); // Windows-compatible
862 Success
= SpInfFindFirstLine(pSetupData
->SetupInf
, L
"HiveInfs.Install", NULL
, &InfContext
); // ReactOS-specific
866 DPRINT1("SpInfFindFirstLine() failed\n");
867 ErrorNumber
= ERROR_FIND_REGISTRY
;
871 else // if (RepairUpdateFlag && !ShouldRepairRegistry)
874 * In case we are doing an update (RepairUpdateFlag == TRUE) and
875 * NO registry hives need a repair (ShouldRepairRegistry == FALSE),
876 * we only update the hives.
879 Success
= SpInfFindFirstLine(pSetupData
->SetupInf
, L
"HiveInfs.Upgrade", NULL
, &InfContext
);
882 /* Nothing to do for update! */
883 DPRINT1("No update needed for the registry!\n");
890 INF_GetDataField(&InfContext
, 0, &Action
);
891 INF_GetDataField(&InfContext
, 1, &File
);
892 INF_GetDataField(&InfContext
, 2, &Section
);
894 DPRINT("Action: %S File: %S Section %S\n", Action
, File
, Section
);
898 INF_FreeData(Action
);
900 INF_FreeData(Section
);
904 if (!_wcsicmp(Action
, L
"AddReg"))
906 else if (!_wcsicmp(Action
, L
"DelReg"))
910 DPRINT1("Unrecognized registry INF action '%S'\n", Action
);
911 INF_FreeData(Action
);
913 INF_FreeData(Section
);
917 INF_FreeData(Action
);
919 if (StatusRoutine
) StatusRoutine(ImportRegHive
, File
);
921 if (!ImportRegistryFile(pSetupData
->SourcePath
.Buffer
,
923 pSetupData
->LanguageId
, Delete
))
925 DPRINT1("Importing %S failed\n", File
);
927 INF_FreeData(Section
);
928 ErrorNumber
= ERROR_IMPORT_HIVE
;
931 } while (SpInfFindNextLine(&InfContext
, &InfContext
));
933 if (!RepairUpdateFlag
|| ShouldRepairRegistry
)
935 /* See the explanation for this test above */
937 /* Update display registry settings */
938 if (StatusRoutine
) StatusRoutine(DisplaySettingsUpdate
);
939 if (!ProcessDisplayRegistry(pSetupData
->SetupInf
, pSetupData
->DisplayList
))
941 ErrorNumber
= ERROR_UPDATE_DISPLAY_SETTINGS
;
946 if (StatusRoutine
) StatusRoutine(LocaleSettingsUpdate
);
947 if (!ProcessLocaleRegistry(pSetupData
->LanguageList
))
949 ErrorNumber
= ERROR_UPDATE_LOCALESETTINGS
;
953 /* Add keyboard layouts */
954 if (StatusRoutine
) StatusRoutine(KeybLayouts
);
955 if (!AddKeyboardLayouts(SelectedLanguageId
))
957 ErrorNumber
= ERROR_ADDING_KBLAYOUTS
;
962 if (!SetGeoID(MUIGetGeoID(SelectedLanguageId
)))
964 ErrorNumber
= ERROR_UPDATE_GEOID
;
968 if (!IsUnattendedSetup
)
970 /* Update keyboard layout settings */
971 if (StatusRoutine
) StatusRoutine(KeybSettingsUpdate
);
972 if (!ProcessKeyboardLayoutRegistry(pSetupData
->LayoutList
, SelectedLanguageId
))
974 ErrorNumber
= ERROR_UPDATE_KBSETTINGS
;
979 /* Add codepage information to registry */
980 if (StatusRoutine
) StatusRoutine(CodePageInfoUpdate
);
981 if (!AddCodePage(SelectedLanguageId
))
983 ErrorNumber
= ERROR_ADDING_CODEPAGE
;
987 /* Set the default pagefile entry */
988 SetDefaultPagefile(DestinationDriveLetter
);
990 /* Update the mounted devices list */
991 // FIXME: This should technically be done by mountmgr (if AutoMount is enabled)!
992 SetMountedDeviceValues(PartitionList
);
997 // TODO: Unload all the registry stuff, perform cleanup,
998 // and copy the created hive files into .sav files.
1000 RegCleanupRegistry(&pSetupData
->DestinationPath
);
1003 * Check whether we were in update/repair mode but we were actually
1004 * repairing the registry hives. If so, we have finished repairing them,
1005 * and we now reset the flag and run the proper registry update.
1006 * Otherwise we have finished the registry update!
1008 if (RepairUpdateFlag
&& ShouldRepairRegistry
)
1010 ShouldRepairRegistry
= FALSE
;