public Hash WriteHashFile(IcebergFile file) { HashedFile hf = new HashedFile(file, CreateHashFromContents(file)); HashStorage.Write(hf); return(hf.Hash); }
public override bool Write(HashedFile hashfile) { try { string checksumPath = $"{hashfile.File}{CHECKSUM_FILE_ENDING}"; using (BinaryWriter checksum = new BinaryWriter(new FileStream(checksumPath, FileMode.OpenOrCreate))) checksum.Write(hashfile.Hash.ToString()); File.SetAttributes(checksumPath, FileAttributes.Hidden); return(true); } catch (IOException e) { logger.Error($"Could not write hash! {e.Message} {e.InnerException}"); return(false); } }
public async Task <ActionResult> Post([FromForm] HashedFile file) { System.Diagnostics.Debug.WriteLine("hash: " + file.Hash); if (file.File == null || file.File.Length == 0) { return(BadRequest("asd")); } if (await _interactor.ScanFile(file.File.OpenReadStream(), "whatever", file.Hash)) { return(Ok()); } else { return(BadRequest()); } }
public List <HashedFile> GetAllHashedFileInstances() { var returnable = new List <HashedFile>(); foreach (DataRow dr in fileHashesDataTable.Rows) { var newHash = new HashedFile(); newHash.FilePath = dr["FilePath"].ToString(); newHash.Hash = dr["Hash"].ToString(); newHash.LastScannedOn = DateTime.Parse(dr["LastScannedOn"].ToString()); newHash.FileModifiedOn = DateTime.Parse(dr["FileModifiedOn"].ToString()); newHash.FileCreatedOn = DateTime.Parse(dr["FileCreatedOn"].ToString()); newHash.FileSize = Int32.Parse(dr["FileSize"].ToString()); returnable.Add(newHash); } return(returnable); }
/// <summary> /// Merge attachments from external location, checking for and eliminating any duplicates. /// </summary> /// <param name="t">Transaction to associate attachments with</param> /// <param name="attachments">The external attachments we are importing.</param> internal void ImportAttachments(Transaction t, List <string> attachments) { if (attachments.Count == 0) { return; } List <HashedFile> existing = new List <HashedFile>(); if (t.HasAttachment) { foreach (string file in GetAttachments(t)) { existing.Add(new HashedFile(file)); } } // now check the new files. foreach (string fileName in attachments) { HashedFile newFile = new HashedFile(fileName); bool found = false; foreach (HashedFile f in existing) { if (f.HashEquals(newFile) && f.DeepEquals(newFile)) { // is identical, so we can skip this one, it is already on our target transaction. found = true; break; } } if (!found) { string newFileName = GetUniqueFileName(t, Path.GetExtension(fileName)); File.Copy(fileName, newFileName); } } t.HasAttachment = true; }
public override bool Exists(HashedFile hashed) => Exists(hashed.File);
public abstract bool Exists(HashedFile file);
public abstract bool Write(HashedFile hash);