示例#1
0
        public Hash WriteHashFile(IcebergFile file)
        {
            HashedFile hf = new HashedFile(file, CreateHashFromContents(file));

            HashStorage.Write(hf);
            return(hf.Hash);
        }
示例#2
0
 public override Hash Load(IcebergFile file)
 {
     try {
         using (BinaryReader reader = new BinaryReader(File.Open(file.Path + CHECKSUM_FILE_ENDING, FileMode.Open))) {
             var val = new Hash(reader.ReadString());
             return(val);
         }
     } catch (IOException e) {
         logger.Fatal($"Completely failed to read a hash ({file})! {e.Message} {e.InnerException}");
         throw e;
     }
 }
示例#3
0
        private void VerifyFiles()
        {
            foreach (var file in Directory.GetFiles(Environment.CurrentDirectory))
            {
                if (hasher.HashStorage.ShouldIgnore(file)) // We don't care about this (right now)
                {
                    continue;
                }

                if (hasher.HashExists(file))
                {
                    // A checksum exists for this file, but is is valid? really though?
                    var possibleNonMatch = new IcebergFile(file);
                    if (!hasher.VerifyStoredChecksum(possibleNonMatch))
                    {
                        logger.Warn($"MISMATCH! {possibleNonMatch.FileInfo.Name} does not match stored hash");
                        hasher.WriteHashFile(possibleNonMatch);
                        changedFiles.Add(possibleNonMatch);
                    }
                }
                else
                {
                    // This appears to be a new file.
                    var newfile = new IcebergFile(file);
                    hasher.WriteHashFile(newfile);
                    changedFiles.Add(newfile);
                    logger.Info($"Encountered a new file: {newfile.FileInfo.Name}");
                }
            }

            if (changedFiles.Count == 0)
            {
                logger.Info("Nothing to do (Your wallet is safe... for now!)");
            }
            else
            {
                logger.Info($"Found {changedFiles.Count} file(s) that will need to be uploaded.");
            }
        }
示例#4
0
 public override bool Exists(IcebergFile file) => Exists(file);
示例#5
0
 public abstract bool Exists(IcebergFile file);
示例#6
0
 public abstract Hash Load(IcebergFile file);
示例#7
0
 public virtual bool VerifyStoredChecksum(IcebergFile volatileFile) => Verify(LoadStoredHash(volatileFile), CreateHashFromContents(volatileFile));
示例#8
0
 protected Hash CreateHashFromContents(IcebergFile file)
 {
     using (var stream = file.FileInfo.Open(FileMode.Open))
         return(Hash(stream));
 }
示例#9
0
 public Hash LoadStoredHash(IcebergFile file)
 {
     return(HashStorage.Load(file));
 }