private void indexAllFilesInSubdirectories(CartridgeDirectory directory) { // Start searching subdirectories for files. foreach (CartridgeDirectory subdirectory in directory.Subdirectories) { AllFiles.AddRange(subdirectory.Files); indexAllFilesInSubdirectories(subdirectory); } }
public CartridgeFile(XmlNode fileNode, CartridgeDirectory parentDirectory) { try { Name = fileNode.SelectSingleNode("descendant::name").InnerText.ToString(); Length = fileNode.SelectSingleNode("descendant::length").InnerText.ToString(); ReadOnly = fileNode.SelectSingleNode("descendant::readonly").InnerText.ToString(); CreationTime = fileNode.SelectSingleNode("descendant::creationtime").InnerText.ToString(); ChangeTime = fileNode.SelectSingleNode("descendant::changetime").InnerText.ToString(); ModifyTime = fileNode.SelectSingleNode("descendant::modifytime").InnerText.ToString(); AccessTime = fileNode.SelectSingleNode("descendant::accesstime").InnerText.ToString(); BackupTime = fileNode.SelectSingleNode("descendant::backuptime").InnerText.ToString(); FileUID = fileNode.SelectSingleNode("descendant::fileuid").InnerText.ToString(); ExtentInfo = fileNode.SelectSingleNode("descendant::extentinfo"); // Get CRC32 hash from filename Regex r = new Regex(@"\[(.*?)\]"); // returns first captured group. Match hash = r.Match(Name); if (hash.Success && hash.Length == 10) { CRC32Hash = hash.Value.Substring(1, 8); } else { Console.WriteLine("[{0}] Invalid or missing hash within filename.", this.GetType().ToString()); } // Calculate filesize FileSize = StaticMethods.FormatBytes(Convert.ToUInt64(Length)); // Store the parent directory. ParentDirectory = parentDirectory; // Store our current filepath. if (ParentDirectory != null) { Path = parentDirectory.Path + @"\" + Name; } else { Path = Name; } } catch (NullReferenceException nullReferenceException) { Console.WriteLine("[{0}] Invalid or missing node.", this.GetType().ToString()); Console.WriteLine(nullReferenceException); } }
public Cartridge(XmlDocument documentRoot, string filename) { // Get our field data from the XML document. Creator = documentRoot.SelectSingleNode("descendant::creator").InnerText.ToString(); VolumeUUID = documentRoot.SelectSingleNode("descendant::volumeuuid").InnerText.ToString(); GenerationNumber = documentRoot.SelectSingleNode("descendant::generationnumber").InnerText.ToString(); UpdateTime = documentRoot.SelectSingleNode("descendant::updatetime").InnerText.ToString(); // !! IMPORTANT !! replace these two lines to add the contents of location and previous generation location //ModifyTime = directoryNode.SelectSingleNode("descendant::modifytime").InnerText.ToString(); //AccessTime = directoryNode.SelectSingleNode("descendant::accesstime").InnerText.ToString(); AllowPolicyUpdate = documentRoot.SelectSingleNode("descendant::allowpolicyupdate").InnerText.ToString(); VolumeLockState = documentRoot.SelectSingleNode("descendant::volumelockstate").InnerText.ToString(); HighestFileUID = documentRoot.SelectSingleNode("descendant::highestfileuid").InnerText.ToString(); // Get the XmlNode for our cartridge data. XmlNode root = documentRoot.SelectSingleNode("//ltfsindex"); // Initialize the RootDirectory object. RootDirectory = new CartridgeDirectory(root.SelectSingleNode("//directory"), null); // Store the cartridge barcode, which is sourced from the filename (unfortunately). if (!string.IsNullOrEmpty(filename) && filename.Length <= 6) { Barcode = filename; } else { Barcode = "NO BARCODE"; } // Count the number of files, directories and get total size used. gatherStatistics(RootDirectory); // Initalize our all files list. AllFiles = new List <CartridgeFile>(); // Add the files from the root to the list of all files. // Move this below the recursive list if you want the root files at the end // of the list. AllFiles.AddRange(RootDirectory.Files); // Get all the files on the cartridge. indexAllFilesInSubdirectories(RootDirectory); }
public CartridgeDirectory(XmlNode directoryNode, CartridgeDirectory parentDirectory) { Name = directoryNode.SelectSingleNode("descendant::name").InnerText.ToString(); ReadOnly = directoryNode.SelectSingleNode("descendant::readonly").InnerText.ToString(); CreationTime = directoryNode.SelectSingleNode("descendant::creationtime").InnerText.ToString(); ChangeTime = directoryNode.SelectSingleNode("descendant::changetime").InnerText.ToString(); ModifyTime = directoryNode.SelectSingleNode("descendant::modifytime").InnerText.ToString(); AccessTime = directoryNode.SelectSingleNode("descendant::accesstime").InnerText.ToString(); BackupTime = directoryNode.SelectSingleNode("descendant::backuptime").InnerText.ToString(); FileUID = directoryNode.SelectSingleNode("descendant::fileuid").InnerText.ToString(); // Store a reference to the parent directory. ParentDirectory = parentDirectory; // Set our current path. if (ParentDirectory != null) { Path = parentDirectory.Path + @"\" + Name; } else { //Path = @"\"; Path = ""; } // Initalize our Lists. Subdirectories = new List <CartridgeDirectory>(); Files = new List <CartridgeFile>(); foreach (XmlNode node in directoryNode.SelectSingleNode("descendant::contents")) { if (node.Name == "directory") { CartridgeDirectory directory = new CartridgeDirectory(node, this); Subdirectories.Add(directory); } if (node.Name == "file") { CartridgeFile file = new CartridgeFile(node, this); Files.Add(file); } } }
private void gatherStatistics(CartridgeDirectory directory) { // Add the total number of files within the directory to the count. GetTotalNumberOfFiles += directory.Files.Count; // Add up the total file size used by this directory. foreach (CartridgeFile file in directory.Files) { GetTotalSpaceUsed += Convert.ToUInt64(file.Length); } foreach (CartridgeDirectory subdirectory in directory.Subdirectories) { // Count the directories as we traverse them. GetTotalNumberOfDirectories++; // Continue our search for directories and files. gatherStatistics(subdirectory); } }