From e2a92634e11021378730da7bfb55f52df185e2c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Fri, 25 Aug 2017 14:38:12 +0000 Subject: [PATCH] [USETUP] Add few checks to forbid the user to attempt installing ReactOS in the installation source directory, or a subdirectory thereof, or to delete the partition containing the installation source. This is needed because the ReactOS installer can also be present from within a HDD partition! svn path=/branches/setup_improvements/; revision=75669 --- base/setup/usetup/usetup.c | 52 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c index 8ce3ec53381..a053d90fd0e 100644 --- a/base/setup/usetup/usetup.c +++ b/base/setup/usetup/usetup.c @@ -1662,12 +1662,34 @@ SelectPartitionPage(PINPUT_RECORD Ir) } else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'D') /* D */ { + WCHAR PathBuffer[MAX_PATH]; + UNICODE_STRING CurrentPartition; + if (PartitionList->CurrentPartition->IsPartitioned == FALSE) { MUIDisplayError(ERROR_DELETE_SPACE, Ir, POPUP_WAIT_ANY_KEY); return SELECT_PARTITION_PAGE; } + StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + L"\\Device\\Harddisk%lu\\Partition%lu\\", + PartitionList->CurrentDisk->DiskNumber, + PartitionList->CurrentPartition->PartitionNumber); + RtlInitUnicodeString(&CurrentPartition, PathBuffer); + + /* + * Check whether the user attempts to delete the partition on which + * the installation source is present. If so, fail with an error. + */ + // &USetupData.SourceRootPath + if (RtlPrefixUnicodeString(&CurrentPartition, &USetupData.SourcePath, TRUE)) + { + PopupError("You cannot delete the partition containing the installation source!", + MUIGetString(STRING_CONTINUE), + Ir, POPUP_WAIT_ENTER); + return SELECT_PARTITION_PAGE; + } + if (PartitionList->CurrentPartition->BootIndicator || PartitionList->CurrentPartition == PartitionList->SystemPartition) { @@ -2705,6 +2727,8 @@ SelectFileSystemPage(PINPUT_RECORD Ir) PartTypeString, ARRAYSIZE(PartTypeString)); + MUIDisplayPage(SELECT_FILE_SYSTEM_PAGE); + if (PartEntry->AutoCreate) { CONSOLE_SetTextXY(6, 8, MUIGetString(STRING_NEWPARTITION)); @@ -2789,8 +2813,6 @@ SelectFileSystemPage(PINPUT_RECORD Ir) DiskEntry->NoMbr ? "GPT" : "MBR"); } - MUIDisplayPage(SELECT_FILE_SYSTEM_PAGE); - if (FileSystemList == NULL) { /* Create the file system list, and by default select the "FAT" file system */ @@ -3228,6 +3250,19 @@ InstallDirectoryPage(PINPUT_RECORD Ir) DiskEntry, PartEntry); + /* + * Check whether the user attempts to install ReactOS within the + * installation source directory, or in a subdirectory thereof. + * If so, fail with an error. + */ + if (RtlPrefixUnicodeString(&USetupData.SourcePath, &USetupData.DestinationPath, TRUE)) + { + PopupError("You cannot install ReactOS within the installation source directory!", + MUIGetString(STRING_CONTINUE), + Ir, POPUP_WAIT_ENTER); + return INSTALL_DIRECTORY_PAGE; + } + return PREPARE_COPY_PAGE; } @@ -3317,6 +3352,19 @@ InstallDirectoryPage(PINPUT_RECORD Ir) DiskEntry, PartEntry); + /* + * Check whether the user attempts to install ReactOS within the + * installation source directory, or in a subdirectory thereof. + * If so, fail with an error. + */ + if (RtlPrefixUnicodeString(&USetupData.SourcePath, &USetupData.DestinationPath, TRUE)) + { + PopupError("You cannot install ReactOS within the installation source directory!", + MUIGetString(STRING_CONTINUE), + Ir, POPUP_WAIT_ENTER); + return INSTALL_DIRECTORY_PAGE; + } + return PREPARE_COPY_PAGE; } else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x08) /* BACKSPACE */