misc cleanups in DiscoHawk

This commit is contained in:
adelikat 2020-01-25 13:43:59 -06:00
parent 45e0abe39d
commit ecd6e7c199
6 changed files with 142 additions and 142 deletions

View File

@ -1,10 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
namespace BizHawk.Client.DiscoHawk namespace BizHawk.Client.DiscoHawk

View File

@ -1,20 +1,14 @@
using System; using System.Windows.Forms;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using BizHawk.Emulation.DiscSystem; using BizHawk.Emulation.DiscSystem;
namespace BizHawk.Client.DiscoHawk namespace BizHawk.Client.DiscoHawk
{ {
class AudioExtractor public class AudioExtractor
{ {
public static string FFmpegPath; public static string FFmpegPath;
public static void Extract(Disc disc, string path, string filebase) public static void Extract(Disc disc, string path, string fileBase)
{ {
var dsr = new DiscSectorReader(disc); var dsr = new DiscSectorReader(disc);
@ -29,9 +23,11 @@ namespace BizHawk.Client.DiscoHawk
var waveData = new byte[trackLength * 2352]; var waveData = new byte[trackLength * 2352];
int startLba = track.LBA; int startLba = track.LBA;
for (int sector = 0; sector < trackLength; sector++) for (int sector = 0; sector < trackLength; sector++)
{
dsr.ReadLBA_2352(startLba + sector, waveData, sector * 2352); dsr.ReadLBA_2352(startLba + sector, waveData, sector * 2352);
}
string mp3Path = $"{Path.Combine(path, filebase)} - Track {track.Number:D2}.mp3"; string mp3Path = $"{Path.Combine(path, fileBase)} - Track {track.Number:D2}.mp3";
if (File.Exists(mp3Path)) if (File.Exists(mp3Path))
{ {
if (!confirmed) if (!confirmed)
@ -40,6 +36,7 @@ namespace BizHawk.Client.DiscoHawk
if (dr == DialogResult.Cancel) return; if (dr == DialogResult.Cancel) return;
confirmed = true; confirmed = true;
} }
File.Delete(mp3Path); File.Delete(mp3Path);
} }

View File

@ -1,11 +1,4 @@
using System; using System.Windows.Forms;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace BizHawk.Client.DiscoHawk namespace BizHawk.Client.DiscoHawk
{ {

View File

@ -1,6 +1,4 @@
using System; using System;
using System.Linq;
using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Reflection; using System.Reflection;
using System.Collections.Generic; using System.Collections.Generic;
@ -12,10 +10,10 @@ using BizHawk.Emulation.DiscSystem;
// cue format preferences notes // cue format preferences notes
//pcejin - // PCEjin -
// does not like session commands // does not like session commands
// it can handle binpercue // it can handle binpercue
//it seems not to be able to handle binpertrack, or maybe i am doing something wrong (still havent ruled it out) // it seems not to be able to handle binpertrack, or maybe i am doing something wrong (still haven't ruled it out)
namespace BizHawk.Client.DiscoHawk namespace BizHawk.Client.DiscoHawk
{ {
@ -26,15 +24,15 @@ namespace BizHawk.Client.DiscoHawk
#if WINDOWS #if WINDOWS
// http://www.codeproject.com/Articles/310675/AppDomain-AssemblyResolve-Event-Tips // http://www.codeproject.com/Articles/310675/AppDomain-AssemblyResolve-Event-Tips
// this will look in subdirectory "dll" to load pinvoked stuff // this will look in subdirectory "dll" to load pinvoked stuff
string dllDir = System.IO.Path.Combine(GetExeDirectoryAbsolute(), "dll"); string dllDir = Path.Combine(GetExeDirectoryAbsolute(), "dll");
SetDllDirectory(dllDir); SetDllDirectory(dllDir);
//in case assembly resolution fails, such as if we moved them into the dll subdiretory, this event handler can reroute to them //in case assembly resolution fails, such as if we moved them into the dll subdirectory, this event handler can reroute to them
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
//but before we even try doing that, whack the MOTW from everything in that directory (thats a dll) // but before we even try doing that, whack the MOTW from everything in that directory (that's a dll)
// otherwise, some people will have crashes at boot-up due to .net security disliking MOTW. // otherwise, some people will have crashes at boot-up due to .net security disliking MOTW.
//some people are getting MOTW through a combination of browser used to download bizhawk, and program used to dearchive it // some people are getting MOTW through a combination of browser used to download BizHawk, and program used to dearchive it
WhackAllMOTW(dllDir); WhackAllMOTW(dllDir);
#endif #endif
} }
@ -45,9 +43,10 @@ namespace BizHawk.Client.DiscoHawk
SubMain(args); SubMain(args);
} }
//NoInlining should keep this code from getting jammed into Main() which would create dependencies on types which havent been setup by the resolver yet... or something like that // NoInlining should keep this code from getting jammed into Main() which would create dependencies on types which haven't been setup by the resolver yet... or something like that
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true)]
public static extern bool ChangeWindowMessageFilterEx(IntPtr hWnd, uint msg, ChangeWindowMessageFilterExAction action, ref CHANGEFILTERSTRUCT changeInfo); public static extern bool ChangeWindowMessageFilterEx(IntPtr hWnd, uint msg, ChangeWindowMessageFilterExAction action, ref CHANGEFILTERSTRUCT changeInfo);
private static class Win32 private static class Win32
{ {
[DllImport("kernel32.dll")] [DllImport("kernel32.dll")]
@ -60,10 +59,10 @@ namespace BizHawk.Client.DiscoHawk
static void SubMain(string[] args) static void SubMain(string[] args)
{ {
//MICROSOFT BROKE DRAG AND DROP IN WINDOWS 7. IT DOESNT WORK ANYMORE // MICROSOFT BROKE DRAG AND DROP IN WINDOWS 7. IT DOESN'T WORK ANYMORE
//WELL, OBVIOUSLY IT DOES SOMETIMES. I DONT REMEMBER THE DETAILS OR WHY WE HAD TO DO THIS SHIT // WELL, OBVIOUSLY IT DOES SOMETIMES. I DON'T REMEMBER THE DETAILS OR WHY WE HAD TO DO THIS SHIT
#if WINDOWS #if WINDOWS
//BUT THE FUNCTION WE NEED DOESNT EXIST UNTIL WINDOWS 7, CONVENIENTLY // BUT THE FUNCTION WE NEED DOESN'T EXIST UNTIL WINDOWS 7, CONVENIENTLY
// SO CHECK FOR IT // SO CHECK FOR IT
IntPtr lib = Win32.LoadLibrary("user32.dll"); IntPtr lib = Win32.LoadLibrary("user32.dll");
IntPtr proc = Win32.GetProcAddress(lib, "ChangeWindowMessageFilterEx"); IntPtr proc = Win32.GetProcAddress(lib, "ChangeWindowMessageFilterEx");
@ -102,11 +101,12 @@ namespace BizHawk.Client.DiscoHawk
return asm; return asm;
//load missing assemblies by trying to find them in the dll directory //load missing assemblies by trying to find them in the dll directory
string dllname = $"{new AssemblyName(args.Name).Name}.dll"; string dllName = $"{new AssemblyName(args.Name).Name}.dll";
string directory = Path.Combine(GetExeDirectoryAbsolute(), "dll"); string directory = Path.Combine(GetExeDirectoryAbsolute(), "dll");
string fname = Path.Combine(directory, dllname); string fname = Path.Combine(directory, dllName);
if (!File.Exists(fname)) return null; if (!File.Exists(fname)) return null;
//it is important that we use LoadFile here and not load from a byte array; otherwise mixed (managed/unamanged) assemblies can't load
// it is important that we use LoadFile here and not load from a byte array; otherwise mixed (managed/unmanaged) assemblies can't load
return Assembly.LoadFile(fname); return Assembly.LoadFile(fname);
} }
} }
@ -129,7 +129,7 @@ namespace BizHawk.Client.DiscoHawk
while (todo.Count > 0) while (todo.Count > 0)
{ {
var di = todo.Dequeue(); var di = todo.Dequeue();
foreach (var disub in di.GetDirectories()) todo.Enqueue(disub); foreach (var diSub in di.GetDirectories()) todo.Enqueue(diSub);
foreach (var fi in di.GetFiles("*.dll")) foreach (var fi in di.GetFiles("*.dll"))
RemoveMOTW(fi.FullName); RemoveMOTW(fi.FullName);
foreach (var fi in di.GetFiles("*.exe")) foreach (var fi in di.GetFiles("*.exe"))
@ -230,12 +230,13 @@ namespace BizHawk.Client.DiscoHawk
if (hawk) if (hawk)
{ {
if (infile == null) if (infile == null)
{
return; return;
}
// TODO - write it out // TODO - write it out
var dmj = new DiscMountJob { IN_DiscInterface = loadDiscInterface, IN_FromPath = infile }; var dmj = new DiscMountJob { IN_DiscInterface = loadDiscInterface, IN_FromPath = infile };
dmj.Run(); dmj.Run();
//var disc = dmj.OUT_Disc;
} }
bool verbose = true; bool verbose = true;
@ -248,7 +249,6 @@ namespace BizHawk.Client.DiscoHawk
var cts = new CancellationTokenSource(); var cts = new CancellationTokenSource();
po.CancellationToken = cts.Token; po.CancellationToken = cts.Token;
po.MaxDegreeOfParallelism = 1; po.MaxDegreeOfParallelism = 1;
//po.MaxDegreeOfParallelism = System.Environment.ProcessorCount - 2; //I'm disk or network bound, no sense hammering this
if(po.MaxDegreeOfParallelism < 0) po.MaxDegreeOfParallelism = 1; if(po.MaxDegreeOfParallelism < 0) po.MaxDegreeOfParallelism = 1;
object olock = new object(); object olock = new object();
int ctr=0; int ctr=0;
@ -263,14 +263,12 @@ namespace BizHawk.Client.DiscoHawk
int strlen = todo.Count.ToString().Length; int strlen = todo.Count.ToString().Length;
string fmt = string.Format("{{0,{0}}}/{{1,{0}}} {{2}}", strlen); string fmt = string.Format("{{0,{0}}}/{{1,{0}}} {{2}}", strlen);
Console.WriteLine(fmt, ctr, todo.Count, Path.GetFileNameWithoutExtension(fp)); Console.WriteLine(fmt, ctr, todo.Count, Path.GetFileNameWithoutExtension(fp));
//if (fp.Contains("Break Out"))
// blocked = false;
} }
if(!blocked) if(!blocked)
foreach (var cmpif in compareDiscInterfaces) foreach (var cmpif in compareDiscInterfaces)
{ {
StringWriter sw = new StringWriter(); var sw = new StringWriter();
bool success = CompareFile(fp, loadDiscInterface, cmpif, verbose, cts, sw); bool success = CompareFile(fp, loadDiscInterface, cmpif, verbose, cts, sw);
if (!success) if (!success)
{ {
@ -296,13 +294,15 @@ namespace BizHawk.Client.DiscoHawk
if (compareDiscInterfaces.Count != 0) if (compareDiscInterfaces.Count != 0)
{ {
StringWriter sw = new StringWriter(); var sw = new StringWriter();
foreach (var cmpif in compareDiscInterfaces) foreach (var cmpif in compareDiscInterfaces)
{
CompareFile(infile, loadDiscInterface, cmpif, verbose, null, sw); CompareFile(infile, loadDiscInterface, cmpif, verbose, null, sw);
}
sw.Flush(); sw.Flush();
string results = sw.ToString(); string results = sw.ToString();
var cr = new ComparisonResults(); var cr = new ComparisonResults { textBox1 = { Text = results } };
cr.textBox1.Text = results;
cr.ShowDialog(); cr.ShowDialog();
} }
@ -311,7 +311,7 @@ namespace BizHawk.Client.DiscoHawk
static bool CompareFile(string infile, DiscInterface loadDiscInterface, DiscInterface cmpif, bool verbose, CancellationTokenSource cancelToken, StringWriter sw) static bool CompareFile(string infile, DiscInterface loadDiscInterface, DiscInterface cmpif, bool verbose, CancellationTokenSource cancelToken, StringWriter sw)
{ {
Disc src_disc = null, dst_disc = null; Disc srcDisc = null, dstDisc = null;
try try
{ {
@ -327,50 +327,58 @@ namespace BizHawk.Client.DiscoHawk
} }
dmj.Run(); dmj.Run();
src_disc = dmj.OUT_Disc; srcDisc = dmj.OUT_Disc;
var dst_dmj = new DiscMountJob { IN_DiscInterface = cmpif, IN_FromPath = infile }; var dstDmj = new DiscMountJob { IN_DiscInterface = cmpif, IN_FromPath = infile };
dst_dmj.Run(); dstDmj.Run();
dst_disc = dst_dmj.OUT_Disc; dstDisc = dstDmj.OUT_Disc;
var src_dsr = new DiscSectorReader(src_disc); var srcDsr = new DiscSectorReader(srcDisc);
var dst_dsr = new DiscSectorReader(dst_disc); var dstDsr = new DiscSectorReader(dstDisc);
var src_toc = src_disc.TOC; var srcToc = srcDisc.TOC;
var dst_toc = dst_disc.TOC; var dstToc = dstDisc.TOC;
var src_databuf = new byte[2448]; var srcDataBuf = new byte[2448];
var dst_databuf = new byte[2448]; var dstDataBuf = new byte[2448];
Action<DiscTOC.TOCItem> sw_dump_toc_one = (item) => void SwDumpTocOne(DiscTOC.TOCItem item)
{ {
if (!item.Exists) if (!item.Exists)
sw.Write("(---missing---)");
else
sw.Write("({0:X2} - {1})", (byte)item.Control, item.LBA);
};
Action<int> sw_dump_toc = (index) =>
{ {
sw.Write("SRC TOC#{0,3} ", index); sw_dump_toc_one(src_toc.TOCItems[index]); sw.WriteLine(); sw.Write("(---missing---)");
sw.Write("DST TOC#{0,3} ", index); sw_dump_toc_one(dst_toc.TOCItems[index]); sw.WriteLine(); }
}; else
{
sw.Write("({0:X2} - {1})", (byte) item.Control, item.LBA);
}
}
void SwDumpToc(int index)
{
sw.Write("SRC TOC#{0,3} ", index);
SwDumpTocOne(srcToc.TOCItems[index]);
sw.WriteLine();
sw.Write("DST TOC#{0,3} ", index);
SwDumpTocOne(dstToc.TOCItems[index]);
sw.WriteLine();
}
//verify sector count //verify sector count
if (src_disc.Session1.LeadoutLBA != dst_disc.Session1.LeadoutLBA) if (srcDisc.Session1.LeadoutLBA != dstDisc.Session1.LeadoutLBA)
{ {
sw.Write("LeadoutTrack.LBA {0} vs {1}\n", src_disc.Session1.LeadoutTrack.LBA, dst_disc.Session1.LeadoutTrack.LBA); sw.Write("LeadoutTrack.LBA {0} vs {1}\n", srcDisc.Session1.LeadoutTrack.LBA, dstDisc.Session1.LeadoutTrack.LBA);
goto SKIPPO; goto SKIPPO;
} }
//verify TOC match //verify TOC match
if (src_disc.TOC.FirstRecordedTrackNumber != dst_disc.TOC.FirstRecordedTrackNumber if (srcDisc.TOC.FirstRecordedTrackNumber != dstDisc.TOC.FirstRecordedTrackNumber
|| src_disc.TOC.LastRecordedTrackNumber != dst_disc.TOC.LastRecordedTrackNumber) || srcDisc.TOC.LastRecordedTrackNumber != dstDisc.TOC.LastRecordedTrackNumber)
{ {
sw.WriteLine("Mismatch of RecordedTrackNumbers: {0}-{1} vs {2}-{3}", sw.WriteLine("Mismatch of RecordedTrackNumbers: {0}-{1} vs {2}-{3}",
src_disc.TOC.FirstRecordedTrackNumber, src_disc.TOC.LastRecordedTrackNumber, srcDisc.TOC.FirstRecordedTrackNumber, srcDisc.TOC.LastRecordedTrackNumber,
dst_disc.TOC.FirstRecordedTrackNumber, dst_disc.TOC.LastRecordedTrackNumber dstDisc.TOC.FirstRecordedTrackNumber, dstDisc.TOC.LastRecordedTrackNumber
); );
goto SKIPPO; goto SKIPPO;
} }
@ -378,20 +386,20 @@ namespace BizHawk.Client.DiscoHawk
bool badToc = false; bool badToc = false;
for (int t = 0; t < 101; t++) for (int t = 0; t < 101; t++)
{ {
if (src_toc.TOCItems[t].Exists != dst_toc.TOCItems[t].Exists if (srcToc.TOCItems[t].Exists != dstToc.TOCItems[t].Exists
|| src_toc.TOCItems[t].Control != dst_toc.TOCItems[t].Control || srcToc.TOCItems[t].Control != dstToc.TOCItems[t].Control
|| src_toc.TOCItems[t].LBA != dst_toc.TOCItems[t].LBA || srcToc.TOCItems[t].LBA != dstToc.TOCItems[t].LBA
) )
{ {
sw.WriteLine("Mismatch in TOCItem"); sw.WriteLine("Mismatch in TOCItem");
sw_dump_toc(t); SwDumpToc(t);
badToc = true; badToc = true;
} }
} }
if (badToc) if (badToc)
goto SKIPPO; goto SKIPPO;
Action<string, int, byte[], int, int> sw_dump_chunk_one = (comment, lba, buf, addr, count) => void SwDumpChunkOne(string comment, int lba, byte[] buf, int addr, int count)
{ {
sw.Write("{0} - ", comment); sw.Write("{0} - ", comment);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
@ -399,29 +407,43 @@ namespace BizHawk.Client.DiscoHawk
if (i + addr >= buf.Length) continue; if (i + addr >= buf.Length) continue;
sw.Write("{0:X2}{1}", buf[addr + i], (i == count - 1) ? " " : " "); sw.Write("{0:X2}{1}", buf[addr + i], (i == count - 1) ? " " : " ");
} }
sw.WriteLine(); sw.WriteLine();
}; }
int[] offenders = new int[12]; int[] offenders = new int[12];
Action<int, int, int, int, int> sw_dump_chunk = (lba, dispaddr, addr, count, numoffenders) =>
void SwDumpChunk(int lba, int dispAddr, int addr, int count, int numOffenders)
{ {
var hashedOffenders = new HashSet<int>(); var hashedOffenders = new HashSet<int>();
for (int i = 0; i < numoffenders; i++) hashedOffenders.Add(offenders[i]); for (int i = 0; i < numOffenders; i++)
{
hashedOffenders.Add(offenders[i]);
}
sw.Write(" "); sw.Write(" ");
for (int i = 0; i < count; i++) sw.Write((hashedOffenders.Contains(dispaddr + i)) ? "vvv " : " "); for (int i = 0; i < count; i++)
{
sw.Write((hashedOffenders.Contains(dispAddr + i)) ? "vvv " : " ");
}
sw.WriteLine(); sw.WriteLine();
sw.Write(" "); sw.Write(" ");
for (int i = 0; i < count; i++) sw.Write("{0:X3} ", dispaddr + i, (i == count - 1) ? " " : " "); for (int i = 0; i < count; i++)
{
sw.Write("{0:X3} ", dispAddr + i, (i == count - 1) ? " " : " ");
}
sw.WriteLine(); sw.WriteLine();
sw.Write(" "); sw.Write(" ");
sw.Write(new string('-', count * 4)); sw.Write(new string('-', count * 4));
sw.WriteLine(); sw.WriteLine();
sw_dump_chunk_one($"SRC #{lba,6} ({new Timestamp(lba)})", lba, src_databuf, addr, count); SwDumpChunkOne($"SRC #{lba,6} ({new Timestamp(lba)})", lba, srcDataBuf, addr, count);
sw_dump_chunk_one($"DST #{lba,6} ({new Timestamp(lba)})", lba, dst_databuf, addr, count); SwDumpChunkOne($"DST #{lba,6} ({new Timestamp(lba)})", lba, dstDataBuf, addr, count);
}; }
//verify each sector contents //verify each sector contents
int nSectors = src_disc.Session1.LeadoutLBA; int nSectors = srcDisc.Session1.LeadoutLBA;
for (int lba = -150; lba < nSectors; lba++) for (int lba = -150; lba < nSectors; lba++)
{ {
if (verbose) if (verbose)
@ -432,46 +454,47 @@ namespace BizHawk.Client.DiscoHawk
if (cancelToken.Token.IsCancellationRequested) if (cancelToken.Token.IsCancellationRequested)
return false; return false;
src_dsr.ReadLBA_2448(lba, src_databuf, 0); srcDsr.ReadLBA_2448(lba, srcDataBuf, 0);
dst_dsr.ReadLBA_2448(lba, dst_databuf, 0); dstDsr.ReadLBA_2448(lba, dstDataBuf, 0);
//check the header //check the header
for (int b = 0; b < 16; b++) for (int b = 0; b < 16; b++)
{ {
if (src_databuf[b] != dst_databuf[b]) if (srcDataBuf[b] != dstDataBuf[b])
{ {
sw.WriteLine("Mismatch in sector header at byte {0}", b); sw.WriteLine("Mismatch in sector header at byte {0}", b);
offenders[0] = b; offenders[0] = b;
sw_dump_chunk(lba, 0, 0, 16, 1); SwDumpChunk(lba, 0, 0, 16, 1);
goto SKIPPO; goto SKIPPO;
} }
} }
//check userdata // check userData
for (int b = 16; b < 2352; b++) for (int b = 16; b < 2352; b++)
{ {
if (src_databuf[b] != dst_databuf[b]) if (srcDataBuf[b] != dstDataBuf[b])
{ {
sw.Write("LBA {0} mismatch at userdata byte {1}; terminating sector cmp\n", lba, b); sw.Write("LBA {0} mismatch at userdata byte {1}; terminating sector cmp\n", lba, b);
goto SKIPPO; goto SKIPPO;
} }
} }
//check subchannels // check subChannels
for (int c = 0, b = 2352; c < 8; c++) for (int c = 0, b = 2352; c < 8; c++)
{ {
int numOffenders = 0; int numOffenders = 0;
for (int e = 0; e < 12; e++, b++) for (int e = 0; e < 12; e++, b++)
{ {
if (src_databuf[b] != dst_databuf[b]) if (srcDataBuf[b] != dstDataBuf[b])
{ {
offenders[numOffenders++] = e; offenders[numOffenders++] = e;
} }
} }
if (numOffenders != 0) if (numOffenders != 0)
{ {
sw.Write("LBA {0} mismatch(es) at subchannel {1}; terminating sector cmp\n", lba, (char)('P' + c)); sw.Write("LBA {0} mismatch(es) at subchannel {1}; terminating sector cmp\n", lba, (char)('P' + c));
sw_dump_chunk(lba, 0, 2352 + c * 12, 12, numOffenders); SwDumpChunk(lba, 0, 2352 + c * 12, 12, numOffenders);
goto SKIPPO; goto SKIPPO;
} }
} }
@ -487,10 +510,10 @@ namespace BizHawk.Client.DiscoHawk
} }
finally finally
{ {
if (src_disc != null) if (srcDisc != null)
src_disc.Dispose(); srcDisc.Dispose();
if (dst_disc != null) if (dstDisc != null)
dst_disc.Dispose(); dstDisc.Dispose();
} }
} //CompareFile } //CompareFile

View File

@ -75,7 +75,7 @@
this.lblMagicDragArea.Size = new System.Drawing.Size(200, 100); this.lblMagicDragArea.Size = new System.Drawing.Size(200, 100);
this.lblMagicDragArea.TabIndex = 1; this.lblMagicDragArea.TabIndex = 1;
this.lblMagicDragArea.DragDrop += new System.Windows.Forms.DragEventHandler(this.lblMagicDragArea_DragDrop); this.lblMagicDragArea.DragDrop += new System.Windows.Forms.DragEventHandler(this.lblMagicDragArea_DragDrop);
this.lblMagicDragArea.DragEnter += new System.Windows.Forms.DragEventHandler(this.lblMagicDragArea_DragEnter); this.lblMagicDragArea.DragEnter += new System.Windows.Forms.DragEventHandler(this.LblMagicDragArea_DragEnter);
// //
// label1 // label1
// //
@ -94,8 +94,8 @@
this.lblMp3ExtractMagicArea.Name = "lblMp3ExtractMagicArea"; this.lblMp3ExtractMagicArea.Name = "lblMp3ExtractMagicArea";
this.lblMp3ExtractMagicArea.Size = new System.Drawing.Size(200, 100); this.lblMp3ExtractMagicArea.Size = new System.Drawing.Size(200, 100);
this.lblMp3ExtractMagicArea.TabIndex = 2; this.lblMp3ExtractMagicArea.TabIndex = 2;
this.lblMp3ExtractMagicArea.DragDrop += new System.Windows.Forms.DragEventHandler(this.lblMp3ExtractMagicArea_DragDrop); this.lblMp3ExtractMagicArea.DragDrop += new System.Windows.Forms.DragEventHandler(this.LblMp3ExtractMagicArea_DragDrop);
this.lblMp3ExtractMagicArea.DragEnter += new System.Windows.Forms.DragEventHandler(this.lblMagicDragArea_DragEnter); this.lblMp3ExtractMagicArea.DragEnter += new System.Windows.Forms.DragEventHandler(this.LblMagicDragArea_DragEnter);
// //
// label2 // label2
// //
@ -113,7 +113,7 @@
this.btnAbout.TabIndex = 3; this.btnAbout.TabIndex = 3;
this.btnAbout.Text = "&About"; this.btnAbout.Text = "&About";
this.btnAbout.UseVisualStyleBackColor = true; this.btnAbout.UseVisualStyleBackColor = true;
this.btnAbout.Click += new System.EventHandler(this.btnAbout_Click); this.btnAbout.Click += new System.EventHandler(this.BtnAbout_Click);
// //
// radioButton1 // radioButton1
// //

View File

@ -1,15 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.IO; using System.IO;
using System.Threading;
using BizHawk.Common;
using BizHawk.Common.StringExtensions; using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.DiscSystem; using BizHawk.Emulation.DiscSystem;
@ -35,16 +27,16 @@ namespace BizHawk.Client.DiscoHawk
private void ExitButton_Click(object sender, EventArgs e) private void ExitButton_Click(object sender, EventArgs e)
{ {
this.Close(); Close();
} }
private void lblMagicDragArea_DragDrop(object sender, DragEventArgs e) private void lblMagicDragArea_DragDrop(object sender, DragEventArgs e)
{ {
List<string> files = validateDrop(e.Data); List<string> files = ValidateDrop(e.Data);
if (files.Count == 0) return; if (files.Count == 0) return;
try try
{ {
this.Cursor = Cursors.WaitCursor; Cursor = Cursors.WaitCursor;
foreach (var file in files) foreach (var file in files)
{ {
var job = new DiscMountJob { IN_FromPath = file }; var job = new DiscMountJob { IN_FromPath = file };
@ -52,7 +44,7 @@ namespace BizHawk.Client.DiscoHawk
var disc = job.OUT_Disc; var disc = job.OUT_Disc;
if (job.OUT_ErrorLevel) if (job.OUT_ErrorLevel)
{ {
System.Windows.Forms.MessageBox.Show(job.OUT_Log, "Error loading disc"); MessageBox.Show(job.OUT_Log, "Error loading disc");
break; break;
} }
@ -61,7 +53,8 @@ namespace BizHawk.Client.DiscoHawk
string outfile = $"{Path.Combine(Path.GetDirectoryName(file), baseName)}.ccd"; string outfile = $"{Path.Combine(Path.GetDirectoryName(file), baseName)}.ccd";
CCD_Format.Dump(disc, outfile); CCD_Format.Dump(disc, outfile);
} }
this.Cursor = Cursors.Default;
Cursor = Cursors.Default;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -97,47 +90,47 @@ namespace BizHawk.Client.DiscoHawk
} }
#endif #endif
private void lblMagicDragArea_DragEnter(object sender, DragEventArgs e) private void LblMagicDragArea_DragEnter(object sender, DragEventArgs e)
{ {
List<string> files = validateDrop(e.Data); List<string> files = ValidateDrop(e.Data);
if (files.Count > 0) e.Effect = files.Count > 0
e.Effect = DragDropEffects.Link; ? DragDropEffects.Link
else e.Effect = DragDropEffects.None; : DragDropEffects.None;
} }
List<string> validateDrop(IDataObject ido) private List<string> ValidateDrop(IDataObject ido)
{ {
List<string> ret = new List<string>(); List<string> ret = new List<string>();
string[] files = (string[])ido.GetData(System.Windows.Forms.DataFormats.FileDrop); string[] files = (string[])ido.GetData(System.Windows.Forms.DataFormats.FileDrop);
if (files == null) return new List<string>(); if (files == null) return new List<string>();
foreach (string str in files) foreach (string str in files)
{ {
string ext = Path.GetExtension(str).ToUpper(); string ext = Path.GetExtension(str)?.ToUpper();
if(!ext.In(new string[]{".CUE",".ISO",".CCD", ".MDS"})) if(!ext.In(".CUE", ".ISO", ".CCD", ".MDS"))
{ {
return new List<string>(); return new List<string>();
} }
ret.Add(str); ret.Add(str);
} }
return ret; return ret;
} }
private void lblMp3ExtractMagicArea_DragDrop(object sender, DragEventArgs e) private void LblMp3ExtractMagicArea_DragDrop(object sender, DragEventArgs e)
{ {
var files = validateDrop(e.Data); var files = ValidateDrop(e.Data);
if (files.Count == 0) return; if (files.Count == 0) return;
foreach (var file in files) foreach (var file in files)
{ {
using (var disc = Disc.LoadAutomagic(file)) using var disc = Disc.LoadAutomagic(file);
{
var path = Path.GetDirectoryName(file); var path = Path.GetDirectoryName(file);
var filename = Path.GetFileNameWithoutExtension(file); var filename = Path.GetFileNameWithoutExtension(file);
AudioExtractor.Extract(disc, path, filename); AudioExtractor.Extract(disc, path, filename);
} }
} }
}
private void btnAbout_Click(object sender, EventArgs e) private void BtnAbout_Click(object sender, EventArgs e)
{ {
new About().ShowDialog(); new About().ShowDialog();
} }