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
,
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 &&
535 _wcsicmp(Value
, L
"$Windows NT$") != 0)
538 return ERROR_SIGNATURE_TXTSETUPSIF
;
543 /* Open 'DiskSpaceRequirements' section */
544 if (!SpInfFindFirstLine(pSetupData
->SetupInf
, L
"DiskSpaceRequirements", L
"FreeSysPartDiskSpace", &Context
))
545 return ERROR_CORRUPT_TXTSETUPSIF
;
547 pSetupData
->RequiredPartitionDiskSpace
= ~0;
549 /* Get the 'FreeSysPartDiskSpace' value */
550 if (!SpInfGetIntField(&Context
, 1, &IntValue
))
551 return ERROR_CORRUPT_TXTSETUPSIF
;
553 pSetupData
->RequiredPartitionDiskSpace
= (ULONG
)IntValue
;
556 // Support "SetupSourceDevice" and "SetupSourcePath" in txtsetup.sif
558 // Support for that should also be added in setupldr.
561 /* Update the Setup Source paths */
562 if (SpInfFindFirstLine(pSetupData
->SetupInf
, L
"SetupData", L
"SetupSourceDevice", &Context
))
565 * Get optional pointer 'SetupSourceDevice' key, its presence
566 * will dictate whether we also need 'SetupSourcePath'.
568 if (INF_GetData(&Context
, NULL
, &Value
))
570 /* Free the old source root path string and create the new one */
571 RtlFreeUnicodeString(&pSetupData
->SourceRootPath
);
572 RtlCreateUnicodeString(&pSetupData
->SourceRootPath
, Value
);
575 if (!SpInfFindFirstLine(pSetupData
->SetupInf
, L
"SetupData", L
"SetupSourcePath", &Context
))
577 /* The 'SetupSourcePath' value is mandatory! */
578 return ERROR_CORRUPT_TXTSETUPSIF
;
581 /* Get pointer 'SetupSourcePath' key */
582 if (!INF_GetData(&Context
, NULL
, &Value
))
584 /* The 'SetupSourcePath' value is mandatory! */
585 return ERROR_CORRUPT_TXTSETUPSIF
;
588 /* Free the old source path string and create the new one */
589 RtlFreeUnicodeString(&pSetupData
->SourceRootDir
);
590 RtlCreateUnicodeString(&pSetupData
->SourceRootDir
, Value
);
595 /* Search for 'DefaultPath' in the 'SetupData' section */
596 pSetupData
->InstallationDirectory
[0] = 0;
597 if (SpInfFindFirstLine(pSetupData
->SetupInf
, L
"SetupData", L
"DefaultPath", &Context
))
599 /* Get pointer 'DefaultPath' key */
600 if (!INF_GetData(&Context
, NULL
, &Value
))
601 return ERROR_CORRUPT_TXTSETUPSIF
;
603 RtlStringCchCopyW(pSetupData
->InstallationDirectory
,
604 ARRAYSIZE(pSetupData
->InstallationDirectory
),
610 return ERROR_SUCCESS
;
614 InitDestinationPaths(
615 IN OUT PUSETUP_DATA pSetupData
,
616 IN PCWSTR InstallationDir
,
617 IN PDISKENTRY DiskEntry
, // FIXME: HACK!
618 IN PPARTENTRY PartEntry
) // FIXME: HACK!
620 WCHAR PathBuffer
[MAX_PATH
];
623 // TODO: Check return status values of the functions!
626 /* Create 'pSetupData->DestinationRootPath' string */
627 RtlFreeUnicodeString(&pSetupData
->DestinationRootPath
);
628 RtlStringCchPrintfW(PathBuffer
, ARRAYSIZE(PathBuffer
),
629 L
"\\Device\\Harddisk%lu\\Partition%lu\\",
630 DiskEntry
->DiskNumber
,
631 PartEntry
->PartitionNumber
);
632 RtlCreateUnicodeString(&pSetupData
->DestinationRootPath
, PathBuffer
);
633 DPRINT("DestinationRootPath: %wZ\n", &pSetupData
->DestinationRootPath
);
635 // FIXME! Which variable to choose?
636 if (!InstallationDir
)
637 InstallationDir
= pSetupData
->InstallationDirectory
;
639 /** Equivalent of 'NTOS_INSTALLATION::SystemArcPath' **/
640 /* Create 'pSetupData->DestinationArcPath' */
641 RtlFreeUnicodeString(&pSetupData
->DestinationArcPath
);
642 RtlStringCchPrintfW(PathBuffer
, ARRAYSIZE(PathBuffer
),
643 L
"multi(0)disk(0)rdisk(%lu)partition(%lu)\\",
644 DiskEntry
->BiosDiskNumber
,
645 PartEntry
->OnDiskPartitionNumber
);
646 ConcatPaths(PathBuffer
, ARRAYSIZE(PathBuffer
), 1, InstallationDir
);
647 RtlCreateUnicodeString(&pSetupData
->DestinationArcPath
, PathBuffer
);
649 /** Equivalent of 'NTOS_INSTALLATION::SystemNtPath' **/
650 /* Create 'pSetupData->DestinationPath' string */
651 RtlFreeUnicodeString(&pSetupData
->DestinationPath
);
652 CombinePaths(PathBuffer
, ARRAYSIZE(PathBuffer
), 2,
653 pSetupData
->DestinationRootPath
.Buffer
, InstallationDir
);
654 RtlCreateUnicodeString(&pSetupData
->DestinationPath
, PathBuffer
);
656 /** Equivalent of 'NTOS_INSTALLATION::PathComponent' **/
657 // FIXME: This is only temporary!! Must be removed later!
658 /***/RtlCreateUnicodeString(&pSetupData
->InstallPath
, InstallationDir
);/***/
660 return STATUS_SUCCESS
;
666 IN OUT PUSETUP_DATA pSetupData
,
671 RtlZeroMemory(pSetupData
, sizeof(*pSetupData
));
673 // pSetupData->ComputerList = NULL;
674 // pSetupData->DisplayList = NULL;
675 // pSetupData->KeyboardList = NULL;
676 // pSetupData->LayoutList = NULL;
677 // pSetupData->LanguageList = NULL;
679 /* Initialize error handling */
680 pSetupData
->LastErrorNumber
= ERROR_SUCCESS
;
681 pSetupData
->ErrorRoutine
= NULL
;
683 /* Initialize global unicode strings */
684 RtlInitUnicodeString(&pSetupData
->SourcePath
, NULL
);
685 RtlInitUnicodeString(&pSetupData
->SourceRootPath
, NULL
);
686 RtlInitUnicodeString(&pSetupData
->SourceRootDir
, NULL
);
687 RtlInitUnicodeString(&pSetupData
->DestinationArcPath
, NULL
);
688 RtlInitUnicodeString(&pSetupData
->DestinationPath
, NULL
);
689 RtlInitUnicodeString(&pSetupData
->DestinationRootPath
, NULL
);
690 RtlInitUnicodeString(&pSetupData
->SystemRootPath
, NULL
);
692 // FIXME: This is only temporary!! Must be removed later!
693 /***/RtlInitUnicodeString(&pSetupData
->InstallPath
, NULL
);/***/
696 // TODO: Load and start SetupDD, and ask it for the information
699 return ERROR_SUCCESS
;
707 /* Get the source path and source root path */
709 // NOTE: Sometimes the source path may not be in SystemRoot !!
710 // (and this is the case when using the 1st-stage GUI setup!)
712 Status
= GetSourcePaths(&pSetupData
->SourcePath
,
713 &pSetupData
->SourceRootPath
,
714 &pSetupData
->SourceRootDir
);
715 if (!NT_SUCCESS(Status
))
717 DPRINT1("GetSourcePaths() failed (Status 0x%08lx)", Status
);
718 return ERROR_NO_SOURCE_DRIVE
;
722 * SourcePath: '\Device\CdRom0\I386'
723 * SourceRootPath: '\Device\CdRom0'
724 * SourceRootDir: '\I386'
726 DPRINT1("SourcePath (1): '%wZ'\n", &pSetupData
->SourcePath
);
727 DPRINT1("SourceRootPath (1): '%wZ'\n", &pSetupData
->SourceRootPath
);
728 DPRINT1("SourceRootDir (1): '%wZ'\n", &pSetupData
->SourceRootDir
);
730 /* Load 'txtsetup.sif' from the installation media */
731 Error
= LoadSetupInf(pSetupData
);
732 if (Error
!= ERROR_SUCCESS
)
734 DPRINT1("LoadSetupInf() failed (Error 0x%lx)", Error
);
737 DPRINT1("SourcePath (2): '%wZ'\n", &pSetupData
->SourcePath
);
738 DPRINT1("SourceRootPath (2): '%wZ'\n", &pSetupData
->SourceRootPath
);
739 DPRINT1("SourceRootDir (2): '%wZ'\n", &pSetupData
->SourceRootDir
);
741 return ERROR_SUCCESS
;
744 return ERROR_SUCCESS
;
749 IN OUT PUSETUP_DATA pSetupData
)
751 /* Destroy the computer settings list */
752 if (pSetupData
->ComputerList
!= NULL
)
754 DestroyGenericList(pSetupData
->ComputerList
, TRUE
);
755 pSetupData
->ComputerList
= NULL
;
758 /* Destroy the display settings list */
759 if (pSetupData
->DisplayList
!= NULL
)
761 DestroyGenericList(pSetupData
->DisplayList
, TRUE
);
762 pSetupData
->DisplayList
= NULL
;
765 /* Destroy the keyboard settings list */
766 if (pSetupData
->KeyboardList
!= NULL
)
768 DestroyGenericList(pSetupData
->KeyboardList
, TRUE
);
769 pSetupData
->KeyboardList
= NULL
;
772 /* Destroy the keyboard layout list */
773 if (pSetupData
->LayoutList
!= NULL
)
775 DestroyGenericList(pSetupData
->LayoutList
, TRUE
);
776 pSetupData
->LayoutList
= NULL
;
779 /* Destroy the languages list */
780 if (pSetupData
->LanguageList
!= NULL
)
782 DestroyGenericList(pSetupData
->LanguageList
, FALSE
);
783 pSetupData
->LanguageList
= NULL
;
786 /* Close the Setup INF */
787 SpInfCloseInfFile(pSetupData
->SetupInf
);
792 * Calls RegInitializeRegistry
793 * Calls ImportRegistryFile
794 * Calls SetDefaultPagefile
795 * Calls SetMountedDeviceValues
799 IN OUT PUSETUP_DATA pSetupData
,
800 /**/IN BOOLEAN RepairUpdateFlag
, /* HACK HACK! */
801 /**/IN PPARTLIST PartitionList
, /* HACK HACK! */
802 /**/IN WCHAR DestinationDriveLetter
, /* HACK HACK! */
803 /**/IN PCWSTR SelectedLanguageId
, /* HACK HACK! */
804 IN PREGISTRY_STATUS_ROUTINE StatusRoutine OPTIONAL
)
806 ERROR_NUMBER ErrorNumber
;
808 INFCONTEXT InfContext
;
813 BOOLEAN ShouldRepairRegistry
= FALSE
;
816 if (RepairUpdateFlag
)
818 DPRINT1("TODO: Updating / repairing the registry is not completely implemented yet!\n");
820 /* Verify the registry hives and check whether we need to update or repair any of them */
821 Status
= VerifyRegistryHives(&pSetupData
->DestinationPath
, &ShouldRepairRegistry
);
822 if (!NT_SUCCESS(Status
))
824 DPRINT1("VerifyRegistryHives failed, Status 0x%08lx\n", Status
);
825 ShouldRepairRegistry
= FALSE
;
827 if (!ShouldRepairRegistry
)
828 DPRINT1("No need to repair the registry\n");
832 ErrorNumber
= ERROR_SUCCESS
;
834 /* Update the registry */
835 if (StatusRoutine
) StatusRoutine(RegHiveUpdate
);
837 /* Initialize the registry and setup the registry hives */
838 Status
= RegInitializeRegistry(&pSetupData
->DestinationPath
);
839 if (!NT_SUCCESS(Status
))
841 DPRINT1("RegInitializeRegistry() failed\n");
842 /********** HACK!!!!!!!!!!! **********/
843 if (Status
== STATUS_NOT_IMPLEMENTED
)
845 /* The hack was called, return its corresponding error */
846 return ERROR_INITIALIZE_REGISTRY
;
849 /*************************************/
851 /* Something else failed */
852 return ERROR_CREATE_HIVE
;
856 if (!RepairUpdateFlag
|| ShouldRepairRegistry
)
859 * We fully setup the hives, in case we are doing a fresh installation
860 * (RepairUpdateFlag == FALSE), or in case we are doing an update
861 * (RepairUpdateFlag == TRUE) BUT we have some registry hives to
862 * "repair" (aka. recreate: ShouldRepairRegistry == TRUE).
865 Success
= SpInfFindFirstLine(pSetupData
->SetupInf
, L
"HiveInfs.Fresh", NULL
, &InfContext
); // Windows-compatible
867 Success
= SpInfFindFirstLine(pSetupData
->SetupInf
, L
"HiveInfs.Install", NULL
, &InfContext
); // ReactOS-specific
871 DPRINT1("SpInfFindFirstLine() failed\n");
872 ErrorNumber
= ERROR_FIND_REGISTRY
;
876 else // if (RepairUpdateFlag && !ShouldRepairRegistry)
879 * In case we are doing an update (RepairUpdateFlag == TRUE) and
880 * NO registry hives need a repair (ShouldRepairRegistry == FALSE),
881 * we only update the hives.
884 Success
= SpInfFindFirstLine(pSetupData
->SetupInf
, L
"HiveInfs.Upgrade", NULL
, &InfContext
);
887 /* Nothing to do for update! */
888 DPRINT1("No update needed for the registry!\n");
895 INF_GetDataField(&InfContext
, 0, &Action
);
896 INF_GetDataField(&InfContext
, 1, &File
);
897 INF_GetDataField(&InfContext
, 2, &Section
);
899 DPRINT("Action: %S File: %S Section %S\n", Action
, File
, Section
);
903 INF_FreeData(Action
);
905 INF_FreeData(Section
);
909 if (!_wcsicmp(Action
, L
"AddReg"))
911 else if (!_wcsicmp(Action
, L
"DelReg"))
915 DPRINT1("Unrecognized registry INF action '%S'\n", Action
);
916 INF_FreeData(Action
);
918 INF_FreeData(Section
);
922 INF_FreeData(Action
);
924 if (StatusRoutine
) StatusRoutine(ImportRegHive
, File
);
926 if (!ImportRegistryFile(pSetupData
->SourcePath
.Buffer
,
928 pSetupData
->LanguageId
, Delete
))
930 DPRINT1("Importing %S failed\n", File
);
932 INF_FreeData(Section
);
933 ErrorNumber
= ERROR_IMPORT_HIVE
;
936 } while (SpInfFindNextLine(&InfContext
, &InfContext
));
938 if (!RepairUpdateFlag
|| ShouldRepairRegistry
)
940 /* See the explanation for this test above */
942 /* Update display registry settings */
943 if (StatusRoutine
) StatusRoutine(DisplaySettingsUpdate
);
944 if (!ProcessDisplayRegistry(pSetupData
->SetupInf
, pSetupData
->DisplayList
))
946 ErrorNumber
= ERROR_UPDATE_DISPLAY_SETTINGS
;
951 if (StatusRoutine
) StatusRoutine(LocaleSettingsUpdate
);
952 if (!ProcessLocaleRegistry(pSetupData
->LanguageList
))
954 ErrorNumber
= ERROR_UPDATE_LOCALESETTINGS
;
958 /* Add keyboard layouts */
959 if (StatusRoutine
) StatusRoutine(KeybLayouts
);
960 if (!AddKeyboardLayouts(SelectedLanguageId
))
962 ErrorNumber
= ERROR_ADDING_KBLAYOUTS
;
967 if (!SetGeoID(MUIGetGeoID(SelectedLanguageId
)))
969 ErrorNumber
= ERROR_UPDATE_GEOID
;
973 if (!IsUnattendedSetup
)
975 /* Update keyboard layout settings */
976 if (StatusRoutine
) StatusRoutine(KeybSettingsUpdate
);
977 if (!ProcessKeyboardLayoutRegistry(pSetupData
->LayoutList
, SelectedLanguageId
))
979 ErrorNumber
= ERROR_UPDATE_KBSETTINGS
;
984 /* Add codepage information to registry */
985 if (StatusRoutine
) StatusRoutine(CodePageInfoUpdate
);
986 if (!AddCodePage(SelectedLanguageId
))
988 ErrorNumber
= ERROR_ADDING_CODEPAGE
;
992 /* Set the default pagefile entry */
993 SetDefaultPagefile(DestinationDriveLetter
);
995 /* Update the mounted devices list */
996 // FIXME: This should technically be done by mountmgr (if AutoMount is enabled)!
997 SetMountedDeviceValues(PartitionList
);
1002 // TODO: Unload all the registry stuff, perform cleanup,
1003 // and copy the created hive files into .sav files.
1005 RegCleanupRegistry(&pSetupData
->DestinationPath
);
1008 * Check whether we were in update/repair mode but we were actually
1009 * repairing the registry hives. If so, we have finished repairing them,
1010 * and we now reset the flag and run the proper registry update.
1011 * Otherwise we have finished the registry update!
1013 if (RepairUpdateFlag
&& ShouldRepairRegistry
)
1015 ShouldRepairRegistry
= FALSE
;