Synchronize with trunk revision 59636 (just before Alex's CreateProcess revamp).
[reactos.git] / base / setup / usetup / interface / usetup.c
index da9d60a..c7686e0 100644 (file)
@@ -26,7 +26,7 @@
  *                  HervĂ© Poussineau (hpoussin@reactos.org)
  */
 
-#include "usetup.h"
+#include <usetup.h>
 
 #define NDEBUG
 #include <debug.h>
@@ -51,11 +51,10 @@ WCHAR DefaultLanguage[20];
 WCHAR DefaultKBLayout[20];
 BOOLEAN RepairUpdateFlag = FALSE;
 HANDLE hPnpThread = INVALID_HANDLE_VALUE;
+PPARTLIST PartitionList = NULL;
 
 /* LOCALS *******************************************************************/
 
-static PPARTLIST PartitionList = NULL;
-
 static PFILE_SYSTEM_LIST FileSystemList = NULL;
 
 static UNICODE_STRING InstallPath;
@@ -507,10 +506,10 @@ CheckUnattendedSetup(VOID)
 
     UnattendDestinationPartitionNumber = IntValue;
 
-    /* Search for 'DestinationPartitionNumber' in the 'Unattend' section */
-    if (!SetupFindFirstLineW(UnattendInf, L"Unattend", L"DestinationPartitionNumber", &Context))
+    /* Search for 'InstallationDirectory' in the 'Unattend' section */
+    if (!SetupFindFirstLineW(UnattendInf, L"Unattend", L"InstallationDirectory", &Context))
     {
-        DPRINT("SetupFindFirstLine() failed for key 'DestinationPartitionNumber'\n");
+        DPRINT("SetupFindFirstLine() failed for key 'InstallationDirectory'\n");
         SetupCloseInfFile(UnattendInf);
         return;
     }
@@ -609,6 +608,9 @@ UpdateKBLayout(VOID)
 static PAGE_NUMBER
 LanguagePage(PINPUT_RECORD Ir)
 {
+    PWCHAR NewLanguageId;
+    BOOL RefreshPage = FALSE;
+
     /* Initialize the computer settings list */
     if (LanguageList == NULL)
     {
@@ -621,6 +623,10 @@ LanguagePage(PINPUT_RECORD Ir)
         }
     }
 
+    /* Load the font */
+    SelectedLanguageId = DefaultLanguage;
+    SetConsoleCodePage();
+
     DrawGenericList(LanguageList,
                     2,
                     18,
@@ -638,36 +644,26 @@ LanguagePage(PINPUT_RECORD Ir)
         if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
             (Ir->Event.KeyEvent.wVirtualKeyCode == VK_DOWN))  /* DOWN */
         {
-#if 0
-            SelectedLanguageId = (PWCHAR)GetListEntryUserData(GetCurrentListEntry(LanguageList));
-
-            /* Redraw language selection page in native language */
-            MUIDisplayPage(LANGUAGE_PAGE);
-#endif
-
             ScrollDownGenericList (LanguageList);
+            RefreshPage = TRUE;
         }
         else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
                  (Ir->Event.KeyEvent.wVirtualKeyCode == VK_UP))  /* UP */
         {
-#if 0
-            SelectedLanguageId = (PWCHAR)GetListEntryUserData(GetCurrentListEntry(LanguageList));
-
-            /* Redraw language selection page in native language */
-            MUIDisplayPage(LANGUAGE_PAGE);
-#endif
-
             ScrollUpGenericList(LanguageList);
+            RefreshPage = TRUE;
         }
         if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
             (Ir->Event.KeyEvent.wVirtualKeyCode == VK_NEXT))  /* PAGE DOWN */
         {
             ScrollPageDownGenericList(LanguageList);
+            RefreshPage = TRUE;
         }
         else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
                  (Ir->Event.KeyEvent.wVirtualKeyCode == VK_PRIOR))  /* PAGE UP */
         {
             ScrollPageUpGenericList(LanguageList);
+            RefreshPage = TRUE;
         }
         else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
                  (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3))  /* F3 */
@@ -686,7 +682,7 @@ LanguagePage(PINPUT_RECORD Ir)
                 UpdateKBLayout();
             }
 
-            // Load the font
+            /* Load the font */
             SetConsoleCodePage();
 
             return INTRO_PAGE;
@@ -695,6 +691,28 @@ LanguagePage(PINPUT_RECORD Ir)
         {
             /* a-z */
             GenericListKeyPress (LanguageList, Ir->Event.KeyEvent.uChar.AsciiChar);
+            RefreshPage = TRUE;
+        }
+
+        if (RefreshPage)
+        {
+            NewLanguageId = (PWCHAR)GetListEntryUserData(GetCurrentListEntry(LanguageList));
+
+            if (SelectedLanguageId != NewLanguageId)
+            {
+                /* Clear the language page */
+                MUIClearPage(LANGUAGE_PAGE);
+
+                SelectedLanguageId = NewLanguageId;
+
+                /* Load the font */
+                SetConsoleCodePage();
+
+                /* Redraw language selection page in native language */
+                MUIDisplayPage(LANGUAGE_PAGE);
+            }
+
+            RefreshPage = FALSE;
         }
     }
 
@@ -710,19 +728,19 @@ LanguagePage(PINPUT_RECORD Ir)
 static PAGE_NUMBER
 SetupStartPage(PINPUT_RECORD Ir)
 {
-    SYSTEM_DEVICE_INFORMATION Sdi;
+    //SYSTEM_DEVICE_INFORMATION Sdi;
     NTSTATUS Status;
     WCHAR FileNameBuffer[MAX_PATH];
     INFCONTEXT Context;
     PWCHAR Value;
     UINT ErrorLine;
-    ULONG ReturnSize;
+    //ULONG ReturnSize;
     PGENERIC_LIST_ENTRY ListEntry;
     INT IntValue;
 
     CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
 
-
+#if 0
     /* Check whether a harddisk is available */
     Status = NtQuerySystemInformation(SystemDeviceInformation,
                                       &Sdi,
@@ -741,6 +759,7 @@ SetupStartPage(PINPUT_RECORD Ir)
         MUIDisplayError(ERROR_NO_HDD, Ir, POPUP_WAIT_ENTER);
         return QUIT_PAGE;
     }
+#endif
 
     /* Get the source path and source root path */
     Status = GetSourcePaths(&SourcePath,
@@ -1402,23 +1421,24 @@ LayoutSettingsPage(PINPUT_RECORD Ir)
 static BOOL
 IsDiskSizeValid(PPARTENTRY PartEntry)
 {
-    ULONGLONG m;
+    ULONGLONG m1, m2;
 
     /*  check for unpartitioned space  */
-    m = PartEntry->UnpartitionedLength; 
-    m = (m + (1 << 19)) >> 20;  /* in MBytes (rounded) */
-    if( m > RequiredPartitionDiskSpace)
+    m1 = PartEntry->UnpartitionedLength;
+    m1 = (m1 + (1 << 19)) >> 20;  /* in MBytes (rounded) */
+
+    if( m1 > RequiredPartitionDiskSpace)
     {
         return TRUE;
     }
 
     /* check for partitioned space */
-    m = PartEntry->PartInfo[0].PartitionLength.QuadPart;
-    m = (m + (1 << 19)) >> 20;  /* in MBytes (rounded) */
-    if (m < RequiredPartitionDiskSpace)
+    m2 = PartEntry->PartInfo[0].PartitionLength.QuadPart;
+    m2 = (m2 + (1 << 19)) >> 20;  /* in MBytes (rounded) */
+    if (m2 < RequiredPartitionDiskSpace)
     {
         /* partition is too small so ask for another partion */
-        DPRINT1("Partition is too small, required disk space is %lu MB\n", RequiredPartitionDiskSpace);
+        DPRINT1("Partition is too small(unpartitioned: %I64u MB, partitioned: %I64u MB), required disk space is %lu MB\n", m1, m2, RequiredPartitionDiskSpace);
         return FALSE;
     }
     else
@@ -1446,8 +1466,6 @@ SelectPartitionPage(PINPUT_RECORD Ir)
         }
     }
 
-    CheckActiveBootPartition(PartitionList);
-
     DrawPartitionList(PartitionList);
 
     /* Warn about partitions created by Linux Fdisk */
@@ -2266,12 +2284,12 @@ static ULONG
 FormatPartitionPage(PINPUT_RECORD Ir)
 {
     WCHAR PathBuffer[MAX_PATH];
-    PDISKENTRY DiskEntry;
     PPARTENTRY PartEntry;
     UCHAR PartNum;
     NTSTATUS Status;
 
 #ifndef NDEBUG
+    PDISKENTRY DiskEntry;
     ULONG Line;
     ULONG i;
     PLIST_ENTRY Entry;
@@ -2287,7 +2305,9 @@ FormatPartitionPage(PINPUT_RECORD Ir)
         return QUIT_PAGE;
     }
 
+#ifndef NDEBUG
     DiskEntry = PartitionList->CurrentDisk;
+#endif
     PartEntry = PartitionList->CurrentPartition;
     PartNum = PartitionList->CurrentPartitionNumber;
 
@@ -2360,8 +2380,6 @@ FormatPartitionPage(PINPUT_RECORD Ir)
             else if (!FileSystemList->Selected->FormatFunc)
                 return QUIT_PAGE;
 
-            CheckActiveBootPartition(PartitionList);
-
 #ifndef NDEBUG
             CONSOLE_PrintTextXY(6, 12,
                                 "Disk: %I64u  Cylinder: %I64u  Track: %I64u",
@@ -2421,19 +2439,6 @@ FormatPartitionPage(PINPUT_RECORD Ir)
                                    PathBuffer);
             DPRINT("DestinationRootPath: %wZ\n", &DestinationRootPath);
 
-
-            /* Set SystemRootPath */
-            RtlFreeUnicodeString(&SystemRootPath);
-            swprintf(PathBuffer,
-                     L"\\Device\\Harddisk%lu\\Partition%lu",
-                     PartitionList->ActiveBootDisk->DiskNumber,
-                     PartitionList->ActiveBootPartition->
-                         PartInfo[PartitionList->ActiveBootPartitionNumber].PartitionNumber);
-            RtlCreateUnicodeString(&SystemRootPath,
-                                   PathBuffer);
-            DPRINT("SystemRootPath: %wZ\n", &SystemRootPath);
-
-
             if (FileSystemList->Selected->FormatFunc)
             {
                 Status = FormatPartition(&DestinationRootPath,
@@ -2450,98 +2455,6 @@ FormatPartitionPage(PINPUT_RECORD Ir)
                 CheckActiveBootPartition(PartitionList);
             }
 
-            /* Install MBR if necessary */
-            if (DiskEntry->NoMbr &&
-                DiskEntry->BiosDiskNumber == 0)
-            {
-                wcscpy(PathBuffer, SourceRootPath.Buffer);
-                wcscat(PathBuffer, L"\\loader\\dosmbr.bin");
-
-                DPRINT("Install MBR bootcode: %S ==> %S\n",
-                       PathBuffer, DestinationRootPath.Buffer);
-
-                /* Install MBR bootcode */
-                Status = InstallMbrBootCodeToDisk(PathBuffer,
-                                                  DestinationRootPath.Buffer);
-                if (!NT_SUCCESS (Status))
-                {
-                    DPRINT1("InstallMbrBootCodeToDisk() failed (Status %lx)\n",
-                            Status);
-                    return FALSE;
-                }
-
-                DiskEntry->NoMbr = FALSE;
-            }
-
-            if (wcscmp(FileSystemList->Selected->FileSystem, L"FAT") == 0)
-            {
-                /* FIXME: Install boot code. This is a hack! */
-                if ((PartEntry->PartInfo[PartNum].PartitionType == PARTITION_FAT32_XINT13) ||
-                    (PartEntry->PartInfo[PartNum].PartitionType == PARTITION_FAT32))
-                {
-                    wcscpy(PathBuffer, SourceRootPath.Buffer);
-                    wcscat(PathBuffer, L"\\loader\\fat32.bin");
-
-                    DPRINT("Install FAT32 bootcode: %S ==> %S\n", PathBuffer,
-                           DestinationRootPath.Buffer);
-
-                    Status = InstallFat32BootCodeToDisk(PathBuffer,
-                                                        DestinationRootPath.Buffer);
-                    if (!NT_SUCCESS(Status))
-                    {
-                        DPRINT1("InstallFat32BootCodeToDisk() failed with status 0x%08lx\n", Status);
-                        /* FIXME: show an error dialog */
-                        DestroyFileSystemList(FileSystemList);
-                        FileSystemList = NULL;
-                        return QUIT_PAGE;
-                    }
-                }
-                else
-                {
-                    wcscpy(PathBuffer, SourceRootPath.Buffer);
-                    wcscat(PathBuffer, L"\\loader\\fat.bin");
-
-                    DPRINT("Install FAT bootcode: %S ==> %S\n", PathBuffer,
-                           DestinationRootPath.Buffer);
-
-                    Status = InstallFat16BootCodeToDisk(PathBuffer,
-                                                        DestinationRootPath.Buffer);
-                    if (!NT_SUCCESS(Status))
-                    {
-                        DPRINT1("InstallFat16BootCodeToDisk() failed with status 0x%.08x\n", Status);
-                        /* FIXME: show an error dialog */
-                        DestroyFileSystemList(FileSystemList);
-                        FileSystemList = NULL;
-                        return QUIT_PAGE;
-                    }
-                }
-            }
-            else if (wcscmp(FileSystemList->Selected->FileSystem, L"EXT2") == 0)
-            {
-                wcscpy(PathBuffer, SourceRootPath.Buffer);
-                wcscat(PathBuffer, L"\\loader\\ext2.bin");
-
-                DPRINT("Install EXT2 bootcode: %S ==> %S\n", PathBuffer,
-                       DestinationRootPath.Buffer);
-
-                Status = InstallFat32BootCodeToDisk(PathBuffer,
-                                                    DestinationRootPath.Buffer);
-                if (!NT_SUCCESS(Status))
-                {
-                    DPRINT1("InstallFat32BootCodeToDisk() failed with status 0x%08lx\n", Status);
-                    /* FIXME: show an error dialog */
-                    DestroyFileSystemList(FileSystemList);
-                    FileSystemList = NULL;
-                    return QUIT_PAGE;
-                }
-            }
-            else if (FileSystemList->Selected->FormatFunc)
-            {
-                DestroyFileSystemList(FileSystemList);
-                FileSystemList = NULL;
-                return QUIT_PAGE;
-            }
-
 #ifndef NDEBUG
             CONSOLE_SetStatusText("   Done.  Press any key ...");
             CONSOLE_ConInKey(Ir);
@@ -2576,15 +2489,6 @@ CheckFileSystemPage(PINPUT_RECORD Ir)
     RtlCreateUnicodeString(&DestinationRootPath, PathBuffer);
     DPRINT("DestinationRootPath: %wZ\n", &DestinationRootPath);
 
-    /* Set SystemRootPath */
-    RtlFreeUnicodeString(&SystemRootPath);
-    swprintf(PathBuffer,
-             L"\\Device\\Harddisk%lu\\Partition%lu",
-    PartitionList->ActiveBootDisk->DiskNumber,
-    PartitionList->ActiveBootPartition->PartInfo[PartNum].PartitionNumber);
-    RtlCreateUnicodeString(&SystemRootPath, PathBuffer);
-    DPRINT("SystemRootPath: %wZ\n", &SystemRootPath);
-
     CONSOLE_SetTextXY(6, 8, MUIGetString(STRING_CHECKINGPART));
 
     CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
@@ -2690,8 +2594,6 @@ InstallDirectoryPage(PINPUT_RECORD Ir)
     PDISKENTRY DiskEntry;
     PPARTENTRY PartEntry;
     WCHAR InstallDir[51];
-    PWCHAR DefaultPath;
-    INFCONTEXT Context;
     ULONG Length;
 
     if (PartitionList == NULL ||
@@ -2705,22 +2607,10 @@ InstallDirectoryPage(PINPUT_RECORD Ir)
     DiskEntry = PartitionList->CurrentDisk;
     PartEntry = PartitionList->CurrentPartition;
 
-    /* Search for 'DefaultPath' in the 'SetupData' section */
-    if (!SetupFindFirstLineW(SetupInf, L"SetupData", L"DefaultPath", &Context))
-    {
-        MUIDisplayError(ERROR_FIND_SETUPDATA, Ir, POPUP_WAIT_ENTER);
-        return QUIT_PAGE;
-    }
-
-    /* Read the 'DefaultPath' data */
-    if (INF_GetData(&Context, NULL, &DefaultPath))
-    {
-        wcscpy(InstallDir, DefaultPath);
-    }
+    if (IsUnattendedSetup)
+        wcscpy(InstallDir, UnattendInstallationDirectory);
     else
-    {
         wcscpy(InstallDir, L"\\ReactOS");
-    }
 
     Length = wcslen(InstallDir);
     CONSOLE_SetInputTextXY(8, 11, 51, InstallDir);
@@ -2866,6 +2756,7 @@ AddSectionToCopyQueue(HINF InfFile,
     PWCHAR FileKeyValue;
     PWCHAR DirKeyValue;
     PWCHAR TargetFileName;
+    WCHAR CompleteOrigFileName[512];
 
     if (SourceCabinet)
         return AddSectionToCopyQueueCab(InfFile, L"SourceFiles", SourceCabinet, DestinationPath, Ir);
@@ -2924,10 +2815,14 @@ AddSectionToCopyQueue(HINF InfFile,
             break;
         }
 
+        wcscpy(CompleteOrigFileName, SourceRootDir.Buffer);
+        wcscat(CompleteOrigFileName, L"\\");
+        wcscat(CompleteOrigFileName, DirKeyValue);
+
         if (!SetupQueueCopy(SetupFileQueue,
                             SourceCabinet,
                             SourceRootPath.Buffer,
-                            SourceRootDir.Buffer,
+                            CompleteOrigFileName,
                             FileKeyName,
                             DirKeyValue,
                             TargetFileName))
@@ -3203,6 +3098,11 @@ FileCopyCallback(PVOID Context,
 
         case SPFILENOTIFY_ENDCOPY:
             CopyContext->CompletedOperations++;
+
+            /* SYSREG checkpoint */
+            if (CopyContext->TotalOperations >> 1 == CopyContext->CompletedOperations)
+                DPRINT1("CHECKPOINT:HALF_COPIED\n");
+
             ProgressNextStep(CopyContext->ProgressBar);
             SetupUpdateMemoryInfo(CopyContext, FALSE);
             break;
@@ -3437,9 +3337,31 @@ BootLoaderPage(PINPUT_RECORD Ir)
     UCHAR PartitionType;
     BOOLEAN InstallOnFloppy;
     USHORT Line = 12;
+    WCHAR PathBuffer[MAX_PATH];
 
     CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
 
+    /* Find or set the active partition */
+    CheckActiveBootPartition(PartitionList);
+
+    /* Update the partition table because we may have changed the active partition */
+    if (WritePartitionsToDisk(PartitionList) == FALSE)
+    {
+        DPRINT("WritePartitionsToDisk() failed\n");
+        MUIDisplayError(ERROR_WRITE_PTABLE, Ir, POPUP_WAIT_ENTER);
+        return QUIT_PAGE;
+    }
+
+    RtlFreeUnicodeString(&SystemRootPath);
+    swprintf(PathBuffer,
+             L"\\Device\\Harddisk%lu\\Partition%lu",
+             PartitionList->ActiveBootDisk->DiskNumber,
+             PartitionList->ActiveBootPartition->
+                PartInfo[PartitionList->ActiveBootPartitionNumber].PartitionNumber);
+    RtlCreateUnicodeString(&SystemRootPath,
+                           PathBuffer);
+    DPRINT("SystemRootPath: %wZ\n", &SystemRootPath);
+
     PartitionType = PartitionList->ActiveBootPartition->
         PartInfo[PartitionList->ActiveBootPartitionNumber].PartitionType;
 
@@ -3503,7 +3425,7 @@ BootLoaderPage(PINPUT_RECORD Ir)
     /* Unattended install on hdd? */
     if (IsUnattendedSetup && UnattendMBRInstallType == 2)
     {
-        return BOOT_LOADER_HARDDISK_PAGE;
+        return BOOT_LOADER_HARDDISK_MBR_PAGE;
     }
 
     MUIDisplayPage(BOOT_LOADER_PAGE);
@@ -3520,9 +3442,9 @@ BootLoaderPage(PINPUT_RECORD Ir)
 
             Line++;
             if (Line<12)
-                Line=14;
+                Line=15;
 
-            if (Line>14)
+            if (Line>15)
                 Line=12;
 
             CONSOLE_InvertTextXY(8, Line, 60, 1);
@@ -3534,9 +3456,9 @@ BootLoaderPage(PINPUT_RECORD Ir)
 
             Line--;
             if (Line<12)
-                Line=14;
+                Line=15;
 
-            if (Line>14)
+            if (Line>15)
                 Line=12;
 
             CONSOLE_InvertTextXY(8, Line, 60, 1);
@@ -3553,13 +3475,17 @@ BootLoaderPage(PINPUT_RECORD Ir)
         {
             if (Line == 12)
             {
-                return BOOT_LOADER_HARDDISK_PAGE;
+                return BOOT_LOADER_HARDDISK_MBR_PAGE;
             }
             else if (Line == 13)
             {
-                return BOOT_LOADER_FLOPPY_PAGE;
+                return BOOT_LOADER_HARDDISK_VBR_PAGE;
             }
             else if (Line == 14)
+            {
+                return BOOT_LOADER_FLOPPY_PAGE;
+            }
+            else if (Line == 15)
             {
                 return SUCCESS_PAGE;
             }
@@ -3615,41 +3541,72 @@ BootLoaderFloppyPage(PINPUT_RECORD Ir)
     return BOOT_LOADER_FLOPPY_PAGE;
 }
 
+static PAGE_NUMBER
+BootLoaderHarddiskVbrPage(PINPUT_RECORD Ir)
+{
+    UCHAR PartitionType;
+    NTSTATUS Status;
+
+    PartitionType = PartitionList->ActiveBootPartition->
+                    PartInfo[PartitionList->ActiveBootPartitionNumber].PartitionType;
+
+    Status = InstallVBRToPartition(&SystemRootPath,
+                                   &SourceRootPath,
+                                   &DestinationArcPath,
+                                   PartitionType);
+    if (!NT_SUCCESS(Status))
+    {
+        MUIDisplayError(ERROR_WRITE_BOOT, Ir, POPUP_WAIT_ENTER);
+        return QUIT_PAGE;
+    }
+
+    return SUCCESS_PAGE;
+}
 
 static PAGE_NUMBER
-BootLoaderHarddiskPage(PINPUT_RECORD Ir)
+BootLoaderHarddiskMbrPage(PINPUT_RECORD Ir)
 {
     UCHAR PartitionType;
     NTSTATUS Status;
+    WCHAR DestinationDevicePathBuffer[MAX_PATH];
+    WCHAR SourceMbrPathBuffer[MAX_PATH];
 
+    /* Step 1: Write the VBR */
     PartitionType = PartitionList->ActiveBootPartition->
         PartInfo[PartitionList->ActiveBootPartitionNumber].PartitionType;
-    if ((PartitionType == PARTITION_FAT_12) ||
-        (PartitionType == PARTITION_FAT_16) ||
-        (PartitionType == PARTITION_HUGE) ||
-        (PartitionType == PARTITION_XINT13) ||
-        (PartitionType == PARTITION_FAT32) ||
-        (PartitionType == PARTITION_FAT32_XINT13))
-    {
-        Status = InstallFatBootcodeToPartition(&SystemRootPath,
-                                               &SourceRootPath,
-                                               &DestinationArcPath,
-                                               PartitionType);
-        if (!NT_SUCCESS(Status))
-        {
-            MUIDisplayError(ERROR_INSTALL_BOOTCODE, Ir, POPUP_WAIT_ENTER);
-            return QUIT_PAGE;
-        }
 
-        return SUCCESS_PAGE;
-    }
-    else
+    Status = InstallVBRToPartition(&SystemRootPath,
+                                   &SourceRootPath,
+                                   &DestinationArcPath,
+                                   PartitionType);
+    if (!NT_SUCCESS(Status))
     {
         MUIDisplayError(ERROR_WRITE_BOOT, Ir, POPUP_WAIT_ENTER);
         return QUIT_PAGE;
     }
 
-    return BOOT_LOADER_HARDDISK_PAGE;
+    /* Step 2: Write the MBR */
+    swprintf(DestinationDevicePathBuffer,
+             L"\\Device\\Harddisk%d\\Partition0",
+             PartitionList->ActiveBootDisk->DiskNumber);
+
+    wcscpy(SourceMbrPathBuffer, SourceRootPath.Buffer);
+    wcscat(SourceMbrPathBuffer, L"\\loader\\dosmbr.bin");
+
+    DPRINT("Install MBR bootcode: %S ==> %S\n",
+            SourceMbrPathBuffer, DestinationDevicePathBuffer);
+
+    Status = InstallMbrBootCodeToDisk(SourceMbrPathBuffer,
+                                      DestinationDevicePathBuffer);
+    if (!NT_SUCCESS (Status))
+    {
+        DPRINT1("InstallMbrBootCodeToDisk() failed (Status %lx)\n",
+                Status);
+        MUIDisplayError(ERROR_INSTALL_BOOTCODE, Ir, POPUP_WAIT_ENTER);
+        return QUIT_PAGE;
+    }
+
+    return SUCCESS_PAGE;
 }
 
 
@@ -3916,8 +3873,12 @@ RunUSetup(VOID)
                 Page = BootLoaderFloppyPage(&Ir);
                 break;
 
-            case BOOT_LOADER_HARDDISK_PAGE:
-                Page = BootLoaderHarddiskPage(&Ir);
+            case BOOT_LOADER_HARDDISK_MBR_PAGE:
+                Page = BootLoaderHarddiskMbrPage(&Ir);
+                break;
+
+            case BOOT_LOADER_HARDDISK_VBR_PAGE:
+                Page = BootLoaderHarddiskVbrPage(&Ir);
                 break;
 
             /* Repair pages */
@@ -3962,7 +3923,7 @@ NtProcessStartup(PPEB Peb)
     RtlNormalizeProcessParams(Peb->ProcessParameters);
 
     ProcessHeap = Peb->ProcessHeap;
-    INF_SetHeap(ProcessHeap);
+    InfSetHeap(ProcessHeap);
     RunUSetup();
 }
 #endif /* __REACTOS__ */