public Hash WriteHashFile(IcebergFile file) { HashedFile hf = new HashedFile(file, CreateHashFromContents(file)); HashStorage.Write(hf); return(hf.Hash); }
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; } }
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."); } }
public override bool Exists(IcebergFile file) => Exists(file);
public abstract bool Exists(IcebergFile file);
public abstract Hash Load(IcebergFile file);
public virtual bool VerifyStoredChecksum(IcebergFile volatileFile) => Verify(LoadStoredHash(volatileFile), CreateHashFromContents(volatileFile));
protected Hash CreateHashFromContents(IcebergFile file) { using (var stream = file.FileInfo.Open(FileMode.Open)) return(Hash(stream)); }
public Hash LoadStoredHash(IcebergFile file) { return(HashStorage.Load(file)); }