[USETUP]: Fix some problems with extra-backslashes in paths, and fix the support...
[reactos.git] / reactos / base / setup / usetup / interface / usetup.c
index f8d0584..84e0e04 100644 (file)
@@ -1618,7 +1618,7 @@ SelectPartitionPage(PINPUT_RECORD Ir)
 
             DestinationDriveLetter = (WCHAR)PartitionList->CurrentPartition->DriveLetter;
 
-            return INSTALL_DIRECTORY_PAGE;
+            return SELECT_FILE_SYSTEM_PAGE;
         }
         else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'P')  /* P */
         {
@@ -1960,7 +1960,7 @@ CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
                                    SectorCount,
                                    FALSE);
 
-            return SELECT_FILE_SYSTEM_PAGE;
+            return SELECT_PARTITION_PAGE;
         }
     }
 
@@ -1981,7 +1981,6 @@ CreateExtendedPartitionPage(PINPUT_RECORD Ir)
     ULONGLONG DiskSize;
     ULONGLONG SectorCount;
     PCHAR Unit;
-    NTSTATUS Status;
 
     if (PartitionList == NULL ||
         PartitionList->CurrentDisk == NULL ||
@@ -2107,14 +2106,6 @@ CreateExtendedPartitionPage(PINPUT_RECORD Ir)
             CreateExtendedPartition(PartitionList,
                                     SectorCount);
 
-            Status = WriteDirtyPartitions(PartitionList);
-            if (!NT_SUCCESS(Status))
-            {
-                DPRINT("WriteDirtyPartitions() failed\n");
-                MUIDisplayError(ERROR_WRITE_PTABLE, Ir, POPUP_WAIT_ENTER);
-                return QUIT_PAGE;
-            }
-
             return SELECT_PARTITION_PAGE;
         }
     }
@@ -2261,7 +2252,7 @@ CreateLogicalPartitionPage(PINPUT_RECORD Ir)
             CreateLogicalPartition(PartitionList,
                                    SectorCount);
 
-            return SELECT_FILE_SYSTEM_PAGE;
+            return SELECT_PARTITION_PAGE;
         }
     }
 
@@ -2278,7 +2269,6 @@ DeletePartitionPage(PINPUT_RECORD Ir)
     ULONGLONG PartSize;
     PCHAR Unit;
     PCHAR PartType;
-    NTSTATUS Status;
 
     if (PartitionList == NULL ||
         PartitionList->CurrentDisk == NULL ||
@@ -2431,14 +2421,6 @@ DeletePartitionPage(PINPUT_RECORD Ir)
         {
             DeleteCurrentPartition(PartitionList);
 
-            Status = WriteDirtyPartitions(PartitionList);
-            if (!NT_SUCCESS(Status))
-            {
-                DPRINT("WriteDirtyPartitions() failed\n");
-                MUIDisplayError(ERROR_WRITE_PTABLE, Ir, POPUP_WAIT_ENTER);
-                return QUIT_PAGE;
-            }
-
             return SELECT_PARTITION_PAGE;
         }
     }
@@ -2447,67 +2429,6 @@ DeletePartitionPage(PINPUT_RECORD Ir)
 }
 
 
-static
-VOID
-UpdatePartitionType(
-    PPARTENTRY PartEntry,
-    LPCWSTR FileSystem)
-{
-    if (wcscmp(FileSystem, L"FAT") == 0)
-    {
-        if (PartEntry->SectorCount.QuadPart < 8192)
-        {
-            /* FAT12 CHS partition (disk is smaller than 4.1MB) */
-            PartEntry->PartitionType = PARTITION_FAT_12;
-        }
-        else if (PartEntry->StartSector.QuadPart < 1450560)
-        {
-            /* Partition starts below the 8.4GB boundary ==> CHS partition */
-
-            if (PartEntry->SectorCount.QuadPart < 65536)
-            {
-                /* FAT16 CHS partition (partiton size < 32MB) */
-                PartEntry->PartitionType = PARTITION_FAT_16;
-            }
-            else if (PartEntry->SectorCount.QuadPart < 1048576)
-            {
-                /* FAT16 CHS partition (partition size < 512MB) */
-                PartEntry->PartitionType = PARTITION_HUGE;
-            }
-            else
-            {
-                /* FAT32 CHS partition (partition size >= 512MB) */
-                PartEntry->PartitionType = PARTITION_FAT32;
-            }
-        }
-        else
-        {
-            /* Partition starts above the 8.4GB boundary ==> LBA partition */
-
-            if (PartEntry->SectorCount.QuadPart < 1048576)
-            {
-                /* FAT16 LBA partition (partition size < 512MB) */
-                PartEntry->PartitionType = PARTITION_XINT13;
-            }
-            else
-            {
-                /* FAT32 LBA partition (partition size >= 512MB) */
-                PartEntry->PartitionType = PARTITION_FAT32_XINT13;
-            }
-        }
-
-        PartEntry->DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType = PartEntry->PartitionType;
-    }
-#if 0
-    else if (wcscmp(FileSystemList->Selected->FileSystem, L"EXT2") == 0)
-    {
-        PartEntry->PartitionType = PARTITION_EXT2;
-        PartEntry->DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType = PartEntry->PartitionType;
-    }
-#endif
-}
-
-
 static PAGE_NUMBER
 SelectFileSystemPage(PINPUT_RECORD Ir)
 {
@@ -2518,7 +2439,6 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
     PCHAR DiskUnit;
     PCHAR PartUnit;
     PCHAR PartType;
-    NTSTATUS Status;
 
     if (PartitionList == NULL ||
         PartitionList->CurrentDisk == NULL ||
@@ -2679,17 +2599,6 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
     {
         if (UnattendFormatPartition)
         {
-            UpdatePartitionType(PartEntry,
-                                FileSystemList->Selected->FileSystem);
-
-            Status = WriteDirtyPartitions(PartitionList);
-            if (!NT_SUCCESS(Status))
-            {
-                DPRINT1("WriteDirtyPartitions() failed (Status 0x%08lx)\n", Status);
-                MUIDisplayError(ERROR_WRITE_PTABLE, Ir, POPUP_WAIT_ENTER);
-                return QUIT_PAGE;
-            }
-
             return FORMAT_PARTITION_PAGE;
         }
 
@@ -2733,19 +2642,6 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
             }
             else
             {
-                UpdatePartitionType(PartEntry,
-                                    FileSystemList->Selected->FileSystem);
-
-                CheckActiveBootPartition(PartitionList);
-
-                Status = WriteDirtyPartitions(PartitionList);
-                if (!NT_SUCCESS(Status))
-                {
-                    DPRINT("WriteDirtyPartitions() failed (Status 0x%08lx)\n", Status);
-                    MUIDisplayError(ERROR_WRITE_PTABLE, Ir, POPUP_WAIT_ENTER);
-                    return QUIT_PAGE;
-                }
-
                 return FORMAT_PARTITION_PAGE;
             }
         }
@@ -2759,7 +2655,7 @@ static ULONG
 FormatPartitionPage(PINPUT_RECORD Ir)
 {
     WCHAR PathBuffer[MAX_PATH];
-//    PDISKENTRY DiskEntry;
+    PDISKENTRY DiskEntry;
     PPARTENTRY PartEntry;
     NTSTATUS Status;
 
@@ -2779,7 +2675,7 @@ FormatPartitionPage(PINPUT_RECORD Ir)
         return QUIT_PAGE;
     }
 
-//    DiskEntry = PartitionList->CurrentDisk;
+    DiskEntry = PartitionList->CurrentDisk;
     PartEntry = PartitionList->CurrentPartition;
 
     while (TRUE)
@@ -2803,7 +2699,59 @@ FormatPartitionPage(PINPUT_RECORD Ir)
         {
             CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
 
-            if (!FileSystemList->Selected->FormatFunc)
+            if (wcscmp(FileSystemList->Selected->FileSystem, L"FAT") == 0)
+            {
+                if (PartEntry->SectorCount.QuadPart < 8192)
+                {
+                    /* FAT12 CHS partition (disk is smaller than 4.1MB) */
+                    PartEntry->PartitionType = PARTITION_FAT_12;
+                }
+                else if (PartEntry->StartSector.QuadPart < 1450560)
+                {
+                    /* Partition starts below the 8.4GB boundary ==> CHS partition */
+
+                    if (PartEntry->SectorCount.QuadPart < 65536)
+                    {
+                        /* FAT16 CHS partition (partiton size < 32MB) */
+                        PartEntry->PartitionType = PARTITION_FAT_16;
+                    }
+                    else if (PartEntry->SectorCount.QuadPart < 1048576)
+                    {
+                        /* FAT16 CHS partition (partition size < 512MB) */
+                        PartEntry->PartitionType = PARTITION_HUGE;
+                    }
+                    else
+                    {
+                        /* FAT32 CHS partition (partition size >= 512MB) */
+                        PartEntry->PartitionType = PARTITION_FAT32;
+                    }
+                }
+                else
+                {
+                    /* Partition starts above the 8.4GB boundary ==> LBA partition */
+
+                    if (PartEntry->SectorCount.QuadPart < 1048576)
+                    {
+                        /* FAT16 LBA partition (partition size < 512MB) */
+                        PartEntry->PartitionType = PARTITION_XINT13;
+                    }
+                    else
+                    {
+                        /* FAT32 LBA partition (partition size >= 512MB) */
+                        PartEntry->PartitionType = PARTITION_FAT32_XINT13;
+                    }
+                }
+
+                DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType = PartEntry->PartitionType;
+            }
+#if 0
+            else if (wcscmp(FileSystemList->Selected->FileSystem, L"EXT2") == 0)
+            {
+                PartEntry->PartitionType = PARTITION_EXT2;
+                DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType = PartEntry->PartitionType;
+            }
+#endif
+            else if (!FileSystemList->Selected->FormatFunc)
                 return QUIT_PAGE;
 
 #ifndef NDEBUG
@@ -2842,6 +2790,15 @@ FormatPartitionPage(PINPUT_RECORD Ir)
             PartEntry = PartitionList->CurrentPartition;
 #endif
 
+            CheckActiveBootPartition(PartitionList);
+
+            if (WritePartitionsToDisk(PartitionList) == FALSE)
+            {
+                DPRINT("WritePartitionsToDisk() failed\n");
+                MUIDisplayError(ERROR_WRITE_PTABLE, Ir, POPUP_WAIT_ENTER);
+                return QUIT_PAGE;
+            }
+
             /* Set DestinationRootPath */
             RtlFreeUnicodeString(&DestinationRootPath);
             swprintf(PathBuffer,
@@ -2874,11 +2831,7 @@ FormatPartitionPage(PINPUT_RECORD Ir)
 
             DestroyFileSystemList(FileSystemList);
             FileSystemList = NULL;
-
-            if (IsUnattendedSetup)
-                return INSTALL_DIRECTORY_PAGE;
-            else
-                return SELECT_PARTITION_PAGE;
+            return INSTALL_DIRECTORY_PAGE;
         }
     }
 
@@ -2975,16 +2928,6 @@ InstallDirectoryPage1(PWCHAR InstallDir,
     RtlCreateUnicodeString(&InstallPath,
                            InstallDir);
 
-    /* Set DestinationRootPath */
-    RtlFreeUnicodeString(&DestinationRootPath);
-    swprintf(PathBuffer,
-             L"\\Device\\Harddisk%lu\\Partition%lu",
-             DiskEntry->DiskNumber,
-             PartEntry->PartitionNumber);
-    RtlCreateUnicodeString(&DestinationRootPath,
-                           PathBuffer);
-    DPRINT("DestinationRootPath: %wZ\n", &DestinationRootPath);
-
     /* Create 'DestinationPath' string */
     RtlFreeUnicodeString(&DestinationPath);
     wcscpy(PathBuffer, DestinationRootPath.Buffer);
@@ -3178,7 +3121,8 @@ AddSectionToCopyQueue(HINF InfFile,
     PWCHAR FileKeyValue;
     PWCHAR DirKeyValue;
     PWCHAR TargetFileName;
-    WCHAR CompleteOrigFileName[512];
+    ULONG Length;
+    WCHAR CompleteOrigDirName[512];
 
     if (SourceCabinet)
         return AddSectionToCopyQueueCab(InfFile, L"SourceFiles", SourceCabinet, DestinationPath, Ir);
@@ -3237,14 +3181,35 @@ AddSectionToCopyQueue(HINF InfFile,
             break;
         }
 
-        wcscpy(CompleteOrigFileName, SourceRootDir.Buffer);
-        wcscat(CompleteOrigFileName, L"\\");
-        wcscat(CompleteOrigFileName, DirKeyValue);
+        if ((DirKeyValue[0] == 0) || (DirKeyValue[0] == L'\\' && DirKeyValue[1] == 0))
+        {
+            /* Installation path */
+            wcscpy(CompleteOrigDirName, SourceRootDir.Buffer);
+        }
+        else if (DirKeyValue[0] == L'\\')
+        {
+            /* Absolute path */
+            wcscpy(CompleteOrigDirName, DirKeyValue);
+        }
+        else // if (DirKeyValue[0] != L'\\')
+        {
+            /* Path relative to the installation path */
+            wcscpy(CompleteOrigDirName, SourceRootDir.Buffer);
+            wcscat(CompleteOrigDirName, L"\\");
+            wcscat(CompleteOrigDirName, DirKeyValue);
+        }
+
+        /* Remove trailing backslash */
+        Length = wcslen(CompleteOrigDirName);
+        if ((Length > 0) && (CompleteOrigDirName[Length - 1] == L'\\'))
+        {
+            CompleteOrigDirName[Length - 1] = 0;
+        }
 
         if (!SetupQueueCopy(SetupFileQueue,
                             SourceCabinet,
                             SourceRootPath.Buffer,
-                            CompleteOrigFileName,
+                            CompleteOrigDirName,
                             FileKeyName,
                             DirKeyValue,
                             TargetFileName))
@@ -3266,7 +3231,7 @@ PrepareCopyPageInfFile(HINF InfFile,
     WCHAR PathBuffer[MAX_PATH];
     INFCONTEXT DirContext;
     PWCHAR AdditionalSectionName = NULL;
-    PWCHAR KeyValue;
+    PWCHAR DirKeyValue;
     ULONG Length;
     NTSTATUS Status;
 
@@ -3290,16 +3255,20 @@ PrepareCopyPageInfFile(HINF InfFile,
     /* Create directories */
 
     /*
-    * FIXME:
-    * Install directories like '\reactos\test' are not handled yet.
-    */
+     * FIXME:
+     * - Install directories like '\reactos\test' are not handled yet.
+     * - Copying files to DestinationRootPath should be done from within
+     *   the SystemPartitionFiles section.
+     *   At the moment we check whether we specify paths like '\foo' or '\\' for that.
+     *   For installing to DestinationPath specify just '\' .
+     */
 
     /* Get destination path */
     wcscpy(PathBuffer, DestinationPath.Buffer);
 
     /* Remove trailing backslash */
     Length = wcslen(PathBuffer);
-    if ((Length > 0) && (PathBuffer[Length - 1] == '\\'))
+    if ((Length > 0) && (PathBuffer[Length - 1] == L'\\'))
     {
         PathBuffer[Length - 1] = 0;
     }
@@ -3331,27 +3300,61 @@ PrepareCopyPageInfFile(HINF InfFile,
     /* Enumerate the directory values and create the subdirectories */
     do
     {
-        if (!INF_GetData(&DirContext, NULL, &KeyValue))
+        if (!INF_GetData(&DirContext, NULL, &DirKeyValue))
         {
             DPRINT1("break\n");
             break;
         }
 
-        if (KeyValue[0] == L'\\' && KeyValue[1] != 0)
+        if ((DirKeyValue[0] == 0) || (DirKeyValue[0] == L'\\' && DirKeyValue[1] == 0))
+        {
+            /* Installation path */
+            DPRINT("InstallationPath: '%S'\n", DirKeyValue);
+
+            wcscpy(PathBuffer, DestinationPath.Buffer);
+
+            DPRINT("FullPath: '%S'\n", PathBuffer);
+        }
+        else if (DirKeyValue[0] == L'\\')
         {
-            DPRINT("Absolute Path: '%S'\n", KeyValue);
+            /* Absolute path */
+            DPRINT("Absolute Path: '%S'\n", DirKeyValue);
 
             wcscpy(PathBuffer, DestinationRootPath.Buffer);
-            wcscat(PathBuffer, KeyValue);
+            wcscat(PathBuffer, DirKeyValue);
+
+            /* Remove trailing backslash */
+            Length = wcslen(PathBuffer);
+            if ((Length > 0) && (PathBuffer[Length - 1] == L'\\'))
+            {
+                PathBuffer[Length - 1] = 0;
+            }
 
             DPRINT("FullPath: '%S'\n", PathBuffer);
+
+            Status = SetupCreateDirectory(PathBuffer);
+            if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_COLLISION)
+            {
+                DPRINT("Creating directory '%S' failed: Status = 0x%08lx", PathBuffer, Status);
+                MUIDisplayError(ERROR_CREATE_DIR, Ir, POPUP_WAIT_ENTER);
+                return FALSE;
+            }
         }
-        else if (KeyValue[0] != L'\\')
+        else // if (DirKeyValue[0] != L'\\')
         {
-            DPRINT("RelativePath: '%S'\n", KeyValue);
+            /* Path relative to the installation path */
+            DPRINT("RelativePath: '%S'\n", DirKeyValue);
+
             wcscpy(PathBuffer, DestinationPath.Buffer);
             wcscat(PathBuffer, L"\\");
-            wcscat(PathBuffer, KeyValue);
+            wcscat(PathBuffer, DirKeyValue);
+
+            /* Remove trailing backslash */
+            Length = wcslen(PathBuffer);
+            if ((Length > 0) && (PathBuffer[Length - 1] == L'\\'))
+            {
+                PathBuffer[Length - 1] = 0;
+            }
 
             DPRINT("FullPath: '%S'\n", PathBuffer);
 
@@ -3363,7 +3366,7 @@ PrepareCopyPageInfFile(HINF InfFile,
                 return FALSE;
             }
         }
-    } while (SetupFindNextLine (&DirContext, &DirContext));
+    } while (SetupFindNextLine(&DirContext, &DirContext));
 
     return TRUE;
 }
@@ -3763,7 +3766,6 @@ BootLoaderPage(PINPUT_RECORD Ir)
     BOOLEAN InstallOnFloppy;
     USHORT Line = 12;
     WCHAR PathBuffer[MAX_PATH];
-    NTSTATUS Status;
 
     CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
 
@@ -3771,10 +3773,9 @@ BootLoaderPage(PINPUT_RECORD Ir)
     CheckActiveBootPartition(PartitionList);
 
     /* Update the partition table because we may have changed the active partition */
-    Status = WriteDirtyPartitions(PartitionList);
-    if (!NT_SUCCESS(Status))
+    if (WritePartitionsToDisk(PartitionList) == FALSE)
     {
-        DPRINT("WriteDirtyPartitions() failed\n");
+        DPRINT("WritePartitionsToDisk() failed\n");
         MUIDisplayError(ERROR_WRITE_PTABLE, Ir, POPUP_WAIT_ENTER);
         return QUIT_PAGE;
     }