Example #1
0
        public void CompareAllFilesFromLatestScanWithAllPreviousFileScans()
        {
            List <FileScan> allFileScans = FileScan.GetAllFileScansFromScan(this.Id);

            //Logger.Log("Changed Files\n");

            foreach (FileScan fileScan in allFileScans)
            {
                FileScan other = FileScan.GetLatestPreviousFileScan(fileScan.Time, this.HashAlgorithm);

                if (other == null)
                {
                    Logger.Log("PREVIOUSLY NOT FOUND;;" + fileScan.FilePath,
                               LogType.Warning);

                    continue;
                }

                if (fileScan.Checksum != other.Checksum)
                {
                    string log = String.Format("CHANGED FILE;{0}",
                                               fileScan.FilePath);
                    Logger.Log(log, LogType.Notification);
                }
            }
        }
        public static void ScanFile(string filePath, Scan scan)
        {
            string checksum = FileChecksumCreator.GetFileChecksum(filePath, scan.HashAlgorithm.Algorithm);
            int    fileSize = 0; //Leave open for now!

            FileScan fileScan = new FileScan
            {
                FilePath = filePath,
                Checksum = checksum,
                FileSize = fileSize,
                ScanId   = scan.Id,
                Time     = DateTime.Now
            };

            if (!fileScan.Insert())
            {
                throw new Exception("Unknown error: the file checksum could not be stored in the database!");
            }
        }
Example #3
0
        public static void StartSingleFileScan(string filePath, AvailableHashAlgorithms hashAlgorithm)
        {
            Scan scan = new Scan
            {
                FilePath      = filePath,
                HashAlgorithm = new FIMHashAlgorithm {
                    Id = (int)hashAlgorithm
                },
                Time = DateTime.Now
            };

            try
            {
                FileScan.ScanFile(filePath, scan);
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message, LogType.Error);
            }
        }
Example #4
0
        public static void StartScanConsole(string filePath, bool recursive, AvailableHashAlgorithms hashAlgorithm)
        {
            Scan scan = new Scan
            {
                FilePath      = filePath,
                HashAlgorithm = new FIMHashAlgorithm {
                    Id = (int)hashAlgorithm
                },
                Time = DateTime.Now
            };

            scan.Insert();

            //insert scan in database

            List <string> allFiles = DirectoryParser.GetAllFiles(filePath, recursive);

            int nFiles = allFiles.Count;
            int i      = 0;

            Console.WriteLine("Scanning ...");
            foreach (string file in allFiles)
            {
                try
                {
                    FileScan.ScanFile(file, scan);

                    Console.WriteLine(Math.Ceiling(((double)i / nFiles) * 100).ToString() + "%");
                    Console.SetCursorPosition(0, Console.CursorTop - 1);
                    System.Threading.Thread.Sleep(50);
                    i++;
                }
                catch (Exception ex)
                {
                    Logger.Log(ex.Message, LogType.Error);

                    continue;
                }
            }
        }
 public bool CompareFileChecksums(FileScan other)
 {
     return(other != null &&
            !string.IsNullOrEmpty(this.Checksum) && !string.IsNullOrEmpty(other.Checksum) &&
            this.Checksum == other.Checksum);
 }