public DatabaseWindowViewModel()
        {
            Threshold = 0;

            IDBs = new ObservableCollection <IDB>();

            InitializeDBs();
            IntializeCommands();

            ComparisonResults = new TitledCollection <Compares>("Comparison Results");
        }
示例#2
0
        async void Audit()
        {
            Reporter.Report($"Auditing {SelectedPlatform.Title}");
            TitledCollection <Audit.Result> resultCollection = null;

            await Task.Run(() =>
            {
                resultCollection = Robin.Audit.AuditRoms(SelectedPlatform);
            });

            AuditResultsCollection.Add(resultCollection);
        }
示例#3
0
        /// <summary>
        /// Audits existance of roms for patforms that are not mame. Cycles through all roms under the platform, checks the existance of a file under ROM.filename, checks the  crc
        /// </summary>
        /// <returns>A list of Audit.Result </returns>
        static TitledCollection <Result> AuditNonMameRoms(Platform platform)
        {
            TitledCollection <Result> returner = new TitledCollection <Result>(platform.Title);

            // Record all files in the directory to keep track of which have been audited
            HashSet <string> files = new HashSet <string>(Directory.GetFiles(platform.RomDirectory));

            int headerLength = (int)platform.HeaderLength;
            int romCount     = platform.Roms.Count;

            Reporter.Tic($"Auditing {romCount} {platform.Title} database ROMs...", out int tic1);
            // First audit all ROMS in the database
            foreach (Rom rom in platform.Roms)
            {
                var result = new Result(rom);
                returner.Add(result);

                if (File.Exists(rom.FilePath))
                {
                    if (rom.CRC32 != null)
                    {
                        if (rom.CRC32 == GetHash(rom.FilePath, HashOption.CRC32, headerLength) ||
                            rom.CRC32 == GetHash(rom.FilePath, HashOption.CRC32, 0))
                        {
                            result.Status = Status.Good;
                        }
                        else
                        {
                            result.Status = Status.Bad;
                        }
                    }

                    else if (rom.MD5 != null)
                    {
                        if (rom.MD5 == GetHash(rom.FilePath, HashOption.MD5, headerLength) ||
                            rom.MD5 == GetHash(rom.FilePath, HashOption.MD5, 0))
                        {
                            result.Status = Status.Good;
                        }
                        else
                        {
                            result.Status = Status.Bad;
                        }
                    }

                    else if (rom.SHA1 != null)
                    {
                        if (rom.SHA1 == GetHash(rom.FilePath, HashOption.SHA1, headerLength) ||
                            rom.SHA1 == GetHash(rom.FilePath, HashOption.SHA1, 0))
                        {
                            result.Status = Status.Good;
                        }
                        else
                        {
                            result.Status = Status.Bad;
                        }
                    }

                    else
                    {
                        result.Status = Status.Unknown;
                    }
                }

                else
                {
                    result.Status = Status.Missing;
                }

                // Remove from the list so we don't check again below
                files.Remove(rom.FilePath);
            }
            Reporter.Toc(tic1);

            // Then go through all files in the folder not checked yet and mark as superfluous
            Reporter.Tic("Creating hash sets...", out int tic2);
            HashSet <string> crcs  = new HashSet <string>(returner.Select(x => x.CRC32));
            HashSet <string> sha1s = new HashSet <string>(returner.Select(x => x.SHA1));
            HashSet <string> md5s  = new HashSet <string>(returner.Select(x => x.MD5));

            Reporter.Toc(tic2);

            Reporter.Tic("Auditing orpan files on disks...", out int tic3);
            foreach (string file in files)
            {
                Result result = new Result
                {
                    Status   = Status.Extra,
                    FilePath = file
                };

                if (crcs.Contains(GetHash(file, HashOption.CRC32, (int)platform.HeaderLength)) ||
                    crcs.Contains(GetHash(file, HashOption.CRC32, 0)) ||
                    md5s.Contains(GetHash(file, HashOption.MD5, (int)platform.HeaderLength)) ||
                    md5s.Contains(GetHash(file, HashOption.MD5, 0)) ||
                    sha1s.Contains(GetHash(file, HashOption.SHA1, (int)platform.HeaderLength)) ||
                    sha1s.Contains(GetHash(file, HashOption.SHA1, 0)))
                {
                    result.Status = Status.Duplicate;
                }
            }
            Reporter.Toc(tic3);

            return(returner);
        }