Emulation.DiscSystem - cleanup - use extension method, using declarations
This commit is contained in:
parent
3f9b93be59
commit
4cf29c5169
|
@ -19,10 +19,8 @@ namespace BizHawk.Emulation.DiscSystem
|
|||
|
||||
public void WriteFile(string fname)
|
||||
{
|
||||
using (FileStream fs = new FileStream(fname, FileMode.Create, FileAccess.Write, FileShare.Read))
|
||||
{
|
||||
WriteStream(fs);
|
||||
}
|
||||
using FileStream fs = new FileStream(fname, FileMode.Create, FileAccess.Write, FileShare.Read);
|
||||
WriteStream(fs);
|
||||
}
|
||||
|
||||
public Stream BaseStream;
|
||||
|
|
|
@ -421,21 +421,17 @@ namespace BizHawk.Emulation.DiscSystem
|
|||
string imgPath = Path.ChangeExtension(path, ".img");
|
||||
string subPath = Path.ChangeExtension(path, ".sub");
|
||||
var buf2448 = new byte[2448];
|
||||
DiscSectorReader dsr = new DiscSectorReader(disc);
|
||||
|
||||
using (var imgFile = File.OpenWrite(imgPath))
|
||||
using (var subFile = File.OpenWrite(subPath))
|
||||
{
|
||||
|
||||
int nLBA = disc.Session1.LeadoutLBA;
|
||||
for (int lba = 0; lba < nLBA; lba++)
|
||||
{
|
||||
dsr.ReadLBA_2448(lba, buf2448, 0);
|
||||
imgFile.Write(buf2448, 0, 2352);
|
||||
subFile.Write(buf2448, 2352, 96);
|
||||
}
|
||||
}
|
||||
DiscSectorReader dsr = new DiscSectorReader(disc);
|
||||
|
||||
using var imgFile = File.OpenWrite(imgPath);
|
||||
using var subFile = File.OpenWrite(subPath);
|
||||
int nLBA = disc.Session1.LeadoutLBA;
|
||||
for (int lba = 0; lba < nLBA; lba++)
|
||||
{
|
||||
dsr.ReadLBA_2448(lba, buf2448, 0);
|
||||
imgFile.Write(buf2448, 0, 2352);
|
||||
subFile.Write(buf2448, 2352, 96);
|
||||
}
|
||||
}
|
||||
|
||||
class SS_CCD : ISectorSynthJob2448
|
||||
|
|
|
@ -251,17 +251,15 @@ namespace BizHawk.Emulation.DiscSystem.CUE
|
|||
//TODO - fix exception-throwing inside
|
||||
//TODO - verify stream-disposing semantics
|
||||
var fs = File.OpenRead(choice);
|
||||
using (var blob = new Disc.Blob_WaveFile())
|
||||
using var blob = new Disc.Blob_WaveFile();
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
blob.Load(fs);
|
||||
cfi.Type = CompiledCueFileType.WAVE;
|
||||
}
|
||||
catch
|
||||
{
|
||||
cfi.Type = CompiledCueFileType.DecodeAudio;
|
||||
}
|
||||
blob.Load(fs);
|
||||
cfi.Type = CompiledCueFileType.WAVE;
|
||||
}
|
||||
catch
|
||||
{
|
||||
cfi.Type = CompiledCueFileType.DecodeAudio;
|
||||
}
|
||||
}
|
||||
else if (blobPathExt == ".APE") cfi.Type = CompiledCueFileType.DecodeAudio;
|
||||
|
|
|
@ -357,10 +357,10 @@ namespace BizHawk.Emulation.DiscSystem
|
|||
{
|
||||
var data = ReadSectorCached(lba);
|
||||
if (data == null) return false;
|
||||
byte[] cmp = System.Text.Encoding.ASCII.GetBytes(s);
|
||||
byte[] cmp = Encoding.ASCII.GetBytes(s);
|
||||
byte[] cmp2 = new byte[cmp.Length];
|
||||
Buffer.BlockCopy(data, n, cmp2, 0, cmp.Length);
|
||||
return System.Linq.Enumerable.SequenceEqual(cmp, cmp2);
|
||||
return cmp.SequenceEqual(cmp2);
|
||||
}
|
||||
|
||||
private bool SectorContains(string s, int lba = 0)
|
||||
|
|
|
@ -23,58 +23,56 @@ namespace BizHawk.Emulation.DiscSystem.SBI
|
|||
/// <exception cref="SBIParseException">file at <see cref="IN_Path"/> does not contain valid header or contains misformatted record</exception>
|
||||
public void Run()
|
||||
{
|
||||
using (var fs = File.OpenRead(IN_Path))
|
||||
using var fs = File.OpenRead(IN_Path);
|
||||
BinaryReader br = new BinaryReader(fs);
|
||||
string sig = br.ReadStringFixedAscii(4);
|
||||
if (sig != "SBI\0")
|
||||
throw new SBIParseException("Missing magic number");
|
||||
|
||||
SubQPatchData ret = new SubQPatchData();
|
||||
List<short> bytes = new List<short>();
|
||||
|
||||
//read records until done
|
||||
for (; ; )
|
||||
{
|
||||
BinaryReader br = new BinaryReader(fs);
|
||||
string sig = br.ReadStringFixedAscii(4);
|
||||
if (sig != "SBI\0")
|
||||
throw new SBIParseException("Missing magic number");
|
||||
//graceful end
|
||||
if (fs.Position == fs.Length)
|
||||
break;
|
||||
|
||||
SubQPatchData ret = new SubQPatchData();
|
||||
List<short> bytes = new List<short>();
|
||||
|
||||
//read records until done
|
||||
for (; ; )
|
||||
if (fs.Position + 4 > fs.Length) throw new SBIParseException("Broken record");
|
||||
var m = BCD2.BCDToInt(br.ReadByte());
|
||||
var s = BCD2.BCDToInt(br.ReadByte());
|
||||
var f = BCD2.BCDToInt(br.ReadByte());
|
||||
var ts = new Timestamp(m, s, f);
|
||||
ret.ABAs.Add(ts.Sector);
|
||||
int type = br.ReadByte();
|
||||
switch (type)
|
||||
{
|
||||
//graceful end
|
||||
if (fs.Position == fs.Length)
|
||||
case 1: //Q0..Q9
|
||||
if (fs.Position + 10 > fs.Length) throw new SBIParseException("Broken record");
|
||||
for (int i = 0; i <= 9; i++) bytes.Add(br.ReadByte());
|
||||
for (int i = 10; i <= 11; i++) bytes.Add(-1);
|
||||
break;
|
||||
|
||||
if (fs.Position + 4 > fs.Length) throw new SBIParseException("Broken record");
|
||||
var m = BCD2.BCDToInt(br.ReadByte());
|
||||
var s = BCD2.BCDToInt(br.ReadByte());
|
||||
var f = BCD2.BCDToInt(br.ReadByte());
|
||||
var ts = new Timestamp(m, s, f);
|
||||
ret.ABAs.Add(ts.Sector);
|
||||
int type = br.ReadByte();
|
||||
switch (type)
|
||||
{
|
||||
case 1: //Q0..Q9
|
||||
if (fs.Position + 10 > fs.Length) throw new SBIParseException("Broken record");
|
||||
for (int i = 0; i <= 9; i++) bytes.Add(br.ReadByte());
|
||||
for (int i = 10; i <= 11; i++) bytes.Add(-1);
|
||||
break;
|
||||
case 2: //Q3..Q5
|
||||
if (fs.Position + 3 > fs.Length) throw new SBIParseException("Broken record");
|
||||
for (int i = 0; i <= 2; i++) bytes.Add(-1);
|
||||
for (int i = 3; i <= 5; i++) bytes.Add(br.ReadByte());
|
||||
for (int i = 6; i <= 11; i++) bytes.Add(-1);
|
||||
break;
|
||||
case 3: //Q7..Q9
|
||||
if (fs.Position + 3 > fs.Length) throw new SBIParseException("Broken record");
|
||||
for (int i = 0; i <= 6; i++) bytes.Add(-1);
|
||||
for (int i = 7; i <= 9; i++) bytes.Add(br.ReadByte());
|
||||
for (int i = 10; i <= 11; i++) bytes.Add(-1);
|
||||
break;
|
||||
default:
|
||||
throw new SBIParseException("Broken record");
|
||||
}
|
||||
case 2: //Q3..Q5
|
||||
if (fs.Position + 3 > fs.Length) throw new SBIParseException("Broken record");
|
||||
for (int i = 0; i <= 2; i++) bytes.Add(-1);
|
||||
for (int i = 3; i <= 5; i++) bytes.Add(br.ReadByte());
|
||||
for (int i = 6; i <= 11; i++) bytes.Add(-1);
|
||||
break;
|
||||
case 3: //Q7..Q9
|
||||
if (fs.Position + 3 > fs.Length) throw new SBIParseException("Broken record");
|
||||
for (int i = 0; i <= 6; i++) bytes.Add(-1);
|
||||
for (int i = 7; i <= 9; i++) bytes.Add(br.ReadByte());
|
||||
for (int i = 10; i <= 11; i++) bytes.Add(-1);
|
||||
break;
|
||||
default:
|
||||
throw new SBIParseException("Broken record");
|
||||
}
|
||||
|
||||
ret.subq = bytes.ToArray();
|
||||
|
||||
OUT_Data = ret;
|
||||
}
|
||||
|
||||
ret.subq = bytes.ToArray();
|
||||
|
||||
OUT_Data = ret;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue