diff --git a/BizHawk.Emulation/DiscSystem/Disc.cs b/BizHawk.Emulation/DiscSystem/Disc.cs index bb3bca87de..7b7aba849c 100644 --- a/BizHawk.Emulation/DiscSystem/Disc.cs +++ b/BizHawk.Emulation/DiscSystem/Disc.cs @@ -67,7 +67,7 @@ using System.Collections.Generic; namespace BizHawk.DiscSystem { - public partial class Disc + public partial class Disc : IDisposable { //TODO - separate these into Read_2352 and Read_2048 (optimizations can be made by ISector implementors depending on what is requested) //(for example, avoiding the 2048 byte sector creating the ECC data and then immediately discarding it) @@ -76,7 +76,7 @@ namespace BizHawk.DiscSystem int Read(byte[] buffer, int offset); } - public interface IBlob + public interface IBlob : IDisposable { int Read(long byte_pos, byte[] buffer, int offset, int count); void Dispose(); @@ -311,6 +311,14 @@ namespace BizHawk.DiscSystem public List Sectors = new List(); public DiscTOC TOC = new DiscTOC(); + public void Dispose() + { + foreach (var blob in Blobs) + { + blob.Dispose(); + } + } + void FromIsoPathInternal(string isoPath) { var session = new DiscTOC.Session(); @@ -453,6 +461,9 @@ namespace BizHawk.DiscSystem return ret; } + /// + /// THIS HASNT BEEN TESTED IN A LONG TIME. DOES IT WORK? + /// public static Disc FromIsoPath(string isoPath) { var ret = new Disc(); diff --git a/DiscoHawk/AudioExtractor.cs b/DiscoHawk/AudioExtractor.cs index 285e43cab5..409b86b730 100644 --- a/DiscoHawk/AudioExtractor.cs +++ b/DiscoHawk/AudioExtractor.cs @@ -1,4 +1,5 @@ using System; +using System.Windows.Forms; using System.Collections.Generic; using System.Linq; using System.Text; @@ -14,6 +15,7 @@ namespace BizHawk public static void Extract(Disc disc, string path, string filebase) { + bool confirmed = false; var tracks = disc.TOC.Sessions[0].Tracks; foreach (var track in tracks) { @@ -25,12 +27,23 @@ namespace BizHawk for (int sector = 0; sector < track.length_aba; sector++) disc.ReadLBA_2352(startLba + sector, waveData, sector * 2352); + string mp3Path = string.Format("{0} - Track {1:D2}.mp3", Path.Combine(path, filebase), track.num); + if(File.Exists(mp3Path)) + { + if (!confirmed) + { + var dr = MessageBox.Show("This file already exists. Do you want extraction to proceed overwriting files, or cancel the entire operation immediately?", "File already exists", MessageBoxButtons.OKCancel); + if (dr == DialogResult.Cancel) return; + confirmed = true; + } + File.Delete(mp3Path); + } + string tempfile = Path.GetTempFileName(); try { File.WriteAllBytes(tempfile, waveData); - string mp3Path = string.Format("{0} - Track {1:D2}.mp3", Path.Combine(path, filebase), track.num); var ffmpeg = new FFMpeg(); ffmpeg.Run("-f", "s16le", "-ar", "44100", "-ac", "2", "-i", tempfile, "-f", "mp3", "-ab", "192k", mp3Path); } diff --git a/DiscoHawk/MainDiscoForm.cs b/DiscoHawk/MainDiscoForm.cs index 084ffd356e..4d13ed04cd 100644 --- a/DiscoHawk/MainDiscoForm.cs +++ b/DiscoHawk/MainDiscoForm.cs @@ -131,10 +131,12 @@ namespace BizHawk if (files.Count == 0) return; foreach (var file in files) { - var disc = Disc.FromCuePath(file); - var path = Path.GetDirectoryName(file); - var filename = Path.GetFileNameWithoutExtension(file); - AudioExtractor.Extract(disc, path, filename); + using (var disc = Disc.FromCuePath(file)) + { + var path = Path.GetDirectoryName(file); + var filename = Path.GetFileNameWithoutExtension(file); + AudioExtractor.Extract(disc, path, filename); + } } } }