// we are adding got files so we can assume a few things: // these got files may be level 1 or level 2 scanned. // // If they are just level 1 then there may or may not be SHA1 / MD5 info, which is unvalidated. // So: We will always have CRC & Size info at a minimum and may also have SHA1 / MD5 // // Next: Due to the possilibity of CRC hash collisions // we could find matching CRC that have different SHA1 & MD5 // so we should seach for one or more matching CRC/Size sets. // then check to see if we have anything else that matches and then either: // add the rom to an existing set or make a new set. private static void MergeGotFiles(RvFile[] gotFilesSortedByCRC, out FileGroup[] fileGroups) { List <FileGroup> listFileGroupsOut = new List <FileGroup>(); // insert a zero byte file. RvFile fileZero = MakeFileZero(); FileGroup newFileGroup = new FileGroup(fileZero); List <FileGroup> lstFileWithSameCRC = new List <FileGroup>(); byte[] crc = fileZero.CRC; lstFileWithSameCRC.Add(newFileGroup); listFileGroupsOut.Add(newFileGroup); foreach (RvFile file in gotFilesSortedByCRC) { if (file.CRC == null) { continue; } if (crc != null && ArrByte.ICompare(crc, file.CRC) == 0) { bool found = false; foreach (FileGroup fileGroup in lstFileWithSameCRC) { if (!fileGroup.FindExactMatch(file)) { continue; } fileGroup.MergeFileIntoGroup(file); found = true; break; } if (found) { continue; } // new File with the same CRC but different sha1/md5/size newFileGroup = new FileGroup(file); lstFileWithSameCRC.Add(newFileGroup); listFileGroupsOut.Add(newFileGroup); continue; } crc = file.CRC; lstFileWithSameCRC.Clear(); newFileGroup = new FileGroup(file); lstFileWithSameCRC.Add(newFileGroup); listFileGroupsOut.Add(newFileGroup); } fileGroups = listFileGroupsOut.ToArray(); }
private static bool CompareAltHash(RvFile dbFile, RvFile testFile) { Debug.WriteLine("ComparingAlt Dat File " + dbFile.TreeFullName); Debug.WriteLine("ComparingAlt File " + testFile.TreeFullName); if (!FileHeaderReader.FileHeaderReader.AltHeaderFile(testFile.HeaderFileType)) { return(false); } if (dbFile.HeaderFileType != testFile.HeaderFileType) { return(false); } bool testFound = false; int retv; if (dbFile.Size != null && testFile.AltSize != null) { retv = ULong.iCompare(dbFile.Size, testFile.AltSize); if (retv != 0) { return(false); } } if (dbFile.CRC != null && testFile.AltCRC != null) { testFound = true; retv = ArrByte.ICompare(dbFile.CRC, testFile.AltCRC); if (retv != 0) { return(false); } } if (dbFile.SHA1 != null && testFile.AltSHA1 != null) { testFound = true; retv = ArrByte.ICompare(dbFile.SHA1, testFile.AltSHA1); if (retv != 0) { return(false); } } if (dbFile.MD5 != null && testFile.AltMD5 != null) { testFound = true; retv = ArrByte.ICompare(dbFile.MD5, testFile.AltMD5); if (retv != 0) { return(false); } } return(testFound); }
private static bool CompareHash(RvFile dbFile, RvFile testFile) { //Debug.WriteLine("Comparing Dat File " + dbFile.TreeFullName); //Debug.WriteLine("Comparing File " + testFile.TreeFullName); bool testFound = false; int retv; if (dbFile.Size != null && testFile.Size != null) { retv = ULong.iCompare(dbFile.Size, testFile.Size); if (retv != 0) { return(false); } //special zero size test case, if the dat size is 0 and the testfile size is 0 //and there are no other hash values in the dat, then assume it is a match. if (testFile.Size == 0 && dbFile.CRC == null && dbFile.SHA1 == null && dbFile.MD5 == null) { return(true); } } if (dbFile.CRC != null && testFile.CRC != null) { testFound = true; retv = ArrByte.ICompare(dbFile.CRC, testFile.CRC); if (retv != 0) { return(false); } } if (dbFile.SHA1 != null && testFile.SHA1 != null) { testFound = true; retv = ArrByte.ICompare(dbFile.SHA1, testFile.SHA1); if (retv != 0) { return(false); } } if (dbFile.MD5 != null && testFile.MD5 != null) { testFound = true; retv = ArrByte.ICompare(dbFile.MD5, testFile.MD5); if (retv != 0) { return(false); } } return(testFound); }
private static int FamilySortAltMD5(FileGroup fileGroup1, FileGroup fileGroup2) { return(ArrByte.ICompare(fileGroup1.AltMD5, fileGroup2.AltMD5)); }
private static int FamilySortSHA1(FileGroup fileGroup1, FileGroup fileGroup2) { return(ArrByte.ICompare(fileGroup1.SHA1, fileGroup2.SHA1)); }
private static int CompareAltMD5(RvFile file, FileGroup fileGroup) { return(ArrByte.ICompare(file.MD5, fileGroup.AltMD5)); }
private static int CompareAltSHA1(RvFile file, FileGroup fileGroup) { return(ArrByte.ICompare(file.SHA1, fileGroup.AltSHA1)); }
private static int CompareAltCRC(RvFile file, FileGroup fileGroup) { return(ArrByte.ICompare(file.CRC, fileGroup.AltCRC)); }
private static void SortCRC(int intBase, int intTop, RvFile[] files, int depth) { int sortSize = intTop - intBase; if (sortSize <= 1) { return; } // if just 2 tests if (sortSize == 2) { // compare the 2 files RvFile t0 = files[intBase]; RvFile t1 = files[intBase + 1]; if (ArrByte.ICompare(t0.CRC, t1.CRC) < 1) { return; } // swap them files[intBase] = t1; files[intBase + 1] = t0; return; } int intMiddle = (intTop + intBase) / 2; if (depth < 2) { Thread t0 = new Thread(() => SortCRC(intBase, intMiddle, files, depth + 1)); Thread t1 = new Thread(() => SortCRC(intMiddle, intTop, files, depth + 1)); t0.Start(); t1.Start(); t0.Join(); t1.Join(); } else { SortCRC(intBase, intMiddle, files, depth + 1); SortCRC(intMiddle, intTop, files, depth + 1); } int intBottomSize = intMiddle - intBase; int intTopSize = intTop - intMiddle; RvFile[] lstBottom = new RvFile[intBottomSize]; RvFile[] lstTop = new RvFile[intTopSize]; if (depth == 0) { Thread t0 = new Thread(() => Array.Copy(files, intBase, lstBottom, 0, intBottomSize)); Thread t1 = new Thread(() => Array.Copy(files, intMiddle, lstTop, 0, intTopSize)); t0.Start(); t1.Start(); t0.Join(); t1.Join(); } else { Array.Copy(files, intBase, lstBottom, 0, intBottomSize); Array.Copy(files, intMiddle, lstTop, 0, intTopSize); } int intBottomCount = 0; int intTopCount = 0; int intCount = intBase; while (intBottomCount < intBottomSize && intTopCount < intTopSize) { if (ArrByte.ICompare(lstBottom[intBottomCount].CRC, lstTop[intTopCount].CRC) < 1) { files[intCount++] = lstBottom[intBottomCount++]; } else { files[intCount++] = lstTop[intTopCount++]; } } while (intBottomCount < intBottomSize) { files[intCount++] = lstBottom[intBottomCount++]; } while (intTopCount < intTopSize) { files[intCount++] = lstTop[intTopCount++]; } }
public int Compare(RvFile x, RvFile y) { int retVal = 0; switch ((eRomGrid)_colIndex) { case eRomGrid.Got: // then by name retVal = x.GotStatus - y.GotStatus; if (retVal != 0) { break; } retVal = x.RepStatus - y.RepStatus; if (retVal != 0) { break; } retVal = string.Compare(x.UiDisplayName ?? "", y.UiDisplayName ?? "", StringComparison.Ordinal); break; case eRomGrid.Rom: retVal = string.Compare(x.UiDisplayName ?? "", y.UiDisplayName ?? "", StringComparison.Ordinal); break; case eRomGrid.Merge: retVal = string.Compare(x.Merge ?? "", y.Merge ?? "", StringComparison.Ordinal); break; case eRomGrid.Size: retVal = ULong.iCompareNull(x.Size, y.Size); break; case eRomGrid.CRC32: retVal = ArrByte.ICompare(x.CRC, y.CRC); break; case eRomGrid.SHA1: retVal = ArrByte.ICompare(x.SHA1, y.SHA1); break; case eRomGrid.MD5: retVal = ArrByte.ICompare(x.MD5, y.MD5); break; case eRomGrid.AltSize: retVal = ULong.iCompareNull(x.AltSize, y.AltSize); break; case eRomGrid.AltCRC32: retVal = ArrByte.ICompare(x.AltCRC, y.AltCRC); break; case eRomGrid.AltSHA1: retVal = ArrByte.ICompare(x.AltSHA1, y.AltSHA1); break; case eRomGrid.AltMD5: retVal = ArrByte.ICompare(x.AltMD5, y.AltMD5); break; case eRomGrid.Status: retVal = string.Compare(x.Status ?? "", y.Status ?? "", StringComparison.Ordinal); break; } if (_sortDir == SortOrder.Descending) { retVal = -retVal; } if (retVal == 0 && _colIndex != 1) { retVal = string.Compare(x.UiDisplayName ?? "", y.UiDisplayName ?? "", StringComparison.Ordinal); } return(retVal); }
public int Compare(RvFile x, RvFile y) { int retVal = 0; switch (_colIndex) { case 1: retVal = string.Compare(x.UiDisplayName ?? "", y.UiDisplayName ?? "", StringComparison.Ordinal); break; case 2: retVal = string.Compare(x.Merge ?? "", y.Merge ?? "", StringComparison.Ordinal); break; case 3: retVal = ULong.iCompareNull(x.Size, y.Size); break; case 4: retVal = ArrByte.ICompare(x.CRC, y.CRC); break; case 5: retVal = ArrByte.ICompare(x.SHA1, y.SHA1); break; case 6: retVal = ArrByte.ICompare(x.MD5, y.MD5); break; case 7: retVal = ULong.iCompareNull(x.AltSize, y.AltSize); break; case 8: retVal = ArrByte.ICompare(x.AltCRC, y.AltCRC); break; case 9: retVal = ArrByte.ICompare(x.AltSHA1, y.AltSHA1); break; case 10: retVal = ArrByte.ICompare(x.AltMD5, y.AltMD5); break; case 11: retVal = string.Compare(x.Status ?? "", y.Status ?? "", StringComparison.Ordinal); break; } if (_sortDir == SortOrder.Descending) { retVal = -retVal; } if (retVal == 0 && _colIndex != 1) { retVal = string.Compare(x.UiDisplayName ?? "", y.UiDisplayName ?? "", StringComparison.Ordinal); } return(retVal); }