Beispiel #1
0
 /// <summary>
 /// Returns an array of valid FATXDrives
 /// </summary>
 public FATX.FATXDrive[] GetFATXDrives(int range)
 {
     List<FATX.FATXDrive> driveList = new List<FATX.FATXDrive>();
     ///Gets physical disks
     for (int i = 0; i < range; i++)
     {
         try
         {
             //Start reading the physical drive
             fs = fs_diskStream(i);
             br = br_diskReader(i);
             //Seek to the FATX partition
             //try
             //{
                 br.BaseStream.Position = (long)FATX.Info.HDDFATX.Partitions.Data;
                 //Read the header
                 byte[] header = br.ReadBytes(0x4);
                 //Convert the header to a string, check if it's fatx
                 if (Encoding.ASCII.GetString(header) == "XTAF")
                 {
                     FATX.FATXDrive drive = new FATXDrive(i, FATX.Info.DriveType.HDD);
                     driveList.Add(drive);
                 }
             //}
             //catch{ }
             br.Close();
             fs.Close();
             diskDrive.Close();
             bool closed = diskDrive.IsClosed;
         }
         catch { fs.Close(); br.Close(); diskDrive.Close(); }
     }
     ///Gets usb drives
     List<string> driveLetters = new List<string>();
     char[] DriveLetters = new char[26] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
     //Loop for each possible drive letter
     for (int i = 0; i < DriveLetters.Length; i++)
     {
         //Create a new drive info
         DriveInfo di = new DriveInfo(DriveLetters[i].ToString());
         //If the drive doesn't exist, it will return false, so if it's true, it exists
         if (di.IsReady)
         {
             //Add it to the drive letters
             driveLetters.Add(DriveLetters[i].ToString());
         }
     }
     ///Check to see if the drive has a subdirectory of "Xbox360"
     List<string> indexesToRemove = new List<string>();
     for (int i = 0; i < driveLetters.Count; i++)
     {
         //If the directory does not exist
         DirectoryInfo di = new DirectoryInfo(driveLetters[i] + ":\\Xbox360");
         if (!di.Exists)
         {
             //Remove the drive from the list
             indexesToRemove.Add(driveLetters[i]);
         }
         else
         {
             //Check to make sure that there's actually files in that directory..
             FileInfo[] fi = di.GetFiles();
             if (fi[0].Name != "Data0000")
             {
                 indexesToRemove.Add(driveLetters[i]);
             }
         }
     }
     for (int i = 0; i < indexesToRemove.Count; i++)
     {
         driveLetters.Remove(indexesToRemove[i]);
     }
     ///Finally create our new FATXDrive...
     for (int i = 0; i < driveLetters.Count; i++)
     {
         driveList.Add(new FATXDrive(driveLetters[i] + ":\\Xbox360", Info.DriveType.USB));
     }
     return driveList.ToArray();
 }