Example #1
0
 private static void HashFile(LocalHash localHash, HashOptions hashOptions)
 {
     FileMode fileMode = FileMode.Create;
     if (false == hashOptions.Overwrite)
     {
         fileMode = FileMode.CreateNew;
     }
     var hashAlgorithm = HashAlgorithmNames.GetHashAlgorithm(hashOptions.HashAlgorithm);
     if (string.IsNullOrEmpty(hashOptions.OutputFilename))
     {
         if (string.IsNullOrEmpty(hashOptions.ExpectedHash))
         {
             byte[] hash = localHash.ComputeHash(hashOptions.SourceFilename,
                 hashAlgorithm, hashOptions.BufferSize);
             ReportHash(hashOptions.HashAlgorithm, localHash.GetHashString(hash));
         }
         else
         {
             localHash.ValidateHash(hashOptions.SourceFilename,
                 hashAlgorithm, hashOptions.BufferSize, localHash.GetHashArray(hashOptions.ExpectedHash));
         }
     }
     else
     {
         if (string.IsNullOrEmpty(hashOptions.ExpectedHash))
         {
             localHash.ComputeHash(hashOptions.SourceFilename, hashOptions.OutputFilename,
                 fileMode, hashAlgorithm, hashOptions.BufferSize);
         }
         else
         {
             localHash.ValidateHash(hashOptions.SourceFilename, hashOptions.OutputFilename, fileMode,
                 hashAlgorithm, hashOptions.BufferSize, localHash.GetHashArray(hashOptions.ExpectedHash));
         }
     }
 }