usetup.c

来自「一个类似windows」· C语言 代码 · 共 2,599 行 · 第 1/5 页

C
2,599
字号
		       PartEntry->PartInfo[0].PartitionType,
		       PartSize,
		       PartUnit);
	}
      else
	{
	  PrintTextXY (8, 10,
		       "%c%c  %s    %I64u %s",
		       (PartEntry->DriveLetter == 0) ? '-' : PartEntry->DriveLetter,
		       (PartEntry->DriveLetter == 0) ? '-' : ':',
		       PartType,
		       PartSize,
		       PartUnit);
	}

      PrintTextXY(6, 12, "on Harddisk %lu (%I64u %s), Port=%hu, Bus=%hu, Id=%hu (%wZ).",
		  DiskEntry->DiskNumber,
		  DiskSize,
		  DiskUnit,
		  DiskEntry->Port,
		  DiskEntry->Bus,
		  DiskEntry->Id,
		  &DiskEntry->DriverName);
    }


  SetTextXY(6, 17, "Select a file system from the list below.");

  SetTextXY(8, 19, "\x07  Press UP or DOWN to select a file system.");
  SetTextXY(8, 21, "\x07  Press ENTER to format the partition.");
  SetTextXY(8, 23, "\x07  Press ESC to select another partition.");

  if (FileSystemList == NULL)
    {
      FileSystemList = CreateFileSystemList (6, 26, PartEntry->New, FsFat);
      if (FileSystemList == NULL)
	{
	  /* FIXME: show an error dialog */
	  return QUIT_PAGE;
	}

      /* FIXME: Add file systems to list */
    }
  DrawFileSystemList (FileSystemList);

  SetStatusText ("   ENTER = Continue   ESC = Cancel   F3 = Quit");

  if (IsUnattendedSetup)
    {
      return(CHECK_FILE_SYSTEM_PAGE);
    }

  while (TRUE)
    {
      ConInKey (Ir);

      if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
	  (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
	{
	  if (ConfirmQuit (Ir) == TRUE)
	    {
	      return QUIT_PAGE;
	    }
	  break;
	}
      else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
	       (Ir->Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)) /* ESC */
	{
	  return SELECT_PARTITION_PAGE;
	}
      else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
	       (Ir->Event.KeyEvent.wVirtualKeyCode == VK_DOWN)) /* DOWN */
	{
	  ScrollDownFileSystemList (FileSystemList);
	}
      else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
	       (Ir->Event.KeyEvent.wVirtualKeyCode == VK_UP)) /* UP */
	{
	  ScrollUpFileSystemList (FileSystemList);
	}
      else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */
	{
	  if (FileSystemList->CurrentFileSystem == FsKeep)
	    {
	      return CHECK_FILE_SYSTEM_PAGE;
	    }
	  else
	    {
	      return FORMAT_PARTITION_PAGE;
	    }
	}
    }

  return SELECT_FILE_SYSTEM_PAGE;
}


static ULONG
FormatPartitionPage (PINPUT_RECORD Ir)
{
  WCHAR PathBuffer[MAX_PATH];
  PDISKENTRY DiskEntry;
  PPARTENTRY PartEntry;
  NTSTATUS Status;

#ifndef NDEBUG
  ULONG Line;
  ULONG i;
  PLIST_ENTRY Entry;
#endif


  SetTextXY(6, 8, "Format partition");

  SetTextXY(6, 10, "Setup will now format the partition. Press ENTER to continue.");

  SetStatusText("   ENTER = Continue   F3 = Quit");


  if (PartitionList == NULL ||
      PartitionList->CurrentDisk == NULL ||
      PartitionList->CurrentPartition == NULL)
    {
      /* FIXME: show an error dialog */
      return QUIT_PAGE;
    }

  DiskEntry = PartitionList->CurrentDisk;
  PartEntry = PartitionList->CurrentPartition;

  while(TRUE)
    {
      ConInKey(Ir);

      if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
	  (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
	{
	  if (ConfirmQuit (Ir) == TRUE)
	    {
	      return QUIT_PAGE;
	    }
	  break;
	}
      else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */
	{
	  SetStatusText ("   Please wait ...");

	  if (PartEntry->PartInfo[0].PartitionType == PARTITION_ENTRY_UNUSED)
	    {
	      switch (FileSystemList->CurrentFileSystem)
	        {
		  case FsFat:
		    if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (4200LL * 1024LL))
		      {
			/* FAT12 CHS partition (disk is smaller than 4.1MB) */
			PartEntry->PartInfo[0].PartitionType = PARTITION_FAT_12;
		      }
		    else if (PartEntry->PartInfo[0].StartingOffset.QuadPart < (1024LL * 255LL * 63LL * 512LL))
		      {
			/* Partition starts below the 8.4GB boundary ==> CHS partition */

			if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (32LL * 1024LL * 1024LL))
			  {
			    /* FAT16 CHS partition (partiton size < 32MB) */
			    PartEntry->PartInfo[0].PartitionType = PARTITION_FAT_16;
			  }
			else if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (512LL * 1024LL * 1024LL))
			  {
			    /* FAT16 CHS partition (partition size < 512MB) */
			    PartEntry->PartInfo[0].PartitionType = PARTITION_HUGE;
			  }
			else
			  {
			    /* FAT32 CHS partition (partition size >= 512MB) */
			    PartEntry->PartInfo[0].PartitionType = PARTITION_FAT32;
			  }
		      }
		    else
		      {
			/* Partition starts above the 8.4GB boundary ==> LBA partition */

			if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (512LL * 1024LL * 1024LL))
			  {
			    /* FAT16 LBA partition (partition size < 512MB) */
			    PartEntry->PartInfo[0].PartitionType = PARTITION_XINT13;
			  }
			else
			  {
			    /* FAT32 LBA partition (partition size >= 512MB) */
			    PartEntry->PartInfo[0].PartitionType = PARTITION_FAT32_XINT13;
			  }
		      }
		    break;

		  case FsKeep:
		    break;

		  default:
		    return QUIT_PAGE;
		}
	    }

	  CheckActiveBootPartition (PartitionList);

#ifndef NDEBUG
	  PrintTextXY (6, 12,
		       "Disk: %I64u  Cylinder: %I64u  Track: %I64u",
		       DiskEntry->DiskSize,
		       DiskEntry->CylinderSize,
		       DiskEntry->TrackSize);

	  Line = 13;
	  DiskEntry = PartitionList->CurrentDisk;
	  Entry = DiskEntry->PartListHead.Flink;
	  while (Entry != &DiskEntry->PartListHead)
	    {
	      PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);

	      if (PartEntry->Unpartitioned == FALSE)
		{

		  for (i = 0; i < 4; i++)
		    {
		      PrintTextXY (6, Line,
				   "%2u:  %2u  %c  %12I64u  %12I64u  %2u  %c",
				   i,
				   PartEntry->PartInfo[i].PartitionNumber,
				   PartEntry->PartInfo[i].BootIndicator ? 'A' : '-',
				   PartEntry->PartInfo[i].StartingOffset.QuadPart,
				   PartEntry->PartInfo[i].PartitionLength.QuadPart,
				   PartEntry->PartInfo[i].PartitionType,
				   PartEntry->PartInfo[i].RewritePartition ? '*' : ' ');

		      Line++;
		    }

		  Line++;
		}

	      Entry = Entry->Flink;
	    }

	  /* Restore the old entry */
	  PartEntry = PartitionList->CurrentPartition;
#endif

	  if (WritePartitionsToDisk (PartitionList) == FALSE)
	    {
	      DPRINT ("WritePartitionsToDisk() failed\n");

	      PopupError ("Setup failed to write partition tables.\n",
			  "ENTER = Reboot computer");

	      while (TRUE)
		{
		  ConInKey (Ir);

		  if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
		    {
		      return QUIT_PAGE;
		    }
		}
	    }

	  /* Set DestinationRootPath */
	  RtlFreeUnicodeString (&DestinationRootPath);
	  swprintf (PathBuffer,
		    L"\\Device\\Harddisk%lu\\Partition%lu",
		    PartitionList->CurrentDisk->DiskNumber,
		    PartitionList->CurrentPartition->PartInfo[0].PartitionNumber);
	  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[0].PartitionNumber);
	  RtlCreateUnicodeString (&SystemRootPath,
				  PathBuffer);
	  DPRINT ("SystemRootPath: %wZ\n", &SystemRootPath);


	  switch (FileSystemList->CurrentFileSystem)
	    {
	      case FsFat:
		Status = FormatPartition (&DestinationRootPath);
		if (!NT_SUCCESS (Status))
		  {
		    DPRINT1 ("FormatPartition() failed with status 0x%.08x\n", Status);
		    /* FIXME: show an error dialog */
		    return QUIT_PAGE;
		  }

		PartEntry->New = FALSE;
		if (FileSystemList != NULL)
		  {
		    DestroyFileSystemList (FileSystemList);
		    FileSystemList = NULL;
		  }

		CheckActiveBootPartition (PartitionList);

		/* FIXME: Install boot code. This is a hack! */
		if ((PartEntry->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13) ||
		    (PartEntry->PartInfo[0].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%.08x\n", Status);
		        /* FIXME: show an error dialog */
		        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 */
		        return QUIT_PAGE;
		      }
		  }
		break;

	      case FsKeep:
		break;

	      default:
		return QUIT_PAGE;
	    }

#ifndef NDEBUG
	  SetStatusText ("   Done.  Press any key ...");
	  ConInKey(Ir);
#endif

	  return INSTALL_DIRECTORY_PAGE;
	}
    }

  return FORMAT_PARTITION_PAGE;
}


static ULONG
CheckFileSystemPage(PINPUT_RECORD Ir)
{
  WCHAR PathBuffer[MAX_PATH];

  SetTextXY(6, 8, "Check file system");

  SetTextXY(6, 10, "At present, ReactOS can not check file systems.");

  SetStatusText("   Please wait ...");


  SetStatusText("   ENTER = Continue   F3 = Quit");


  /* Set DestinationRootPath */
  RtlFreeUnicodeString (&DestinationRootPath);
  swprintf (PathBuffer,
	    L"\\Device\\Harddisk%lu\\Partition%lu",
	    PartitionList->CurrentDisk->DiskNumber,
	    PartitionList->CurrentPartition->PartInfo[0].PartitionNumber);
  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[0].PartitionNumber);
  RtlCreateUnicodeString (&SystemRootPath,
			  PathBuffer);
  DPRINT ("SystemRootPath: %wZ\n", &SystemRootPath);


  if (IsUnattendedSetup)
    {
      return(INSTALL_DIRECTORY_PAGE);
    }

  while(TRUE)
    {
      ConInKey(Ir);

      if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) &&
	  (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */
	{
	  if (ConfirmQuit(Ir) == TRUE)
	    return(QUIT_PAGE);
	  break;
	}
      else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
	{
	  return(INSTALL_DIRECTORY_PAGE);
	}
    }

  return(CHECK_FILE_SYSTEM_PAGE);
}


static PAGE_NUMBER
InstallDirectoryPage1(PWCHAR InstallDir, PDISKENTRY DiskEntry, PPARTENTRY PartEntry)
{
  WCHAR PathBuffer[MAX_PATH];

  /* Create 'InstallPath' string */
  RtlFreeUnicodeString(&InstallPath);
  RtlCreateUnicodeString(&InstallPath,
			 InstallDir);

  /* Create 'DestinationPath' string */
  RtlFreeUnicodeString(&DestinationPath);
  wcscpy(PathBuffer,
	 DestinationRootPath.Buffer);
  if (InstallDir[0] != L'\\')
    wcscat(PathBuffer,
	   L"\\");
  wcscat(PathBuffer, InstallDir);
  RtlCreateUnicodeString(&DestinationPath,
			 PathBuffer);

  /* Create 'DestinationArcPath' */
  RtlFreeUnicodeString(&DestinationArcPath);
  swprintf(PathBuffer,
	   L"multi(0)disk(0)rdisk(%lu)partition(%lu)",
	   DiskEntry->BiosDiskNumber,
	   PartEntry->PartInfo[0].PartitionNumber);
  if (InstallDir[0] != L'\\')
    wcscat(PathBuffer,
	   L"\\");
  wcscat(PathBuffer, InstallDir);
  RtlCreateUnicodeString(&DestinationArcPath,
			 PathBuffer);

  return(PREPARE_COPY_PAGE);
}


static PAGE_NUMBER
InstallDirectoryPage(PINPUT_RECORD Ir)
{
  PDISKENTRY DiskEntry;
  PPARTENTRY PartEntry;
  WCHAR InstallDir[51];
  PWCHAR DefaultPath;
  PINFCONTEXT Context;
  ULONG Length;

  if (PartitionList == NULL ||
      PartitionList->CurrentDisk == NULL ||
      PartitionList->CurrentPartition == NULL)
    {
      /* FIXME: show an error dialog */
      return QUIT_PAGE;
    }

  DiskEntry = PartitionList->CurrentDisk;
  PartEntry = PartitionList->CurrentPartition;

  /* Search for 'DefaultPath' in the 'SetupData' section */
  if (!InfFindFirstLine (SetupInf, L"SetupData", L"DefaultPath", &Context))
    {
      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;
	    }
	}
    }

  /* Read the 'DefaultPath' data */
  if (InfGetData (Context, NULL, &DefaultPath))
    {
      wcscpy(InstallDir, DefaultPath);
    }
  else
    {
      wcscpy(InstallDir, L"\\ReactOS");
    }
  InfFreeContext(Context);
  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 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?