make discs disposable and polish up discohawk extractor

This commit is contained in:
zeromus 2011-09-04 06:15:41 +00:00
parent 7cd0cd87f5
commit 44c8a62803
3 changed files with 33 additions and 7 deletions

View File

@ -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<SectorEntry> Sectors = new List<SectorEntry>();
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;
}
/// <summary>
/// THIS HASNT BEEN TESTED IN A LONG TIME. DOES IT WORK?
/// </summary>
public static Disc FromIsoPath(string isoPath)
{
var ret = new Disc();

View File

@ -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);
}

View File

@ -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);
}
}
}
}