Exemple #1
0
        private static HashFile[] ReadHashFiles(FileInfo[] files, long maxSize)
        {
            Console.Write("Reading Hashfiles");
            var hashFiles = files
                            .Select(f => HashFile.Create(f))
                            .Where(h => h != null && h.SourceFile != null && h.SourceFile.Exists && (maxSize == -1 || h.SourceFile.Length <= maxSize))
                            .ToArray();

            var filtered =
                (
                    from file in hashFiles
                    join hash in hashdata.Values
                    on file.SourceName.ToLower()
                    equals hash.Path.ToLower()
                    into hashlist
                    from h in hashlist.DefaultIfEmpty()
                    where
                    h == null ||
                    // h.Updated.AddMinutes(20) < DateTime.Now ||
                    (file.SourceFile.Length != h.FileLength || file.SourceFile.LastWriteTime != h.LastWriteTime)
                    select file
                ).ToArray();

            Console.WriteLine(" - Loaded {0} of {2} Hashfile{1}", filtered.Length, hashFiles.Length == 1 ? "" : "s", hashFiles.Length);

            return(filtered.Length < 1 ? null : filtered);
        }
Exemple #2
0
        private static void ProcessHashFile(HashFile hashfile)
        {
            Console.WriteLine("{0}", hashfile.SourceName);
            Console.WriteLine("\tSize: {0}", ReadableFileSize(hashfile.SourceFile.Length));
            Console.Write("\tHash: ");

            string hash = CalculateHash(hashfile.SourceFile);

            if (exit_loops)
            {
                return;
            }

            Console.WriteLine(hash);

            string status = hash == hashfile.Hash ? "OK" : "Invalid Hash";

            Console.WriteLine("\tStatus: {0}", status);

            // update/add database
            var hashent = GetDBHashEntry(hashfile.SourceName);

            if (hashent == null)
            {
                hashent = new Hash {
                    Path = hashfile.SourceName
                };
                DB.Hashes.InsertOnSubmit(hashent);
            }
            hashent.LastWriteTime = hashfile.SourceFile.LastWriteTime;
            hashent.FileLength    = hashfile.SourceFile.Length;
            hashent.SPHash        = hashfile.Hash;
            hashent.FileHash      = hash;
            hashent.Updated       = DateTime.Now;
            DB.SubmitChanges();

            Console.WriteLine();
            Log(string.Join("\t", new string[] { hashfile.SourceName, hashfile.SourceFile.Length.ToString(), hash, status }));
        }
Exemple #3
0
        private static void ProcessHashFiles(HashFile[] hashFiles)
        {
            DateTime startTime = DateTime.Now;
            Log("Started: {0:yyyy-MM-dd HH:mm:ss}", startTime);
            foreach (var hashfile in hashFiles)
            {
                if (exit_loops)
                {
                    Console.WriteLine("User cancelled scan");
                    break;
                }
                ProcessHashFile(hashfile);
            }
            Log("Finished: {0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);
            TimeSpan elasped = DateTime.Now - startTime;
            Log("Elapsed: {0}", elasped);

            long totalSize = hashFiles.Sum(f => f.SourceFile.Length);
            double rate = (totalSize / (1024 * 1024.0)) / Math.Max(elasped.TotalMinutes, 1.0/ 60);
            Log("Speed: {0:#,0.00} MB/min", rate);

            Log("");
        }
Exemple #4
0
        private static void ProcessHashFile(HashFile hashfile)
        {
            Console.WriteLine("{0}", hashfile.SourceName);
            Console.WriteLine("\tSize: {0}", ReadableFileSize(hashfile.SourceFile.Length));
            Console.Write("\tHash: ");

            string hash = CalculateHash(hashfile.SourceFile);
            if (exit_loops)
                return;

            Console.WriteLine(hash);

            string status = hash == hashfile.Hash ? "OK" : "Invalid Hash";
            Console.WriteLine("\tStatus: {0}", status);

            // update/add database
            var hashent = GetDBHashEntry(hashfile.SourceName);
            if (hashent == null)
            {
                hashent = new Hash { Path = hashfile.SourceName };
                DB.Hashes.InsertOnSubmit(hashent);
            }
            hashent.LastWriteTime = hashfile.SourceFile.LastWriteTime;
            hashent.FileLength = hashfile.SourceFile.Length;
            hashent.SPHash = hashfile.Hash;
            hashent.FileHash = hash;
            hashent.Updated = DateTime.Now;
            DB.SubmitChanges();

            Console.WriteLine();
            Log(string.Join("\t", new string[] { hashfile.SourceName, hashfile.SourceFile.Length.ToString(), hash, status }));
        }