protected void CompareManifestsRecursiveSource( ManifestDirectoryInfo sourceDir, ManifestDirectoryInfo destDir, HashSet <ManifestFileInfo> destFileMatch) { foreach (ManifestFileInfo sourceFile in sourceDir.Files.Values) { if (destDir != null && destDir.Files.ContainsKey(sourceFile.Name)) { ManifestFileInfo destFile = destDir.Files[sourceFile.Name]; destFileMatch.Add(destFile); if (sourceFile.FileHash.Equals(destFile.FileHash) == false) { ChangedFiles.Add(sourceFile, destFile); } else { if (Manifest.CompareManifestDates( sourceFile.LastModifiedUtc, destFile.LastModifiedUtc) == false) { LastModifiedDateFiles.Add(sourceFile, destFile); } if (Manifest.CompareManifestDates( sourceFile.RegisteredUtc, destFile.RegisteredUtc) == false) { RegisteredDateFiles.Add(sourceFile, destFile); } } } else { SourceOnlyFiles.Add(sourceFile); } } foreach (ManifestDirectoryInfo nextSourceDir in sourceDir.Subdirectories.Values) { ManifestDirectoryInfo nextDestDir = null; if (destDir != null && destDir.Subdirectories.ContainsKey(nextSourceDir.Name)) { nextDestDir = destDir.Subdirectories[nextSourceDir.Name]; } CompareManifestsRecursiveSource( nextSourceDir, nextDestDir, destFileMatch); } }
/// <summary> /// Add a new fileinfo to the list of changed files. /// </summary> /// <param name="change"></param> internal void AddNewChange(ChangedFile change) { if (Application.Current == null) { return; } if (Application.Current.Dispatcher.CheckAccess()) { if (!ChangedFiles.Contains(change)) { ChangedFiles.Add(change); } } else { AddChangeDelegate del = new AddChangeDelegate(AddNewChange); Application.Current.Dispatcher.Invoke(del, new object[] { change }); } }
internal void AddNewChangeSet(IEnumerable <ChangedFile> changes) { if (Application.Current == null) { return; } if (Application.Current.Dispatcher.CheckAccess()) { foreach (var change in changes) { if (!ChangedFiles.Contains(change)) { ChangedFiles.Add(change); } } } else { AddChangesDelegate del = new AddChangesDelegate(AddNewChangeSet); Application.Current.Dispatcher.Invoke(del, new object[] { changes }); } }
protected void UpdateRecursive( DirectoryInfo currentDirectoryInfo, ManifestDirectoryInfo currentManfestDirInfo) { // Setup data for current directory Dictionary <String, FileInfo> fileDict = new Dictionary <string, FileInfo>(); Dictionary <String, DirectoryInfo> dirDict = new Dictionary <string, DirectoryInfo>(); if (currentDirectoryInfo != null) { FileInfo[] fileList = null; try { fileList = currentDirectoryInfo.GetFiles(); } catch (Exception) { WriteLine(Manifest.MakeStandardPathString( currentManfestDirInfo)); if (IgnoreFile(Manifest.MakeStandardPathString( currentManfestDirInfo)) == true) { // This was implemented primarily to allow the user to // silence the process of skipping over inaccessible // system directories by ignoring them. For example, // in some cases the "$RECYCLE BIN" under Windows // is not accessible and will generate an error. The // user can now add such directories to the ignore list // and they will be silently ignored. The special // message for showProgress alerts the user that the // directory is actually being skipped altogether // since it can't be accessed. The only significant // implication of this is that the ignored files won't // be enumerated and counted as being ignored. if (ShowProgress) { WriteLine( Manifest.MakeStandardPathString(currentManfestDirInfo) + " [IGNORED DIRECTORY AND CANNOT ACCESS]"); } } else { ForceWriteLine("Could not access contents of: " + currentDirectoryInfo.FullName); } return; } foreach (FileInfo nextFileInfo in fileList) { fileDict.Add(nextFileInfo.Name.Normalize(), nextFileInfo); } DirectoryInfo[] dirList = currentDirectoryInfo.GetDirectories(); foreach (DirectoryInfo nextDirInfo in dirList) { dirDict.Add(nextDirInfo.Name.Normalize(), nextDirInfo); } } // Clone in case we modify during iteration List <ManifestFileInfo> fileListClone = new List <ManifestFileInfo>(currentManfestDirInfo.Files.Values); // Iterate through existing manifest entries foreach (ManifestFileInfo nextManFileInfo in fileListClone) { if (ShowProgress) { Write(Manifest.MakeStandardPathString(nextManFileInfo)); } if (fileDict.ContainsKey(nextManFileInfo.Name)) { FileCheckedCount++; FileInfo nextFileInfo = fileDict[nextManFileInfo.Name]; if (IgnoreFile(Manifest.MakeStandardPathString(nextManFileInfo))) { Write(" [NEWLY IGNORED]"); currentManfestDirInfo.Files.Remove( nextManFileInfo.Name); NewlyIgnoredFiles.Add(nextManFileInfo); } else if (nextFileInfo.Length != nextManFileInfo.FileLength && Update == false && AlwaysCheckHash == false) { // Don't compute hash if we aren't doing an update Write(" [DIFFERENT]"); ChangedFiles.Add(nextManFileInfo); } else if (AlwaysCheckHash == true || MakeNewHash == true || nextManFileInfo.FileHash == null || Manifest.CompareManifestDateToFilesystemDate(nextFileInfo.LastWriteTimeUtc, nextManFileInfo.LastModifiedUtc) == false || nextFileInfo.Length != nextManFileInfo.FileLength) { FileHash checkHash = null; Exception exception = null; try { string hashType = Manifest.DefaultHashMethod; if (nextManFileInfo.FileHash != null) { hashType = nextManFileInfo.FileHash.HashType; } checkHash = FileHash.ComputeHash( nextFileInfo, hashType); } catch (Exception ex) { exception = ex; } if (exception != null) { WriteLine(" [ERROR]"); WriteLine(exception.ToString()); ErrorFiles.Add(nextManFileInfo); } else { if (nextManFileInfo.FileHash == null) { Write(" [NULL HASH IN MANIFEST]"); ChangedFiles.Add(nextManFileInfo); } else if (checkHash.Equals(nextManFileInfo.FileHash) == false) { Write(" [DIFFERENT]"); ChangedFiles.Add(nextManFileInfo); } else { if (Manifest.CompareManifestDateToFilesystemDate( nextFileInfo.LastWriteTimeUtc, nextManFileInfo.LastModifiedUtc) == false) { Write(" [LAST MODIFIED DATE]"); LastModifiedDateFiles.Add(nextManFileInfo); if (BackDate == true) { nextFileInfo.LastWriteTimeUtc = nextManFileInfo.LastModifiedUtc; } } } } FileHash newHash = checkHash; if (MakeNewHash) { newHash = FileHash.ComputeHash( nextFileInfo, GetNewHashType(Manifest)); } // Update hash and last modified date accordingly nextManFileInfo.FileHash = newHash; nextManFileInfo.LastModifiedUtc = nextFileInfo.LastWriteTimeUtc; nextManFileInfo.FileLength = nextFileInfo.Length; } else { Write(" [SKIPPED]"); } } else { Write(" [MISSING]"); currentManfestDirInfo.Files.Remove(nextManFileInfo.Name); MissingFiles.Add(nextManFileInfo); } WriteLine(""); } // Clone in case we modify during iteration List <ManifestDirectoryInfo> directoryListClone = new List <ManifestDirectoryInfo>( currentManfestDirInfo.Subdirectories.Values); foreach (ManifestDirectoryInfo nextManDirInfo in directoryListClone) { DirectoryInfo nextDirInfo = null; if (dirDict.ContainsKey(nextManDirInfo.Name)) { nextDirInfo = dirDict[nextManDirInfo.Name]; } UpdateRecursive( nextDirInfo, nextManDirInfo); if (nextManDirInfo.Empty) { currentManfestDirInfo.Subdirectories.Remove( nextManDirInfo.Name); } } // Look for new files foreach (String nextFileName in fileDict.Keys) { FileInfo nextFileInfo = fileDict[nextFileName]; if (currentManfestDirInfo.Files.ContainsKey( nextFileName) == false) { ManifestFileInfo newManFileInfo = new ManifestFileInfo( nextFileName, currentManfestDirInfo); Write(Manifest.MakeStandardPathString(newManFileInfo)); if (IgnoreFile(Manifest.MakeStandardPathString(newManFileInfo))) { IgnoredFiles.Add(newManFileInfo); // Don't groom the manifest file! if (Manifest.MakeNativePathString(newManFileInfo) != ManifestNativeFilePath) { IgnoredFilesForGroom.Add(nextFileInfo); } Write(" [IGNORED]"); } else { FileCheckedCount++; bool checkHash = false; if (Update == true || AlwaysCheckHash == true || TrackMoves == true) { checkHash = true; } Exception exception = null; if (checkHash) { try { newManFileInfo.FileHash = FileHash.ComputeHash( nextFileInfo, GetNewHashType(Manifest)); } catch (Exception ex) { exception = ex; } } if (checkHash && newManFileInfo.FileHash == null) { ErrorFiles.Add(newManFileInfo); WriteLine(" [ERROR]"); WriteLine(exception.ToString()); } else { NewFiles.Add(newManFileInfo); NewFilesForGroom.Add(nextFileInfo); Write(" [NEW]"); } newManFileInfo.FileLength = nextFileInfo.Length; newManFileInfo.LastModifiedUtc = nextFileInfo.LastWriteTimeUtc; newManFileInfo.RegisteredUtc = DateTime.Now.ToUniversalTime(); currentManfestDirInfo.Files.Add( nextFileName, newManFileInfo); } WriteLine(""); } } // Recurse looking for new directories foreach (String nextDirName in dirDict.Keys) { DirectoryInfo nextDirInfo = dirDict[nextDirName]; if (currentManfestDirInfo.Subdirectories.ContainsKey( nextDirName) == false) { ManifestDirectoryInfo nextManDirInfo = new ManifestDirectoryInfo( nextDirName, currentManfestDirInfo); currentManfestDirInfo.Subdirectories.Add( nextDirName, nextManDirInfo); UpdateRecursive( nextDirInfo, nextManDirInfo); if (nextManDirInfo.Empty) { currentManfestDirInfo.Subdirectories.Remove( nextDirName); } } } }