[USETUP]
[reactos.git] / reactos / base / setup / usetup / interface / usetup.c
index 87c0bc5..ea1711e 100644 (file)
@@ -12,9 +12,9 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 /*
  * COPYRIGHT:       See COPYING in the top level directory
@@ -79,6 +79,8 @@ static PGENERIC_LIST KeyboardList = NULL;
 static PGENERIC_LIST LayoutList = NULL;
 static PGENERIC_LIST LanguageList = NULL;
 
+static LANGID LanguageId = 0;
+
 /* FUNCTIONS ****************************************************************/
 
 static VOID
@@ -422,6 +424,7 @@ CheckUnattendedSetup(VOID)
     UnattendInf = SetupOpenInfFileW(UnattendInfPath,
                                     NULL,
                                     INF_STYLE_WIN4,
+                                    LanguageId,
                                     &ErrorLine);
 
     if (UnattendInf == INVALID_HANDLE_VALUE)
@@ -580,6 +583,11 @@ UpdateKBLayout(VOID)
     if (LayoutList == NULL)
     {
         LayoutList = CreateKeyboardLayoutList(SetupInf, DefaultKBLayout);
+        if (LayoutList == NULL)
+        {
+            /* FIXME: Handle error! */
+            return;
+        }
     }
 
     ListEntry = GetFirstListEntry(LayoutList);
@@ -673,6 +681,8 @@ LanguagePage(PINPUT_RECORD Ir)
         {
             SelectedLanguageId = (PWCHAR)GetListEntryUserData(GetCurrentListEntry(LanguageList));
 
+            LanguageId = (LANGID)(wcstol(SelectedLanguageId, NULL, 16) & 0xFFFF);
+
             if (wcscmp(SelectedLanguageId, DefaultLanguage))
             {
                 UpdateKBLayout();
@@ -760,6 +770,7 @@ SetupStartPage(PINPUT_RECORD Ir)
     SetupInf = SetupOpenInfFileW(FileNameBuffer,
                                  NULL,
                                  INF_STYLE_WIN4,
+                                 LanguageId,
                                  &ErrorLine);
 
     if (SetupInf == INVALID_HANDLE_VALUE)
@@ -841,9 +852,9 @@ SetupStartPage(PINPUT_RECORD Ir)
 
                        ListEntry = GetNextListEntry(ListEntry);
                }
-        SetConsoleCodePage();
+               SetConsoleCodePage();
 
-           return INSTALL_INTRO_PAGE;
+               return INSTALL_INTRO_PAGE;
     }
 
     return LANGUAGE_PAGE;
@@ -1781,8 +1792,8 @@ CreatePartitionPage (PINPUT_RECORD Ir)
             else
             {
                 /* Round-up by cylinder size */
-                PartSize = ROUND_UP (PartSize * 1024 * 1024,
-                                     DiskEntry->CylinderSize);
+                PartSize = (PartSize * 1024 * 1024 + DiskEntry->CylinderSize - 1) /
+                           DiskEntry->CylinderSize * DiskEntry->CylinderSize;
 
                 /* But never get larger than the unpartitioned disk space */
                 if (PartSize > PartEntry->UnpartitionedLength)
@@ -2380,6 +2391,28 @@ 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! */
@@ -3018,6 +3051,7 @@ PrepareCopyPage(PINPUT_RECORD Ir)
                                           InfFileSize,
                                           (const CHAR*) NULL,
                                           INF_STYLE_WIN4,
+                                          LanguageId,
                                           &ErrorLine);
 
         if (InfHandle == INVALID_HANDLE_VALUE)
@@ -3106,6 +3140,7 @@ PAGE_NUMBER
 FileCopyPage(PINPUT_RECORD Ir)
 {
     COPYCONTEXT CopyContext;
+    unsigned int mem_bar_width;
 
     MUIDisplayPage(FILE_COPY_PAGE);
 
@@ -3126,7 +3161,7 @@ FileCopyPage(PINPUT_RECORD Ir)
                                                 MUIGetString(STRING_SETUPCOPYINGFILES));
 
     // fit memory bars to screen width, distribute them uniform
-    unsigned int mem_bar_width = (xScreen - 26) / 5;
+    mem_bar_width = (xScreen - 26) / 5;
     mem_bar_width -= mem_bar_width % 2;  // make even
     /* ATTENTION: The following progress bars are debug stuff, which should not be translated!! */
     /* Create the paged pool progress bar */
@@ -3246,7 +3281,7 @@ RegistryPage(PINPUT_RECORD Ir)
 
         CONSOLE_SetStatusText(MUIGetString(STRING_IMPORTFILE), File);
 
-        if (!ImportRegistryFile(File, Section, Delete))
+        if (!ImportRegistryFile(File, Section, LanguageId, Delete))
         {
             DPRINT("Importing %S failed\n", File);
 
@@ -3323,7 +3358,20 @@ BootLoaderPage(PINPUT_RECORD Ir)
 
     CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
 
-    PartitionType = PartitionList->ActiveBootPartition->PartInfo[0].PartitionType;
+    PartitionType = PartitionList->ActiveBootPartition->
+        PartInfo[PartitionList->ActiveBootPartitionNumber].PartitionType;
+
+    if (IsUnattendedSetup)
+    {
+        if (UnattendMBRInstallType == 0) /* skip MBR installation */
+        {
+            return SUCCESS_PAGE;
+        }
+        else if (UnattendMBRInstallType == 1) /* install on floppy */
+        {
+            return BOOT_LOADER_FLOPPY_PAGE;
+        }
+    }
 
     if (PartitionType == PARTITION_ENTRY_UNUSED)
     {
@@ -3370,20 +3418,10 @@ BootLoaderPage(PINPUT_RECORD Ir)
         return BOOT_LOADER_FLOPPY_PAGE;
     }
 
-    if (IsUnattendedSetup)
+    /* Unattended install on hdd? */
+    if (IsUnattendedSetup && UnattendMBRInstallType == 2)
     {
-        if (UnattendMBRInstallType == 0) /* skip MBR installation */
-        {
-            return SUCCESS_PAGE;
-        }
-        else if (UnattendMBRInstallType == 1) /* install on floppy */
-        {
-            return BOOT_LOADER_FLOPPY_PAGE;
-        }
-        else if (UnattendMBRInstallType == 2) /* install on hdd */
-        {
-            return BOOT_LOADER_HARDDISK_PAGE;
-        }
+        return BOOT_LOADER_HARDDISK_PAGE;
     }
 
     MUIDisplayPage(BOOT_LOADER_PAGE);
@@ -3496,7 +3534,8 @@ BootLoaderHarddiskPage(PINPUT_RECORD Ir)
     UCHAR PartitionType;
     NTSTATUS Status;
 
-    PartitionType = PartitionList->ActiveBootPartition->PartInfo[0].PartitionType;
+    PartitionType = PartitionList->ActiveBootPartition->
+        PartInfo[PartitionList->ActiveBootPartitionNumber].PartitionType;
     if ((PartitionType == PARTITION_FAT_12) ||
         (PartitionType == PARTITION_FAT_16) ||
         (PartitionType == PARTITION_HUGE) ||