private bool LoadDisc(string path, CoreComm nextComm, HawkFile file, string ext, string forcedCoreName, out IEmulator nextEmulator, out GameInfo game) { var disc = DiscExtensions.CreateAnyType(path, str => DoLoadErrorCallback(str, "???", LoadErrorType.DiscError)); if (disc == null) { game = null; nextEmulator = null; return(false); } game = MakeGameFromDisc(disc, ext, Path.GetFileNameWithoutExtension(file.Name)); var cip = new CoreInventoryParameters(this) { Comm = nextComm, Game = game, Discs = { new DiscAsset { DiscData = disc, DiscType = new DiscIdentifier(disc).DetectDiscType(), DiscName = Path.GetFileNameWithoutExtension(path) } }, }; nextEmulator = MakeCoreFromCoreInventory(cip, forcedCoreName); return(true); }
private IEmulator MakeCoreFromCoreInventory(CoreInventoryParameters cip, string forcedCoreName = null) { IReadOnlyCollection <CoreInventory.Core> cores; if (forcedCoreName != null) { var singleCore = CoreInventory.Instance.GetCores(cip.Game.System).SingleOrDefault(c => c.Name == forcedCoreName); cores = singleCore != null ? new[] { singleCore } : Array.Empty <CoreInventory.Core>(); } else { _config.PreferredCores.TryGetValue(cip.Game.System, out var preferredCore); var dbForcedCoreName = cip.Game.ForcedCore; cores = CoreInventory.Instance.GetCores(cip.Game.System) .OrderBy(c => { if (c.Name == preferredCore) { return((int)CorePriority.UserPreference); } if (string.Equals(c.Name, dbForcedCoreName, StringComparison.InvariantCultureIgnoreCase)) { return((int)CorePriority.GameDbPreference); } return((int)c.Priority); }) .ToList(); if (cores.Count == 0) { throw new InvalidOperationException("No core was found to try on the game"); } } var exceptions = new List <Exception>(); foreach (var core in cores) { try { return(core.Create(cip)); } catch (Exception e) { if (e is MissingFirmwareException || e.InnerException is MissingFirmwareException) { throw; } exceptions.Add(e); } } throw new AggregateException("No core could load the game", exceptions); }
private void LoadM3U(string path, CoreComm nextComm, HawkFile file, string forcedCoreName, out IEmulator nextEmulator, out GameInfo game) { M3U_File m3u; using (var sr = new StreamReader(path)) m3u = M3U_File.Read(sr); if (m3u.Entries.Count == 0) { throw new InvalidOperationException("Can't load an empty M3U"); } m3u.Rebase(Path.GetDirectoryName(path)); var discs = m3u.Entries .Select(e => e.Path) .Where(p => Disc.IsValidExtension(Path.GetExtension(p))) .Select(path => new { d = DiscExtensions.CreateAnyType(path, str => DoLoadErrorCallback(str, "???", LoadErrorType.DiscError)), p = path, }) .Where(a => a.d != null) .Select(a => (IDiscAsset) new DiscAsset { DiscData = a.d, DiscType = new DiscIdentifier(a.d).DetectDiscType(), DiscName = Path.GetFileNameWithoutExtension(a.p) }) .ToList(); if (m3u.Entries.Count == 0) { throw new InvalidOperationException("Couldn't load any contents of the M3U as discs"); } game = MakeGameFromDisc(discs[0].DiscData, Path.GetExtension(m3u.Entries[0].Path), discs[0].DiscName); var cip = new CoreInventoryParameters(this) { Comm = nextComm, Game = game, Discs = discs }; nextEmulator = MakeCoreFromCoreInventory(cip, forcedCoreName); }
private IEmulator MakeCoreFromCoreInventory(CoreInventoryParameters cip) { _config.PreferredCores.TryGetValue(cip.Game.System, out var preferredCore); var forcedCore = cip.Game.ForcedCore; var cores = CoreInventory.Instance.GetCores(cip.Game.System) .OrderBy(c => { if (c.Name == preferredCore) { return((int)CorePriority.UserPreference); } if (string.Equals(c.Name, forcedCore, StringComparison.InvariantCultureIgnoreCase)) { return((int)CorePriority.GameDbPreference); } return((int)c.Priority); }) .ToList(); if (cores.Count == 0) { throw new InvalidOperationException("No core was found to try on the game"); } var exceptions = new List <Exception>(); foreach (var core in cores) { try { return(core.Create(cip)); } catch (Exception e) { if (e is MissingFirmwareException || e.InnerException is MissingFirmwareException) { throw; } exceptions.Add(e); } } throw new AggregateException("No core could load the game", exceptions); }
private void LoadOther(CoreComm nextComm, HawkFile file, string forcedCoreName, out IEmulator nextEmulator, out RomGame rom, out GameInfo game, out bool cancel) { cancel = false; rom = new RomGame(file); // hacky for now if (file.Extension == ".exe") { rom.GameInfo.System = "PSX"; } else if (file.Extension == ".nsf") { rom.GameInfo.System = "NES"; } Debug.WriteLine(rom.GameInfo.System); if (string.IsNullOrEmpty(rom.GameInfo.System)) { // Has the user picked a preference for this extension? if (PreferredPlatformIsDefined(rom.Extension.ToLowerInvariant())) { rom.GameInfo.System = _config.PreferredPlatformsForExtensions[rom.Extension.ToLowerInvariant()]; } else if (ChoosePlatform != null) { var result = ChoosePlatform(rom); if (!string.IsNullOrEmpty(result)) { rom.GameInfo.System = result; } else { cancel = true; } } } game = rom.GameInfo; nextEmulator = null; if (game.System == null) { return; // The user picked nothing in the Core picker } switch (game.System) { case "GB": case "GBC": if (_config.GbAsSgb) { game.System = "SGB"; } break; case "Arcade": nextEmulator = new MAME( file.Directory, file.CanonicalName, GetCoreSyncSettings <MAME, MAME.SyncSettings>(), out var gameName ); rom.GameInfo.Name = gameName; return; } var cip = new CoreInventoryParameters(this) { Comm = nextComm, Game = game, Roms = { new RomAsset { RomData = rom.RomData, FileData = rom.FileData, Extension = rom.Extension, Game = game } }, }; nextEmulator = MakeCoreFromCoreInventory(cip, forcedCoreName); }
private bool LoadDisc(string path, CoreComm nextComm, HawkFile file, string ext, out IEmulator nextEmulator, out GameInfo game) { var disc = DiscExtensions.CreateAnyType(path, str => DoLoadErrorCallback(str, "???", LoadErrorType.DiscError)); if (disc == null) { game = null; nextEmulator = null; return(false); } // TODO - use more sophisticated IDer var discType = new DiscIdentifier(disc).DetectDiscType(); var discHasher = new DiscHasher(disc); var discHash = discType == DiscType.SonyPSX ? discHasher.Calculate_PSX_BizIDHash().ToString("X8") : discHasher.OldHash(); game = Database.CheckDatabase(discHash); if (game == null) { // try to use our wizard methods game = new GameInfo { Name = Path.GetFileNameWithoutExtension(file.Name), Hash = discHash }; switch (discType) { case DiscType.SegaSaturn: game.System = "SAT"; break; case DiscType.SonyPSP: game.System = "PSP"; break; case DiscType.MegaCD: game.System = "GEN"; break; case DiscType.PCFX: game.System = "PCFX"; break; case DiscType.TurboGECD: case DiscType.TurboCD: game.System = "PCECD"; break; case DiscType.Amiga: case DiscType.CDi: case DiscType.Dreamcast: case DiscType.GameCube: case DiscType.NeoGeoCD: case DiscType.Panasonic3DO: case DiscType.Playdia: case DiscType.Wii: // no supported emulator core for these (yet) game.System = discType.ToString(); throw new NoAvailableCoreException(discType.ToString()); case DiscType.AudioDisc: case DiscType.UnknownCDFS: case DiscType.UnknownFormat: game.System = PreferredPlatformIsDefined(ext) ? _config.PreferredPlatformsForExtensions[ext] : "NULL"; break; default: //"for an unknown disc, default to psx instead of pce-cd, since that is far more likely to be what they are attempting to open" [5e07ab3ec3b8b8de9eae71b489b55d23a3909f55, year 2015] case DiscType.SonyPSX: game.System = "PSX"; break; } } var cip = new CoreInventoryParameters(this) { Comm = nextComm, Game = game, Discs = { new DiscAsset { DiscData = disc, DiscType = new DiscIdentifier(disc).DetectDiscType(), DiscName = Path.GetFileNameWithoutExtension(path) } }, }; nextEmulator = MakeCoreFromCoreInventory(cip); return(true); }