move a bit more logic from RomLoader to Disc
This commit is contained in:
parent
32aa623eff
commit
c830452775
|
@ -202,7 +202,7 @@ namespace BizHawk.Client.Common
|
||||||
private List<Disc> DiscsFromXml(XmlGame xmlGame, string systemId, DiscType diskType)
|
private List<Disc> DiscsFromXml(XmlGame xmlGame, string systemId, DiscType diskType)
|
||||||
{
|
{
|
||||||
var discs = new List<Disc>();
|
var discs = new List<Disc>();
|
||||||
foreach (var e in xmlGame.AssetFullPaths.Where(a => IsDisc(Path.GetExtension(a))))
|
foreach (var e in xmlGame.AssetFullPaths.Where(a => Disc.IsValidExtension(Path.GetExtension(a))))
|
||||||
{
|
{
|
||||||
var disc = diskType.Create(e, str => { DoLoadErrorCallback(str, systemId, LoadErrorType.DiscError); });
|
var disc = diskType.Create(e, str => { DoLoadErrorCallback(str, systemId, LoadErrorType.DiscError); });
|
||||||
if (disc != null)
|
if (disc != null)
|
||||||
|
@ -417,7 +417,7 @@ namespace BizHawk.Client.Common
|
||||||
System = "PSX"
|
System = "PSX"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (IsDisc(ext))
|
else if (Disc.IsValidExtension(ext))
|
||||||
{
|
{
|
||||||
if (file.IsArchive)
|
if (file.IsArchive)
|
||||||
{
|
{
|
||||||
|
@ -768,7 +768,8 @@ namespace BizHawk.Client.Common
|
||||||
break;
|
break;
|
||||||
case "GEN":
|
case "GEN":
|
||||||
var genDiscs = DiscsFromXml(xmlGame, "GEN", DiscType.MegaCD);
|
var genDiscs = DiscsFromXml(xmlGame, "GEN", DiscType.MegaCD);
|
||||||
var romBytes = xmlGame.Assets.Where(a => !IsDisc(a.Key))
|
var romBytes = xmlGame.Assets
|
||||||
|
.Where(a => !Disc.IsValidExtension(a.Key))
|
||||||
.Select(a => a.Value)
|
.Select(a => a.Value)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
if (!genDiscs.Any() && romBytes == null)
|
if (!genDiscs.Any() && romBytes == null)
|
||||||
|
@ -1107,11 +1108,5 @@ namespace BizHawk.Client.Common
|
||||||
Game = game;
|
Game = game;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsDisc(string extension) =>
|
|
||||||
extension == ".iso"
|
|
||||||
|| extension == ".cue"
|
|
||||||
|| extension == ".ccd"
|
|
||||||
|| extension == ".mds";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,5 +129,10 @@ namespace BizHawk.Emulation.DiscSystem
|
||||||
internal Disc()
|
internal Disc()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
public static bool IsValidExtension(string extension) =>
|
||||||
|
extension == ".iso"
|
||||||
|
|| extension == ".cue"
|
||||||
|
|| extension == ".ccd"
|
||||||
|
|| extension == ".mds";
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,15 +4,15 @@ namespace BizHawk.Emulation.DiscSystem
|
||||||
{
|
{
|
||||||
public static class DiscExtensions
|
public static class DiscExtensions
|
||||||
{
|
{
|
||||||
public static Disc Create(this DiscType diskType, string discPath, Action<string> errorCallback)
|
public static Disc Create(this DiscType type, string path, Action<string> errorCallback)
|
||||||
{
|
{
|
||||||
//--- load the disc in a context which will let us abort if it's going to take too long
|
//--- load the disc in a context which will let us abort if it's going to take too long
|
||||||
var discMountJob = new DiscMountJob { IN_FromPath = discPath, IN_SlowLoadAbortThreshold = 8 };
|
var discMountJob = new DiscMountJob { IN_FromPath = path, IN_SlowLoadAbortThreshold = 8 };
|
||||||
discMountJob.Run();
|
discMountJob.Run();
|
||||||
var disc = discMountJob.OUT_Disc;
|
var disc = discMountJob.OUT_Disc;
|
||||||
if (disc == null)
|
if (disc == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"Can't find the file specified: {discPath}");
|
throw new InvalidOperationException($"Can't find the file specified: {path}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (discMountJob.OUT_SlowLoadAborted)
|
if (discMountJob.OUT_SlowLoadAborted)
|
||||||
|
@ -28,9 +28,9 @@ namespace BizHawk.Emulation.DiscSystem
|
||||||
|
|
||||||
var discType = new DiscIdentifier(disc).DetectDiscType();
|
var discType = new DiscIdentifier(disc).DetectDiscType();
|
||||||
|
|
||||||
if (discType != diskType)
|
if (discType != type)
|
||||||
{
|
{
|
||||||
errorCallback($"Not a {diskType} disc");
|
errorCallback($"Not a {type} disc");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue