public static IList <GameProgramInfo> GetGameProgramInfos(string romPath) { var bytes = DatastoreService.GetRomBytes(romPath); var md5key = RomBytesService.ToMD5Key(bytes); var romPropertiesCsv = AssetService.GetAssetByLines(Asset.ROMProperties); return(RomPropertiesService.ToGameProgramInfo(romPropertiesCsv) .Where(gpi => gpi.MD5 == md5key) .ToList()); }
static void Import(IEnumerable <string> paths) { DirectoryScanCompleted = false; CancelRequested = false; FilesExamined = 0; FilesRecognized = 0; var romPropertiesCsv = AssetService.GetAssetByLines(Asset.ROMProperties); var gameProgramInfoSet = RomPropertiesService.ToGameProgramInfo(romPropertiesCsv); var gameProgramInfoMd5Dict = gameProgramInfoSet.GroupBy(r => r.MD5).ToDictionary(g => g.Key, g => g.ToList()); var importedGameProgramInfoMd5Dict = new Dictionary <string, ImportedGameProgramInfo>(); var importedSpecialBinaryInfoSet = new List <ImportedSpecialBinaryInfo>(); DirectoryScanCompleted = true; foreach (var path in paths) { if (CancelRequested) { break; } FilesExamined++; var bytes = DatastoreService.GetRomBytes(path); if (bytes.Length == 0) { continue; } var md5key = RomBytesService.ToMD5Key(bytes); if (!gameProgramInfoMd5Dict.TryGetValue(md5key, out var gpiList)) { var specialBinaryType = RomBytesService.ToSpecialBinaryType(md5key); if (specialBinaryType != SpecialBinaryType.None) { var sbi = new ImportedSpecialBinaryInfo { Type = specialBinaryType, StorageKey = path }; importedSpecialBinaryInfoSet.Add(sbi); } continue; } FilesRecognized++; foreach (var gpi in gpiList) { if (!importedGameProgramInfoMd5Dict.TryGetValue(md5key, out var igpi)) { igpi = new(gpi); igpi.PersistedStateAt = DatastoreService.PersistedMachineAt(gpi); importedGameProgramInfoMd5Dict.Add(md5key, igpi); } igpi.StorageKeySet.Add(path); } } if (CancelRequested) { return; } DatastoreService.ImportedGameProgramInfo = importedGameProgramInfoMd5Dict.Values .Where(igpi => igpi.StorageKeySet.Count > 0) .OrderBy(igpi => igpi.GameProgramInfo.Title); DatastoreService.ImportedSpecialBinaryInfo = importedSpecialBinaryInfoSet; }