Example #1
0
        public String StoreFile(FileInfo file)
        {
            string hash = ComputeHash.SHA1(file);

            if (FileExists(hash))
            {
                return(hash);
            }

            FileInfo destination = GetFileInfo(hash);

            Debug.Assert(destination != null, "destination filename is null");
            Directory.CreateDirectory(destination.DirectoryName);
            File.Copy(file.FullName, destination.FullName);

            // verify the hash, paranoid, but would detect some possible hardware issues
            string hashNew = ComputeHash.SHA1(destination);

            if (hash != hashNew)
            {
                destination.Delete();
                throw new Exception("Copy not equal to original image (SHA1 hash differs)");
            }
            destination.Attributes = destination.Attributes | FileAttributes.ReadOnly;
            return(hashNew);
        }
Example #2
0
 public FileInformation(FileInfo file)
     : this()
 {
     Id       = ComputeHash.SHA1(file);
     FileSize = file.Length;
     Title    = file.Name;
     MimeType = MimeExtractor.MimeType.Extract(file);
     RefreshMetadata(file);
     AddPath(file);
 }