/// <summary> /// This coroutine looking all drives. /// </summary> /// <returns>Drive.</returns> private IEnumerator SearchDrives() { yield return(0); // The buttons are disabled, to avoid errors that the player could do. BackButton.GetComponent <UIButton>().isEnabled = false; OpenButton.GetComponent <UIButton>().isEnabled = false; ActionButton.GetComponent <UIButton>().isEnabled = false; // It deletes all trail of the previous search. _drivesPath.Clear(); _drivesName.Clear(); // The drives are searched. LogicalVolume drive = new LogicalVolume(); drive.Find(); // The drives found are extracted. foreach (string path in drive.DrivesPath) { _drivesPath.Add(path); } foreach (string name in drive.DrivesName) { _drivesName.Add(name); } // to the UIPopupList component the drives as selection option are assigned. gameObject.GetComponent <UIPopupList>().items = _drivesName; gameObject.GetComponent <UIPopupList>().value = DrivesName[0]; // It saves the path in the buttons. OpenButton.GetComponent <UIDirectoryFinderButton>().PathToSearch = DrivesPath[0]; ActionButton.GetComponent <UIDirectoryFinderButton>().PathToSearch = DrivesPath[0]; // It shows the drive name chosen. FolderSelected.text = gameObject.GetComponent <UIPopupList>().value; // The buttons are enabled. BackButton.GetComponent <UIButton>().isEnabled = true; OpenButton.GetComponent <UIButton>().isEnabled = true; ActionButton.GetComponent <UIButton>().isEnabled = true; }
public async Task BasicFileScan() { // Arrange // Prepare DB & files Assert.IsTrue(PrepareDirectories()); Assert.IsTrue(await ResetDatabase(), "Could not create database"); var targetDir = Path.Combine(testDirD, "dir1"); File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "KeyMap.txt")), Path.Combine(targetDir, "KeyMap.txt")); File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "0266554465.jpeg")), Path.Combine(targetDir, "0266554465.jpeg")); File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "Nikon-1-V3-sample-photo.jpg")), Path.Combine(targetDir, "Nikon-1-V3-sample-photo.jpg")); File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "randomExe.exe")), Path.Combine(targetDir, "randomExe.exe")); File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "umlaut_äü(&テスト.txt")), Path.Combine(targetDir, "umlaut_äü(&テスト.txt")); var archiveLabel = "BasicFileScanArchive"; // Create reference file index var fileRootDir = Path.GetFullPath(targetDir).Substring(Path.GetPathRoot(targetDir).Length); var refFi = new FileIndex(); var dDrive = new LogicalVolume() { SerialNumber = "2822F77D", Size = 499971518464, Type = DriveType.Fixed, VolumeName = "Games", MountPoint = "D:\\" }; refFi.LogicalVolumes.Add(dDrive); var refArchive = new Archive() { RootDirectoryPath = fileRootDir, Volume = dDrive, Index = refFi, Label = archiveLabel }; refFi.Archives.Add(refArchive); var d1 = new FileDirectory() { Archive = refArchive, DirectoryName = Path.GetFullPath(testDirD).Substring(Path.GetPathRoot(testDirD).Length), Name = "dir1" }; refArchive.RootDirectory = d1; var h1 = new FileHash() { Checksum = "F03F01D5778DFB6DC499BFFC11C26EF7", Length = 56199, CreationTime = DateTime.Parse("2018-02-01 20:54:52.4866447"), LastWriteTime = DateTime.Parse("2018-01-31 22:27:16.2543275") }; var f1 = new FileNode() { DirectoryName = fileRootDir, Name = "0266554465.jpeg", Extension = ".jpeg", Checksum = "F03F01D5778DFB6DC499BFFC11C26EF7", Hash = h1, Archive = refArchive, Parent = d1, }; h1.AddNode(f1); refFi.Hashes.Add(h1); d1.FileNodes.Add(f1); var h2 = new FileHash() { Checksum = "9BFCF0A5F4660C7251F487F085C2580B", Length = 12155, CreationTime = DateTime.Parse("2018-02-01 20:54:52.5009427"), LastWriteTime = DateTime.Parse("2018-01-31 22:25:31.9274553") }; var f2 = new FileNode() { DirectoryName = fileRootDir, Name = "KeyMap.txt", Extension = ".txt", Checksum = "9BFCF0A5F4660C7251F487F085C2580B", Hash = h2, Archive = refArchive, Parent = d1 }; h2.AddNode(f2); refFi.Hashes.Add(h2); d1.FileNodes.Add(f2); var h3 = new FileHash() { Checksum = "C9C02F785EE42EFACE21B3164BE718C2", Length = 75349, CreationTime = DateTime.Parse("2018-02-01 20:54:52.51192"), LastWriteTime = DateTime.Parse("2018-01-31 22:25:54.6826964") }; var f3 = new FileNode() { DirectoryName = fileRootDir, Name = "Nikon-1-V3-sample-photo.jpg", Extension = ".jpg", Checksum = "C9C02F785EE42EFACE21B3164BE718C2", Hash = h3, Archive = refArchive, Parent = d1 }; h3.AddNode(f3); refFi.Hashes.Add(h3); d1.FileNodes.Add(f3); var h4 = new FileHash() { Checksum = "F6BA3E6C9CA1D37B980536ECF4075C77", Length = 13824, CreationTime = DateTime.Parse("2018-02-01 20:54:52.5334261"), LastWriteTime = DateTime.Parse("2018-01-31 22:28:23.013479") }; var f4 = new FileNode() { DirectoryName = fileRootDir, Name = "randomExe.exe", Extension = ".exe", Checksum = "F6BA3E6C9CA1D37B980536ECF4075C77", Hash = h4, Archive = refArchive, Parent = d1 }; h4.AddNode(f4); refFi.Hashes.Add(h4); d1.FileNodes.Add(f4); var h5 = new FileHash() { Checksum = "D41D8CD98F00B204E9800998ECF8427E", Length = 0, CreationTime = DateTime.Parse("2018-02-01 20:54:52.5399261"), LastWriteTime = DateTime.Parse("2018-01-31 22:27:04.4650235") }; var f5 = new FileNode() { DirectoryName = fileRootDir, Name = "umlaut_äü(&テスト.txt", Extension = ".txt", Checksum = "D41D8CD98F00B204E9800998ECF8427E", Hash = h5, Archive = refArchive, Parent = d1 }; h5.AddNode(f5); refFi.Hashes.Add(h5); d1.FileNodes.Add(f5); // Act var diffFi = new FileIndex(); var diffArchive = await diffFi.CreateArchiveAsync(new DirectoryInfo(targetDir), new CancellationTokenSource().Token, new Progress <int>(), new Progress <string>(), archiveLabel); // Several attributes are created on the fly, so we need to copy them // to the reference archive refArchive.Guid = diffArchive.Guid; // Assert Assert.AreEqual(refFi.Archives.Count, diffFi.Archives.Count, "Archive count incorrect."); Assert.AreEqual(refFi.LogicalVolumes.Count, diffFi.LogicalVolumes.Count, "LogicalVolume count incorrect."); foreach (var refVolume in refFi.LogicalVolumes) { Assert.IsTrue(diffFi.LogicalVolumes.Contains(refVolume), "LogicalVolume not found."); } Assert.AreEqual(refFi.Hashes.Count, diffFi.Hashes.Count, "FileHash count incorrect."); foreach (var refHash in refFi.Hashes) { Assert.IsTrue(diffFi.Hashes.Contains(refHash), "FileHash not found."); Assert.AreEqual(refHash, diffFi.Hashes.FirstOrDefault(x => x.Equals(refHash)), "FileHash not equal."); } Assert.AreEqual(refArchive.GetFileNodes().Count, diffArchive.GetFileNodes().Count, "FileNodes count incorrect."); foreach (var refNode in refArchive.GetFileNodes()) { Assert.IsTrue(diffArchive.GetFileNodes().Contains(refNode), "FileNode not found."); } Assert.AreEqual(refArchive.GetFileDirectories().Count, diffArchive.GetFileDirectories().Count, "FileDirectory count incorrect."); foreach (var refNode in refArchive.GetFileDirectories()) { Assert.IsTrue(diffArchive.GetFileDirectories().Contains(refNode), "FileDirectory not found."); } }
/// <summary> /// Validates that the volume has a valid partition. /// </summary> /// <param name="volume">The volume to validate.</param> /// <returns>Returns true if the volume is valid.</returns> private bool ValidateVolumePartition(LogicalVolume volume) { for (int i = 0; i < volume.PartitionMaps.Count; i++) { PartitionMap map = volume.PartitionMaps[0]; bool found = false; foreach (var partition in this.Partitions) { if (partition.Number == map.PartitionNumber) { // partition can only be member of one volume if (partition.VolumeIndex >= 0) { return false; } // Add cross references between partitions and volumes. map.PartitionNumber = this.Partitions.IndexOf(partition); partition.VolumeIndex = this.LogicalVolumes.IndexOf(volume); found = true; } } if (!found) { return false; } } return true; }
/// <summary> /// Reads a logical volume descriptor from the buffer. /// </summary> /// <param name="buffer">The buffer to read the data from.</param> /// <returns>Returns true if the descriptor is valid.</returns> private bool ReadLogicalDescriptor(byte[] buffer) { LogicalVolume volume = new LogicalVolume(); volume.Id.Parse(84, buffer); volume.BlockSize = UdfHelper.Get32(212, buffer); if (volume.BlockSize < VirtualSectorSize || volume.BlockSize > MaxExtents) { return false; } volume.FileSetLocation.Parse(248, buffer); int numPartitionMaps = UdfHelper.Get32(268, buffer); if (numPartitionMaps > MaxPartitions) { return false; } int position = 440; for (int index = 0; index < numPartitionMaps; index++) { if (position + 2 > SectorSize) { return false; } PartitionMap pm = new PartitionMap(); pm.Type = buffer[position]; byte length = buffer[position + 1]; if (position + length > SectorSize) { return false; } if (pm.Type == 1) { if (position + 6 > SectorSize) { return false; } pm.PartitionNumber = UdfHelper.Get16(position + 4, buffer); } else { return false; } position += length; pm.PartitionIndex = volume.PartitionMaps.Count; volume.PartitionMaps.Add(pm); } this.LogicalVolumes.Add(volume); return true; }