/// <summary> /// Determines if the source ROM's configuration file is already in the cache. /// </summary> /// <param name="rom">The ROM whose configuration file's presence in the cache is being tested.</param> /// <param name="romStagingAreaPath">The staging area directory for the ROM.</param> /// <param name="changed">If set to <c>true</c>, the config file changed.</param> /// <returns><c>true</c> if the configuration file is present and both CRC32 checksums match. If a ROM does not /// have a configuration file, then the function will also return <c>true</c>.</returns> public static bool IsConfigFileInCache(this IRom rom, string romStagingAreaPath, out bool changed) { changed = true; var configFilePath = rom.GetCachedConfigFilePath(romStagingAreaPath); bool configFilePathInCache = (configFilePath == null) || (!string.IsNullOrWhiteSpace(configFilePath) && System.IO.File.Exists(configFilePath)); if (configFilePathInCache) { if (configFilePath != null) { var sourceConfigCrc = rom.RefreshCfgCrc(out changed); var destConfigCrc = INTV.Core.Utility.Crc32.OfFile(configFilePath); configFilePathInCache = sourceConfigCrc == destConfigCrc; } else { // No .cfg file in cache. It's changed if there is one on the original ROM, otherwise, not. if (rom.Format == RomFormat.Luigi) { var cachedLuigiPath = rom.GetCachedRomFilePath(romStagingAreaPath); if (!string.IsNullOrEmpty(cachedLuigiPath) && System.IO.File.Exists(cachedLuigiPath)) { uint luigiCfgCrc; Rom.GetRefreshedCrcs(cachedLuigiPath, null, out luigiCfgCrc); changed = rom.CfgCrc != luigiCfgCrc; } } else { changed = rom.CfgCrc != 0; } } } return(configFilePathInCache); }
public void Rom_GetRefreshedCrcsFromNullBinPathAndValidCfgPath_ThrowsAgumentNullException() { var cfgPath = RomTestStorageAccess.Initialize(TestRomResources.TestCfgPath).First(); var cfgCrc = 0u; Assert.Throws <ArgumentNullException>(() => Rom.GetRefreshedCrcs(null, cfgPath, out cfgCrc)); }
public void Rom_GetRefreshedCrcsFromNullPaths_ThrowsAgumentNullException() { RomTestStorageAccess.Initialize(); var cfgCrc = 0u; Assert.Throws <ArgumentNullException>(() => Rom.GetRefreshedCrcs(null, null, out cfgCrc)); }
public void Rom_GetRefreshedCrcsFromBinPathAndNullCfgPath_GetsCorrectBinCrcAndZeroCfgCrc() { var romPath = RomTestStorageAccess.Initialize(TestRomResources.TestBinPath).First(); var cfgCrc = 0u; var crc = Rom.GetRefreshedCrcs(romPath, null, out cfgCrc); Assert.Equal(TestRomResources.TestBinCrc, crc); Assert.Equal(0u, cfgCrc); }
public void Rom_GetRefreshedCrcsFromValidBinAndCfgPaths_GetsCorrectBinAndCfgCrcs(string testRomPath, string testCfgPath, uint expectedRomCrc, uint expectedCfgCrc) { var paths = RomTestStorageAccess.Initialize(testRomPath, testCfgPath); var romPath = paths[0]; var cfgPath = testCfgPath == null ? null : paths[1]; var cfgCrc = 0u; var crc = Rom.GetRefreshedCrcs(romPath, cfgPath, out cfgCrc); Assert.Equal(expectedRomCrc, crc); Assert.Equal(expectedCfgCrc, cfgCrc); }
/// <summary> /// Determines if the source ROM is already in the cache. /// </summary> /// <param name="rom">The ROM whose presence in the cache is being tested.</param> /// <param name="romStagingAreaPath">The staging area directory for the ROM.</param> /// <param name="changed">Set to <c>true</c> if the ROM is different than what's in the cache.</param> /// <returns><c>true</c> if all necessary elements for the ROM are in the cache.</returns> /// <remarks>To be considered current in the cache, the source and cached files must have the same CRC32 checksum. If a ROM also /// has a configuration file, the CRC32 checksums of the configuration files must also match.</remarks> public static bool IsInCache(this IRom rom, string romStagingAreaPath, out bool changed) { #if REPORT_PERFORMANCE var stopwatch = System.Diagnostics.Stopwatch.StartNew(); var stopwatch2 = System.Diagnostics.Stopwatch.StartNew(); #endif // REPORT_PERFORMANCE changed = true; var cachedRomPath = rom.GetCachedRomFilePath(romStagingAreaPath); bool fileInCache = System.IO.File.Exists(cachedRomPath); #if REPORT_PERFORMANCE stopwatch2.Stop(); _accumulatedGetPathTime += stopwatch2.Elapsed; #endif // REPORT_PERFORMANCE if (fileInCache) { #if REPORT_PERFORMANCE stopwatch2.Restart(); #endif // REPORT_PERFORMANCE bool romChanged, cfgChanged = false; uint preexistingCfgCrc; uint preexistingCrc = Rom.GetRefreshedCrcs(cachedRomPath, rom.ConfigPath, out preexistingCfgCrc); #if REPORT_PERFORMANCE stopwatch2.Stop(); _accumulatedGetCrcsTime += stopwatch2.Elapsed; stopwatch2.Restart(); #endif // REPORT_PERFORMANCE fileInCache = (rom.RefreshCrc(out romChanged) == preexistingCrc) && rom.IsConfigFileInCache(romStagingAreaPath, out cfgChanged); // use CanonicalRomComparerStrict.Default here? if (fileInCache && !romChanged && !cfgChanged) { if (rom.Format == RomFormat.Luigi) { changed = !File.Exists(rom.RomPath) || (INTV.Core.Utility.Crc32.OfFile(rom.RomPath) != INTV.Core.Utility.Crc32.OfFile(cachedRomPath)); } else if (rom.Format == RomFormat.Bin) { // when the preexistingRom is created, it recomputes the .cfg file's CRC, so see if it's changed cfgChanged = rom.CfgCrc != preexistingCfgCrc; } } changed = romChanged || cfgChanged; #if REPORT_PERFORMANCE stopwatch2.Stop(); _accumulatedCacheRecheckTime += stopwatch2.Elapsed; #endif // REPORT_PERFORMANCE } #if REPORT_PERFORMANCE stopwatch.Stop(); _accumulatedCacheCheckTime += stopwatch.Elapsed; #endif // REPORT_PERFORMANCE return(fileInCache); }