Skip to content

Commit 6ea1171

Browse files
committed
RomLoader: graceful disc failures
1 parent 6a0fe16 commit 6ea1171

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

BizHawk.Client.Common/RomLoader.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,9 @@ public bool LoadRom(string path, CoreComm nextComm, bool forceAccurateCore = fal
514514
// try to use our wizard methods
515515
game = new GameInfo { Name = Path.GetFileNameWithoutExtension(file.Name), Hash = discHash };
516516

517-
switch (new DiscIdentifier(disc).DetectDiscType())
517+
var dt = new DiscIdentifier(disc).DetectDiscType();
518+
519+
switch (dt)
518520
{
519521
case DiscType.SegaSaturn:
520522
game.System = "SAT";
@@ -532,9 +534,23 @@ public bool LoadRom(string path, CoreComm nextComm, bool forceAccurateCore = fal
532534
case DiscType.PCFX:
533535
game.System = "PCFX";
534536
break;
537+
case DiscType.TurboCD:
538+
game.System = "PCECD";
539+
break;
540+
541+
case DiscType.Amiga:
542+
case DiscType.CDi:
543+
case DiscType.Dreamcast:
544+
case DiscType.GameCube:
545+
case DiscType.NeoGeoCD:
546+
case DiscType.Panasonic3DO:
547+
case DiscType.Playdia:
548+
case DiscType.Wii:
549+
// no supported emulator core for these (yet)
550+
game.System = dt.ToString();
551+
throw new NoAvailableCoreException(dt.ToString());
535552

536553
case DiscType.AudioDisc:
537-
case DiscType.TurboCD:
538554
case DiscType.UnknownCDFS:
539555
case DiscType.UnknownFormat:
540556
if (PreferredPlatformIsDefined(ext))
@@ -543,7 +559,7 @@ public bool LoadRom(string path, CoreComm nextComm, bool forceAccurateCore = fal
543559
}
544560
else
545561
{
546-
game.System = "PCECD";
562+
game.System = "NULL"; // "PCECD";
547563
}
548564

549565
break;
@@ -552,6 +568,9 @@ public bool LoadRom(string path, CoreComm nextComm, bool forceAccurateCore = fal
552568

553569
switch (game.System)
554570
{
571+
case "NULL":
572+
nextEmulator = null;
573+
break;
555574
case "GEN":
556575
var genesis = new GPGX(nextComm, null, new[] { disc }, GetCoreSettings<GPGX>(), GetCoreSyncSettings<GPGX>());
557576
nextEmulator = genesis;
@@ -1029,7 +1048,14 @@ public bool LoadRom(string path, CoreComm nextComm, bool forceAccurateCore = fal
10291048
DoMessageCallback("Failed to load a GB rom in SGB mode. Disabling SGB Mode.");
10301049
return LoadRom(path, nextComm, false, recursiveCount + 1);
10311050
}
1032-
else
1051+
1052+
// handle exceptions thrown by the new detected systems that bizhawk does not have cores for
1053+
else if (ex is NoAvailableCoreException)
1054+
{
1055+
DoLoadErrorCallback(ex.Message + "\n\n" + ex, system);
1056+
}
1057+
1058+
else
10331059
{
10341060
DoLoadErrorCallback("A core accepted the rom, but threw an exception while loading it:\n\n" + ex, system);
10351061
}

BizHawk.Emulation.Common/EmulationExceptions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ public UnsupportedGameException(string message)
2020
}
2121
}
2222

23+
public class NoAvailableCoreException : Exception
24+
{
25+
public NoAvailableCoreException()
26+
: base("System is currently NOT emulated")
27+
{
28+
}
29+
30+
public NoAvailableCoreException(string message)
31+
: base ("System is currently NOT emulated: " + message)
32+
{
33+
34+
}
35+
}
36+
2337
public class CGBNotSupportedException : Exception
2438
{
2539
public CGBNotSupportedException()

0 commit comments

Comments
 (0)