public override void CalculateHashes(byte[] rom, IHashWorkManager worker, float startProgress, float endProgress) { // Hashes are calculated using the thread pool due to the fact that NDS roms are MASSIVE worker.QueueTask((SimpleDelegate) delegate { if (!worker.AbortPending) { worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.SHA256, HashFlags.FileHash, HashFlags.RomHash); } }); worker.QueueTask((SimpleDelegate) delegate { if (!worker.AbortPending) { worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.SHA1, HashFlags.FileHash, HashFlags.RomHash); } }); worker.QueueTask((SimpleDelegate) delegate { if (!worker.AbortPending) { worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.CRC32, HashFlags.FileHash, HashFlags.RomHash); } }); worker.QueueTask((SimpleDelegate) delegate { if (!worker.AbortPending) { worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.MD5, HashFlags.FileHash, HashFlags.RomHash); } }); // Can not return until all hashes are ready worker.WaitAll(); }
public override void CalculateHashes(byte[] rom, IHashWorkManager worker, float startProgress, float endProgress) { // N64 hashes are calculated using the thread pool because the ROMs tend to be large bool byteswapped = N64.IsByteswapped(rom) == N64ByteSwap.Swapped; byte[] swappedRom = new byte[rom.Length]; // Watch out for odd # of bytes! int len = rom.Length & (~1); for (int i = 0; i < len; i += 2) { swappedRom[i] = rom[i + 1]; swappedRom[i + 1] = rom[i]; } HashFlags originalType = byteswapped ? HashFlags.RomHash_ByteSwap : HashFlags.RomHash; HashFlags swappedType = byteswapped ? HashFlags.RomHash : HashFlags.RomHash_ByteSwap; worker.QueueTask((SimpleDelegate) delegate { if (!worker.AbortPending) { worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.SHA256, originalType, HashFlags.FileHash); } }); worker.QueueTask((SimpleDelegate) delegate { if (!worker.AbortPending) { worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.SHA1, originalType, HashFlags.FileHash); } }); worker.QueueTask((SimpleDelegate) delegate { if (!worker.AbortPending) { worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.CRC32, originalType, HashFlags.FileHash); } }); worker.QueueTask((SimpleDelegate) delegate { if (!worker.AbortPending) { worker.AddHashes(rom, 0, rom.Length, () => worker.AbortPending, HashFlags.MD5, originalType, HashFlags.FileHash); } }); // We can not byte-swap the ROM while it is being hashed worker.WaitAll(); worker.QueueTask((SimpleDelegate) delegate { if (!worker.AbortPending) { worker.AddHashes(swappedRom, 0, swappedRom.Length, () => worker.AbortPending, HashFlags.SHA256, swappedType); } }); worker.QueueTask((SimpleDelegate) delegate { if (!worker.AbortPending) { worker.AddHashes(swappedRom, 0, swappedRom.Length, () => worker.AbortPending, HashFlags.SHA1, swappedType); } }); worker.QueueTask((SimpleDelegate) delegate { if (!worker.AbortPending) { worker.AddHashes(swappedRom, 0, swappedRom.Length, () => worker.AbortPending, HashFlags.CRC32, swappedType); } }); worker.QueueTask((SimpleDelegate) delegate { if (!worker.AbortPending) { worker.AddHashes(swappedRom, 0, swappedRom.Length, () => worker.AbortPending, HashFlags.MD5, swappedType); } }); // We can not return until all hashes are calculated worker.WaitAll(); }