private static int RomSortCRCSizeFunc(RvFile a, RvFile b) { int retv = ArrByte.iCompare(a.CRC, b.CRC); if (retv == 0) { retv = ULong.iCompare(a.Size, b.Size); } return(retv); }
private static void DatSetRenameAndRemoveDups(RvDat tDat) { if (tDat.Games == null) { return; } for (int g = 0; g < tDat.Games.Count; g++) { RvGame tGame = tDat.Games[g]; for (int r = 0; r < tGame.RomCount - 1; r++) { RvRom f0 = tGame.Roms[r]; RvRom f1 = tGame.Roms[r + 1]; if (f0.Name != f1.Name) { continue; } if ((f0.Size != f1.Size) || (ArrByte.iCompare(f0.CRC, f1.CRC) != 0)) { tGame.Roms.RemoveAt(r + 1); // remove F1 f1.Name = f1.Name + "_" + ArrByte.ToString(f1.CRC); // rename F1; int pos = tGame.AddRom(f1); // if this rename moved the File back up the list, start checking again from that file. if (pos < r) { r = pos; } } else { tGame.Roms.RemoveAt(r + 1); } r--; } } }
private static int RomSortSHA1CHDFunc(RvFile a, RvFile b) { int retv = ArrByte.iCompare(a.SHA1CHD, b.SHA1CHD); return(retv); }
private static bool FullCompare(RvBase var1, RvBase var2) { int retv = DBHelper.CompareName(var1, var2); if (retv != 0) { return(false); } FileType v1 = var1.FileType; FileType v2 = var2.FileType; retv = Math.Sign(v1.CompareTo(v2)); if (retv != 0) { return(false); } // filetypes are now know to be the same // Dir's and Zip's are not deep scanned so matching here is done if ((v1 == FileType.Dir) || (v1 == FileType.Zip)) { return(true); } RvFile f1 = (RvFile)var1; RvFile f2 = (RvFile)var2; if (f1.Size != null && f2.Size != null) { retv = ULong.iCompare(f1.Size, f2.Size); if (retv != 0) { return(false); } } if (f1.CRC != null && f2.CRC != null) { retv = ArrByte.iCompare(f1.CRC, f2.CRC); if (retv != 0) { return(false); } } if (f1.SHA1 != null && f2.SHA1 != null) { retv = ArrByte.iCompare(f1.SHA1, f2.SHA1); if (retv != 0) { return(false); } } if (f1.MD5 != null && f2.MD5 != null) { retv = ArrByte.iCompare(f1.MD5, f2.MD5); if (retv != 0) { return(false); } } if (f1.SHA1CHD != null && f2.SHA1CHD != null) { retv = ArrByte.iCompare(f1.SHA1CHD, f2.SHA1CHD); if (retv != 0) { return(false); } } if (f1.MD5CHD != null && f2.MD5CHD != null) { retv = ArrByte.iCompare(f1.MD5CHD, f2.MD5CHD); if (retv != 0) { return(false); } } return(true); }
private static bool FullCompare(RvBase dbFile, RvBase testFile, bool secondPass, string fullDir = "", eScanLevel sLevel = eScanLevel.Level3) { Debug.WriteLine("Comparing Dat File " + dbFile.TreeFullName); Debug.WriteLine("Comparing File " + testFile.TreeFullName); int retv = DBHelper.CompareName(dbFile, testFile); if (retv != 0) { return(false); } FileType dbfileType = dbFile.FileType; FileType dbtestFile = testFile.FileType; retv = Math.Sign(dbfileType.CompareTo(dbtestFile)); if (retv != 0) { return(false); } // filetypes are now know to be the same // Dir's and Zip's are not deep scanned so matching here is done if ((dbfileType == FileType.Dir) || (dbfileType == FileType.Zip)) { return(true); } RvFile dbFileF = (RvFile)dbFile; RvFile testFileF = (RvFile)testFile; if (dbFileF.Size != null && testFileF.Size != null) { retv = ULong.iCompare(dbFileF.Size, testFileF.Size); if (retv != 0) { return(false); } } if (dbFileF.CRC != null && testFileF.CRC != null) { retv = ArrByte.iCompare(dbFileF.CRC, testFileF.CRC); if (retv != 0) { return(false); } } if (dbFileF.SHA1 != null && testFileF.SHA1 != null) { retv = ArrByte.iCompare(dbFileF.SHA1, testFileF.SHA1); if (retv != 0) { return(false); } } if (dbFileF.MD5 != null && testFileF.MD5 != null) { retv = ArrByte.iCompare(dbFileF.MD5, testFileF.MD5); if (retv != 0) { return(false); } } if (dbFileF.SHA1CHD != null && testFileF.SHA1CHD != null) { retv = ArrByte.iCompare(dbFileF.SHA1CHD, testFileF.SHA1CHD); if (retv != 0) { return(false); } } if (dbFileF.MD5CHD != null && testFileF.MD5CHD != null) { retv = ArrByte.iCompare(dbFileF.MD5CHD, testFileF.MD5CHD); if (retv != 0) { return(false); } } // beyond here we only test files if (dbtestFile != FileType.File) { return(true); } // if scanning at level 3 then we have already deep checked the file so all is OK. if (sLevel == eScanLevel.Level3) { return(true); } // if we got this far then everything we have so far has matched, but that may not be enough. // now we see if we need to get any more info and try again. // if the file stamps do not match or the file in the DB we are comparing with has not been deep scanned // and the file we are scanning has not already been deep scanned, then we need to do a deep scan, and check the deep scan values // files are always deep scanned, so the test for IsDeepScanned(dbFileF) is probably not really needed here. if ((dbFileF.TimeStamp != testFileF.TimeStamp || !IsDeepScanned(dbFileF)) && !IsDeepScanned(testFileF)) { if (!secondPass) { return(false); } DeepScanFile(fullDir, testFileF); if (dbFileF.CRC != null && testFileF.CRC != null) { retv = ArrByte.iCompare(dbFileF.CRC, testFileF.CRC); if (retv != 0) { return(false); } } if (dbFileF.SHA1 != null && testFileF.SHA1 != null) { retv = ArrByte.iCompare(dbFileF.SHA1, testFileF.SHA1); if (retv != 0) { return(false); } } if (dbFileF.MD5 != null && testFileF.MD5 != null) { retv = ArrByte.iCompare(dbFileF.MD5, testFileF.MD5); if (retv != 0) { return(false); } } } // CHDman test, if we are only scanning at level 1 then don't do CHDman test so we are done. if (sLevel == eScanLevel.Level1) { return(true); } if ((dbFileF.TimeStamp != testFileF.TimeStamp || (!IschdmanScanned(dbFileF)) && !IschdmanScanned(testFileF))) { ChdManCheck(fullDir, testFileF); } return(true); }
private static void DatSetMergeSets(RvDat tDat) { for (int g = tDat.Games.Count - 1; g >= 0; g--) { RvGame mGame = tDat.Games[g]; List <RvGame> lstParentGames = new List <RvGame>(); FindParentSet(mGame, tDat, ref lstParentGames); while ((lstParentGames.Count > 0) && ((lstParentGames[lstParentGames.Count - 1].IsBios ?? "").ToLower() == "yes")) { lstParentGames.RemoveAt(lstParentGames.Count - 1); } if (lstParentGames.Count <= 0) { continue; } RvGame romofGame = lstParentGames[lstParentGames.Count - 1]; bool founderror = false; for (int r = 0; r < mGame.RomCount; r++) { string name = mGame.Roms[r].Name; string mergename = mGame.Roms[r].Merge; for (int r1 = 0; r1 < romofGame.RomCount; r1++) { if ( ((name == romofGame.Roms[r1].Name.ToLower()) || (mergename == romofGame.Roms[r1].Name.ToLower())) && ((ArrByte.iCompare(mGame.Roms[r].CRC, romofGame.Roms[r1].CRC) != 0) || (mGame.Roms[r].Size != romofGame.Roms[r1].Size)) ) { founderror = true; } } } if (founderror) { mGame.RomOf = null; continue; } for (int r = 0; r < mGame.RomCount; r++) { string name = mGame.Roms[r].Name; string mergename = mGame.Roms[r].Merge; bool found = false; for (int r1 = 0; r1 < romofGame.RomCount; r1++) { if ( ((name == romofGame.Roms[r1].Name.ToLower()) || (mergename == romofGame.Roms[r1].Name.ToLower())) && (ArrByte.iCompare(mGame.Roms[r].CRC, romofGame.Roms[r1].CRC) == 0) && (mGame.Roms[r].Size == romofGame.Roms[r1].Size) ) { found = true; break; } } if (!found) { romofGame.AddRom(mGame.Roms[r]); } } tDat.Games.RemoveAt(g); } }
private static void DatSetMergeSets(RvDir tDat) { for (int g = tDat.ChildCount - 1; g >= 0; g--) { RvDir mGame = (RvDir)tDat.Child(g); if (mGame.Game == null) { DatSetMergeSets(mGame); continue; } List <RvDir> lstParentGames = new List <RvDir>(); FindParentSet(mGame, tDat, ref lstParentGames); while (lstParentGames.Count > 0 && lstParentGames[lstParentGames.Count - 1].Game.GetData(RvGame.GameData.IsBios).ToLower() == "yes") { lstParentGames.RemoveAt(lstParentGames.Count - 1); } if (lstParentGames.Count <= 0) { continue; } RvDir romofGame = lstParentGames[lstParentGames.Count - 1]; bool founderror = false; for (int r = 0; r < mGame.ChildCount; r++) { string name = mGame.Child(r).Name; string mergename = ((RvFile)mGame.Child(r)).Merge; for (int r1 = 0; r1 < romofGame.ChildCount; r1++) { if ((name == romofGame.Child(r1).Name || mergename == romofGame.Child(r1).Name) && (ArrByte.iCompare(((RvFile)mGame.Child(r)).CRC, ((RvFile)romofGame.Child(r1)).CRC) != 0 || ((RvFile)mGame.Child(r)).Size != ((RvFile)romofGame.Child(r1)).Size)) { founderror = true; } } } if (founderror) { mGame.Game.DeleteData(RvGame.GameData.RomOf); continue; } for (int r = 0; r < mGame.ChildCount; r++) { string name = mGame.Child(r).Name; string mergename = ((RvFile)mGame.Child(r)).Merge; bool found = false; for (int r1 = 0; r1 < romofGame.ChildCount; r1++) { if ((name == romofGame.Child(r1).Name || mergename == romofGame.Child(r1).Name) && (ArrByte.iCompare(((RvFile)mGame.Child(r)).CRC, ((RvFile)romofGame.Child(r1)).CRC) == 0 && ((RvFile)mGame.Child(r)).Size == ((RvFile)romofGame.Child(r1)).Size)) { found = true; break; } } if (!found) { romofGame.ChildAdd(mGame.Child(r)); } } tDat.ChildRemove(g); } }