2008-10-13 19:25:11 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2009-08-06 13:03:02 +00:00
|
|
|
using System.Collections.Specialized;
|
2008-10-13 19:25:11 +00:00
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
2008-11-08 16:47:23 +00:00
|
|
|
using System.Diagnostics;
|
2008-11-28 22:20:17 +00:00
|
|
|
using CUETools.Processor;
|
2008-10-13 19:25:11 +00:00
|
|
|
|
|
|
|
|
namespace JDP
|
|
|
|
|
{
|
|
|
|
|
public partial class frmBatch : Form
|
|
|
|
|
{
|
|
|
|
|
public frmBatch()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_config = new CUEConfig();
|
2008-10-25 18:42:28 +00:00
|
|
|
_batchPaths = new List<string>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddInputPath(string path)
|
|
|
|
|
{
|
|
|
|
|
_batchPaths.Add(path);
|
2008-10-13 19:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string InputPath
|
|
|
|
|
{
|
|
|
|
|
get { return pathIn; }
|
|
|
|
|
set { pathIn = value; }
|
|
|
|
|
}
|
2008-12-01 20:24:16 +00:00
|
|
|
|
2009-08-06 13:03:02 +00:00
|
|
|
public string Profile
|
2008-10-13 19:25:11 +00:00
|
|
|
{
|
2009-08-06 13:03:02 +00:00
|
|
|
get { return _profileName; }
|
|
|
|
|
set { _profileName = value; }
|
2008-10-13 19:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-06 13:03:02 +00:00
|
|
|
CUEConfig _config;
|
|
|
|
|
CUEToolsProfile _profile = null;
|
|
|
|
|
string _profileName = "verify";
|
2008-10-13 19:25:11 +00:00
|
|
|
Thread _workThread;
|
|
|
|
|
CUESheet _workClass;
|
|
|
|
|
string pathIn;
|
|
|
|
|
string pathOut;
|
2008-11-18 14:48:26 +00:00
|
|
|
bool _reducePriority;
|
2008-10-13 19:25:11 +00:00
|
|
|
DateTime _startedAt;
|
2008-10-25 18:42:28 +00:00
|
|
|
List<string> _batchPaths;
|
2008-10-13 19:25:11 +00:00
|
|
|
|
2008-11-12 05:45:48 +00:00
|
|
|
public static string ShortenString(string input, int max)
|
2008-10-25 18:42:28 +00:00
|
|
|
{
|
|
|
|
|
if (input.Length < max)
|
|
|
|
|
return input;
|
|
|
|
|
return "..." + input.Substring(input.Length - max);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-12 05:45:48 +00:00
|
|
|
public void SetStatus(object sender, CUEToolsProgressEventArgs e)
|
2008-10-13 19:25:11 +00:00
|
|
|
{
|
|
|
|
|
this.BeginInvoke((MethodInvoker)delegate()
|
|
|
|
|
{
|
2008-11-12 05:45:48 +00:00
|
|
|
if (e.percentDisk == 0)
|
2008-10-13 19:25:11 +00:00
|
|
|
{
|
|
|
|
|
_startedAt = DateTime.Now;
|
2008-11-12 05:45:48 +00:00
|
|
|
Text = e.status;
|
2008-10-13 19:25:11 +00:00
|
|
|
}
|
2008-11-12 05:45:48 +00:00
|
|
|
else if (e.percentDisk > 0.02)
|
2008-10-13 19:25:11 +00:00
|
|
|
{
|
|
|
|
|
TimeSpan span = DateTime.Now - _startedAt;
|
2008-11-12 05:45:48 +00:00
|
|
|
TimeSpan eta = new TimeSpan ((long) (span.Ticks/e.percentDisk));
|
|
|
|
|
Text = String.Format("{0}, ETA {1}:{2:00}.", e.status, (int)eta.TotalMinutes, eta.Seconds);
|
2008-10-13 19:25:11 +00:00
|
|
|
} else
|
2008-11-12 05:45:48 +00:00
|
|
|
Text = e.status;
|
2008-12-07 23:12:01 +00:00
|
|
|
progressBar1.Value = Math.Max(0,Math.Min(100,(int)(e.percentTrck*100)));
|
|
|
|
|
progressBar2.Value = Math.Max(0,Math.Min(100,(int)(e.percentDisk*100)));
|
2008-11-12 05:45:48 +00:00
|
|
|
string inputSuffix = e.output != null ? "=>" : "";
|
|
|
|
|
if (e.input == null)
|
2008-10-25 18:42:28 +00:00
|
|
|
txtInputFile.Text = inputSuffix;
|
|
|
|
|
else
|
2008-11-12 05:45:48 +00:00
|
|
|
txtInputFile.Text = ShortenString(e.input, 120) + " " + inputSuffix;
|
|
|
|
|
if (e.output == null)
|
2008-10-25 18:42:28 +00:00
|
|
|
txtOutputFile.Text = "";
|
|
|
|
|
else
|
2008-11-12 05:45:48 +00:00
|
|
|
txtOutputFile.Text = ShortenString(e.output, 120);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PasswordRequired(object sender, ArchivePasswordRequiredEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Invoke((MethodInvoker)delegate()
|
|
|
|
|
{
|
|
|
|
|
frmPassword dlg = new frmPassword();
|
|
|
|
|
if (dlg.ShowDialog(this) == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
e.Password = dlg.txtPassword.Text;
|
|
|
|
|
e.ContinueOperation = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
e.ContinueOperation = false;
|
2008-10-13 19:25:11 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WriteAudioFilesThread(object o)
|
|
|
|
|
{
|
|
|
|
|
CUESheet cueSheet = (CUESheet)o;
|
2009-08-06 13:03:02 +00:00
|
|
|
CUEToolsScript script = _profile._script == null || !_config.scripts.ContainsKey(_profile._script) ? null : _config.scripts[_profile._script];
|
2008-10-13 19:25:11 +00:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2008-11-12 05:45:48 +00:00
|
|
|
_startedAt = DateTime.Now;
|
|
|
|
|
if (_batchPaths.Count != 0)
|
|
|
|
|
pathIn = _batchPaths[0];
|
|
|
|
|
|
|
|
|
|
pathIn = Path.GetFullPath(pathIn);
|
|
|
|
|
|
2009-08-08 16:14:06 +00:00
|
|
|
this.Invoke((MethodInvoker)delegate()
|
|
|
|
|
{
|
|
|
|
|
textBox1.Text += "Processing " + pathIn + ":\r\n";
|
|
|
|
|
textBox1.Select(0, 0);
|
|
|
|
|
});
|
2008-11-12 05:45:48 +00:00
|
|
|
|
2009-08-06 13:03:02 +00:00
|
|
|
if (!File.Exists(pathIn) && !Directory.Exists(pathIn))
|
|
|
|
|
throw new Exception("Input CUE Sheet not found.");
|
2008-11-12 05:45:48 +00:00
|
|
|
|
2009-08-08 16:14:06 +00:00
|
|
|
if (_profile._action == CUEAction.CorrectFilenames)
|
|
|
|
|
throw new Exception("CorrectFilenames action not yet supported in commandline mode.");
|
|
|
|
|
if (_profile._action == CUEAction.CreateDummyCUE)
|
|
|
|
|
throw new Exception("CreateDummyCUE action not yet supported in commandline mode.");
|
|
|
|
|
|
|
|
|
|
bool useAR = _profile._action == CUEAction.Verify || _profile._useAccurateRip;
|
|
|
|
|
|
2009-08-06 13:03:02 +00:00
|
|
|
cueSheet.Action = _profile._action;
|
|
|
|
|
cueSheet.OutputStyle = _profile._CUEStyle;
|
|
|
|
|
cueSheet.WriteOffset = _profile._writeOffset;
|
2008-12-09 07:25:48 +00:00
|
|
|
cueSheet.Open(pathIn);
|
2009-08-08 16:14:06 +00:00
|
|
|
if (useAR)
|
|
|
|
|
cueSheet.UseAccurateRip();
|
2009-08-06 13:03:02 +00:00
|
|
|
|
|
|
|
|
pathOut = CUESheet.GenerateUniqueOutputPath(_config,
|
|
|
|
|
_profile._outputTemplate,
|
|
|
|
|
_profile._CUEStyle == CUEStyle.SingleFileWithCUE ? "." + _profile._outputAudioFormat : ".cue",
|
|
|
|
|
_profile._action,
|
|
|
|
|
new NameValueCollection(),
|
|
|
|
|
pathIn,
|
|
|
|
|
cueSheet);
|
|
|
|
|
if (pathOut == "" || (_profile._action != CUEAction.Verify && File.Exists(pathOut)))
|
|
|
|
|
throw new Exception("Could not generate output path.");
|
|
|
|
|
|
|
|
|
|
cueSheet.GenerateFilenames(_profile._outputAudioType, _profile._outputAudioFormat, pathOut);
|
2008-11-12 05:45:48 +00:00
|
|
|
cueSheet.UsePregapForFirstTrackInSingleFile = false;
|
2009-08-08 16:14:06 +00:00
|
|
|
|
2009-08-06 13:03:02 +00:00
|
|
|
if (script == null)
|
|
|
|
|
cueSheet.Go();
|
|
|
|
|
else
|
|
|
|
|
/* status = */ cueSheet.ExecuteScript(script);
|
2008-10-13 19:25:11 +00:00
|
|
|
this.Invoke((MethodInvoker)delegate()
|
|
|
|
|
{
|
2008-10-25 18:42:28 +00:00
|
|
|
if (_batchPaths.Count == 0)
|
2008-10-13 19:25:11 +00:00
|
|
|
Text = "Done.";
|
2008-10-25 18:42:28 +00:00
|
|
|
|
|
|
|
|
//TimeSpan span = DateTime.Now - _startedAt;
|
|
|
|
|
progressBar1.Value = 0;
|
|
|
|
|
progressBar2.Value = 0;
|
2008-12-02 03:03:08 +00:00
|
|
|
if (cueSheet.IsCD)
|
|
|
|
|
{
|
2009-03-04 21:30:56 +00:00
|
|
|
textBox1.Text += cueSheet.LOGContents;
|
2008-12-02 03:03:08 +00:00
|
|
|
textBox1.Show();
|
|
|
|
|
}
|
2009-08-08 16:14:06 +00:00
|
|
|
else if (useAR)
|
2008-10-25 18:42:28 +00:00
|
|
|
{
|
|
|
|
|
StringWriter sw = new StringWriter();
|
|
|
|
|
cueSheet.GenerateAccurateRipLog(sw);
|
|
|
|
|
textBox1.Text += sw.ToString();
|
|
|
|
|
sw.Close();
|
|
|
|
|
textBox1.Show();
|
2008-10-13 19:25:11 +00:00
|
|
|
}
|
2008-10-25 18:42:28 +00:00
|
|
|
textBox1.Text += "----------------------------------------------------------\r\n";
|
|
|
|
|
textBox1.Select(0, 0);
|
2008-10-13 19:25:11 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (StopException)
|
|
|
|
|
{
|
2008-10-25 18:42:28 +00:00
|
|
|
_batchPaths.Clear();
|
2008-10-13 19:25:11 +00:00
|
|
|
this.Invoke((MethodInvoker)delegate()
|
|
|
|
|
{
|
|
|
|
|
Text = "Aborted.";
|
2008-10-25 18:42:28 +00:00
|
|
|
textBox1.Text += "Aborted.";
|
2008-10-13 19:25:11 +00:00
|
|
|
progressBar1.Value = 0;
|
|
|
|
|
progressBar2.Value = 0;
|
|
|
|
|
});
|
|
|
|
|
}
|
2008-11-07 22:43:26 +00:00
|
|
|
#if !DEBUG
|
2008-10-13 19:25:11 +00:00
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
this.Invoke((MethodInvoker)delegate()
|
|
|
|
|
{
|
|
|
|
|
Text = "Error: " + ex.Message;
|
2008-10-25 18:42:28 +00:00
|
|
|
textBox1.Show();
|
2008-11-12 05:45:48 +00:00
|
|
|
textBox1.Text += "Error";
|
|
|
|
|
for (Exception e = ex; e != null; e = e.InnerException)
|
|
|
|
|
textBox1.Text += ": " + e.Message;
|
|
|
|
|
textBox1.Text += "\r\n----------------------------------------------------------\r\n";
|
2008-10-25 18:42:28 +00:00
|
|
|
textBox1.Select(0, 0);
|
2008-10-13 19:25:11 +00:00
|
|
|
});
|
|
|
|
|
}
|
2008-11-07 22:43:26 +00:00
|
|
|
#endif
|
2008-10-13 19:25:11 +00:00
|
|
|
|
2008-10-25 18:42:28 +00:00
|
|
|
if (_batchPaths.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
_batchPaths.RemoveAt(0);
|
|
|
|
|
this.BeginInvoke((MethodInvoker)delegate()
|
|
|
|
|
{
|
|
|
|
|
if (_batchPaths.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
Text = "All done.";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
StartConvert();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2008-10-13 19:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartConvert()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2008-11-12 05:45:48 +00:00
|
|
|
CUESheet cueSheet = new CUESheet(_config);
|
|
|
|
|
cueSheet.PasswordRequired += new ArchivePasswordRequiredHandler(PasswordRequired);
|
|
|
|
|
cueSheet.CUEToolsProgress += new CUEToolsProgressHandler(SetStatus);
|
2008-10-13 19:25:11 +00:00
|
|
|
|
|
|
|
|
_workThread = new Thread(WriteAudioFilesThread);
|
|
|
|
|
_workClass = cueSheet;
|
2008-10-22 11:45:53 +00:00
|
|
|
_workThread.Priority = ThreadPriority.BelowNormal;
|
|
|
|
|
_workThread.IsBackground = true;
|
2008-10-13 19:25:11 +00:00
|
|
|
_workThread.Start(cueSheet);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Text = "Error: " + ex.Message;
|
2008-10-25 18:42:28 +00:00
|
|
|
textBox1.Show();
|
|
|
|
|
textBox1.Text += "Error: " + ex.Message + "\r\n";
|
|
|
|
|
textBox1.Text += "----------------------------------------------------------\r\n";
|
|
|
|
|
textBox1.Select(0, 0);
|
|
|
|
|
}
|
2008-10-13 19:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void frmBatch_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
textBox1.Hide();
|
2009-05-01 15:16:26 +00:00
|
|
|
SettingsReader sr = new SettingsReader("CUE Tools", "settings.txt", Application.ExecutablePath);
|
2008-11-18 14:48:26 +00:00
|
|
|
_config.Load(sr);
|
|
|
|
|
_reducePriority = sr.LoadBoolean("ReducePriority") ?? true;
|
2009-08-06 13:03:02 +00:00
|
|
|
|
|
|
|
|
_profile = new CUEToolsProfile(_profileName);
|
|
|
|
|
sr = new SettingsReader("CUE Tools", string.Format("profile-{0}.txt", _profileName), Application.ExecutablePath);
|
|
|
|
|
_profile.Load(sr);
|
2008-11-18 14:48:26 +00:00
|
|
|
|
|
|
|
|
if (_reducePriority)
|
2008-11-08 16:47:23 +00:00
|
|
|
Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Idle;
|
|
|
|
|
|
2009-08-06 13:03:02 +00:00
|
|
|
if (_profile._action != CUEAction.Verify)
|
2008-10-25 18:42:28 +00:00
|
|
|
txtOutputFile.Show();
|
|
|
|
|
|
2008-10-13 19:25:11 +00:00
|
|
|
StartConvert();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void frmBatch_FormClosing(Object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if ((_workThread != null) && (_workThread.IsAlive))
|
|
|
|
|
{
|
|
|
|
|
_workClass.Stop();
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|