Example #1
0
            /// <summary>
            /// Backup the target path if needed.
            /// </summary>
            public void BackupIfNeeded(FileHashesSet fileHashes, BackupFolders backupFolders)
            {
                if (!File.Exists(targetPath))
                {
                    return;
                }
                var    hashes = fileHashes.Get(Path.GetDirectoryName(targetPath));
                string originalHash;

                if (hashes.TryGetHash(targetPath, out originalHash))
                {
                    // Compare with existing
                    var currentHash = Hash(targetPath);
                    if (currentHash == originalHash)
                    {
                        return; // No need to backup
                    }
                }
                var backupFolder = backupFolders.Get(Path.GetDirectoryName(targetPath));

                Directory.CreateDirectory(backupFolder);
                File.Copy(targetPath, Path.Combine(backupFolder, Path.GetFileName(targetPath)));
            }
Example #2
0
            /// <summary>
            /// Update the hash of the target path.
            /// </summary>
            public void UpdateHash(FileHashesSet fileHashes)
            {
                var hashes = fileHashes.Get(Path.GetDirectoryName(targetPath));

                hashes.Add(targetPath, Hash(targetPath));
            }
Example #3
0
 /// <summary>
 /// Update the hash of the target path.
 /// </summary>
 public void UpdateHash(FileHashesSet fileHashes)
 {
     var hashes = fileHashes.Get(Path.GetDirectoryName(targetPath));
     hashes.Add(targetPath, Hash(targetPath));
 }
Example #4
0
 /// <summary>
 /// Backup the target path if needed.
 /// </summary>
 public void BackupIfNeeded(FileHashesSet fileHashes, BackupFolders backupFolders)
 {
     if (!File.Exists(targetPath))
         return;
     var hashes = fileHashes.Get(Path.GetDirectoryName(targetPath));
     string originalHash;
     if (hashes.TryGetHash(targetPath, out originalHash))
     {
         // Compare with existing
         var currentHash = Hash(targetPath);
         if (currentHash == originalHash)
             return; // No need to backup
     }
     var backupFolder = backupFolders.Get(Path.GetDirectoryName(targetPath));
     Directory.CreateDirectory(backupFolder);
     File.Copy(targetPath, Path.Combine(backupFolder, Path.GetFileName(targetPath)));
 }