mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
CUETools.Processor refactoring work in progress.
This commit is contained in:
@@ -78,11 +78,51 @@ namespace CUETools.Processor
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Events
|
#region Properties
|
||||||
|
|
||||||
public event EventHandler<CompressionPasswordRequiredEventArgs> PasswordRequired;
|
public string InputPath
|
||||||
public event EventHandler<CUEToolsProgressEventArgs> CUEToolsProgress;
|
{
|
||||||
public event EventHandler<CUEToolsSelectionEventArgs> CUEToolsSelection;
|
get
|
||||||
|
{
|
||||||
|
return _inputPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AccurateRipVerify ArVerify
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _arVerify;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CUEToolsDB CTDB
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _CUEToolsDB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ICDRipper CDRipper
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _ripper;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_ripper = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CUEMetadata Metadata
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return cueMetadata;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -161,42 +201,6 @@ namespace CUETools.Processor
|
|||||||
_ripper = null;
|
_ripper = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string InputPath
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _inputPath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccurateRipVerify ArVerify
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _arVerify;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CUEToolsDB CTDB
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _CUEToolsDB;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICDRipper CDRipper
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _ripper;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_ripper = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CopyMetadata(CUEMetadata metadata)
|
public void CopyMetadata(CUEMetadata metadata)
|
||||||
{
|
{
|
||||||
if (this.cueMetadata == null)
|
if (this.cueMetadata == null)
|
||||||
@@ -204,14 +208,6 @@ namespace CUETools.Processor
|
|||||||
this.cueMetadata.CopyMetadata(metadata);
|
this.cueMetadata.CopyMetadata(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CUEMetadata Metadata
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return cueMetadata;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void ReportProgress(string status, double percent)
|
protected void ReportProgress(string status, double percent)
|
||||||
{
|
{
|
||||||
ShowProgress(status, percent, null, null);
|
ShowProgress(status, percent, null, null);
|
||||||
@@ -311,7 +307,7 @@ namespace CUETools.Processor
|
|||||||
{
|
{
|
||||||
TagLib.File fileInfo;
|
TagLib.File fileInfo;
|
||||||
TagLib.UserDefined.AdditionalFileTypes.Config = _config;
|
TagLib.UserDefined.AdditionalFileTypes.Config = _config;
|
||||||
TagLib.File.IFileAbstraction file = (TagLib.File.IFileAbstraction)new TagLib.File.LocalFileAbstraction(path);
|
TagLib.File.IFileAbstraction file = new TagLib.File.LocalFileAbstraction(path);
|
||||||
fileInfo = TagLib.File.Create(file);
|
fileInfo = TagLib.File.Create(file);
|
||||||
NameValueCollection tags = Tagging.Analyze(fileInfo);
|
NameValueCollection tags = Tagging.Analyze(fileInfo);
|
||||||
if (tags.Get("CUESHEET") == null)
|
if (tags.Get("CUESHEET") == null)
|
||||||
@@ -493,112 +489,6 @@ namespace CUETools.Processor
|
|||||||
return tocFromCDEntry;
|
return tocFromCDEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CDImageLayout TocFromLog(string eacLog)
|
|
||||||
{
|
|
||||||
CDImageLayout tocFromLog = new CDImageLayout();
|
|
||||||
using (StringReader sr = new StringReader(eacLog))
|
|
||||||
{
|
|
||||||
bool isEACLog = false;
|
|
||||||
bool iscdda2wavlog = false;
|
|
||||||
string lineStr;
|
|
||||||
int prevTrNo = 1, prevTrStart = 0;
|
|
||||||
uint firstPreGap = 0;
|
|
||||||
while ((lineStr = sr.ReadLine()) != null)
|
|
||||||
{
|
|
||||||
if (isEACLog)
|
|
||||||
{
|
|
||||||
string[] n = lineStr.Split('|');
|
|
||||||
uint trNo, trStart, trEnd;
|
|
||||||
if (n.Length == 5 && uint.TryParse(n[0], out trNo) && uint.TryParse(n[3], out trStart) && uint.TryParse(n[4], out trEnd) && trNo == tocFromLog.TrackCount + 1)
|
|
||||||
{
|
|
||||||
bool isAudio = true;
|
|
||||||
if (tocFromLog.TrackCount >= _toc.TrackCount &&
|
|
||||||
trStart == tocFromLog[tocFromLog.TrackCount].End + 1U + 152U * 75U
|
|
||||||
)
|
|
||||||
isAudio = false;
|
|
||||||
if (tocFromLog.TrackCount < _toc.TrackCount &&
|
|
||||||
!_toc[tocFromLog.TrackCount + 1].IsAudio
|
|
||||||
)
|
|
||||||
isAudio = false;
|
|
||||||
tocFromLog.AddTrack(new CDTrack(trNo, trStart, trEnd + 1 - trStart, isAudio, false));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string[] sepTrack = { "Track" };
|
|
||||||
string[] sepGap = { "Pre-gap length" };
|
|
||||||
|
|
||||||
string[] partsTrack = lineStr.Split(sepTrack, StringSplitOptions.None);
|
|
||||||
if (partsTrack.Length == 2 && uint.TryParse(partsTrack[1], out trNo))
|
|
||||||
{
|
|
||||||
prevTrNo = (int)trNo;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
string[] partsGap = lineStr.Split(sepGap, StringSplitOptions.None);
|
|
||||||
if (partsGap.Length == 2)
|
|
||||||
{
|
|
||||||
string[] n1 = partsGap[1].Split(':', '.');
|
|
||||||
int h, m, s, f;
|
|
||||||
if (n1.Length == 4 && int.TryParse(n1[0], out h) && int.TryParse(n1[1], out m) && int.TryParse(n1[2], out s) && int.TryParse(n1[3], out f))
|
|
||||||
{
|
|
||||||
uint gap = (uint)((f * 3 + 2) / 4 + 75 * (s + 60 * (m + 60 * h)));
|
|
||||||
if (prevTrNo == 1)
|
|
||||||
gap -= 150;
|
|
||||||
if (prevTrNo == 1)
|
|
||||||
firstPreGap = gap - _toc[1].Start;
|
|
||||||
//else
|
|
||||||
//firstPreGap += gap;
|
|
||||||
while (prevTrNo > tocFromLog.TrackCount && _toc.TrackCount > tocFromLog.TrackCount)
|
|
||||||
{
|
|
||||||
tocFromLog.AddTrack(new CDTrack((uint)tocFromLog.TrackCount + 1,
|
|
||||||
_toc[tocFromLog.TrackCount + 1].Start + firstPreGap,
|
|
||||||
_toc[tocFromLog.TrackCount + 1].Length,
|
|
||||||
_toc[tocFromLog.TrackCount + 1].IsAudio, false));
|
|
||||||
}
|
|
||||||
if (prevTrNo <= tocFromLog.TrackCount)
|
|
||||||
tocFromLog[prevTrNo].Pregap = gap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (iscdda2wavlog)
|
|
||||||
{
|
|
||||||
foreach (string entry in lineStr.Split(','))
|
|
||||||
{
|
|
||||||
string[] n = entry.Split('(');
|
|
||||||
if (n.Length < 2) continue;
|
|
||||||
// assert n.Length == 2;
|
|
||||||
string key = n[0].Trim(' ', '.');
|
|
||||||
int trStart = int.Parse(n[1].Trim(' ', ')'));
|
|
||||||
bool isAudio = true; // !!!
|
|
||||||
if (key != "1")
|
|
||||||
tocFromLog.AddTrack(new CDTrack((uint)prevTrNo, (uint)prevTrStart, (uint)(trStart - prevTrStart), isAudio, false));
|
|
||||||
if (key == "lead-out")
|
|
||||||
{
|
|
||||||
iscdda2wavlog = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
prevTrNo = int.Parse(key);
|
|
||||||
prevTrStart = trStart;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (lineStr.StartsWith("TOC of the extracted CD")
|
|
||||||
|| lineStr.StartsWith("Exact Audio Copy")
|
|
||||||
|| lineStr.StartsWith("EAC extraction logfile")
|
|
||||||
|| lineStr.StartsWith("CUERipper")
|
|
||||||
|| lineStr.StartsWith(" Track | Start | Length | Start sector | End sector")
|
|
||||||
)
|
|
||||||
isEACLog = true;
|
|
||||||
else if (lineStr.StartsWith("Table of Contents: starting sectors"))
|
|
||||||
iscdda2wavlog = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tocFromLog.TrackCount == 0)
|
|
||||||
return null;
|
|
||||||
tocFromLog[1][0].Start = 0;
|
|
||||||
return tocFromLog;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Open(string pathIn)
|
public void Open(string pathIn)
|
||||||
{
|
{
|
||||||
_inputPath = pathIn;
|
_inputPath = pathIn;
|
||||||
@@ -802,9 +692,9 @@ namespace CUETools.Processor
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_isArchive)
|
if (_isArchive)
|
||||||
pathAudio = LocateFile(_archiveCUEpath, line.Params[1], _archiveContents);
|
pathAudio = FileLocator.LocateFile(_archiveCUEpath, line.Params[1], _archiveContents);
|
||||||
else
|
else
|
||||||
pathAudio = LocateFile(_inputDir, line.Params[1], null);
|
pathAudio = FileLocator.LocateFile(_inputDir, line.Params[1], null);
|
||||||
fileIsBinary = (pathAudio == null);
|
fileIsBinary = (pathAudio == null);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
@@ -817,9 +707,9 @@ namespace CUETools.Processor
|
|||||||
if (!_hasEmbeddedCUESheet)
|
if (!_hasEmbeddedCUESheet)
|
||||||
{
|
{
|
||||||
if (_isArchive)
|
if (_isArchive)
|
||||||
pathAudio = LocateFile(_archiveCUEpath, line.Params[1], _archiveContents);
|
pathAudio = FileLocator.LocateFile(_archiveCUEpath, line.Params[1], _archiveContents);
|
||||||
else
|
else
|
||||||
pathAudio = LocateFile(_inputDir, line.Params[1], null);
|
pathAudio = FileLocator.LocateFile(_inputDir, line.Params[1], null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1134,7 +1024,7 @@ namespace CUETools.Processor
|
|||||||
{
|
{
|
||||||
foreach (CUEToolsSourceFile sf in _logFiles)
|
foreach (CUEToolsSourceFile sf in _logFiles)
|
||||||
{
|
{
|
||||||
CDImageLayout tocFromLog1 = TocFromLog(sf.contents);
|
CDImageLayout tocFromLog1 = LogToTocParser.LogToToc(this._toc, sf.contents);
|
||||||
if (tocFromLog1 != null && tocFromLog1.TOCID == _toc.TOCID)
|
if (tocFromLog1 != null && tocFromLog1.TOCID == _toc.TOCID)
|
||||||
{
|
{
|
||||||
if (_eacLog == null)
|
if (_eacLog == null)
|
||||||
@@ -1154,13 +1044,15 @@ namespace CUETools.Processor
|
|||||||
_eacLog = selectedLogFile != null ? selectedLogFile.contents : null;
|
_eacLog = selectedLogFile != null ? selectedLogFile.contents : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
CDImageLayout tocFromLog = _eacLog == null ? null : TocFromLog(_eacLog);
|
CDImageLayout tocFromLog = _eacLog == null ? null : LogToTocParser.LogToToc(this._toc, _eacLog);
|
||||||
|
|
||||||
if (tocFromLog == null)
|
if (tocFromLog == null)
|
||||||
{
|
{
|
||||||
string tocPath = Path.ChangeExtension(InputPath, ".toc");
|
string tocPath = Path.ChangeExtension(InputPath, ".toc");
|
||||||
if (File.Exists(tocPath))
|
if (File.Exists(tocPath))
|
||||||
tocFromLog = TocFromLog((new StreamReader(tocPath, CUESheet.Encoding)).ReadToEnd());
|
{
|
||||||
|
tocFromLog = LogToTocParser.LogToToc(this._toc, new StreamReader(tocPath, CUESheet.Encoding).ReadToEnd());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use pregaps from log
|
// use pregaps from log
|
||||||
@@ -1542,46 +1434,6 @@ namespace CUETools.Processor
|
|||||||
return GetCommonTag(delegate(TagLib.File file) { return Tagging.TagListToSingleValue(Tagging.GetMiscTag(file, tagName)); });
|
return GetCommonTag(delegate(TagLib.File file) { return Tagging.TagListToSingleValue(Tagging.GetMiscTag(file, tagName)); });
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string LocateFile(string dir, string file, List<string> contents)
|
|
||||||
{
|
|
||||||
List<string> dirList, fileList;
|
|
||||||
string altDir;
|
|
||||||
|
|
||||||
dirList = new List<string>();
|
|
||||||
fileList = new List<string>();
|
|
||||||
altDir = Path.GetDirectoryName(file);
|
|
||||||
file = Path.GetFileName(file);
|
|
||||||
|
|
||||||
dirList.Add(dir);
|
|
||||||
if (altDir.Length != 0)
|
|
||||||
{
|
|
||||||
dirList.Add(Path.IsPathRooted(altDir) ? altDir : Path.Combine(dir, altDir));
|
|
||||||
}
|
|
||||||
|
|
||||||
fileList.Add(file);
|
|
||||||
fileList.Add(file.Replace(' ', '_'));
|
|
||||||
fileList.Add(file.Replace('_', ' '));
|
|
||||||
|
|
||||||
for (int iDir = 0; iDir < dirList.Count; iDir++)
|
|
||||||
{
|
|
||||||
for (int iFile = 0; iFile < fileList.Count; iFile++)
|
|
||||||
{
|
|
||||||
string path = Path.Combine(dirList[iDir], fileList[iFile]);
|
|
||||||
if (contents == null && System.IO.File.Exists(path))
|
|
||||||
return path;
|
|
||||||
if (contents != null)
|
|
||||||
{
|
|
||||||
List<string> matching = contents.FindAll(s => s.ToLower().Replace('/', Path.DirectorySeparatorChar) ==
|
|
||||||
path.ToLower().Replace('/', Path.DirectorySeparatorChar));
|
|
||||||
if (matching.Count == 1)
|
|
||||||
return matching[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool IsCDROM(string pathIn)
|
private static bool IsCDROM(string pathIn)
|
||||||
{
|
{
|
||||||
return pathIn.Length == 3 && pathIn.Substring(1) == ":\\" && new DriveInfo(pathIn).DriveType == DriveType.CDRom;
|
return pathIn.Length == 3 && pathIn.Substring(1) == ":\\" && new DriveInfo(pathIn).DriveType == DriveType.CDRom;
|
||||||
@@ -3552,7 +3404,7 @@ namespace CUETools.Processor
|
|||||||
//}
|
//}
|
||||||
filePos.Add(lines.Count - 1);
|
filePos.Add(lines.Count - 1);
|
||||||
origFiles.Add(line.Params[1]);
|
origFiles.Add(line.Params[1]);
|
||||||
foundAll &= (LocateFile(dir, line.Params[1], files) != null);
|
foundAll &= (FileLocator.LocateFile(dir, line.Params[1], files) != null);
|
||||||
}
|
}
|
||||||
if (line.Params.Count == 3 && line.Params[0].ToUpper() == "REM" && line.Params[1].ToUpper() == "DISCID")
|
if (line.Params.Count == 3 && line.Params[0].ToUpper() == "REM" && line.Params[1].ToUpper() == "DISCID")
|
||||||
CDDBID = line.Params[2].ToLower();
|
CDDBID = line.Params[2].ToLower();
|
||||||
@@ -3573,7 +3425,7 @@ namespace CUETools.Processor
|
|||||||
for (int j = 0; j < origFiles.Count; j++)
|
for (int j = 0; j < origFiles.Count; j++)
|
||||||
{
|
{
|
||||||
string newFilename = Path.ChangeExtension(Path.GetFileName(origFiles[j]), "." + format.Key);
|
string newFilename = Path.ChangeExtension(Path.GetFileName(origFiles[j]), "." + format.Key);
|
||||||
string locatedFilename = LocateFile(dir, newFilename, files);
|
string locatedFilename = FileLocator.LocateFile(dir, newFilename, files);
|
||||||
if (locatedFilename != null)
|
if (locatedFilename != null)
|
||||||
newFiles.Add(locatedFilename);
|
newFiles.Add(locatedFilename);
|
||||||
}
|
}
|
||||||
@@ -3664,7 +3516,6 @@ namespace CUETools.Processor
|
|||||||
private int[] CalculateAudioFileLengths(CUEStyle style)
|
private int[] CalculateAudioFileLengths(CUEStyle style)
|
||||||
{
|
{
|
||||||
int iTrack, iIndex, iFile;
|
int iTrack, iIndex, iFile;
|
||||||
TrackInfo track;
|
|
||||||
int[] fileLengths;
|
int[] fileLengths;
|
||||||
bool htoaToFile = (style == CUEStyle.GapsAppended && _config.preserveHTOA && _toc.Pregap != 0);
|
bool htoaToFile = (style == CUEStyle.GapsAppended && _config.preserveHTOA && _toc.Pregap != 0);
|
||||||
bool discardOutput;
|
bool discardOutput;
|
||||||
@@ -3682,8 +3533,6 @@ namespace CUETools.Processor
|
|||||||
|
|
||||||
for (iTrack = 0; iTrack < TrackCount; iTrack++)
|
for (iTrack = 0; iTrack < TrackCount; iTrack++)
|
||||||
{
|
{
|
||||||
track = _tracks[iTrack];
|
|
||||||
|
|
||||||
if (style == CUEStyle.GapsPrepended || style == CUEStyle.GapsLeftOut)
|
if (style == CUEStyle.GapsPrepended || style == CUEStyle.GapsLeftOut)
|
||||||
iFile++;
|
iFile++;
|
||||||
|
|
||||||
@@ -4508,5 +4357,13 @@ namespace CUETools.Processor
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
|
||||||
|
public event EventHandler<CompressionPasswordRequiredEventArgs> PasswordRequired;
|
||||||
|
public event EventHandler<CUEToolsProgressEventArgs> CUEToolsProgress;
|
||||||
|
public event EventHandler<CUEToolsSelectionEventArgs> CUEToolsSelection;
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,8 +100,10 @@
|
|||||||
<Compile Include="CUETrackMetadata.cs" />
|
<Compile Include="CUETrackMetadata.cs" />
|
||||||
<Compile Include="FileGroupInfo.cs" />
|
<Compile Include="FileGroupInfo.cs" />
|
||||||
<Compile Include="FileGroupInfoType.cs" />
|
<Compile Include="FileGroupInfoType.cs" />
|
||||||
|
<Compile Include="FileLocator.cs" />
|
||||||
<Compile Include="General.cs" />
|
<Compile Include="General.cs" />
|
||||||
<Compile Include="IndexInfo.cs" />
|
<Compile Include="IndexInfo.cs" />
|
||||||
|
<Compile Include="LogToTocParser.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Settings\SettingsReader.cs" />
|
<Compile Include="Settings\SettingsReader.cs" />
|
||||||
<Compile Include="Settings\SettingsShared.cs" />
|
<Compile Include="Settings\SettingsShared.cs" />
|
||||||
|
|||||||
48
CUETools.Processor/FileLocator.cs
Normal file
48
CUETools.Processor/FileLocator.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace CUETools.Processor
|
||||||
|
{
|
||||||
|
class FileLocator
|
||||||
|
{
|
||||||
|
public static string LocateFile(string dir, string file, List<string> contents)
|
||||||
|
{
|
||||||
|
List<string> dirList, fileList;
|
||||||
|
string altDir;
|
||||||
|
|
||||||
|
dirList = new List<string>();
|
||||||
|
fileList = new List<string>();
|
||||||
|
altDir = Path.GetDirectoryName(file);
|
||||||
|
file = Path.GetFileName(file);
|
||||||
|
|
||||||
|
dirList.Add(dir);
|
||||||
|
if (altDir.Length != 0)
|
||||||
|
{
|
||||||
|
dirList.Add(Path.IsPathRooted(altDir) ? altDir : Path.Combine(dir, altDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
fileList.Add(file);
|
||||||
|
fileList.Add(file.Replace(' ', '_'));
|
||||||
|
fileList.Add(file.Replace('_', ' '));
|
||||||
|
|
||||||
|
for (int iDir = 0; iDir < dirList.Count; iDir++)
|
||||||
|
{
|
||||||
|
for (int iFile = 0; iFile < fileList.Count; iFile++)
|
||||||
|
{
|
||||||
|
string path = Path.Combine(dirList[iDir], fileList[iFile]);
|
||||||
|
if (contents == null && System.IO.File.Exists(path))
|
||||||
|
return path;
|
||||||
|
if (contents != null)
|
||||||
|
{
|
||||||
|
List<string> matching = contents.FindAll(s => s.ToLower().Replace('/', Path.DirectorySeparatorChar) ==
|
||||||
|
path.ToLower().Replace('/', Path.DirectorySeparatorChar));
|
||||||
|
if (matching.Count == 1)
|
||||||
|
return matching[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
115
CUETools.Processor/LogToTocParser.cs
Normal file
115
CUETools.Processor/LogToTocParser.cs
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using CUETools.CDImage;
|
||||||
|
|
||||||
|
namespace CUETools.Processor
|
||||||
|
{
|
||||||
|
class LogToTocParser
|
||||||
|
{
|
||||||
|
public static CDImageLayout LogToToc(CDImageLayout toc, string eacLog)
|
||||||
|
{
|
||||||
|
CDImageLayout tocFromLog = new CDImageLayout();
|
||||||
|
using (StringReader sr = new StringReader(eacLog))
|
||||||
|
{
|
||||||
|
bool isEACLog = false;
|
||||||
|
bool iscdda2wavlog = false;
|
||||||
|
string lineStr;
|
||||||
|
int prevTrNo = 1, prevTrStart = 0;
|
||||||
|
uint firstPreGap = 0;
|
||||||
|
while ((lineStr = sr.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
if (isEACLog)
|
||||||
|
{
|
||||||
|
string[] n = lineStr.Split('|');
|
||||||
|
uint trNo, trStart, trEnd;
|
||||||
|
if (n.Length == 5 && uint.TryParse(n[0], out trNo) && uint.TryParse(n[3], out trStart) && uint.TryParse(n[4], out trEnd) && trNo == tocFromLog.TrackCount + 1)
|
||||||
|
{
|
||||||
|
bool isAudio = true;
|
||||||
|
if (tocFromLog.TrackCount >= toc.TrackCount &&
|
||||||
|
trStart == tocFromLog[tocFromLog.TrackCount].End + 1U + 152U * 75U
|
||||||
|
)
|
||||||
|
isAudio = false;
|
||||||
|
if (tocFromLog.TrackCount < toc.TrackCount &&
|
||||||
|
!toc[tocFromLog.TrackCount + 1].IsAudio
|
||||||
|
)
|
||||||
|
isAudio = false;
|
||||||
|
tocFromLog.AddTrack(new CDTrack(trNo, trStart, trEnd + 1 - trStart, isAudio, false));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string[] sepTrack = { "Track" };
|
||||||
|
string[] sepGap = { "Pre-gap length" };
|
||||||
|
|
||||||
|
string[] partsTrack = lineStr.Split(sepTrack, StringSplitOptions.None);
|
||||||
|
if (partsTrack.Length == 2 && uint.TryParse(partsTrack[1], out trNo))
|
||||||
|
{
|
||||||
|
prevTrNo = (int)trNo;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] partsGap = lineStr.Split(sepGap, StringSplitOptions.None);
|
||||||
|
if (partsGap.Length == 2)
|
||||||
|
{
|
||||||
|
string[] n1 = partsGap[1].Split(':', '.');
|
||||||
|
int h, m, s, f;
|
||||||
|
if (n1.Length == 4 && int.TryParse(n1[0], out h) && int.TryParse(n1[1], out m) && int.TryParse(n1[2], out s) && int.TryParse(n1[3], out f))
|
||||||
|
{
|
||||||
|
uint gap = (uint)((f * 3 + 2) / 4 + 75 * (s + 60 * (m + 60 * h)));
|
||||||
|
if (prevTrNo == 1)
|
||||||
|
gap -= 150;
|
||||||
|
if (prevTrNo == 1)
|
||||||
|
firstPreGap = gap - toc[1].Start;
|
||||||
|
//else
|
||||||
|
//firstPreGap += gap;
|
||||||
|
while (prevTrNo > tocFromLog.TrackCount && toc.TrackCount > tocFromLog.TrackCount)
|
||||||
|
{
|
||||||
|
tocFromLog.AddTrack(new CDTrack((uint)tocFromLog.TrackCount + 1,
|
||||||
|
toc[tocFromLog.TrackCount + 1].Start + firstPreGap,
|
||||||
|
toc[tocFromLog.TrackCount + 1].Length,
|
||||||
|
toc[tocFromLog.TrackCount + 1].IsAudio, false));
|
||||||
|
}
|
||||||
|
if (prevTrNo <= tocFromLog.TrackCount)
|
||||||
|
tocFromLog[prevTrNo].Pregap = gap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (iscdda2wavlog)
|
||||||
|
{
|
||||||
|
foreach (string entry in lineStr.Split(','))
|
||||||
|
{
|
||||||
|
string[] n = entry.Split('(');
|
||||||
|
if (n.Length < 2) continue;
|
||||||
|
// assert n.Length == 2;
|
||||||
|
string key = n[0].Trim(' ', '.');
|
||||||
|
int trStart = int.Parse(n[1].Trim(' ', ')'));
|
||||||
|
bool isAudio = true; // !!!
|
||||||
|
if (key != "1")
|
||||||
|
tocFromLog.AddTrack(new CDTrack((uint)prevTrNo, (uint)prevTrStart, (uint)(trStart - prevTrStart), isAudio, false));
|
||||||
|
if (key == "lead-out")
|
||||||
|
{
|
||||||
|
iscdda2wavlog = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
prevTrNo = int.Parse(key);
|
||||||
|
prevTrStart = trStart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (lineStr.StartsWith("TOC of the extracted CD")
|
||||||
|
|| lineStr.StartsWith("Exact Audio Copy")
|
||||||
|
|| lineStr.StartsWith("EAC extraction logfile")
|
||||||
|
|| lineStr.StartsWith("CUERipper")
|
||||||
|
|| lineStr.StartsWith(" Track | Start | Length | Start sector | End sector")
|
||||||
|
)
|
||||||
|
isEACLog = true;
|
||||||
|
else if (lineStr.StartsWith("Table of Contents: starting sectors"))
|
||||||
|
iscdda2wavlog = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tocFromLog.TrackCount == 0)
|
||||||
|
return null;
|
||||||
|
tocFromLog[1][0].Start = 0;
|
||||||
|
return tocFromLog;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user