mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
* option to set process priority to idle (enabled by default)
* input can be a directory with audio files and no cue sheet.
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
using CUEToolsLib;
|
||||
|
||||
namespace JDP
|
||||
@@ -178,8 +179,16 @@ namespace JDP
|
||||
textBox1.Text += "Processing " + pathIn + ":\r\n";
|
||||
textBox1.Select (0,0);
|
||||
|
||||
string cueName;
|
||||
if (!File.Exists(pathIn))
|
||||
throw new Exception("Input CUE Sheet not found.");
|
||||
{
|
||||
if (!Directory.Exists (pathIn))
|
||||
throw new Exception("Input CUE Sheet not found.");
|
||||
if (!pathIn.EndsWith(new string(Path.DirectorySeparatorChar, 1)))
|
||||
pathIn = pathIn + Path.DirectorySeparatorChar;
|
||||
cueName = Path.GetFileNameWithoutExtension(Path.GetDirectoryName(pathIn)) + ".cue";
|
||||
} else
|
||||
cueName = Path.GetFileNameWithoutExtension(pathIn) + ".cue";
|
||||
|
||||
bool outputAudio = _accurateOffset || !_accurateRip;
|
||||
cueSheet = new CUESheet(pathIn, _config);
|
||||
@@ -192,7 +201,7 @@ namespace JDP
|
||||
if (!Directory.Exists(outDir))
|
||||
{
|
||||
Directory.CreateDirectory(outDir);
|
||||
pathOut = Path.Combine(outDir, Path.GetFileNameWithoutExtension(pathIn) + ".cue");
|
||||
pathOut = Path.Combine(outDir, cueName);
|
||||
pathFound = true;
|
||||
break;
|
||||
}
|
||||
@@ -200,7 +209,7 @@ namespace JDP
|
||||
if (!pathFound)
|
||||
throw new Exception("Could not create a folder.");
|
||||
} else
|
||||
pathOut = pathIn;
|
||||
pathOut = Path.Combine(Path.GetDirectoryName(pathIn), cueName);
|
||||
cueSheet.GenerateFilenames(_audioFormat, pathOut);
|
||||
if (outputAudio)
|
||||
{
|
||||
@@ -254,6 +263,9 @@ namespace JDP
|
||||
}
|
||||
catch { };
|
||||
|
||||
if (_config.processPriorityIdle)
|
||||
Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Idle;
|
||||
|
||||
if (_accurateOffset || !_accurateRip)
|
||||
txtOutputFile.Show();
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
using CUEToolsLib;
|
||||
|
||||
namespace JDP {
|
||||
@@ -189,6 +190,8 @@ namespace JDP {
|
||||
private void frmCUETools_Load(object sender, EventArgs e) {
|
||||
_batchPaths = new List<string>();
|
||||
LoadSettings();
|
||||
if (_config.processPriorityIdle)
|
||||
Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Idle;
|
||||
SetupControls(false);
|
||||
UpdateOutputPath();
|
||||
updateOutputStyles();
|
||||
@@ -226,8 +229,15 @@ namespace JDP {
|
||||
bool outputCUE = (cueStyle != CUEStyle.SingleFileWithCUE) && !rbArVerify.Checked;
|
||||
bool accurateRip = !rbArNone.Checked;
|
||||
|
||||
if (!File.Exists(pathIn)) {
|
||||
throw new Exception("Input CUE Sheet not found.");
|
||||
if (!File.Exists(pathIn))
|
||||
{
|
||||
if (!Directory.Exists(pathIn))
|
||||
throw new Exception("Input CUE Sheet not found.");
|
||||
if (!pathIn.EndsWith(new string(Path.DirectorySeparatorChar, 1)))
|
||||
{
|
||||
pathIn = pathIn + Path.DirectorySeparatorChar;
|
||||
txtInputPath.Text = pathIn;
|
||||
}
|
||||
}
|
||||
|
||||
cueSheet = new CUESheet(pathIn, _config);
|
||||
@@ -285,8 +295,7 @@ namespace JDP {
|
||||
p[1] = outDir;
|
||||
p[2] = cueStyle;
|
||||
|
||||
SetupControls(true);
|
||||
//System.Diagnostics; Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.High;
|
||||
SetupControls(true);
|
||||
_workThread.Priority = ThreadPriority.BelowNormal;
|
||||
_workThread.IsBackground = true;
|
||||
_workThread.Start(p);
|
||||
@@ -776,9 +785,20 @@ namespace JDP {
|
||||
pathIn = txtInputPath.Text;
|
||||
pathOut = String.Empty;
|
||||
|
||||
if ((pathIn.Length != 0) && File.Exists(pathIn)) {
|
||||
dir = Path.GetDirectoryName(pathIn);
|
||||
file = Path.GetFileNameWithoutExtension(pathIn);
|
||||
if ((pathIn.Length != 0) && (File.Exists(pathIn) || Directory.Exists(pathIn)))
|
||||
{
|
||||
if (Directory.Exists(pathIn))
|
||||
{
|
||||
if (!pathIn.EndsWith(new string(Path.DirectorySeparatorChar, 1)))
|
||||
pathIn = pathIn + Path.DirectorySeparatorChar;
|
||||
dir = Path.GetDirectoryName(pathIn);
|
||||
file = Path.GetFileNameWithoutExtension(dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
dir = Path.GetDirectoryName(pathIn);
|
||||
file = Path.GetFileNameWithoutExtension(pathIn);
|
||||
}
|
||||
ext = ".cue";
|
||||
|
||||
if (rbEmbedCUE.Checked)
|
||||
@@ -858,24 +878,14 @@ namespace JDP {
|
||||
string[] audioExts = new string[] { "*.wav", "*.flac", "*.wv", "*.ape", "*.m4a" };
|
||||
for (int i = 0; i < audioExts.Length; i++)
|
||||
{
|
||||
string [] audioFiles = Directory.GetFiles(dir, audioExts[i]);
|
||||
if (audioFiles.Length < 2)
|
||||
string cueSheet = CUESheet.CreateDummyCUESheet(dir, audioExts[i]);
|
||||
if (cueSheet == null)
|
||||
continue;
|
||||
Array.Sort (audioFiles);
|
||||
string cueName = Path.GetFileName(dir) + ".cuetools" + audioExts[i].Substring(1) + ".cue";
|
||||
cueName = Path.Combine(dir, cueName);
|
||||
StringWriter sw = new StringWriter();
|
||||
sw.WriteLine(String.Format("REM COMMENT \"CUETools generated dummy CUE sheet\""));
|
||||
for (int iFile = 0; iFile < audioFiles.Length; iFile++)
|
||||
{
|
||||
sw.WriteLine(String.Format("FILE \"{0}\" WAVE", Path.GetFileName (audioFiles[iFile])));
|
||||
sw.WriteLine(String.Format(" TRACK {0:00} AUDIO", iFile+1));
|
||||
sw.WriteLine(String.Format(" INDEX 01 00:00:00"));
|
||||
}
|
||||
sw.Close();
|
||||
bool utf8Required = CUESheet.Encoding.GetString(CUESheet.Encoding.GetBytes(sw.ToString())) != sw.ToString();
|
||||
bool utf8Required = CUESheet.Encoding.GetString(CUESheet.Encoding.GetBytes(cueSheet)) != cueSheet;
|
||||
StreamWriter sw1 = new StreamWriter(cueName, false, utf8Required ? Encoding.UTF8 : CUESheet.Encoding);
|
||||
sw1.Write(sw.ToString());
|
||||
sw1.Write(cueSheet);
|
||||
sw1.Close();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -234,6 +234,7 @@ namespace CUEToolsLib
|
||||
public bool createM3U;
|
||||
public bool createCUEFileWhenEmbedded;
|
||||
public bool truncate4608ExtraSamples;
|
||||
public bool processPriorityIdle;
|
||||
|
||||
public CUEConfig()
|
||||
{
|
||||
@@ -273,6 +274,7 @@ namespace CUEToolsLib
|
||||
createM3U = false;
|
||||
createCUEFileWhenEmbedded = false;
|
||||
truncate4608ExtraSamples = true;
|
||||
processPriorityIdle = true;
|
||||
}
|
||||
|
||||
public void Save (SettingsWriter sw)
|
||||
@@ -313,6 +315,7 @@ namespace CUEToolsLib
|
||||
sw.Save("CreateM3U", createM3U);
|
||||
sw.Save("CreateCUEFileWhenEmbedded", createCUEFileWhenEmbedded);
|
||||
sw.Save("Truncate4608ExtraSamples", truncate4608ExtraSamples);
|
||||
sw.Save("ProcessPriorityIdle", processPriorityIdle);
|
||||
}
|
||||
|
||||
public void Load(SettingsReader sr)
|
||||
@@ -353,6 +356,7 @@ namespace CUEToolsLib
|
||||
createM3U = sr.LoadBoolean("CreateM3U") ?? false;
|
||||
createCUEFileWhenEmbedded = sr.LoadBoolean("CreateCUEFileWhenEmbedded") ?? false;
|
||||
truncate4608ExtraSamples = sr.LoadBoolean("Truncate4608ExtraSamples") ?? true;
|
||||
processPriorityIdle = sr.LoadBoolean("ProcessPriorityIdle") ?? true;
|
||||
}
|
||||
|
||||
public string CleanseString (string s)
|
||||
@@ -461,6 +465,18 @@ namespace CUEToolsLib
|
||||
|
||||
TextReader sr;
|
||||
|
||||
if (Directory.Exists(pathIn))
|
||||
{
|
||||
if (cueDir + Path.DirectorySeparatorChar != pathIn)
|
||||
throw new Exception("Input directory must end on path separator character.");
|
||||
string cueSheet = null;
|
||||
string[] audioExts = new string[] { "*.wav", "*.flac", "*.wv", "*.ape", "*.m4a" };
|
||||
for (i = 0; i < audioExts.Length && cueSheet == null; i++)
|
||||
cueSheet = CUESheet.CreateDummyCUESheet(pathIn, audioExts[i]);
|
||||
if (cueSheet == null)
|
||||
throw new Exception("Input directory doesn't contain supported audio files.");
|
||||
sr = new StringReader(cueSheet);
|
||||
} else
|
||||
if (Path.GetExtension(pathIn).ToLower() != ".cue")
|
||||
{
|
||||
IAudioSource audioSource;
|
||||
@@ -2070,6 +2086,24 @@ namespace CUEToolsLib
|
||||
decodedAudioDest.Close();
|
||||
}
|
||||
|
||||
public static string CreateDummyCUESheet(string path, string extension)
|
||||
{
|
||||
string[] audioFiles = Directory.GetFiles(path, extension);
|
||||
if (audioFiles.Length < 2)
|
||||
return null;
|
||||
Array.Sort(audioFiles);
|
||||
StringWriter sw = new StringWriter();
|
||||
sw.WriteLine(String.Format("REM COMMENT \"CUETools generated dummy CUE sheet\""));
|
||||
for (int iFile = 0; iFile < audioFiles.Length; iFile++)
|
||||
{
|
||||
sw.WriteLine(String.Format("FILE \"{0}\" WAVE", Path.GetFileName(audioFiles[iFile])));
|
||||
sw.WriteLine(String.Format(" TRACK {0:00} AUDIO", iFile + 1));
|
||||
sw.WriteLine(String.Format(" INDEX 01 00:00:00"));
|
||||
}
|
||||
sw.Close();
|
||||
return sw.ToString();
|
||||
}
|
||||
|
||||
public static string CorrectAudioFilenames(string path, bool always) {
|
||||
string[] audioExts = new string[] { "*.wav", "*.flac", "*.wv", "*.ape", "*.m4a" };
|
||||
List<string> lines = new List<string>();
|
||||
|
||||
Reference in New Issue
Block a user