Copy file dates of source file too.
authorEric Kohl <eric.kohl@reactos.org>
Sat, 8 Feb 2003 00:19:32 +0000 (00:19 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 8 Feb 2003 00:19:32 +0000 (00:19 +0000)
Get default install directory from txtsetup.sif.

svn path=/trunk/; revision=4116

reactos/subsys/system/usetup/filesup.c
reactos/subsys/system/usetup/usetup.c

index b9dc565..15d9917 100644 (file)
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: filesup.c,v 1.4 2003/01/17 13:18:15 ekohl Exp $
+/* $Id: filesup.c,v 1.5 2003/02/08 00:19:32 ekohl Exp $
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS text-mode setup
  * FILE:            subsys/system/usetup/filesup.c
@@ -48,15 +48,6 @@ CreateDirectory(PWCHAR DirectoryName)
   RtlCreateUnicodeString(&PathName,
                         DirectoryName);
 
-#if 0
-  ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
-  ObjectAttributes.RootDirectory = NULL;
-  ObjectAttributes.ObjectName = &PathName;
-  ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE | OBJ_INHERIT;
-  ObjectAttributes.SecurityDescriptor = NULL;
-  ObjectAttributes.SecurityQualityOfService = NULL;
-#endif
-
   InitializeObjectAttributes(&ObjectAttributes,
                             &PathName,
                             OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
@@ -119,10 +110,10 @@ SetupCopyFile(PWCHAR SourceFileName,
                      FILE_SHARE_READ,
                      FILE_SYNCHRONOUS_IO_ALERT | FILE_SEQUENTIAL_ONLY);
   if (!NT_SUCCESS(Status))
-  {
+    {
 CHECKPOINT1;
-    return(Status);
-  }
+      return(Status);
+    }
 
   Status = NtQueryInformationFile(FileHandleSource,
                                  &IoStatusBlock,
@@ -130,22 +121,22 @@ CHECKPOINT1;
                                  sizeof(FILE_STANDARD_INFORMATION),
                                  FileStandardInformation);
   if (!NT_SUCCESS(Status))
-  {
+    {
 CHECKPOINT1;
-    NtClose(FileHandleSource);
-    return(Status);
-  }
+     NtClose(FileHandleSource);
+     return(Status);
+    }
 
   Status = NtQueryInformationFile(FileHandleSource,
                                  &IoStatusBlock,&FileBasic,
                                  sizeof(FILE_BASIC_INFORMATION),
                                  FileBasicInformation);
   if (!NT_SUCCESS(Status))
-  {
+    {
 CHECKPOINT1;
-    NtClose(FileHandleSource);
-    return(Status);
-  }
+      NtClose(FileHandleSource);
+      return(Status);
+    }
 
   RtlInitUnicodeString(&FileName,
                       DestinationFileName);
@@ -168,11 +159,11 @@ CHECKPOINT1;
                        NULL,
                        0);
   if (!NT_SUCCESS(Status))
-  {
+    {
 CHECKPOINT1;
-    NtClose(FileHandleSource);
-    return(Status);
-  }
+      NtClose(FileHandleSource);
+      return(Status);
+    }
 
   FilePosition.CurrentByteOffset.QuadPart = 0;
 
@@ -182,12 +173,12 @@ CHECKPOINT1;
                                sizeof(FILE_POSITION_INFORMATION),
                                FilePositionInformation);
   if (!NT_SUCCESS(Status))
-  {
+    {
 CHECKPOINT1;
-    NtClose(FileHandleSource);
-    NtClose(FileHandleDest);
-    return(Status);
-  }
+      NtClose(FileHandleSource);
+      NtClose(FileHandleDest);
+      return(Status);
+    }
 
   Status = NtSetInformationFile(FileHandleDest,
                                &IoStatusBlock,
@@ -195,18 +186,18 @@ CHECKPOINT1;
                                sizeof(FILE_POSITION_INFORMATION),
                                FilePositionInformation);
   if (!NT_SUCCESS(Status))
-  {
+    {
 CHECKPOINT1;
-    NtClose(FileHandleSource);
-    NtClose(FileHandleDest);
-    return(Status);
-  }
+      NtClose(FileHandleSource);
+      NtClose(FileHandleDest);
+      return(Status);
+    }
 
   RegionSize = PAGE_ROUND_UP(FileStandard.EndOfFile.u.LowPart);
   if (RegionSize > 0x100000)
-  {
-     RegionSize = 0x100000;
-  }
+    {
+      RegionSize = 0x100000;
+    }
   Status = NtAllocateVirtualMemory(NtCurrentProcess(),
                                   (PVOID *)&Buffer,
                                   2,
@@ -214,66 +205,81 @@ CHECKPOINT1;
                                   MEM_RESERVE | MEM_COMMIT,
                                   PAGE_READWRITE);
   if (!NT_SUCCESS(Status))
-  {
-CHECKPOINT1;
-    NtClose(FileHandleSource);
-    NtClose(FileHandleDest);
-    return(Status);
-  }
-
-  while (TRUE)
-  {
-    Status = NtReadFile(FileHandleSource,
-                       NULL,
-                       NULL,
-                       NULL,
-                       &IoStatusBlock,
-                       Buffer,
-                       RegionSize,
-                       NULL,
-                       NULL);
-    if (!NT_SUCCESS(Status))
     {
-      NtFreeVirtualMemory(NtCurrentProcess(),
-                         (PVOID *)&Buffer,
-                         &RegionSize,
-                         MEM_RELEASE);
+CHECKPOINT1;
       NtClose(FileHandleSource);
       NtClose(FileHandleDest);
-      if (Status == STATUS_END_OF_FILE)
-      {
-       DPRINT("STATUS_END_OF_FILE\n");
-       break;
-      }
-CHECKPOINT1;
       return(Status);
     }
 
-DPRINT("Bytes read %lu\n", IoStatusBlock.Information);
-
-    Status = NtWriteFile(FileHandleDest,
-                        NULL,
-                        NULL,
-                        NULL,
-                        &IoStatusBlock,
-                        Buffer,
-                        IoStatusBlock.Information,
-                        NULL,
-                        NULL);
-    if (!NT_SUCCESS(Status))
+  while (TRUE)
     {
+      Status = NtReadFile(FileHandleSource,
+                         NULL,
+                         NULL,
+                         NULL,
+                         &IoStatusBlock,
+                         Buffer,
+                         RegionSize,
+                         NULL,
+                         NULL);
+      if (!NT_SUCCESS(Status))
+       {
+         NtFreeVirtualMemory(NtCurrentProcess(),
+                             (PVOID *)&Buffer,
+                             &RegionSize,
+                             MEM_RELEASE);
+         if (Status == STATUS_END_OF_FILE)
+           {
+             DPRINT("STATUS_END_OF_FILE\n");
+             break;
+           }
 CHECKPOINT1;
-      NtFreeVirtualMemory(NtCurrentProcess(),
-                         (PVOID *)&Buffer,
-                         &RegionSize,
-                         MEM_RELEASE);
-      NtClose(FileHandleSource);
-      NtClose(FileHandleDest);
-      return(Status);
+         NtClose(FileHandleSource);
+         NtClose(FileHandleDest);
+         return(Status);
+       }
+
+      DPRINT("Bytes read %lu\n", IoStatusBlock.Information);
+
+      Status = NtWriteFile(FileHandleDest,
+                          NULL,
+                          NULL,
+                          NULL,
+                          &IoStatusBlock,
+                          Buffer,
+                          IoStatusBlock.Information,
+                          NULL,
+                          NULL);
+      if (!NT_SUCCESS(Status))
+       {
+CHECKPOINT1;
+         NtFreeVirtualMemory(NtCurrentProcess(),
+                             (PVOID *)&Buffer,
+                             &RegionSize,
+                             MEM_RELEASE);
+         NtClose(FileHandleSource);
+         NtClose(FileHandleDest);
+         return(Status);
+       }
     }
-  }
 
-  return(STATUS_SUCCESS);
+
+  /* Copy file date/time from source file */
+  Status = NtSetInformationFile(FileHandleDest,
+                               &IoStatusBlock,
+                               &FileBasic,
+                               sizeof(FILE_BASIC_INFORMATION),
+                               FileBasicInformation);
+  if (!NT_SUCCESS(Status))
+    {
+      DPRINT("NtSetInformationFile() failed (Status %lx)\n", Status);
+    }
+
+  NtClose(FileHandleSource);
+  NtClose(FileHandleDest);
+
+  return(Status);
 }
 
 
@@ -312,10 +318,10 @@ DoesFileExist(PWSTR PathName,
                      0,
                      FILE_SYNCHRONOUS_IO_ALERT);
   if (!NT_SUCCESS(Status))
-  {
+    {
 CHECKPOINT1;
-    return(FALSE);
-  }
+      return(FALSE);
+    }
 
   NtClose(FileHandle);
 
index 7aecaef..20d1883 100644 (file)
@@ -407,39 +407,39 @@ StartPage(PINPUT_RECORD Ir)
                        &FileName,
                        TRUE);
   if (!NT_SUCCESS(Status))
-  {
-    PopupError("Setup failed to load the file TXTSETUP.SIF.\n",
-              "ENTER = Reboot computer");
+    {
+      PopupError("Setup failed to load the file TXTSETUP.SIF.\n",
+                "ENTER = Reboot computer");
 
       while(TRUE)
-      {
-       ConInKey(Ir);
-
-       if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
        {
-         return(QUIT_PAGE);
+         ConInKey(Ir);
+
+         if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D)       /* ENTER */
+           {
+             return(QUIT_PAGE);
+           }
        }
-      }
-  }
+    }
 
   /* Open 'Version' section */
   Section = IniCacheGetSection(IniCache,
                               L"Version");
   if (Section == NULL)
-  {
-    PopupError("Setup found a corrupt TXTSETUP.SIF.\n",
-              "ENTER = Reboot computer");
+    {
+      PopupError("Setup found a corrupt TXTSETUP.SIF.\n",
+                "ENTER = Reboot computer");
 
       while(TRUE)
-      {
-       ConInKey(Ir);
-
-       if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
        {
-         return(QUIT_PAGE);
+         ConInKey(Ir);
+
+         if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D)       /* ENTER */
+           {
+             return(QUIT_PAGE);
+           }
        }
-      }
-  }
+    }
 
 
   /* Get pointer 'Signature' key */
@@ -447,37 +447,37 @@ StartPage(PINPUT_RECORD Ir)
                          L"Signature",
                          &Value);
   if (!NT_SUCCESS(Status))
-  {
-    PopupError("Setup found a corrupt TXTSETUP.SIF.\n",
-              "ENTER = Reboot computer");
+    {
+      PopupError("Setup found a corrupt TXTSETUP.SIF.\n",
+                "ENTER = Reboot computer");
 
       while(TRUE)
-      {
-       ConInKey(Ir);
-
-       if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
        {
-         return(QUIT_PAGE);
+         ConInKey(Ir);
+
+         if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D)       /* ENTER */
+           {
+             return(QUIT_PAGE);
+           }
        }
-      }
-  }
+    }
 
   /* Check 'Signature' string */
   if (_wcsicmp(Value, L"$ReactOS$") != 0)
-  {
-    PopupError("Setup found an invalid signature in TXTSETUP.SIF.\n",
-              "ENTER = Reboot computer");
-
-    while(TRUE)
     {
-      ConInKey(Ir);
+      PopupError("Setup found an invalid signature in TXTSETUP.SIF.\n",
+                "ENTER = Reboot computer");
 
-      if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D)  /* ENTER */
-      {
-       return(QUIT_PAGE);
-      }
+      while(TRUE)
+       {
+         ConInKey(Ir);
+
+         if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D)       /* ENTER */
+           {
+             return(QUIT_PAGE);
+           }
+       }
     }
-  }
 
   return(INTRO_PAGE);
 }
@@ -492,9 +492,9 @@ RepairIntroPage(PINPUT_RECORD Ir)
 
   SetTextXY(6, 12, "The repair functions are not implemented yet.");
 
-  SetTextXY(8, 15, "\xf9  Press ESC to return to the main page.");
+  SetTextXY(8, 15, "\xfa  Press ESC to return to the main page.");
 
-  SetTextXY(8, 17, "\xf9  Press ENTER to reboot your computer.");
+  SetTextXY(8, 17, "\xfa  Press ENTER to reboot your computer.");
 
   SetStatusText("   ESC = Main page  ENTER = Reboot");
 
@@ -531,13 +531,13 @@ IntroPage(PINPUT_RECORD Ir)
   SetTextXY(6, 11, "This part of the setup copies the ReactOS Operating System to your");
   SetTextXY(6, 12, "computer and prepares the second part of the setup.");
 
-  SetTextXY(8, 15, "\xf9  Press ENTER to install ReactOS.");
+  SetTextXY(8, 15, "\xfa  Press ENTER to install ReactOS.");
 
-  SetTextXY(8, 17, "\xf9  Press E to start the emergency repair console.");
+  SetTextXY(8, 17, "\xfa  Press E to start the emergency repair console.");
 
-  SetTextXY(8, 19, "\xf9  Press R to repair ReactOS.");
+  SetTextXY(8, 19, "\xfa  Press R to repair ReactOS.");
 
-  SetTextXY(8, 21, "\xf9  Press F3 to quit without installing ReactOS.");
+  SetTextXY(8, 21, "\xfa  Press F3 to quit without installing ReactOS.");
 
 
   SetStatusText("   ENTER = Continue   F3 = Quit");
@@ -587,9 +587,9 @@ InstallIntroPage(PINPUT_RECORD Ir)
 
 
 
-  SetTextXY(8, 21, "\xf9  Press ENTER to install ReactOS.");
+  SetTextXY(8, 21, "\xfa  Press ENTER to install ReactOS.");
 
-  SetTextXY(8, 23, "\xf9  Press F3 to quit without installing ReactOS.");
+  SetTextXY(8, 23, "\xfa  Press F3 to quit without installing ReactOS.");
 
 
   SetStatusText("   ENTER = Continue   F3 = Quit");
@@ -626,10 +626,10 @@ SelectPartitionPage(PINPUT_RECORD Ir)
   SetTextXY(6, 8, "The list below shows existing partitions and unused disk");
   SetTextXY(6, 9, "space for new partitions.");
 
-  SetTextXY(8, 11, "\xf9  Press UP or DOWN to select a list entry.");
-  SetTextXY(8, 13, "\xf9  Press ENTER to install ReactOS onto the selected partition.");
-  SetTextXY(8, 15, "\xf9  Press C to create a new partition.");
-  SetTextXY(8, 17, "\xf9  Press D to delete an existing partition.");
+  SetTextXY(8, 11, "\xfa  Press UP or DOWN to select a list entry.");
+  SetTextXY(8, 13, "\xfa  Press ENTER to install ReactOS onto the selected partition.");
+  SetTextXY(8, 15, "\xfa  Press C to create a new partition.");
+  SetTextXY(8, 17, "\xfa  Press D to delete an existing partition.");
 
   SetStatusText("   Please wait...");
 
@@ -789,9 +789,9 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
 
   SetTextXY(6, 17, "Select a file system for the partition from the list below.");
 
-  SetTextXY(8, 19, "\xf9  Press UP or DOWN to select a file system.");
-  SetTextXY(8, 21, "\xf9  Press ENTER to format the partition.");
-  SetTextXY(8, 23, "\xf9  Press ESC to select another partition.");
+  SetTextXY(8, 19, "\xfa  Press UP or DOWN to select a file system.");
+  SetTextXY(8, 21, "\xfa  Press ENTER to format the partition.");
+  SetTextXY(8, 23, "\xfa  Press ESC to select another partition.");
 
   /* FIXME: use a real list later */
   SetInvertedTextXY(6, 26, " Keep current file system (no changes) ");
@@ -861,23 +861,56 @@ CheckFileSystemPage(PINPUT_RECORD Ir)
 static ULONG
 InstallDirectoryPage(PINPUT_RECORD Ir)
 {
+  PINICACHESECTION Section;
   WCHAR PathBuffer[MAX_PATH];
   WCHAR InstallDir[51];
+  PWCHAR DefaultPath;
   ULONG Length;
+  NTSTATUS Status;
 
-  SetTextXY(6, 8, "Setup installs ReactOS files onto the selected partition. Choose a");
-  SetTextXY(6, 9, "directory where you want ReactOS to be installed:");
+  /* Open 'SetupData' section */
+  Section = IniCacheGetSection(IniCache,
+                              L"SetupData");
+  if (Section == NULL)
+    {
+      PopupError("Setup failed to find the 'SetupData' section\n"
+                "in TXTSETUP.SIF.\n",
+                "ENTER = Reboot computer");
+
+      while(TRUE)
+       {
+         ConInKey(Ir);
+
+         if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D)       /* ENTER */
+           {
+             return(QUIT_PAGE);
+           }
+       }
+    }
 
-  wcscpy(InstallDir, L"\\reactos");
+  /* Read the 'DefaultPath' key */
+  Status = IniCacheGetKey(Section,
+                         L"DefaultPath",
+                         &DefaultPath);
+  if (!NT_SUCCESS(Status))
+    {
+      wcscpy(InstallDir, L"\\reactos");
+    }
+  else
+    {
+      wcscpy(InstallDir, DefaultPath);
+    }
   Length = wcslen(InstallDir);
 
+  SetTextXY(6, 8, "Setup installs ReactOS files onto the selected partition. Choose a");
+  SetTextXY(6, 9, "directory where you want ReactOS to be installed:");
+
   SetInputTextXY(8, 11, 51, InstallDir);
 
   SetTextXY(6, 14, "To change the suggested directory, press BACKSPACE to delete");
   SetTextXY(6, 15, "characters and then type the directory where you want ReactOS to");
   SetTextXY(6, 16, "be installed.");
 
-
   SetStatusText("   ENTER = Continue   F3 = Quit");
 
   while(TRUE)
@@ -893,7 +926,7 @@ InstallDirectoryPage(PINPUT_RECORD Ir)
        }
       else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
        {
-         /* Create 'DestinationPath' string */
+         /* Create 'InstallPath' string */
          RtlFreeUnicodeString(&InstallPath);
          RtlCreateUnicodeString(&InstallPath,
                                 InstallDir);