make discs disposable and polish up discohawk extractor
This commit is contained in:
parent
7cd0cd87f5
commit
44c8a62803
|
@ -67,7 +67,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace BizHawk.DiscSystem
|
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)
|
//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)
|
//(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);
|
int Read(byte[] buffer, int offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IBlob
|
public interface IBlob : IDisposable
|
||||||
{
|
{
|
||||||
int Read(long byte_pos, byte[] buffer, int offset, int count);
|
int Read(long byte_pos, byte[] buffer, int offset, int count);
|
||||||
void Dispose();
|
void Dispose();
|
||||||
|
@ -311,6 +311,14 @@ namespace BizHawk.DiscSystem
|
||||||
public List<SectorEntry> Sectors = new List<SectorEntry>();
|
public List<SectorEntry> Sectors = new List<SectorEntry>();
|
||||||
public DiscTOC TOC = new DiscTOC();
|
public DiscTOC TOC = new DiscTOC();
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
foreach (var blob in Blobs)
|
||||||
|
{
|
||||||
|
blob.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FromIsoPathInternal(string isoPath)
|
void FromIsoPathInternal(string isoPath)
|
||||||
{
|
{
|
||||||
var session = new DiscTOC.Session();
|
var session = new DiscTOC.Session();
|
||||||
|
@ -453,6 +461,9 @@ namespace BizHawk.DiscSystem
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// THIS HASNT BEEN TESTED IN A LONG TIME. DOES IT WORK?
|
||||||
|
/// </summary>
|
||||||
public static Disc FromIsoPath(string isoPath)
|
public static Disc FromIsoPath(string isoPath)
|
||||||
{
|
{
|
||||||
var ret = new Disc();
|
var ret = new Disc();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -14,6 +15,7 @@ namespace BizHawk
|
||||||
|
|
||||||
public static void Extract(Disc disc, string path, string filebase)
|
public static void Extract(Disc disc, string path, string filebase)
|
||||||
{
|
{
|
||||||
|
bool confirmed = false;
|
||||||
var tracks = disc.TOC.Sessions[0].Tracks;
|
var tracks = disc.TOC.Sessions[0].Tracks;
|
||||||
foreach (var track in tracks)
|
foreach (var track in tracks)
|
||||||
{
|
{
|
||||||
|
@ -25,12 +27,23 @@ namespace BizHawk
|
||||||
for (int sector = 0; sector < track.length_aba; sector++)
|
for (int sector = 0; sector < track.length_aba; sector++)
|
||||||
disc.ReadLBA_2352(startLba + sector, waveData, sector * 2352);
|
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();
|
string tempfile = Path.GetTempFileName();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.WriteAllBytes(tempfile, waveData);
|
File.WriteAllBytes(tempfile, waveData);
|
||||||
string mp3Path = string.Format("{0} - Track {1:D2}.mp3", Path.Combine(path, filebase), track.num);
|
|
||||||
var ffmpeg = new FFMpeg();
|
var ffmpeg = new FFMpeg();
|
||||||
ffmpeg.Run("-f", "s16le", "-ar", "44100", "-ac", "2", "-i", tempfile, "-f", "mp3", "-ab", "192k", mp3Path);
|
ffmpeg.Run("-f", "s16le", "-ar", "44100", "-ac", "2", "-i", tempfile, "-f", "mp3", "-ab", "192k", mp3Path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,10 +131,12 @@ namespace BizHawk
|
||||||
if (files.Count == 0) return;
|
if (files.Count == 0) return;
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
var disc = Disc.FromCuePath(file);
|
using (var disc = Disc.FromCuePath(file))
|
||||||
var path = Path.GetDirectoryName(file);
|
{
|
||||||
var filename = Path.GetFileNameWithoutExtension(file);
|
var path = Path.GetDirectoryName(file);
|
||||||
AudioExtractor.Extract(disc, path, filename);
|
var filename = Path.GetFileNameWithoutExtension(file);
|
||||||
|
AudioExtractor.Extract(disc, path, filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue