private static void IncludeNewFileItems(FileItems newFileItems) { bool itemsListFoundInGroupLists = false; foreach (FileItems fileItems in mFileItemsList) { if (fileItems.PathToDirectory == newFileItems.PathToDirectory) { itemsListFoundInGroupLists = true; foreach (var newFileItem in newFileItems.FileItemList) { if (!fileItems.CurrentListContainsFileHash(newFileItem.MD5Hash)) { fileItems.FileItemList.Add(newFileItem); } } } } if (!itemsListFoundInGroupLists) { newFileItems.FileItemsfile = Path.Combine(mGroupDirInfo.FullName, newFileItems.DirInfo.Name + "_metadata.xml"); newFileItems.SaveToFile(); mFileItemsList.Add(newFileItems); } }
public static FileItems GetFileItems(DirectoryInfo dirInfo, string pattern = null, DirectoryInfo altDirInfo = null) { string dirMetaFile; string metaFileName = string.Format("{0}_metadata.xml", dirInfo.Name); dirMetaFile = altDirInfo == null ? Path.Combine(dirInfo.FullName, metaFileName) : Path.Combine(altDirInfo.FullName, metaFileName); Console.WriteLine("Looking for {0}", dirMetaFile); FileItems fileItems; if (!File.Exists(dirMetaFile)) { fileItems = new FileItems() { PathToDirectory = dirInfo.FullName, FileItemsfile = dirMetaFile, DirInfo = dirInfo }; var files = string.IsNullOrEmpty(pattern) ? dirInfo.GetFiles() : dirInfo.GetFiles(pattern); foreach (var file in files) { fileItems.FileItemList.Add(new FileItem { Name = file.Name, Size = file.Length, MD5Hash = GetChecksum(file) }); } fileItems.SaveToFile(); fileItems.NewMetaFileCreated = true; } else { fileItems = new FileItems(); fileItems.DirInfo = dirInfo; FileItems fileItemsRead = FileItems.ReadMetadataFile(dirMetaFile); Regex filter = String.IsNullOrEmpty(pattern) ? null : new Regex(pattern); foreach (var el in fileItemsRead.FileItemList) { if (filter == null || filter.IsMatch(el.Name)) { fileItems.FileItemList.Add(el); fileItems.PathToDirectory = dirInfo.FullName; } } fileItems.NewMetaFileCreated = false; } return fileItems; }