diff --git a/ArCueDotNet/ArCueDotNet.csproj b/ArCueDotNet/ArCueDotNet.csproj index ed2bb1b..cc009e0 100644 --- a/ArCueDotNet/ArCueDotNet.csproj +++ b/ArCueDotNet/ArCueDotNet.csproj @@ -81,7 +81,7 @@ - + {4911BD82-49EF-4858-8B51-5394F86739A4} CUETools.Processor diff --git a/CUETools.AccurateRip/CUETools.AccurateRip.csproj b/CUETools.AccurateRip/CUETools.AccurateRip.csproj index a4823c0..3299464 100644 --- a/CUETools.AccurateRip/CUETools.AccurateRip.csproj +++ b/CUETools.AccurateRip/CUETools.AccurateRip.csproj @@ -87,7 +87,7 @@ - + {6458A13A-30EF-45A9-9D58-E5031B17BEE2} CUETools.Codecs diff --git a/FLACDotNet/AssemblyInfo.cpp b/CUETools.Codec.FLAC/AssemblyInfo.cpp similarity index 100% rename from FLACDotNet/AssemblyInfo.cpp rename to CUETools.Codec.FLAC/AssemblyInfo.cpp diff --git a/FLACDotNet/flacdotnet.cpp b/CUETools.Codec.FLAC/CUETools.Codecs.FLAC.cpp similarity index 96% rename from FLACDotNet/flacdotnet.cpp rename to CUETools.Codec.FLAC/CUETools.Codecs.FLAC.cpp index 4f091a0..2a348b0 100644 --- a/FLACDotNet/flacdotnet.cpp +++ b/CUETools.Codec.FLAC/CUETools.Codecs.FLAC.cpp @@ -181,7 +181,7 @@ namespace FLACDotNet { } } - virtual bool UpdateTags (bool preserveTime) + bool UpdateTags (bool preserveTime) { Close (); diff --git a/FLACDotNet/FLACDotNet.vcproj b/CUETools.Codec.FLAC/CUETools.Codecs.FLAC.vcproj similarity index 94% rename from FLACDotNet/FLACDotNet.vcproj rename to CUETools.Codec.FLAC/CUETools.Codecs.FLAC.vcproj index d11a418..4bafacb 100644 --- a/FLACDotNet/FLACDotNet.vcproj +++ b/CUETools.Codec.FLAC/CUETools.Codecs.FLAC.vcproj @@ -2,9 +2,9 @@ @@ -344,7 +344,7 @@ > diff --git a/APEDotNet/app.ico b/CUETools.Codec.FLAC/app.ico similarity index 100% rename from APEDotNet/app.ico rename to CUETools.Codec.FLAC/app.ico diff --git a/FLACDotNet/app.rc b/CUETools.Codec.FLAC/app.rc similarity index 100% rename from FLACDotNet/app.rc rename to CUETools.Codec.FLAC/app.rc diff --git a/FLACDotNet/cuesheet.c b/CUETools.Codec.FLAC/cuesheet.c similarity index 100% rename from FLACDotNet/cuesheet.c rename to CUETools.Codec.FLAC/cuesheet.c diff --git a/APEDotNet/resource.h b/CUETools.Codec.FLAC/resource.h similarity index 100% rename from APEDotNet/resource.h rename to CUETools.Codec.FLAC/resource.h diff --git a/ALACDotNet/ALACDotNet.cs b/CUETools.Codecs.ALAC/ALACDotNet.cs similarity index 100% rename from ALACDotNet/ALACDotNet.cs rename to CUETools.Codecs.ALAC/ALACDotNet.cs diff --git a/ALACDotNet/CUETools.Codecs.ALAC.csproj b/CUETools.Codecs.ALAC/CUETools.Codecs.ALAC.csproj similarity index 96% rename from ALACDotNet/CUETools.Codecs.ALAC.csproj rename to CUETools.Codecs.ALAC/CUETools.Codecs.ALAC.csproj index 41281b4..117f506 100644 --- a/ALACDotNet/CUETools.Codecs.ALAC.csproj +++ b/CUETools.Codecs.ALAC/CUETools.Codecs.ALAC.csproj @@ -87,7 +87,7 @@ - + {6458A13A-30EF-45A9-9D58-E5031B17BEE2} CUETools.Codecs diff --git a/ALACDotNet/Properties/AssemblyInfo.cs b/CUETools.Codecs.ALAC/Properties/AssemblyInfo.cs similarity index 100% rename from ALACDotNet/Properties/AssemblyInfo.cs rename to CUETools.Codecs.ALAC/Properties/AssemblyInfo.cs diff --git a/APEDotNet/AssemblyInfo.cpp b/CUETools.Codecs.APE/AssemblyInfo.cpp similarity index 100% rename from APEDotNet/AssemblyInfo.cpp rename to CUETools.Codecs.APE/AssemblyInfo.cpp diff --git a/APEDotNet/apedotnet.cpp b/CUETools.Codecs.APE/CUETools.Codecs.APE.cpp similarity index 94% rename from APEDotNet/apedotnet.cpp rename to CUETools.Codecs.APE/CUETools.Codecs.APE.cpp index 93dcd48..a68b6b5 100644 --- a/APEDotNet/apedotnet.cpp +++ b/CUETools.Codecs.APE/CUETools.Codecs.APE.cpp @@ -229,16 +229,6 @@ namespace APEDotNet { } } - virtual bool UpdateTags(bool preserveTime) - { - Close (); - APETagDotNet^ apeTag = gcnew APETagDotNet (_path, true, false); - apeTag->SetStringTags (_tags, true); - apeTag->Save(); - apeTag->Close(); - return true; - } - virtual UInt32 Read([Out] array^ buff, UInt32 sampleCount) { UInt32 buffOffset = 0; diff --git a/APEDotNet/APEDotNet.h b/CUETools.Codecs.APE/CUETools.Codecs.APE.h similarity index 100% rename from APEDotNet/APEDotNet.h rename to CUETools.Codecs.APE/CUETools.Codecs.APE.h diff --git a/APEDotNet/APEDotNet.vcproj b/CUETools.Codecs.APE/CUETools.Codecs.APE.vcproj similarity index 93% rename from APEDotNet/APEDotNet.vcproj rename to CUETools.Codecs.APE/CUETools.Codecs.APE.vcproj index c35b71c..b1072e9 100644 --- a/APEDotNet/APEDotNet.vcproj +++ b/CUETools.Codecs.APE/CUETools.Codecs.APE.vcproj @@ -2,9 +2,9 @@ @@ -349,7 +349,7 @@ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > - + {6458A13A-30EF-45A9-9D58-E5031B17BEE2} CUETools.Codecs diff --git a/LossyWAVDotNet/LossyWAV.cs b/CUETools.Codecs.LossyWAV/LossyWAV.cs similarity index 100% rename from LossyWAVDotNet/LossyWAV.cs rename to CUETools.Codecs.LossyWAV/LossyWAV.cs diff --git a/LossyWAVDotNet/Properties/AssemblyInfo.cs b/CUETools.Codecs.LossyWAV/Properties/AssemblyInfo.cs similarity index 100% rename from LossyWAVDotNet/Properties/AssemblyInfo.cs rename to CUETools.Codecs.LossyWAV/Properties/AssemblyInfo.cs diff --git a/WavPackDotNet/AssemblyInfo.cpp b/CUETools.Codecs.WavPack/AssemblyInfo.cpp similarity index 100% rename from WavPackDotNet/AssemblyInfo.cpp rename to CUETools.Codecs.WavPack/AssemblyInfo.cpp diff --git a/WavPackDotNet/WavPackDotNet.cpp b/CUETools.Codecs.WavPack/CUETools.Codecs.WavPack.cpp similarity index 95% rename from WavPackDotNet/WavPackDotNet.cpp rename to CUETools.Codecs.WavPack/CUETools.Codecs.WavPack.cpp index a0bd2dc..df54ebf 100644 --- a/WavPackDotNet/WavPackDotNet.cpp +++ b/CUETools.Codecs.WavPack/CUETools.Codecs.WavPack.cpp @@ -172,20 +172,9 @@ namespace WavPackDotNet { } } - virtual bool UpdateTags(bool preserveTime) - { - Close (); - APETagDotNet^ apeTag = gcnew APETagDotNet (_path, true, false); - apeTag->SetStringTags (_tags, true); - apeTag->Save(); - apeTag->Close(); - return true; - } - virtual void Close() { - if (_wpc != NULL) - _wpc = WavpackCloseFile(_wpc); + _wpc = WavpackCloseFile(_wpc); if (_IO != nullptr) { _IO->Close (); diff --git a/WavPackDotNet/WavPackDotNet.vcproj b/CUETools.Codecs.WavPack/CUETools.Codecs.WavPack.vcproj similarity index 94% rename from WavPackDotNet/WavPackDotNet.vcproj rename to CUETools.Codecs.WavPack/CUETools.Codecs.WavPack.vcproj index de23456..14bbb48 100644 --- a/WavPackDotNet/WavPackDotNet.vcproj +++ b/CUETools.Codecs.WavPack/CUETools.Codecs.WavPack.vcproj @@ -2,9 +2,9 @@ @@ -352,7 +352,7 @@ > diff --git a/WavPackDotNet/app.ico b/CUETools.Codecs.WavPack/app.ico similarity index 100% rename from WavPackDotNet/app.ico rename to CUETools.Codecs.WavPack/app.ico diff --git a/WavPackDotNet/app.rc b/CUETools.Codecs.WavPack/app.rc similarity index 100% rename from WavPackDotNet/app.rc rename to CUETools.Codecs.WavPack/app.rc diff --git a/WavPackDotNet/resource.h b/CUETools.Codecs.WavPack/resource.h similarity index 100% rename from WavPackDotNet/resource.h rename to CUETools.Codecs.WavPack/resource.h diff --git a/AudioCodecsDotNet/CUETools.Codecs.csproj b/CUETools.Codecs/CUETools.Codecs.csproj similarity index 100% rename from AudioCodecsDotNet/CUETools.Codecs.csproj rename to CUETools.Codecs/CUETools.Codecs.csproj diff --git a/AudioCodecsDotNet/Codecs.cs b/CUETools.Codecs/Codecs.cs similarity index 100% rename from AudioCodecsDotNet/Codecs.cs rename to CUETools.Codecs/Codecs.cs diff --git a/AudioCodecsDotNet/Properties/AssemblyInfo.cs b/CUETools.Codecs/Properties/AssemblyInfo.cs similarity index 100% rename from AudioCodecsDotNet/Properties/AssemblyInfo.cs rename to CUETools.Codecs/Properties/AssemblyInfo.cs diff --git a/CUETools.Ripper.Console/CUERipper.csproj b/CUETools.Ripper.Console/CUERipper.csproj index 97254d0..e2013ee 100644 --- a/CUETools.Ripper.Console/CUERipper.csproj +++ b/CUETools.Ripper.Console/CUERipper.csproj @@ -81,7 +81,7 @@ - + {6458A13A-30EF-45A9-9D58-E5031B17BEE2} CUETools.Codecs @@ -97,7 +97,7 @@ {8CF07381-BEA2-4AFC-B3DD-9B2F21C65A3A} CUETools.Ripper.SCSI - + {E70FA90A-7012-4A52-86B5-362B699D1540} FLACDotNet diff --git a/CUETools.Ripper.SCSI/CUETools.Ripper.SCSI.csproj b/CUETools.Ripper.SCSI/CUETools.Ripper.SCSI.csproj index 9607ba5..af670bc 100644 --- a/CUETools.Ripper.SCSI/CUETools.Ripper.SCSI.csproj +++ b/CUETools.Ripper.SCSI/CUETools.Ripper.SCSI.csproj @@ -89,7 +89,7 @@ - + {6458A13A-30EF-45A9-9D58-E5031B17BEE2} CUETools.Codecs diff --git a/CUETools/CUETools.csproj b/CUETools/CUETools.csproj index e078fa2..0c6a2b5 100644 --- a/CUETools/CUETools.csproj +++ b/CUETools/CUETools.csproj @@ -185,7 +185,7 @@ - + {4911BD82-49EF-4858-8B51-5394F86739A4} CUETools.Processor diff --git a/CUETools/CUETools.sln b/CUETools/CUETools.sln index bed4e7e..8939518 100644 --- a/CUETools/CUETools.sln +++ b/CUETools/CUETools.sln @@ -3,12 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CUETools", "CUETools.csproj", "{EF351583-A9CD-4530-92C3-20AC02136BC2}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FLACDotNet", "..\FLACDotNet\FLACDotNet.vcproj", "{E70FA90A-7012-4A52-86B5-362B699D1540}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CUETools.Codecs.FLAC", "..\CUETools.Codec.FLAC\CUETools.Codecs.FLAC.vcproj", "{E70FA90A-7012-4A52-86B5-362B699D1540}" ProjectSection(ProjectDependencies) = postProject {4CEFBC84-C215-11DB-8314-0800200C9A66} = {4CEFBC84-C215-11DB-8314-0800200C9A66} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APEDotNet", "..\APEDotNet\APEDotNet.vcproj", "{9AE965C4-301E-4C01-B90F-297AF341ACC6}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CUETools.Codecs.APE", "..\CUETools.Codecs.APE\CUETools.Codecs.APE.vcproj", "{9AE965C4-301E-4C01-B90F-297AF341ACC6}" ProjectSection(ProjectDependencies) = postProject {0B9C97D4-61B8-4294-A1DF-BA90752A1779} = {0B9C97D4-61B8-4294-A1DF-BA90752A1779} {CA200BCB-DFC6-4153-9BD4-785BC768B26B} = {CA200BCB-DFC6-4153-9BD4-785BC768B26B} @@ -16,7 +16,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APEDotNet", "..\APEDotNet\A EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CodecLibs", "CodecLibs", "{8B179853-B7D6-479C-B8B2-6CBCE835D040}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WavPackDotNet", "..\WavPackDotNet\WavPackDotNet.vcproj", "{CC2E74B6-534A-43D8-9F16-AC03FE955000}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CUETools.Codecs.WavPack", "..\CUETools.Codecs.WavPack\CUETools.Codecs.WavPack.vcproj", "{CC2E74B6-534A-43D8-9F16-AC03FE955000}" ProjectSection(ProjectDependencies) = postProject {CA200BCB-DFC6-4153-9BD4-785BC768B26B} = {CA200BCB-DFC6-4153-9BD4-785BC768B26B} {5CCCB9CF-0384-458F-BA08-72B73866840F} = {5CCCB9CF-0384-458F-BA08-72B73866840F} @@ -34,7 +34,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libwavpack", "..\wavpack-4. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArCueDotNet", "..\ArCueDotNet\ArCueDotNet.csproj", "{A5A8D8FA-9E32-4010-8AAF-AE580C5AF728}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CUETools.Processor", "..\CUEToolsLib\CUETools.Processor.csproj", "{4911BD82-49EF-4858-8B51-5394F86739A4}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CUETools.Processor", "..\CUETools.Processor\CUETools.Processor.csproj", "{4911BD82-49EF-4858-8B51-5394F86739A4}" ProjectSection(ProjectDependencies) = postProject {9AE965C4-301E-4C01-B90F-297AF341ACC6} = {9AE965C4-301E-4C01-B90F-297AF341ACC6} {CC2E74B6-534A-43D8-9F16-AC03FE955000} = {CC2E74B6-534A-43D8-9F16-AC03FE955000} @@ -43,13 +43,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CUETools.Processor", "..\CU EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HDCDDotNet", "..\HDCDDotNet\HDCDDotNet.csproj", "{32338A04-5B6B-4C63-8EE7-C6400F73B5D7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CUETools.Codecs", "..\AudioCodecsDotNet\CUETools.Codecs.csproj", "{6458A13A-30EF-45A9-9D58-E5031B17BEE2}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CUETools.Codecs", "..\CUETools.Codecs\CUETools.Codecs.csproj", "{6458A13A-30EF-45A9-9D58-E5031B17BEE2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CUETools.Codecs.ALAC", "..\ALACDotNet\CUETools.Codecs.ALAC.csproj", "{F2EC7193-D5E5-4252-9803-5CEB407E910F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CUETools.Codecs.ALAC", "..\CUETools.Codecs.ALAC\CUETools.Codecs.ALAC.csproj", "{F2EC7193-D5E5-4252-9803-5CEB407E910F}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnRarDotNet", "..\UnRarDotNet\UnRarDotNet.csproj", "{8427CAA5-80B8-4952-9A68-5F3DFCFBDF40}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CUETools.Codecs.LossyWAV", "..\LossyWAVDotNet\CUETools.Codecs.LossyWAV.csproj", "{8A0426FA-0BC2-4C49-A6E5-1F9A68156F19}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CUETools.Codecs.LossyWAV", "..\CUETools.Codecs.LossyWAV\CUETools.Codecs.LossyWAV.csproj", "{8A0426FA-0BC2-4C49-A6E5-1F9A68156F19}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LossyWAVSharp", "..\LossyWAVSharp\LossyWAVSharp.csproj", "{A574F3B1-E38B-4EE4-9394-49D6E2DF52EA}" EndProject diff --git a/CUEToolsLib/AudioReadWrite.cs b/CUEToolsLib/AudioReadWrite.cs deleted file mode 100644 index a363fab..0000000 --- a/CUEToolsLib/AudioReadWrite.cs +++ /dev/null @@ -1,102 +0,0 @@ -using System; -using System.IO; -using FLACDotNet; -using WavPackDotNet; -using APEDotNet; -using CUETools.Codecs; -using CUETools.Codecs.ALAC; -using CUETools.Codecs.LossyWAV; -using System.Collections.Generic; -using System.Collections.Specialized; - -namespace CUETools.Processor -{ - public static class AudioReadWrite { - public static IAudioSource GetAudioSource(string path, Stream IO, string extension) - { - switch (extension) - { - case ".wav": - return new WAVReader(path, IO); - case ".m4a": - return new ALACReader(path, IO); -#if !MONO - case ".flac": - return new FLACReader(path, IO); - case ".wv": - return new WavPackReader(path, IO, null); - case ".ape": - return new APEReader(path, IO); -#endif - default: - throw new Exception("Unsupported audio type."); - } - } - - public static IAudioSource GetAudioSource(string path, Stream IO) - { - string extension = Path.GetExtension(path).ToLower(); - string filename = Path.GetFileNameWithoutExtension(path); - string secondExtension = Path.GetExtension(filename).ToLower(); - if (secondExtension != ".lossy" && secondExtension != ".lwcdf") - return GetAudioSource(path, IO, extension); - - string lossyPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(filename) + ".lossy" + extension); - string lwcdfPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(filename) + ".lwcdf" + extension); - IAudioSource lossySource = GetAudioSource(lossyPath, null, extension); - IAudioSource lwcdfSource = GetAudioSource(lwcdfPath, null, extension); - return new LossyWAVReader(lossySource, lwcdfSource); - } - - public static IAudioDest GetAudioDest(string path, int bitsPerSample, int channelCount, int sampleRate, long finalSampleCount, string extension, CUEConfig config) { - IAudioDest dest; - switch (extension) { - case ".wav": - dest = new WAVWriter(path, bitsPerSample, channelCount, sampleRate, null); - break; -#if !MONO - case ".flac": - dest = new FLACWriter(path, bitsPerSample, channelCount, sampleRate); - ((FLACWriter)dest).CompressionLevel = (int)config.flacCompressionLevel; - ((FLACWriter)dest).Verify = config.flacVerify; - break; - case ".wv": - dest = new WavPackWriter(path, bitsPerSample, channelCount, sampleRate); - ((WavPackWriter)dest).CompressionMode = config.wvCompressionMode; - ((WavPackWriter)dest).ExtraMode = config.wvExtraMode; - ((WavPackWriter)dest).MD5Sum = config.wvStoreMD5; - break; - case ".ape": - dest = new APEWriter(path, bitsPerSample, channelCount, sampleRate); - ((APEWriter)dest).CompressionLevel = (int)config.apeCompressionLevel; - break; - case ".dummy": - dest = new DummyWriter(path, bitsPerSample, channelCount, sampleRate); - break; -#endif - default: - throw new Exception("Unsupported audio type."); - } - dest.FinalSampleCount = finalSampleCount; - return dest; - } - - public static IAudioDest GetAudioDest(string path, long finalSampleCount, CUEConfig config) - { - string extension = Path.GetExtension(path).ToLower(); - string filename = Path.GetFileNameWithoutExtension(path); - if (Path.GetExtension(filename).ToLower() != ".lossy") - { - int bitsPerSample = (config.detectHDCD && config.decodeHDCD) ? (config.decodeHDCDto24bit ? 24 : 20) : 16; - return GetAudioDest(path, bitsPerSample, 2, 44100, finalSampleCount, extension, config); - } - - string lwcdfPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(filename) + ".lwcdf" + extension); - int destBitsPerSample = (config.detectHDCD && config.decodeHDCD) ? ((!config.decodeHDCDtoLW16 && config.decodeHDCDto24bit) ? 24 : 20) : 16; - int lossyBitsPerSample = (config.detectHDCD && config.decodeHDCD && !config.decodeHDCDtoLW16) ? 24 : 16; - IAudioDest lossyDest = GetAudioDest(path, lossyBitsPerSample, 2, 44100, finalSampleCount, extension, config); - IAudioDest lwcdfDest = GetAudioDest(lwcdfPath, destBitsPerSample, 2, 44100, finalSampleCount, extension, config); - return new LossyWAVWriter(lossyDest, lwcdfDest, destBitsPerSample, 2, 44100, config.lossyWAVQuality); - } - } -} \ No newline at end of file diff --git a/CUEToolsLib/CUETools.Processor.csproj b/CUEToolsLib/CUETools.Processor.csproj deleted file mode 100644 index 8cbb8de..0000000 --- a/CUEToolsLib/CUETools.Processor.csproj +++ /dev/null @@ -1,149 +0,0 @@ - - - Debug - AnyCPU - 8.0.50727 - 2.0 - {4911BD82-49EF-4858-8B51-5394F86739A4} - Library - Properties - CUETools.Processor - CUETools.Processor - - - true - full - false - ..\bin\win32\Debug\ - DEBUG;TRACE - prompt - 4 - true - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - true - - - true - ..\bin\win32\Debug\ - DEBUG;TRACE - full - x86 - C:\Program Files (x86)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules - true - GlobalSuppressions.cs - prompt - true - - - ..\bin\win32\Release\ - TRACE - true - true - pdbonly - x86 - C:\Program Files (x86)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules - true - GlobalSuppressions.cs - prompt - - - true - ..\bin\x64\Debug\ - DEBUG;TRACE - full - x64 - C:\Program Files (x86)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules - true - GlobalSuppressions.cs - prompt - true - - - ..\bin\x64\Release\ - TRACE - true - true - pdbonly - x64 - C:\Program Files (x86)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules - true - GlobalSuppressions.cs - prompt - - - - - - - - - - - - - - - {F2EC7193-D5E5-4252-9803-5CEB407E910F} - CUETools.Codecs.ALAC - - - {9AE965C4-301E-4C01-B90F-297AF341ACC6} - APEDotNet - - - {6458A13A-30EF-45A9-9D58-E5031B17BEE2} - CUETools.Codecs - - - {5802C7E9-157E-4124-946D-70B5AE48A5A1} - CUETools.AccurateRip - - - {1DD41038-D885-46C5-8DDE-E0B82F066584} - CUETools.CDImage - - - {8CF07381-BEA2-4AFC-B3DD-9B2F21C65A3A} - CUETools.Ripper.SCSI - - - {E70FA90A-7012-4A52-86B5-362B699D1540} - FLACDotNet - - - {32338A04-5B6B-4C63-8EE7-C6400F73B5D7} - HDCDDotNet - - - {8A0426FA-0BC2-4C49-A6E5-1F9A68156F19} - CUETools.Codecs.LossyWAV - - - {74C2036B-2C9B-4FC8-B7BD-AE81A8DCE533} - MusicBrainz - - - {8427CAA5-80B8-4952-9A68-5F3DFCFBDF40} - UnRarDotNet - - - {CC2E74B6-534A-43D8-9F16-AC03FE955000} - WavPackDotNet - - - - - \ No newline at end of file diff --git a/CUEToolsLib/Main.cs b/CUEToolsLib/Main.cs deleted file mode 100644 index 06c8f80..0000000 --- a/CUEToolsLib/Main.cs +++ /dev/null @@ -1,2636 +0,0 @@ -// **************************************************************************** -// -// CUE Tools -// Copyright (C) 2006-2007 Moitah (moitah@yahoo.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// **************************************************************************** - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Text; -using System.Globalization; -using System.IO; -using System.Net; -using System.Security.Cryptography; -using System.Threading; -using System.Xml; -using HDCDDotNet; -using CUETools.Codecs; -using CUETools.Codecs.LossyWAV; -using CUETools.CDImage; -using CUETools.AccurateRip; -using CUETools.Ripper.SCSI; -using MusicBrainz; -#if !MONO -using UnRarDotNet; -using FLACDotNet; -#endif - -namespace CUETools.Processor -{ - public enum OutputAudioFormat - { - WAV, - FLAC, - WavPack, - APE, - NoAudio - } - - public enum AccurateRipMode - { - None, - Verify, - VerifyThenConvert, - VerifyAndConvert - } - - public enum CUEStyle - { - SingleFileWithCUE, - SingleFile, - GapsPrepended, - GapsAppended, - GapsLeftOut - } - - public static class General { - public static string FormatExtension(OutputAudioFormat value) - { - switch (value) - { - case OutputAudioFormat.FLAC: return ".flac"; - case OutputAudioFormat.WavPack: return ".wv"; - case OutputAudioFormat.APE: return ".ape"; - case OutputAudioFormat.WAV: return ".wav"; - case OutputAudioFormat.NoAudio: return ".dummy"; - } - return ".wav"; - } - - public static CUELine FindCUELine(List list, string command) { - command = command.ToUpper(); - foreach (CUELine line in list) { - if (line.Params[0].ToUpper() == command) { - return line; - } - } - return null; - } - - public static CUELine FindCUELine(List list, string command, string command2) - { - command = command.ToUpper(); - command2 = command2.ToUpper(); - foreach (CUELine line in list) - { - if (line.Params.Count > 1 && line.Params[0].ToUpper() == command && line.Params[1].ToUpper() == command2) - { - return line; - } - } - return null; - } - - public static void SetCUELine(List list, string command, string value, bool quoted) - { - CUELine line = General.FindCUELine(list, command); - if (line == null) - { - line = new CUELine(); - line.Params.Add(command); line.IsQuoted.Add(false); - line.Params.Add(value); line.IsQuoted.Add(quoted); - list.Add(line); - } - else - { - line.Params[1] = value; - line.IsQuoted[1] = quoted; - } - } - - public static void SetCUELine(List list, string command, string command2, string value, bool quoted) - { - CUELine line = General.FindCUELine(list, command, command2); - if (line == null) - { - line = new CUELine(); - line.Params.Add(command); line.IsQuoted.Add(false); - line.Params.Add(command2); line.IsQuoted.Add(false); - line.Params.Add(value); line.IsQuoted.Add(quoted); - list.Add(line); - } - else - { - line.Params[2] = value; - line.IsQuoted[2] = quoted; - } - } - - public static string ReplaceMultiple(string s, List find, List replace) - { - if (find.Count != replace.Count) - { - throw new ArgumentException(); - } - StringBuilder sb; - int iChar, iFind; - string f; - bool found; - - sb = new StringBuilder(); - - for (iChar = 0; iChar < s.Length; iChar++) - { - found = false; - for (iFind = 0; iFind < find.Count; iFind++) - { - f = find[iFind]; - if ((f.Length <= (s.Length - iChar)) && (s.Substring(iChar, f.Length) == f)) - { - if (replace[iFind] == null) - { - return null; - } - sb.Append(replace[iFind]); - iChar += f.Length - 1; - found = true; - break; - } - } - - if (!found) - { - sb.Append(s[iChar]); - } - } - - return sb.ToString(); - } - - public static string EmptyStringToNull(string s) - { - return ((s != null) && (s.Length == 0)) ? null : s; - } - } - - public class CUEConfig { - public uint fixWhenConfidence; - public uint fixWhenPercent; - public uint encodeWhenConfidence; - public uint encodeWhenPercent; - public bool encodeWhenZeroOffset; - public bool writeArTagsOnVerify; - public bool writeArLogOnVerify; - public bool writeArTagsOnConvert; - public bool writeArLogOnConvert; - public bool fixOffset; - public bool noUnverifiedOutput; - public bool autoCorrectFilenames; - public bool flacVerify; - public uint flacCompressionLevel; - public uint apeCompressionLevel; - public bool preserveHTOA; - public int wvCompressionMode; - public int wvExtraMode; - public bool wvStoreMD5; - public bool keepOriginalFilenames; - public string trackFilenameFormat; - public string singleFilenameFormat; - public bool removeSpecial; - public string specialExceptions; - public bool replaceSpaces; - public bool embedLog; - public bool fillUpCUE; - public bool filenamesANSISafe; - public bool bruteForceDTL; - public bool detectHDCD; - public bool decodeHDCD; - public bool wait750FramesForHDCD; - public bool createM3U; - public bool createTOC; - public bool createCUEFileWhenEmbedded; - public bool truncate4608ExtraSamples; - public int lossyWAVQuality; - public bool decodeHDCDtoLW16; - public bool decodeHDCDto24bit; - - public CUEConfig() - { - fixWhenConfidence = 2; - fixWhenPercent = 51; - encodeWhenConfidence = 2; - encodeWhenPercent = 100; - encodeWhenZeroOffset = false; - fixOffset = false; - noUnverifiedOutput = false; - writeArTagsOnConvert = true; - writeArLogOnConvert = true; - writeArTagsOnVerify = false; - writeArLogOnVerify = true; - - autoCorrectFilenames = true; - flacVerify = false; - flacCompressionLevel = 8; - apeCompressionLevel = 2; - preserveHTOA = true; - wvCompressionMode = 1; - wvExtraMode = 0; - wvStoreMD5 = false; - keepOriginalFilenames = true; - trackFilenameFormat = "%N-%A-%T"; - singleFilenameFormat = "%F"; - removeSpecial = false; - specialExceptions = "-()"; - replaceSpaces = true; - embedLog = true; - fillUpCUE = true; - filenamesANSISafe = true; - bruteForceDTL = false; - detectHDCD = true; - wait750FramesForHDCD = true; - decodeHDCD = false; - createM3U = false; - createTOC = false; - createCUEFileWhenEmbedded = false; - truncate4608ExtraSamples = true; - lossyWAVQuality = 5; - decodeHDCDtoLW16 = false; - decodeHDCDto24bit = true; - } - - public void Save (SettingsWriter sw) - { - sw.Save("ArFixWhenConfidence", fixWhenConfidence); - sw.Save("ArFixWhenPercent", fixWhenPercent); - sw.Save("ArEncodeWhenConfidence", encodeWhenConfidence); - sw.Save("ArEncodeWhenPercent", encodeWhenPercent); - sw.Save("ArEncodeWhenZeroOffset", encodeWhenZeroOffset); - sw.Save("ArNoUnverifiedOutput", noUnverifiedOutput); - sw.Save("ArFixOffset", fixOffset); - sw.Save("ArWriteCRC", writeArTagsOnConvert); - sw.Save("ArWriteLog", writeArLogOnConvert); - sw.Save("ArWriteTagsOnVerify", writeArTagsOnVerify); - sw.Save("ArWriteLogOnVerify", writeArLogOnVerify); - - sw.Save("PreserveHTOA", preserveHTOA); - sw.Save("AutoCorrectFilenames", autoCorrectFilenames); - sw.Save("FLACCompressionLevel", flacCompressionLevel); - sw.Save("APECompressionLevel", apeCompressionLevel); - sw.Save("FLACVerify", flacVerify); - sw.Save("WVCompressionMode", wvCompressionMode); - sw.Save("WVExtraMode", wvExtraMode); - sw.Save("WVStoreMD5", wvStoreMD5); - sw.Save("KeepOriginalFilenames", keepOriginalFilenames); - sw.Save("SingleFilenameFormat", singleFilenameFormat); - sw.Save("TrackFilenameFormat", trackFilenameFormat); - sw.Save("RemoveSpecialCharacters", removeSpecial); - sw.Save("SpecialCharactersExceptions", specialExceptions); - sw.Save("ReplaceSpaces", replaceSpaces); - sw.Save("EmbedLog", embedLog); - sw.Save("FillUpCUE", fillUpCUE); - sw.Save("FilenamesANSISafe", filenamesANSISafe); - sw.Save("BruteForceDTL", bruteForceDTL); - sw.Save("DetectHDCD", detectHDCD); - sw.Save("Wait750FramesForHDCD", wait750FramesForHDCD); - sw.Save("DecodeHDCD", decodeHDCD); - sw.Save("CreateM3U", createM3U); - sw.Save("CreateTOC", createTOC); - sw.Save("CreateCUEFileWhenEmbedded", createCUEFileWhenEmbedded); - sw.Save("Truncate4608ExtraSamples", truncate4608ExtraSamples); - sw.Save("LossyWAVQuality", lossyWAVQuality); - sw.Save("DecodeHDCDToLossyWAV16", decodeHDCDtoLW16); - sw.Save("DecodeHDCDTo24bit", decodeHDCDto24bit); - } - - public void Load(SettingsReader sr) - { - fixWhenConfidence = sr.LoadUInt32("ArFixWhenConfidence", 1, 1000) ?? 2; - fixWhenPercent = sr.LoadUInt32("ArFixWhenPercent", 1, 100) ?? 51; - encodeWhenConfidence = sr.LoadUInt32("ArEncodeWhenConfidence", 1, 1000) ?? 2; - encodeWhenPercent = sr.LoadUInt32("ArEncodeWhenPercent", 1, 100) ?? 100; - encodeWhenZeroOffset = sr.LoadBoolean("ArEncodeWhenZeroOffset") ?? false; - noUnverifiedOutput = sr.LoadBoolean("ArNoUnverifiedOutput") ?? false; - fixOffset = sr.LoadBoolean("ArFixOffset") ?? false; - writeArTagsOnConvert = sr.LoadBoolean("ArWriteCRC") ?? true; - writeArLogOnConvert = sr.LoadBoolean("ArWriteLog") ?? true; - writeArTagsOnVerify = sr.LoadBoolean("ArWriteTagsOnVerify") ?? false; - writeArLogOnVerify = sr.LoadBoolean("ArWriteLogOnVerify") ?? true; - - preserveHTOA = sr.LoadBoolean("PreserveHTOA") ?? true; - autoCorrectFilenames = sr.LoadBoolean("AutoCorrectFilenames") ?? true; - flacCompressionLevel = sr.LoadUInt32("FLACCompressionLevel", 0, 8) ?? 8; - flacVerify = sr.LoadBoolean("FLACVerify") ?? false; - apeCompressionLevel = sr.LoadUInt32("APECompressionLevel", 1, 5) ?? 2; - wvCompressionMode = sr.LoadInt32("WVCompressionMode", 0, 3) ?? 1; - wvExtraMode = sr.LoadInt32("WVExtraMode", 0, 6) ?? 0; - wvStoreMD5 = sr.LoadBoolean("WVStoreMD5") ?? false; - keepOriginalFilenames = sr.LoadBoolean("KeepOriginalFilenames") ?? true; - singleFilenameFormat = sr.Load("SingleFilenameFormat") ?? "%F"; - trackFilenameFormat = sr.Load("TrackFilenameFormat") ?? "%N-%A-%T"; - removeSpecial = sr.LoadBoolean("RemoveSpecialCharacters") ?? false; - specialExceptions = sr.Load("SpecialCharactersExceptions") ?? "-()"; - replaceSpaces = sr.LoadBoolean("ReplaceSpaces") ?? true; - embedLog = sr.LoadBoolean("EmbedLog") ?? true; - fillUpCUE = sr.LoadBoolean("FillUpCUE") ?? true; - filenamesANSISafe = sr.LoadBoolean("FilenamesANSISafe") ?? true; - bruteForceDTL = sr.LoadBoolean("BruteForceDTL") ?? false; - detectHDCD = sr.LoadBoolean("DetectHDCD") ?? true; - wait750FramesForHDCD = sr.LoadBoolean("Wait750FramesForHDCD") ?? true; - decodeHDCD = sr.LoadBoolean("DecodeHDCD") ?? false; - createM3U = sr.LoadBoolean("CreateM3U") ?? false; - createTOC = sr.LoadBoolean("CreateTOC") ?? false; - createCUEFileWhenEmbedded = sr.LoadBoolean("CreateCUEFileWhenEmbedded") ?? false; - truncate4608ExtraSamples = sr.LoadBoolean("Truncate4608ExtraSamples") ?? true; - lossyWAVQuality = sr.LoadInt32("LossyWAVQuality", 0, 10) ?? 5; - decodeHDCDtoLW16 = sr.LoadBoolean("DecodeHDCDToLossyWAV16") ?? false; - decodeHDCDto24bit = sr.LoadBoolean("DecodeHDCDTo24bit") ?? true; - } - - public string CleanseString (string s) - { - StringBuilder sb = new StringBuilder(); - char[] invalid = Path.GetInvalidFileNameChars(); - - if (filenamesANSISafe) - s = Encoding.Default.GetString(Encoding.Default.GetBytes(s)); - - for (int i = 0; i < s.Length; i++) - { - char ch = s[i]; - if (filenamesANSISafe && removeSpecial && specialExceptions.IndexOf(ch) < 0 && !( - ((ch >= 'a') && (ch <= 'z')) || - ((ch >= 'A') && (ch <= 'Z')) || - ((ch >= '0') && (ch <= '9')) || - (ch == ' ') || (ch == '_'))) - ch = '_'; - if ((Array.IndexOf(invalid, ch) >= 0) || (replaceSpaces && ch == ' ')) - sb.Append("_"); - else - sb.Append(ch); - } - - return sb.ToString(); - } - } - - public class CUEToolsProgressEventArgs - { - public string status = string.Empty; - public double percentTrck = 0; - public double percentDisk = 0.0; - public string input = string.Empty; - public string output = string.Empty; - } - - public class ArchivePasswordRequiredEventArgs - { - public string Password = string.Empty; - public bool ContinueOperation = true; - } - - public delegate void CUEToolsProgressHandler(object sender, CUEToolsProgressEventArgs e); - public delegate void ArchivePasswordRequiredHandler(object sender, ArchivePasswordRequiredEventArgs e); - - public class CUESheet { - private bool _stop, _pause; - private List _attributes; - private List _tracks; - private List _sources; - private List _sourcePaths, _trackFilenames; - private string _htoaFilename, _singleFilename; - private bool _hasHTOAFilename, _hasTrackFilenames, _hasSingleFilename, _appliedWriteOffset; - private bool _hasEmbeddedCUESheet; - private bool _paddedToFrame, _truncated4608, _usePregapForFirstTrackInSingleFile; - private int _writeOffset; - private AccurateRipMode _accurateRipMode; - private uint? _dataTrackLength; - private uint? _minDataTrackLength; - private string _accurateRipId; - private string _accurateRipIdActual; - private string _mbDiscId; - private string _mbReleaseId; - private string _eacLog; - private string _cuePath; - private NameValueCollection _albumTags; - private const int _arOffsetRange = 5 * 588 - 1; - private HDCDDotNet.HDCDDotNet hdcdDecoder; - private bool _outputLossyWAV = false; - private CUEConfig _config; - private string _cddbDiscIdTag; - private bool _isCD; - private string _driveName; - private int _driveOffset; - private BitArray _cdErrors; - private bool _isArchive; - private List _archiveContents; - private string _archiveCUEpath; - private string _archivePath; - private string _archivePassword; - private CUEToolsProgressEventArgs _progress; - private AccurateRipVerify _arVerify; - - public event ArchivePasswordRequiredHandler PasswordRequired; - public event CUEToolsProgressHandler CUEToolsProgress; - - public CUESheet(CUEConfig config) - { - _config = config; - _progress = new CUEToolsProgressEventArgs(); - _attributes = new List(); - _tracks = new List(); - _trackFilenames = new List(); - _toc = new CDImageLayout(); - _sources = new List(); - _sourcePaths = new List(); - _albumTags = new NameValueCollection(); - _stop = false; - _pause = false; - _cuePath = null; - _paddedToFrame = false; - _truncated4608 = false; - _usePregapForFirstTrackInSingleFile = false; - _accurateRipMode = AccurateRipMode.None; - _appliedWriteOffset = false; - _dataTrackLength = null; - _minDataTrackLength = null; - hdcdDecoder = null; - _hasEmbeddedCUESheet = false; - _isArchive = false; - _isCD = false; - } - - public void Open(string pathIn, bool outputLossyWAV) - { - if (_config.detectHDCD) - { - try { hdcdDecoder = new HDCDDotNet.HDCDDotNet(2, 44100, ((_outputLossyWAV && _config.decodeHDCDtoLW16) || !_config.decodeHDCDto24bit) ? 20 : 24, _config.decodeHDCD); } - catch { } - } - _outputLossyWAV = outputLossyWAV; - string cueDir = Path.GetDirectoryName(pathIn) ?? pathIn; -#if !MONO - if (cueDir == pathIn) - { - CDDriveReader ripper = new CDDriveReader(); - ripper.Open(pathIn[0]); - _toc = ripper.TOC; - _driveName = ripper.ARName; - ripper.Close(); - if (_toc.AudioTracks > 0) - { - if (!AccurateRipVerify.FindDriveReadOffset(_driveName, out _driveOffset)) - throw new Exception("Failed to find drive read offset for drive" + _driveName); - _isCD = true; - SourceInfo cdInfo; - cdInfo.Path = pathIn; - cdInfo.Offset = 0; - cdInfo.Length = _toc.AudioLength * 588; - _sources.Add(cdInfo); - for (int iTrack = 0; iTrack < _toc.AudioTracks; iTrack++) - { - _trackFilenames.Add(string.Format("{0:00}.wav", iTrack + 1)); - _tracks.Add(new TrackInfo()); - } - _hasTrackFilenames = false; - _accurateRipId = _accurateRipIdActual = AccurateRipVerify.CalculateAccurateRipId(_toc); - _arVerify = new AccurateRipVerify(_toc); - - Release release; - ReleaseQueryParameters p = new ReleaseQueryParameters(); - p.DiscId = _toc.MusicBrainzId; - Query results = Release.Query(p); - MusicBrainzService.XmlRequest += new EventHandler(MusicBrainz_LookupProgress); - _progress.percentDisk = 0; - try - { - release = results.First(); - General.SetCUELine(_attributes, "REM", "DISCID", AccurateRipVerify.CalculateCDDBId(_toc), false); - General.SetCUELine(_attributes, "REM", "COMMENT", CDDriveReader.RipperVersion(), true); - General.SetCUELine(_attributes, "REM", "DATE", release.GetEvents()[0].Date.Substring(0, 4), false); - General.SetCUELine(_attributes, "PERFORMER", release.GetArtist(), true); - General.SetCUELine(_attributes, "TITLE", release.GetTitle(), true); - for (int iTrack = 0; iTrack < _toc.AudioTracks; iTrack++) - { - General.SetCUELine(_tracks[iTrack].Attributes, "TITLE", release.GetTracks()[iTrack].GetTitle(), true); - General.SetCUELine(_tracks[iTrack].Attributes, "PERFORMER ", release.GetTracks()[iTrack].GetArtist(), true); - } - } - catch - { - release = null; - } - return; - } - } -#endif - - SourceInfo sourceInfo; - string lineStr, command, pathAudio = null, fileType; - CUELine line; - TrackInfo trackInfo = null; - int timeRelativeToFileStart, absoluteFileStartTime = 0; - int fileTimeLengthSamples = 0, fileTimeLengthFrames = 0, i; - int trackNumber = 0; - bool seenFirstFileIndex = false, seenDataTrack = false; - List indexes = new List(); - IndexInfo indexInfo; - NameValueCollection _trackTags = null; - TextReader sr; - - if (Directory.Exists(pathIn)) - { - if (cueDir + Path.DirectorySeparatorChar != pathIn && cueDir != 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); - } -#if !MONO - else if (Path.GetExtension(pathIn).ToLower() == ".rar") - { - Unrar _unrar = new Unrar(); - _unrar.PasswordRequired += new PasswordRequiredHandler(unrar_PasswordRequired); - string cueName = null, cueText = null; - _unrar.Open(pathIn, Unrar.OpenMode.List); - _archiveContents = new List(); - while (_unrar.ReadHeader()) - { - if (!_unrar.CurrentFile.IsDirectory) - { - _archiveContents.Add(_unrar.CurrentFile.FileName); - if (Path.GetExtension(_unrar.CurrentFile.FileName).ToLower() == ".cue") - cueName = _unrar.CurrentFile.FileName; - } - _unrar.Skip(); - } - _unrar.Close(); - if (cueName != null) - { - RarStream rarStream = new RarStream(pathIn, cueName); - rarStream.PasswordRequired += new PasswordRequiredHandler(unrar_PasswordRequired); - StreamReader cueReader = new StreamReader(rarStream, CUESheet.Encoding); - cueText = cueReader.ReadToEnd(); - cueReader.Close(); - rarStream.Close(); - if (cueText == "") - throw new Exception("Empty cue sheet."); - } - if (cueText == null) - throw new Exception("Input archive doesn't contain a cue sheet."); - _archiveCUEpath = Path.GetDirectoryName(cueName); - sr = new StringReader(cueText); - _isArchive = true; - _archivePath = pathIn; - } -#endif - else if (Path.GetExtension(pathIn).ToLower() == ".cue") - { - if (_config.autoCorrectFilenames) - sr = new StringReader (CorrectAudioFilenames(pathIn, false)); - else - sr = new StreamReader (pathIn, CUESheet.Encoding); - - try - { - StreamReader logReader = new StreamReader(Path.ChangeExtension(pathIn, ".log"), CUESheet.Encoding); - _eacLog = logReader.ReadToEnd(); - logReader.Close(); - } - catch { } - } else - { - IAudioSource audioSource; - NameValueCollection tags; - string cuesheetTag = null; - - audioSource = AudioReadWrite.GetAudioSource(pathIn,null); - tags = audioSource.Tags; - cuesheetTag = tags.Get("CUESHEET"); - _accurateRipId = tags.Get("ACCURATERIPID"); - _eacLog = tags.Get("LOG"); - if (_eacLog == null) _eacLog = tags.Get("LOGFILE"); - if (_eacLog == null) _eacLog = tags.Get("EACLOG"); - audioSource.Close(); - if (cuesheetTag == null) - throw new Exception("Input file does not contain a .cue sheet."); - sr = new StringReader (cuesheetTag); - pathAudio = pathIn; - _hasEmbeddedCUESheet = true; - } - - using (sr) { - while ((lineStr = sr.ReadLine()) != null) { - line = new CUELine(lineStr); - if (line.Params.Count > 0) { - command = line.Params[0].ToUpper(); - - if (command == "FILE") { - fileType = line.Params[2].ToUpper(); - if ((fileType == "BINARY") || (fileType == "MOTOROLA")) { - seenDataTrack = true; - } - else if (seenDataTrack) { - throw new Exception("Audio tracks cannot appear after data tracks."); - } - else { - if (!_hasEmbeddedCUESheet) - { - if (_isArchive) - pathAudio = LocateFile(_archiveCUEpath, line.Params[1], _archiveContents); - else - pathAudio = LocateFile(cueDir, line.Params[1], null); - if (pathAudio == null) - throw new Exception("Unable to locate file \"" + line.Params[1] + "\"."); - } else - { - if (_sourcePaths.Count > 0 ) - throw new Exception("Extra file in embedded CUE sheet: \"" + line.Params[1] + "\"."); - } - _sourcePaths.Add(pathAudio); - absoluteFileStartTime += fileTimeLengthFrames; - NameValueCollection tags; - fileTimeLengthSamples = GetSampleLength(pathAudio, out tags); - if ((fileTimeLengthSamples % 588) == 492 && _config.truncate4608ExtraSamples) - { - _truncated4608 = true; - fileTimeLengthSamples -= 4608; - } - fileTimeLengthFrames = (int)((fileTimeLengthSamples + 587) / 588); - if (_hasEmbeddedCUESheet) - _albumTags = tags; - else - _trackTags = tags; - seenFirstFileIndex = false; - } - } - else if (command == "TRACK") { - if (line.Params[2].ToUpper() != "AUDIO") { - seenDataTrack = true; - } - else if (seenDataTrack) { - throw new Exception("Audio tracks cannot appear after data tracks."); - } - else { - trackNumber = int.Parse(line.Params[1]); - if (trackNumber != _tracks.Count + 1) { - throw new Exception("Invalid track number."); - } - trackInfo = new TrackInfo(); - _tracks.Add(trackInfo); - _toc.AddTrack(new CDTrack((uint)trackNumber, 0, 0, true, false)); - } - } - else if (seenDataTrack) { - // Ignore lines belonging to data tracks - } - else if (command == "INDEX") { - timeRelativeToFileStart = CDImageLayout.TimeFromString(line.Params[2]); - if (!seenFirstFileIndex) - { - if (timeRelativeToFileStart != 0) - { - throw new Exception("First index must start at file beginning."); - } - if (trackNumber > 0 && _trackTags != null && _trackTags.Count != 0) - _tracks[trackNumber-1]._trackTags = _trackTags; - seenFirstFileIndex = true; - sourceInfo.Path = pathAudio; - sourceInfo.Offset = 0; - sourceInfo.Length = (uint)fileTimeLengthSamples; - _sources.Add(sourceInfo); - if ((fileTimeLengthSamples % 588) != 0) - { - sourceInfo.Path = null; - sourceInfo.Offset = 0; - sourceInfo.Length = (uint)((fileTimeLengthFrames * 588) - fileTimeLengthSamples); - _sources.Add(sourceInfo); - _paddedToFrame = true; - } - } - indexInfo.Track = trackNumber; - indexInfo.Index = Int32.Parse(line.Params[1]); - indexInfo.Time = absoluteFileStartTime + timeRelativeToFileStart; - indexes.Add(indexInfo); - } - else if (command == "PREGAP") { - if (seenFirstFileIndex) { - throw new Exception("Pregap must occur at the beginning of a file."); - } - int pregapLength = CDImageLayout.TimeFromString(line.Params[1]); - indexInfo.Track = trackNumber; - indexInfo.Index = 0; - indexInfo.Time = absoluteFileStartTime; - indexes.Add(indexInfo); - sourceInfo.Path = null; - sourceInfo.Offset = 0; - sourceInfo.Length = (uint)pregapLength * 588; - _sources.Add(sourceInfo); - absoluteFileStartTime += pregapLength; - } - else if (command == "POSTGAP") { - throw new Exception("POSTGAP command isn't supported."); - } - else if ((command == "REM") && - (line.Params.Count >= 3) && - (line.Params[1].Length >= 10) && - (line.Params[1].Substring(0, 10).ToUpper() == "REPLAYGAIN")) - { - // Remove ReplayGain lines - } - else if ((command == "REM") && - (line.Params.Count == 3) && - (line.Params[1].ToUpper() == "DATATRACKLENGTH")) - { - _dataTrackLength = (uint)CDImageLayout.TimeFromString(line.Params[2]); - } - else if ((command == "REM") && - (line.Params.Count == 3) && - (line.Params[1].ToUpper() == "ACCURATERIPID")) - { - _accurateRipId = line.Params[2]; - } - //else if ((command == "REM") && - // (line.Params.Count == 3) && - // (line.Params[1].ToUpper() == "SHORTEN")) - //{ - // fileTimeLengthFrames -= General.TimeFromString(line.Params[2]); - //} - //else if ((command == "REM") && - // (line.Params.Count == 3) && - // (line.Params[1].ToUpper() == "LENGTHEN")) - //{ - // fileTimeLengthFrames += General.TimeFromString(line.Params[2]); - //} - else - { - if (trackInfo != null) - { - trackInfo.Attributes.Add(line); - } - else - { - _attributes.Add(line); - } - } - } - } - sr.Close(); - } - - if (trackNumber == 0) { - throw new Exception("File must contain at least one audio track."); - } - - // Add dummy track for calculation purposes - indexInfo.Track = trackNumber + 1; - indexInfo.Index = 1; - indexInfo.Time = absoluteFileStartTime + fileTimeLengthFrames; - indexes.Add(indexInfo); - - // Calculate the length of each index - for (i = 0; i < indexes.Count - 1; i++) - { - if (indexes[i + 1].Time - indexes[i].Time < 0) - throw new Exception("Indexes must be in chronological order."); - if ((indexes[i+1].Track != indexes[i].Track || indexes[i+1].Index != indexes[i].Index + 1) && - (indexes[i + 1].Track != indexes[i].Track + 1 || indexes[i].Index < 1 || indexes[i + 1].Index > 1)) - throw new Exception("Indexes must be in chronological order."); - if (indexes[i].Index == 1 && (i == 0 || indexes[i - 1].Index != 0)) - _toc[indexes[i].Track].AddIndex(new CDTrackIndex(0U, (uint)indexes[i].Time)); - _toc[indexes[i].Track].AddIndex(new CDTrackIndex((uint)indexes[i].Index, (uint)indexes[i].Time)); - } - - // Calculate the length of each track - for (int iTrack = 1; iTrack <= TrackCount; iTrack++) - { - _toc[iTrack].Start = _toc[iTrack][1].Start; - _toc[iTrack].Length = (iTrack == TrackCount ? (uint)indexes[indexes.Count - 1].Time - _toc[iTrack].Start : _toc[iTrack + 1][1].Start - _toc[iTrack].Start); - } - - // Store the audio filenames, generating generic names if necessary - _hasSingleFilename = (_sourcePaths.Count == 1); - _singleFilename = _hasSingleFilename ? Path.GetFileName(_sourcePaths[0]) : - "Range.wav"; - - _hasHTOAFilename = (_sourcePaths.Count == (TrackCount + 1)); - _htoaFilename = _hasHTOAFilename ? Path.GetFileName(_sourcePaths[0]) : "01.00.wav"; - - _hasTrackFilenames = (_sourcePaths.Count == TrackCount) || _hasHTOAFilename; - for (i = 0; i < TrackCount; i++) { - _trackFilenames.Add( _hasTrackFilenames ? Path.GetFileName( - _sourcePaths[i + (_hasHTOAFilename ? 1 : 0)]) : String.Format("{0:00}.wav", i + 1) ); - } - - if (_hasTrackFilenames) - for (i = 0; i < TrackCount; i++) - { - TrackInfo track = _tracks[i]; - string artist = track._trackTags.Get("ARTIST"); - string title = track._trackTags.Get("TITLE"); - if (track.Artist == "" && artist != null) - track.Artist = artist; - if (track.Title == "" && title != null) - track.Title = title; - } - if (!_hasEmbeddedCUESheet && _hasSingleFilename) - { - _albumTags = _tracks[0]._trackTags; - _tracks[0]._trackTags = new NameValueCollection(); - } - if (_config.fillUpCUE) - { - if (General.FindCUELine(_attributes, "PERFORMER") == null && GetCommonTag("ALBUM ARTIST") != null) - General.SetCUELine(_attributes, "PERFORMER", GetCommonTag("ALBUM ARTIST"), true); - if (General.FindCUELine(_attributes, "PERFORMER") == null && GetCommonTag("ARTIST") != null) - General.SetCUELine(_attributes, "PERFORMER", GetCommonTag("ARTIST"), true); - if (General.FindCUELine(_attributes, "TITLE") == null && GetCommonTag("ALBUM") != null) - General.SetCUELine(_attributes, "TITLE", GetCommonTag("ALBUM"), true); - if (General.FindCUELine(_attributes, "REM", "DATE") == null && GetCommonTag("DATE") != null) - General.SetCUELine(_attributes, "REM", "DATE", GetCommonTag("DATE"), false); - if (General.FindCUELine(_attributes, "REM", "DATE") == null && GetCommonTag("YEAR") != null) - General.SetCUELine(_attributes, "REM", "DATE", GetCommonTag("YEAR"), false); - if (General.FindCUELine(_attributes, "REM", "GENRE") == null && GetCommonTag("GENRE") != null) - General.SetCUELine(_attributes, "REM", "GENRE", GetCommonTag("GENRE"), true); - } - - CUELine cddbDiscIdLine = General.FindCUELine(_attributes, "REM", "DISCID"); - _cddbDiscIdTag = cddbDiscIdLine != null && cddbDiscIdLine.Params.Count == 3 ? cddbDiscIdLine.Params[2] : null; - if (_cddbDiscIdTag == null) _cddbDiscIdTag = GetCommonTag("DISCID"); - - if (_accurateRipId == null) - _accurateRipId = GetCommonTag("ACCURATERIPID"); - - if (_accurateRipId == null && _dataTrackLength == null && _eacLog != null) - { - sr = new StringReader(_eacLog); - bool isEACLog = false; - CDImageLayout tocFromLog = new CDImageLayout(); - 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)) - tocFromLog.AddTrack(new CDTrack(trNo, trStart, trEnd + 1 - trStart, - tocFromLog.TrackCount < _toc.TrackCount || trStart != tocFromLog[tocFromLog.TrackCount].End + 1U + 152U * 75U, false)); - } else - if (lineStr.StartsWith("TOC of the extracted CD") - || lineStr.StartsWith("Exact Audio Copy") - || lineStr.StartsWith("CUERipper")) - isEACLog = true; - } - if (tocFromLog.TrackCount == _toc.TrackCount + 1 && !tocFromLog[tocFromLog.TrackCount].IsAudio) - _accurateRipId = AccurateRipVerify.CalculateAccurateRipId(tocFromLog); - } - - if (_accurateRipId == null && _dataTrackLength != null) - { - CDImageLayout toc2 = new CDImageLayout(_toc); - toc2.AddTrack(new CDTrack((uint)_toc.TrackCount, _toc.Length + 152U * 75U, _dataTrackLength.Value, false, false)); - _accurateRipId = AccurateRipVerify.CalculateAccurateRipId(toc2); - } - - if (_dataTrackLength == null && _cddbDiscIdTag != null) - { - uint cddbDiscIdNum; - if (uint.TryParse(_cddbDiscIdTag, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out cddbDiscIdNum) && (cddbDiscIdNum & 0xff) == TrackCount + 1) - { - uint lengthFromTag = ((cddbDiscIdNum >> 8) & 0xffff); - _minDataTrackLength = ((lengthFromTag + _toc[1].Start / 75) - 152) * 75 - _toc.Length; - } - } - - _accurateRipIdActual = AccurateRipVerify.CalculateAccurateRipId(_toc); - if (_accurateRipId == null) - _accurateRipId = _accurateRipIdActual; - - _arVerify = new AccurateRipVerify(_toc); - - //if (!_dataTrackLength.HasValue && _cddbDiscIdTag != null) - //{ - // uint cddbDiscIdNum = UInt32.Parse(_cddbDiscIdTag, NumberStyles.HexNumber); - // if ((cddbDiscIdNum & 0xff) == TrackCount) - // { - // _cutOneFrame = true; - // string cddbDiscIdTagCut = CalculateAccurateRipId().Split('-')[2]; - // if (cddbDiscIdTagCut.ToUpper() != _cddbDiscIdTag.ToUpper()) - // _cutOneFrame = false; - // } - //} - } - - public static Encoding Encoding { - get { - return Encoding.Default; - } - } - - private void ShowProgress(string status, double percentTrack, double percentDisk, string input, string output) - { - if (this.CUEToolsProgress == null) - return; - _progress.status = status; - _progress.percentTrck = percentTrack; - _progress.percentDisk = percentDisk; - _progress.input = input; - _progress.output = output; - this.CUEToolsProgress(this, _progress); - } - -#if !MONO - private void CDReadProgress(object sender, ReadProgressArgs e) - { - lock (this) - { - if (_stop) - throw new StopException(); - if (_pause) - { - ShowProgress("Paused...", 0, 0, null, null); - Monitor.Wait(this); - } - } - if (this.CUEToolsProgress == null) - return; - CDDriveReader audioSource = (CDDriveReader)sender; - int processed = e.Position - e.PassStart; - TimeSpan elapsed = DateTime.Now - e.PassTime; - double speed = elapsed.TotalSeconds > 0 ? processed / elapsed.TotalSeconds / 75 : 1.0; - _progress.percentDisk = (double)(e.PassStart + (processed + e.Pass * (e.PassEnd - e.PassStart)) / (audioSource.CorrectionQuality + 1)) / audioSource.TOC.AudioLength; - _progress.percentTrck = (double) (e.Position - e.PassStart) / (e.PassEnd - e.PassStart); - _progress.status = string.Format("Ripping @{0:00.00}x {1}", speed, e.Pass > 0 ? " (Retry " + e.Pass.ToString() + ")" : ""); - this.CUEToolsProgress(this, _progress); - } - - private void MusicBrainz_LookupProgress(object sender, XmlRequestEventArgs e) - { - if (this.CUEToolsProgress == null) - return; - _progress.percentDisk = (1.0 + _progress.percentDisk) / 2; - _progress.percentTrck = 0; - _progress.input = e.Uri.ToString(); - _progress.output = null; - _progress.status = "Looking up album via MusicBrainz"; - this.CUEToolsProgress(this, _progress); - } - - private void unrar_ExtractionProgress(object sender, ExtractionProgressEventArgs e) - { - if (this.CUEToolsProgress == null) - return; - _progress.percentTrck = e.PercentComplete/100; - this.CUEToolsProgress(this, _progress); - } - - private void unrar_PasswordRequired(object sender, PasswordRequiredEventArgs e) - { - if (_archivePassword != null) - { - e.ContinueOperation = true; - e.Password = _archivePassword; - return; - } - if (this.PasswordRequired != null) - { - ArchivePasswordRequiredEventArgs e1 = new ArchivePasswordRequiredEventArgs(); - this.PasswordRequired(this, e1); - if (e1.ContinueOperation && e1.Password != "") - { - _archivePassword = e1.Password; - e.ContinueOperation = true; - e.Password = e1.Password; - return; - } - } - throw new IOException("Password is required for extraction."); - } -#endif - - public string GetCommonTag(string tagName) - { - if (_hasEmbeddedCUESheet || _hasSingleFilename) - return _albumTags.Get(tagName); - if (_hasTrackFilenames) - { - string tagValue = null; - bool commonValue = true; - for (int i = 0; i < TrackCount; i++) - { - TrackInfo track = _tracks[i]; - string newValue = track._trackTags.Get (tagName); - if (tagValue == null) - tagValue = newValue; - else - commonValue = (newValue == null || tagValue == newValue); - } - return commonValue ? tagValue : null; - } - return null; - } - - private static string LocateFile(string dir, string file, List contents) { - List dirList, fileList; - string altDir, path; - - dirList = new List(); - fileList = new List(); - 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++) { - path = Path.Combine(dirList[iDir], fileList[iFile]); - if ( (contents == null && File.Exists(path)) - || (contents != null && contents.Contains (path))) - return path; - } - } - - return null; - } - - public void GenerateFilenames (OutputAudioFormat format, string outputPath) - { - _cuePath = outputPath; - - string extension = General.FormatExtension(format); - List find, replace; - string filename; - int iTrack; - - find = new List(); - replace = new List(); - - find.Add("%D"); // 0: Album artist - find.Add("%C"); // 1: Album title - find.Add("%N"); // 2: Track number - find.Add("%A"); // 3: Track artist - find.Add("%T"); // 4: Track title - find.Add("%F"); // 5: Input filename - - replace.Add(General.EmptyStringToNull(_config.CleanseString(Artist))); - replace.Add(General.EmptyStringToNull(_config.CleanseString(Title))); - replace.Add(null); - replace.Add(null); - replace.Add(null); - replace.Add(Path.GetFileNameWithoutExtension(outputPath)); - - if (_outputLossyWAV) - extension = ".lossy" + extension; - if (_config.detectHDCD && _config.decodeHDCD && (!_outputLossyWAV || !_config.decodeHDCDtoLW16)) - { - if (_config.decodeHDCDto24bit ) - extension = ".24bit" + extension; - else - extension = ".20bit" + extension; - } - - if (_config.keepOriginalFilenames && HasSingleFilename) - { - SingleFilename = Path.ChangeExtension(SingleFilename, extension); - } - else - { - filename = General.ReplaceMultiple(_config.singleFilenameFormat, find, replace); - if (filename == null) - filename = "Range"; - filename += extension; - SingleFilename = filename; - } - - for (iTrack = -1; iTrack < TrackCount; iTrack++) - { - bool htoa = (iTrack == -1); - - if (_config.keepOriginalFilenames && htoa && HasHTOAFilename) - { - HTOAFilename = Path.ChangeExtension(HTOAFilename, extension); - } - else if (_config.keepOriginalFilenames && !htoa && HasTrackFilenames) - { - TrackFilenames[iTrack] = Path.ChangeExtension( - TrackFilenames[iTrack], extension); - } - else - { - string trackStr = htoa ? "01.00" : String.Format("{0:00}", iTrack + 1); - string artist = Tracks[htoa ? 0 : iTrack].Artist; - string title = htoa ? "(HTOA)" : Tracks[iTrack].Title; - - replace[2] = trackStr; - replace[3] = General.EmptyStringToNull(_config.CleanseString(artist==""?Artist:artist)); - replace[4] = General.EmptyStringToNull(_config.CleanseString(title)); - - filename = General.ReplaceMultiple(_config.trackFilenameFormat, find, replace); - if (filename == null) - filename = replace[2]; - filename += extension; - - if (htoa) - { - HTOAFilename = filename; - } - else - { - TrackFilenames[iTrack] = filename; - } - } - } - } - - private int GetSampleLength(string path, out NameValueCollection tags) - { - IAudioSource audioSource; - - ShowProgress("Analyzing input file...", 0.0, 0.0, path, null); -#if !MONO - if (_isArchive) - { - RarStream IO = new RarStream(_archivePath, path); - IO.PasswordRequired += new PasswordRequiredHandler(unrar_PasswordRequired); - IO.ExtractionProgress += new ExtractionProgressHandler(unrar_ExtractionProgress); - audioSource = AudioReadWrite.GetAudioSource(path, IO); - } else -#endif - audioSource = AudioReadWrite.GetAudioSource(path, null); - - if ((audioSource.BitsPerSample != 16) || - (audioSource.ChannelCount != 2) || - (audioSource.SampleRate != 44100) || - (audioSource.Length > Int32.MaxValue)) - { - audioSource.Close(); - throw new Exception("Audio format is invalid."); - } - - tags = audioSource.Tags; - audioSource.Close(); - return (int)audioSource.Length; - } - - public void WriteText(string path, string text) - { - bool utf8Required = CUESheet.Encoding.GetString(CUESheet.Encoding.GetBytes(text)) != text; - StreamWriter sw1 = new StreamWriter(path, false, utf8Required ? Encoding.UTF8 : CUESheet.Encoding); - sw1.Write(text); - sw1.Close(); - } - - public string LOGContents() - { - if (!_isCD) - return null; -#if !MONO - StringWriter logWriter = new StringWriter(); - logWriter.WriteLine("{0}", CDDriveReader.RipperVersion()); - logWriter.WriteLine("Extraction logfile from : {0}", DateTime.Now); - logWriter.WriteLine("Used drive : {0}", _driveName); - logWriter.WriteLine("Read offset correction : {0}", _driveOffset); - //logWriter.WriteLine("Read command : {0}", ); - //logWriter.WriteLine("Secure mode : {0}", ); - if (hdcdDecoder != null && hdcdDecoder.Detected) - { - hdcd_decoder_statistics stats; - hdcdDecoder.GetStatistics(out stats); - logWriter.WriteLine("HDCD : peak extend: {0}, transient filter: {1}, gain: {2}", - (stats.enabled_peak_extend ? (stats.disabled_peak_extend ? "some" : "yes") : "none"), - (stats.enabled_transient_filter ? (stats.disabled_transient_filter ? "some" : "yes") : "none"), - stats.min_gain_adjustment == stats.max_gain_adjustment ? - (stats.min_gain_adjustment == 1.0 ? "none" : String.Format("{0:0.0}dB", (Math.Log10(stats.min_gain_adjustment) * 20))) : - String.Format("{0:0.0}dB..{1:0.0}dB", (Math.Log10(stats.min_gain_adjustment) * 20), (Math.Log10(stats.max_gain_adjustment) * 20)) - ); - logWriter.WriteLine(); - } - logWriter.WriteLine(); - logWriter.WriteLine("TOC of the extracted CD"); - logWriter.WriteLine(); - logWriter.WriteLine(" Track | Start | Length | Start sector | End sector"); - logWriter.WriteLine(" ---------------------------------------------------------"); - for (int track = 1; track <= _toc.TrackCount; track++) - logWriter.WriteLine("{0,9} | {1,8} | {2,8} | {3,9} | {4,9}", - _toc[track].Number, - _toc[track].StartMSF, - _toc[track].LengthMSF, - _toc[track].Start, - _toc[track].End); - bool wereErrors = false; - for (int iTrack = 0; iTrack < _toc.AudioTracks; iTrack++) - { - int cdErrors = 0; - bool crcMismatch = _accurateRipMode == AccurateRipMode.VerifyThenConvert && - _arVerify.BackupCRC(iTrack) != _arVerify.CRC(iTrack); - for (uint iSector = _toc[iTrack + 1].Start; iSector <= _toc[iTrack + 1].End; iSector++) - if (_cdErrors[(int)iSector]) - cdErrors++; - if (crcMismatch || cdErrors != 0) - { - if (!wereErrors) - { - logWriter.WriteLine(); - logWriter.WriteLine("Errors detected"); - logWriter.WriteLine(); - } - wereErrors = true; - if (crcMismatch) - logWriter.WriteLine("Track {0} contains {1} errors, CRC mismatch: test {2:X8} vs copy {3:X8}", iTrack + 1, cdErrors, _arVerify.BackupCRC(iTrack), _arVerify.CRC(iTrack)); - else - logWriter.WriteLine("Track {0} contains {1} errors", iTrack + 1, cdErrors); - } - } - if (_accurateRipMode != AccurateRipMode.None) - { - logWriter.WriteLine(); - logWriter.WriteLine("AccurateRip summary"); - logWriter.WriteLine(); - _arVerify.GenerateFullLog(logWriter, 0); - logWriter.WriteLine(); - } - logWriter.WriteLine(); - logWriter.WriteLine("End of status report"); - logWriter.Close(); - return logWriter.ToString(); -#else - return null; -#endif - } - - public string M3UContents(CUEStyle style) - { - StringWriter sw = new StringWriter(); - if (style == CUEStyle.GapsAppended && _config.preserveHTOA && _toc.Pregap != 0) - WriteLine(sw, 0, _htoaFilename); - for (int iTrack = 0; iTrack < TrackCount; iTrack++) - WriteLine(sw, 0, _trackFilenames[iTrack]); - sw.Close(); - return sw.ToString(); - } - - public string TOCContents() - { - StringWriter sw = new StringWriter(); - for (int iTrack = 0; iTrack < TrackCount; iTrack++) - WriteLine(sw, 0, "\t" + _toc[iTrack+1].Start + 150); - sw.Close(); - return sw.ToString(); - } - - public string CUESheetContents(CUEStyle style) - { - StringWriter sw = new StringWriter(); - int i, iTrack, iIndex; - bool htoaToFile = (style == CUEStyle.GapsAppended && _config.preserveHTOA && _toc.Pregap != 0); - - uint timeRelativeToFileStart = 0; - - using (sw) - { - if (_config.writeArTagsOnConvert) - WriteLine(sw, 0, "REM ACCURATERIPID " + _accurateRipId); - - for (i = 0; i < _attributes.Count; i++) - WriteLine(sw, 0, _attributes[i]); - - if (style == CUEStyle.SingleFile || style == CUEStyle.SingleFileWithCUE) - WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _singleFilename)); - - if (htoaToFile) - WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _htoaFilename)); - - for (iTrack = 0; iTrack < TrackCount; iTrack++) - { - if ((style == CUEStyle.GapsPrepended) || - (style == CUEStyle.GapsLeftOut) || - ((style == CUEStyle.GapsAppended) && - ((_toc[iTrack+1].Pregap == 0) || ((iTrack == 0) && !htoaToFile)))) - { - WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _trackFilenames[iTrack])); - timeRelativeToFileStart = 0; - } - - WriteLine(sw, 1, String.Format("TRACK {0:00} AUDIO", iTrack + 1)); - for (i = 0; i < _tracks[iTrack].Attributes.Count; i++) - WriteLine(sw, 2, _tracks[iTrack].Attributes[i]); - - if (_toc[iTrack + 1].Pregap != 0) - { - if (((style == CUEStyle.GapsLeftOut) || - ((style == CUEStyle.GapsAppended) && (iTrack == 0) && !htoaToFile) || - ((style == CUEStyle.SingleFile || style == CUEStyle.SingleFileWithCUE) && (iTrack == 0) && _usePregapForFirstTrackInSingleFile))) - WriteLine(sw, 2, "PREGAP " + CDImageLayout.TimeToString(_toc[iTrack + 1].Pregap)); - else - { - WriteLine(sw, 2, String.Format("INDEX 00 {0}", CDImageLayout.TimeToString(timeRelativeToFileStart))); - timeRelativeToFileStart += _toc[iTrack + 1].Pregap; - if (style == CUEStyle.GapsAppended) - { - WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _trackFilenames[iTrack])); - timeRelativeToFileStart = 0; - } - } - } - for (iIndex = 1; iIndex <= _toc[iTrack+1].LastIndex; iIndex++) - { - WriteLine(sw, 2, String.Format( "INDEX {0:00} {1}", iIndex, CDImageLayout.TimeToString(timeRelativeToFileStart))); - timeRelativeToFileStart += _toc.IndexLength(iTrack + 1, iIndex); - } - } - } - sw.Close(); - return sw.ToString(); - } - - public void GenerateAccurateRipLog(TextWriter sw) - { - sw.WriteLine("[Verification date: {0}]", DateTime.Now); - sw.WriteLine("[Disc ID: {0}]", _accurateRipId); - if (_dataTrackLength.HasValue) - sw.WriteLine("Assuming a data track was present, length {0}.", CDImageLayout.TimeToString(_dataTrackLength.Value)); - else - { - if (_cddbDiscIdTag != null && _accurateRipId.Split('-')[2].ToUpper() != _cddbDiscIdTag.ToUpper()) - sw.WriteLine("CDDBId mismatch: {0} vs {1}", _cddbDiscIdTag.ToUpper(), _accurateRipId.Split('-')[2].ToUpper()); - if (_minDataTrackLength.HasValue) - sw.WriteLine("Data track was probably present, length {0}-{1}.", CDImageLayout.TimeToString(_minDataTrackLength.Value), CDImageLayout.TimeToString(_minDataTrackLength.Value + 74)); - if (_accurateRipIdActual != _accurateRipId) - sw.WriteLine("Using preserved id, actual id is {0}.", _accurateRipIdActual); - if (_truncated4608) - sw.WriteLine("Truncated 4608 extra samples in some input files."); - if (_paddedToFrame) - sw.WriteLine("Padded some input files to a frame boundary."); - } - - if (hdcdDecoder != null && hdcdDecoder.Detected) - { - hdcd_decoder_statistics stats; - hdcdDecoder.GetStatistics(out stats); - sw.WriteLine("HDCD: peak extend: {0}, transient filter: {1}, gain: {2}", - (stats.enabled_peak_extend ? (stats.disabled_peak_extend ? "some" : "yes") : "none"), - (stats.enabled_transient_filter ? (stats.disabled_transient_filter ? "some" : "yes") : "none"), - stats.min_gain_adjustment == stats.max_gain_adjustment ? - (stats.min_gain_adjustment == 1.0 ? "none" : String.Format ("{0:0.0}dB", (Math.Log10(stats.min_gain_adjustment) * 20))) : - String.Format ("{0:0.0}dB..{1:0.0}dB", (Math.Log10(stats.min_gain_adjustment) * 20), (Math.Log10(stats.max_gain_adjustment) * 20)) - ); - } - - if (0 != _writeOffset) - sw.WriteLine("Offset applied: {0}", _writeOffset); - _arVerify.GenerateFullLog(sw, 0); - } - - public void GenerateAccurateRipTagsForTrack(NameValueCollection tags, int offset, int bestOffset, int iTrack, string prefix) - { - uint total = 0; - uint matching = 0; - uint matching2 = 0; - uint matching3 = 0; - for (int iDisk = 0; iDisk < _arVerify.AccDisks.Count; iDisk++) - { - total += _arVerify.AccDisks[iDisk].tracks[iTrack].count; - if (_arVerify.CRC(iTrack, offset) == - _arVerify.AccDisks[iDisk].tracks[iTrack].CRC) - matching += _arVerify.AccDisks[iDisk].tracks[iTrack].count; - if (_arVerify.CRC(iTrack, bestOffset) == - _arVerify.AccDisks[iDisk].tracks[iTrack].CRC) - matching2 += _arVerify.AccDisks[iDisk].tracks[iTrack].count; - for (int oi = -_arOffsetRange; oi <= _arOffsetRange; oi++) - if (_arVerify.CRC(iTrack, oi) == - _arVerify.AccDisks[iDisk].tracks[iTrack].CRC) - matching3 += _arVerify.AccDisks[iDisk].tracks[iTrack].count; - } - tags.Add(String.Format("{0}ACCURATERIPCRC", prefix), String.Format("{0:x8}", _arVerify.CRC(iTrack, offset))); - tags.Add(String.Format("{0}AccurateRipDiscId", prefix), String.Format("{0:000}-{1}-{2:00}", TrackCount, _accurateRipId, iTrack+1)); - tags.Add(String.Format("{0}ACCURATERIPCOUNT", prefix), String.Format("{0}", matching)); - tags.Add(String.Format("{0}ACCURATERIPCOUNTALLOFFSETS", prefix), String.Format("{0}", matching3)); - tags.Add(String.Format("{0}ACCURATERIPTOTAL", prefix), String.Format("{0}", total)); - if (bestOffset != offset) - tags.Add(String.Format("{0}ACCURATERIPCOUNTWITHOFFSET", prefix), String.Format("{0}", matching2)); - } - - public void GenerateAccurateRipTags(NameValueCollection tags, int offset, int bestOffset, int iTrack) - { - tags.Add("ACCURATERIPID", _accurateRipId); - if (bestOffset != offset) - tags.Add("ACCURATERIPOFFSET", String.Format("{1}{0}", bestOffset - offset, bestOffset > offset ? "+" : "")); - if (iTrack != -1) - GenerateAccurateRipTagsForTrack(tags, offset, bestOffset, iTrack, ""); - else - for (iTrack = 0; iTrack < TrackCount; iTrack++) - { - GenerateAccurateRipTagsForTrack(tags, offset, bestOffset, iTrack, - String.Format("cue_track{0:00}_", iTrack + 1)); - } - } - - public void CleanupTags (NameValueCollection tags, string substring) - { - string [] keys = tags.AllKeys; - for (int i = 0; i < keys.Length; i++) - if (keys[i].ToUpper().Contains(substring)) - tags.Remove (keys[i]); - } - - private void FindBestOffset(uint minConfidence, bool optimizeConfidence, out uint outTracksMatch, out int outBestOffset) - { - uint bestTracksMatch = 0; - uint bestConfidence = 0; - int bestOffset = 0; - - for (int offset = -_arOffsetRange; offset <= _arOffsetRange; offset++) - { - uint tracksMatch = 0; - uint sumConfidence = 0; - - for (int iTrack = 0; iTrack < TrackCount; iTrack++) - { - uint confidence = 0; - - for (int di = 0; di < (int)_arVerify.AccDisks.Count; di++) - if (_arVerify.CRC(iTrack, offset) == _arVerify.AccDisks[di].tracks[iTrack].CRC) - confidence += _arVerify.AccDisks[di].tracks[iTrack].count; - - if (confidence >= minConfidence) - tracksMatch++; - - sumConfidence += confidence; - } - - if (tracksMatch > bestTracksMatch - || (tracksMatch == bestTracksMatch && optimizeConfidence && sumConfidence > bestConfidence) - || (tracksMatch == bestTracksMatch && optimizeConfidence && sumConfidence == bestConfidence && Math.Abs(offset) < Math.Abs(bestOffset)) - || (tracksMatch == bestTracksMatch && !optimizeConfidence && Math.Abs(offset) < Math.Abs(bestOffset)) - ) - { - bestTracksMatch = tracksMatch; - bestConfidence = sumConfidence; - bestOffset = offset; - } - } - outBestOffset = bestOffset; - outTracksMatch = bestTracksMatch; - } - - public void WriteAudioFiles(string dir, CUEStyle style) { - string[] destPaths; - int[] destLengths; - bool htoaToFile = ((style == CUEStyle.GapsAppended) && _config.preserveHTOA && - (_toc.Pregap != 0)); - - if (_isCD && (style == CUEStyle.GapsLeftOut || style == CUEStyle.GapsPrepended) && (_accurateRipMode == AccurateRipMode.None || _accurateRipMode == AccurateRipMode.VerifyAndConvert)) - throw new Exception("When ripping a CD, gaps Left Out/Gaps prepended modes can only be used in verify-then-convert mode"); - - if (_usePregapForFirstTrackInSingleFile) - throw new Exception("UsePregapForFirstTrackInSingleFile is not supported for writing audio files."); - - if (style == CUEStyle.SingleFile || style == CUEStyle.SingleFileWithCUE) { - destPaths = new string[1]; - destPaths[0] = Path.Combine(dir, _singleFilename); - } - else { - destPaths = new string[TrackCount + (htoaToFile ? 1 : 0)]; - if (htoaToFile) { - destPaths[0] = Path.Combine(dir, _htoaFilename); - } - for (int i = 0; i < TrackCount; i++) { - destPaths[i + (htoaToFile ? 1 : 0)] = Path.Combine(dir, _trackFilenames[i]); - } - } - - if (_accurateRipMode != AccurateRipMode.Verify) - for (int i = 0; i < destPaths.Length; i++) - for (int j = 0; j < _sourcePaths.Count; j++) - if (destPaths[i].ToLower() == _sourcePaths[j].ToLower()) - throw new Exception("Source and destination audio file paths cannot be the same."); - - destLengths = CalculateAudioFileLengths(style); - - bool SkipOutput = false; - - if (_accurateRipMode != AccurateRipMode.None) - { - ShowProgress((string)"Contacting AccurateRip database...", 0, 0, null, null); - if (!_dataTrackLength.HasValue && _minDataTrackLength.HasValue && _accurateRipId == _accurateRipIdActual && _config.bruteForceDTL) - { - uint minDTL = _minDataTrackLength.Value; - CDImageLayout toc2 = new CDImageLayout(_toc); - toc2.AddTrack(new CDTrack((uint)_toc.TrackCount, _toc.Length + 152 * 75, minDTL, false, false)); - for (uint dtl = minDTL; dtl < minDTL + 75; dtl++) - { - toc2[toc2.TrackCount].Length = dtl; - _accurateRipId = AccurateRipVerify.CalculateAccurateRipId(toc2); - _arVerify.ContactAccurateRip(_accurateRipId); - if (_arVerify.AccResult != HttpStatusCode.NotFound) - { - _dataTrackLength = dtl; - break; - } - ShowProgress((string)"Contacting AccurateRip database...", 0, (dtl - minDTL) / 75.0, null, null); - lock (this) { - if (_stop) - throw new StopException(); - if (_pause) - { - ShowProgress("Paused...", 0, 0, null, null); - Monitor.Wait(this); - } - else - Monitor.Wait(this, 1000); - } - } - if (_arVerify.AccResult != HttpStatusCode.OK) - { - _accurateRipId = _accurateRipIdActual; - } - } else - _arVerify.ContactAccurateRip(_accurateRipId); - - if (_arVerify.AccResult != HttpStatusCode.OK) - { - if (_accurateRipMode == AccurateRipMode.Verify || _config.noUnverifiedOutput) - { - if ((_accurateRipMode != AccurateRipMode.Verify && _config.writeArLogOnConvert) || - (_accurateRipMode == AccurateRipMode.Verify && _config.writeArLogOnVerify)) - { - if (!Directory.Exists(dir)) - Directory.CreateDirectory(dir); - StreamWriter sw = new StreamWriter(Path.ChangeExtension(_cuePath, ".accurip"), - false, CUESheet.Encoding); - GenerateAccurateRipLog(sw); - sw.Close(); - } - if (_config.createTOC) - { - if (!Directory.Exists(dir)) - Directory.CreateDirectory(dir); - WriteText(Path.ChangeExtension(_cuePath, ".toc"), TOCContents()); - } - return; - } - if (_accurateRipMode == AccurateRipMode.VerifyThenConvert && _isCD) - { - _writeOffset = 0; - WriteAudioFilesPass(dir, style, destPaths, destLengths, htoaToFile, true); - _arVerify.CreateBackup(_writeOffset); - } - } - else if (_accurateRipMode == AccurateRipMode.VerifyThenConvert) - { - _writeOffset = 0; - WriteAudioFilesPass(dir, style, destPaths, destLengths, htoaToFile, true); - - uint tracksMatch; - int bestOffset; - - if (_config.noUnverifiedOutput) - { - FindBestOffset(_config.encodeWhenConfidence, false, out tracksMatch, out bestOffset); - if (tracksMatch * 100 < _config.encodeWhenPercent * TrackCount || (_config.encodeWhenZeroOffset && bestOffset != 0)) - SkipOutput = true; - } - - if (!SkipOutput && _config.fixOffset) - { - FindBestOffset(_config.fixWhenConfidence, false, out tracksMatch, out bestOffset); - if (tracksMatch * 100 >= _config.fixWhenPercent * TrackCount) - _writeOffset = bestOffset; - } - _arVerify.CreateBackup(_writeOffset); - } - } - - if (!SkipOutput) - { - if (_accurateRipMode != AccurateRipMode.Verify) - { - if (!Directory.Exists(dir)) - Directory.CreateDirectory(dir); - } - if (_isCD) - destLengths = CalculateAudioFileLengths(style); // need to recalc, might have changed after scanning the CD - WriteAudioFilesPass(dir, style, destPaths, destLengths, htoaToFile, _accurateRipMode == AccurateRipMode.Verify); - if (_accurateRipMode != AccurateRipMode.Verify) - { - string logContents = LOGContents(); - string cueContents = CUESheetContents(style); - bool needNewCRCs = _accurateRipMode != AccurateRipMode.None && - (_accurateRipMode == AccurateRipMode.VerifyAndConvert || _isCD) && - _config.writeArTagsOnConvert && - _arVerify.AccResult == HttpStatusCode.OK; - uint tracksMatch = 0; - int bestOffset = 0; - if (needNewCRCs) - FindBestOffset(1, true, out tracksMatch, out bestOffset); - - if (logContents != null) - WriteText(Path.ChangeExtension(_cuePath, ".log"), logContents); - if (style != CUEStyle.SingleFileWithCUE) - { - WriteText(_cuePath, cueContents); -#if !MONO - if (needNewCRCs && style != CUEStyle.SingleFile) - { - for (int iTrack = 0; iTrack < TrackCount; iTrack++) - { - IAudioSource audioSource = AudioReadWrite.GetAudioSource(destPaths[iTrack + (htoaToFile ? 1 : 0)], null); - CleanupTags(audioSource.Tags, "ACCURATERIP"); - GenerateAccurateRipTags(audioSource.Tags, 0, bestOffset, iTrack); - audioSource.UpdateTags(false); - audioSource.Close(); - audioSource = null; - } - } -#endif - } - else - { - if (_config.createCUEFileWhenEmbedded) - WriteText(Path.ChangeExtension(_cuePath, ".cue"), cueContents); -#if !MONO - if (needNewCRCs || _isCD) - { - IAudioSource audioSource = AudioReadWrite.GetAudioSource(destPaths[0], null); - if (_isCD) - { - if (_accurateRipMode != AccurateRipMode.VerifyThenConvert) - audioSource.Tags.Add("CUESHEET", cueContents); - audioSource.Tags.Add("LOG", logContents); - } - if (needNewCRCs) - { - CleanupTags(audioSource.Tags, "ACCURATERIP"); - GenerateAccurateRipTags(audioSource.Tags, 0, bestOffset, -1); - } - audioSource.UpdateTags(false); - audioSource.Close(); - audioSource = null; - } -#endif - } - if (style != CUEStyle.SingleFileWithCUE && style != CUEStyle.SingleFile && _config.createM3U) - WriteText(Path.ChangeExtension(_cuePath, ".m3u"), M3UContents(style)); - } - } - - if (_accurateRipMode != AccurateRipMode.None) - { - ShowProgress((string)"Generating AccurateRip report...", 0, 0, null, null); - if (_accurateRipMode == AccurateRipMode.Verify && _config.writeArTagsOnVerify && _writeOffset == 0 && !_isArchive && !_isCD) - { - uint tracksMatch; - int bestOffset; - FindBestOffset(1, true, out tracksMatch, out bestOffset); - - if (_hasEmbeddedCUESheet) - { - IAudioSource audioSource = AudioReadWrite.GetAudioSource(_sourcePaths[0], null); - NameValueCollection tags = audioSource.Tags; - CleanupTags(tags, "ACCURATERIP"); - GenerateAccurateRipTags (tags, 0, bestOffset, -1); -#if !MONO - if (audioSource is FLACReader) - audioSource.UpdateTags (true); -#endif - audioSource.Close(); - audioSource = null; - } else if (_hasTrackFilenames) - { - for (int iTrack = 0; iTrack < TrackCount; iTrack++) - { - string src = _sourcePaths[iTrack + (_hasHTOAFilename ? 1 : 0)]; - IAudioSource audioSource = AudioReadWrite.GetAudioSource(src, null); -#if !MONO - if (audioSource is FLACReader) - { - NameValueCollection tags = audioSource.Tags; - CleanupTags(tags, "ACCURATERIP"); - GenerateAccurateRipTags (tags, 0, bestOffset, iTrack); - audioSource.UpdateTags(true); - } -#endif - audioSource.Close(); - audioSource = null; - } - } - } - - if ((_accurateRipMode != AccurateRipMode.Verify && _config.writeArLogOnConvert) || - (_accurateRipMode == AccurateRipMode.Verify && _config.writeArLogOnVerify)) - { - if (!Directory.Exists(dir)) - Directory.CreateDirectory(dir); - StreamWriter sw = new StreamWriter(Path.ChangeExtension(_cuePath, ".accurip"), - false, CUESheet.Encoding); - GenerateAccurateRipLog(sw); - sw.Close(); - } - if (_config.createTOC) - { - if (!Directory.Exists(dir)) - Directory.CreateDirectory(dir); - WriteText(Path.ChangeExtension(_cuePath, ".toc"), TOCContents()); - } - } - } - - private void SetTrackTags(IAudioDest audioDest, int iTrack, int bestOffset) - { - NameValueCollection destTags = new NameValueCollection(); - - if (_hasEmbeddedCUESheet) - { - string trackPrefix = String.Format ("cue_track{0:00}_", iTrack + 1); - string[] keys = _albumTags.AllKeys; - for (int i = 0; i < keys.Length; i++) - { - if (keys[i].ToLower().StartsWith(trackPrefix) - || !keys[i].ToLower().StartsWith("cue_track")) - { - string name = keys[i].ToLower().StartsWith(trackPrefix) ? - keys[i].Substring(trackPrefix.Length) : keys[i]; - string[] values = _albumTags.GetValues(keys[i]); - for (int j = 0; j < values.Length; j++) - destTags.Add(name, values[j]); - } - } - } - else if (_hasTrackFilenames) - destTags.Add(_tracks[iTrack]._trackTags); - else if (_hasSingleFilename) - { - // TODO? - } - - destTags.Remove("CUESHEET"); - destTags.Remove("TRACKNUMBER"); - destTags.Remove("LOG"); - destTags.Remove("LOGFILE"); - destTags.Remove("EACLOG"); - CleanupTags(destTags, "ACCURATERIP"); - CleanupTags(destTags, "REPLAYGAIN"); - - if (destTags.Get("TITLE") == null && "" != _tracks[iTrack].Title) - destTags.Add("TITLE", _tracks[iTrack].Title); - if (destTags.Get("ARTIST") == null && "" != _tracks[iTrack].Artist) - destTags.Add("ARTIST", _tracks[iTrack].Artist); - destTags.Add("TRACKNUMBER", (iTrack + 1).ToString()); - if (_config.writeArTagsOnConvert) - { - if (!_isCD && _accurateRipMode == AccurateRipMode.VerifyThenConvert && _arVerify.AccResult == HttpStatusCode.OK) - GenerateAccurateRipTags(destTags, _writeOffset, bestOffset, iTrack); - else - destTags.Add("ACCURATERIPID", _accurateRipId); - } - audioDest.SetTags(destTags); - } - - private void SetAlbumTags(IAudioDest audioDest, int bestOffset, bool fWithCUE) - { - NameValueCollection destTags = new NameValueCollection(); - - if (_hasEmbeddedCUESheet || _hasSingleFilename) - { - destTags.Add(_albumTags); - if (!fWithCUE) - CleanupTags(destTags, "CUE_TRACK"); - } - else if (_hasTrackFilenames) - { - for (int iTrack = 0; iTrack < TrackCount; iTrack++) - { - string[] keys = _tracks[iTrack]._trackTags.AllKeys; - for (int i = 0; i < keys.Length; i++) - { - string singleValue = GetCommonTag (keys[i]); - if (singleValue != null) - { - if (destTags.Get(keys[i]) == null) - destTags.Add(keys[i], singleValue); - } - else if (fWithCUE && keys[i].ToUpper() != "TRACKNUMBER") - { - string[] values = _tracks[iTrack]._trackTags.GetValues(keys[i]); - for (int j = 0; j < values.Length; j++) - destTags.Add(String.Format("cue_track{0:00}_{1}", iTrack + 1, keys[i]), values[j]); - } - } - } - } - - destTags.Remove("CUESHEET"); - destTags.Remove("TITLE"); - destTags.Remove("TRACKNUMBER"); - CleanupTags(destTags, "ACCURATERIP"); - CleanupTags(destTags, "REPLAYGAIN"); - - if (fWithCUE && (!_isCD || _accurateRipMode == AccurateRipMode.VerifyThenConvert)) - destTags.Add("CUESHEET", CUESheetContents(CUEStyle.SingleFileWithCUE)); - - if (_config.embedLog) - { - destTags.Remove("LOG"); - destTags.Remove("LOGFILE"); - destTags.Remove("EACLOG"); - if (_eacLog != null) - destTags.Add("LOG", _eacLog); - } - - if (_config.writeArTagsOnConvert) - { - if (fWithCUE && !_isCD && _accurateRipMode == AccurateRipMode.VerifyThenConvert && _arVerify.AccResult == HttpStatusCode.OK) - GenerateAccurateRipTags(destTags, _writeOffset, bestOffset, -1); - else - destTags.Add("ACCURATERIPID", _accurateRipId); - } - audioDest.SetTags(destTags); - } - - public void WriteAudioFilesPass(string dir, CUEStyle style, string[] destPaths, int[] destLengths, bool htoaToFile, bool noOutput) - { - const int buffLen = 16384; - int iTrack, iIndex; - int[,] sampleBuffer = new int[buffLen, 2]; - TrackInfo track; - IAudioSource audioSource = null; - IAudioDest audioDest = null; - bool discardOutput; - int iSource = -1; - int iDest = -1; - uint samplesRemSource = 0; - CDImageLayout updatedTOC = null; - - if (_writeOffset != 0) - { - uint absOffset = (uint)Math.Abs(_writeOffset); - SourceInfo sourceInfo; - - sourceInfo.Path = null; - sourceInfo.Offset = 0; - sourceInfo.Length = absOffset; - - if (_writeOffset < 0) - { - _sources.Insert(0, sourceInfo); - - int last = _sources.Count - 1; - while (absOffset >= _sources[last].Length) - { - absOffset -= _sources[last].Length; - _sources.RemoveAt(last--); - } - sourceInfo = _sources[last]; - sourceInfo.Length -= absOffset; - _sources[last] = sourceInfo; - } - else - { - _sources.Add(sourceInfo); - - while (absOffset >= _sources[0].Length) - { - absOffset -= _sources[0].Length; - _sources.RemoveAt(0); - } - sourceInfo = _sources[0]; - sourceInfo.Offset += absOffset; - sourceInfo.Length -= absOffset; - _sources[0] = sourceInfo; - } - - _appliedWriteOffset = true; - } - - uint tracksMatch; - int bestOffset = _writeOffset; - if (!noOutput && _accurateRipMode == AccurateRipMode.VerifyThenConvert && _config.writeArTagsOnConvert && _arVerify.AccResult == HttpStatusCode.OK) - FindBestOffset(1, true, out tracksMatch, out bestOffset); - - if (hdcdDecoder != null) - hdcdDecoder.Reset(); - - if (style == CUEStyle.SingleFile || style == CUEStyle.SingleFileWithCUE) - { - iDest++; - audioDest = GetAudioDest(destPaths[iDest], destLengths[iDest], noOutput); - if (!noOutput) - SetAlbumTags(audioDest, bestOffset, style == CUEStyle.SingleFileWithCUE); - } - - uint currentOffset = 0, previousOffset = 0; - uint trackLength = _toc.Pregap * 588; - uint diskLength = 588 * (_toc[_toc.TrackCount].IsAudio ? _toc[_toc.TrackCount].End + 1 : _toc[_toc.TrackCount - 1].End + 1); - uint diskOffset = 0; - - if (_accurateRipMode != AccurateRipMode.None) - _arVerify.Init(); - - ShowProgress(String.Format("{2} track {0:00} ({1:00}%)...", 0, 0, noOutput ? "Verifying" : "Writing"), 0, 0.0, null, null); - - try - { - for (iTrack = 0; iTrack < TrackCount; iTrack++) - { - track = _tracks[iTrack]; - - if ((style == CUEStyle.GapsPrepended) || (style == CUEStyle.GapsLeftOut)) - { - iDest++; - if (hdcdDecoder != null) - hdcdDecoder.AudioDest = null; - if (audioDest != null) - audioDest.Close(); - audioDest = GetAudioDest(destPaths[iDest], destLengths[iDest], noOutput); - if (!noOutput) - SetTrackTags(audioDest, iTrack, bestOffset); - } - - for (iIndex = 0; iIndex <= _toc[iTrack + 1].LastIndex; iIndex++) - { - uint samplesRemIndex = _toc.IndexLength(iTrack + 1, iIndex) * 588; - - if (iIndex == 1) - { - previousOffset = currentOffset; - currentOffset = 0; - trackLength = _toc[iTrack + 1].Length * 588; - } - - if ((style == CUEStyle.GapsAppended) && (iIndex == 1)) - { - if (hdcdDecoder != null) - hdcdDecoder.AudioDest = null; - if (audioDest != null) - audioDest.Close(); - iDest++; - audioDest = GetAudioDest(destPaths[iDest], destLengths[iDest], noOutput); - if (!noOutput) - SetTrackTags(audioDest, iTrack, bestOffset); - } - - if ((style == CUEStyle.GapsAppended) && (iIndex == 0) && (iTrack == 0)) - { - discardOutput = !htoaToFile; - if (htoaToFile) - { - iDest++; - audioDest = GetAudioDest(destPaths[iDest], destLengths[iDest], noOutput); - } - } - else if ((style == CUEStyle.GapsLeftOut) && (iIndex == 0)) - { - discardOutput = true; - } - else - { - discardOutput = false; - } - - while (samplesRemIndex != 0) - { - if (samplesRemSource == 0) - { -#if !MONO - if (_isCD && audioSource != null && audioSource is CDDriveReader) - { - updatedTOC = ((CDDriveReader)audioSource).TOC; - _cdErrors = ((CDDriveReader)audioSource).Errors; - } -#endif - if (audioSource != null) audioSource.Close(); - audioSource = GetAudioSource(++iSource); - samplesRemSource = (uint)_sources[iSource].Length; - } - - uint copyCount = (uint)Math.Min(Math.Min(samplesRemIndex, samplesRemSource), buffLen); - - if (trackLength > 0 && !_isCD) - { - double trackPercent = (double)currentOffset / trackLength; - double diskPercent = (double)diskOffset / diskLength; - ShowProgress(String.Format("{2} track {0:00} ({1:00}%)...", iIndex > 0 ? iTrack + 1 : iTrack, (uint)(100*trackPercent), - noOutput ? "Verifying" : "Writing"), trackPercent, diskPercent, - _isCD ? string.Format("{0}: {1:00} - {2}", audioSource.Path, iTrack + 1, _tracks[iTrack].Title) : audioSource.Path, discardOutput ? null : audioDest.Path); - } - - if (audioSource.Read(sampleBuffer, copyCount) != copyCount) - throw new Exception("samples read != samples expected"); - if (!discardOutput) - { - if (!_config.detectHDCD || !_config.decodeHDCD) - audioDest.Write(sampleBuffer, copyCount); - if (_config.detectHDCD && hdcdDecoder != null) - { - if (_config.wait750FramesForHDCD && diskOffset > 750 * 588 && !hdcdDecoder.Detected) - { - hdcdDecoder.AudioDest = null; - hdcdDecoder = null; - if (_config.decodeHDCD) - { - audioSource.Close(); - audioDest.Delete(); - throw new Exception("HDCD not detected."); - } - } - else - { - if (_config.decodeHDCD) - hdcdDecoder.AudioDest = (discardOutput || noOutput) ? null : audioDest; - hdcdDecoder.Process(sampleBuffer, copyCount); - } - } - } - if (_accurateRipMode != AccurateRipMode.None) - _arVerify.Write(sampleBuffer, copyCount); - - currentOffset += copyCount; - diskOffset += copyCount; - samplesRemIndex -= copyCount; - samplesRemSource -= copyCount; - - lock (this) - { - if (_stop) - throw new StopException(); - if (_pause) - { - ShowProgress("Paused...", 0, 0, null, null); - Monitor.Wait(this); - } - } - } - } - } - } - catch (Exception ex) - { - if (hdcdDecoder != null) - hdcdDecoder.AudioDest = null; - hdcdDecoder = null; - try { if (audioSource != null) audioSource.Close(); } - catch { } - audioSource = null; - try { if (audioDest != null) audioDest.Close(); } - catch { } - audioDest = null; - throw ex; - } - -#if !MONO - if (_isCD && audioSource != null && audioSource is CDDriveReader) - { - updatedTOC = ((CDDriveReader)audioSource).TOC; - _cdErrors = ((CDDriveReader)audioSource).Errors; - } - if (updatedTOC != null) - { - _toc = updatedTOC; - if (_toc.Catalog != null) - General.SetCUELine(_attributes, "CATALOG", _toc.Catalog, false); - for (iTrack = 1; iTrack <= _toc.TrackCount; iTrack++) - { - if (_toc[iTrack].IsAudio && _toc[iTrack].ISRC != null) - General.SetCUELine(_tracks[iTrack - 1].Attributes, "ISRC", _toc[iTrack].ISRC, false); - if (_toc[iTrack].IsAudio && _toc[iTrack].PreEmphasis) - General.SetCUELine(_tracks[iTrack - 1].Attributes, "FLAGS", "PRE", false); - } - } -#endif - - if (hdcdDecoder != null) - hdcdDecoder.AudioDest = null; - if (audioSource != null) - audioSource.Close(); - if (audioDest != null) - audioDest.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) - { - StreamReader sr = new StreamReader(path, CUESheet.Encoding); - string cue = sr.ReadToEnd(); - sr.Close(); - return CorrectAudioFilenames(Path.GetDirectoryName(path), cue, always); - } - - public static string CorrectAudioFilenames(string dir, string cue, bool always) { - string[] audioExts = new string[] { "*.wav", "*.flac", "*.wv", "*.ape", "*.m4a" }; - List lines = new List(); - List filePos = new List(); - List origFiles = new List(); - bool foundAll = true; - string[] audioFiles = null; - string lineStr; - CUELine line; - int i; - - using (StringReader sr = new StringReader(cue)) { - while ((lineStr = sr.ReadLine()) != null) { - lines.Add(lineStr); - line = new CUELine(lineStr); - if ((line.Params.Count == 3) && (line.Params[0].ToUpper() == "FILE")) { - string fileType = line.Params[2].ToUpper(); - if ((fileType != "BINARY") && (fileType != "MOTOROLA")) { - filePos.Add(lines.Count - 1); - origFiles.Add(line.Params[1]); - foundAll &= (LocateFile(dir, line.Params[1], null) != null); - } - } - } - sr.Close(); - } - - if (!foundAll || always) - { - foundAll = false; - for (i = 0; i < audioExts.Length; i++) - { - foundAll = true; - List newFiles = new List(); - for (int j = 0; j < origFiles.Count; j++) - { - string newFilename = Path.ChangeExtension(Path.GetFileName(origFiles[j]), audioExts[i].Substring(1)); - foundAll &= LocateFile(dir, newFilename, null) != null; - newFiles.Add (newFilename); - } - if (foundAll) - { - audioFiles = newFiles.ToArray(); - break; - } - } - if (!foundAll) - for (i = 0; i < audioExts.Length; i++) - { - audioFiles = Directory.GetFiles(dir == "" ? "." : dir, audioExts[i]); - if (audioFiles.Length == filePos.Count) - { - Array.Sort(audioFiles); - foundAll = true; - break; - } - } - if (!foundAll) - throw new Exception("Unable to locate the audio files."); - - for (i = 0; i < filePos.Count; i++) - lines[filePos[i]] = "FILE \"" + Path.GetFileName(audioFiles[i]) + "\" WAVE"; - } - - using (StringWriter sw = new StringWriter()) { - for (i = 0; i < lines.Count; i++) { - sw.WriteLine(lines[i]); - } - return sw.ToString (); - } - } - - private int[] CalculateAudioFileLengths(CUEStyle style) - { - int iTrack, iIndex, iFile; - TrackInfo track; - int[] fileLengths; - bool htoaToFile = (style == CUEStyle.GapsAppended && _config.preserveHTOA && _toc.Pregap != 0); - bool discardOutput; - - if (style == CUEStyle.SingleFile || style == CUEStyle.SingleFileWithCUE) { - fileLengths = new int[1]; - iFile = 0; - } - else { - fileLengths = new int[TrackCount + (htoaToFile ? 1 : 0)]; - iFile = -1; - } - - for (iTrack = 0; iTrack < TrackCount; iTrack++) { - track = _tracks[iTrack]; - - if (style == CUEStyle.GapsPrepended || style == CUEStyle.GapsLeftOut) - iFile++; - - for (iIndex = 0; iIndex <= _toc[iTrack+1].LastIndex; iIndex++) { - if (style == CUEStyle.GapsAppended && (iIndex == 1 || (iIndex == 0 && iTrack == 0 && htoaToFile))) - iFile++; - - if (style == CUEStyle.GapsAppended && iIndex == 0 && iTrack == 0) - discardOutput = !htoaToFile; - else - discardOutput = (style == CUEStyle.GapsLeftOut && iIndex == 0); - - if (!discardOutput) - fileLengths[iFile] += (int)_toc.IndexLength(iTrack + 1, iIndex) * 588; - } - } - - return fileLengths; - } - - public void Stop() { - lock (this) { - if (_pause) - { - _pause = false; - Monitor.Pulse(this); - } - _stop = true; - } - } - - public void Pause() - { - lock (this) - { - if (_pause) - { - _pause = false; - Monitor.Pulse(this); - } else - { - _pause = true; - } - } - } - - public int TrackCount { - get { - return _tracks.Count; - } - } - - private IAudioDest GetAudioDest(string path, int finalSampleCount, bool noOutput) - { - if (noOutput) - return new DummyWriter(path, (_config.detectHDCD && _config.decodeHDCD) ? 24 : 16, 2, 44100); - return AudioReadWrite.GetAudioDest(path, finalSampleCount, _config); - } - - private IAudioSource GetAudioSource(int sourceIndex) { - SourceInfo sourceInfo = _sources[sourceIndex]; - IAudioSource audioSource; - - if (sourceInfo.Path == null) { - audioSource = new SilenceGenerator(sourceInfo.Offset + sourceInfo.Length); - } - else { -#if !MONO - if (_isCD) - { - CDDriveReader ripper = new CDDriveReader(); - ripper.Open(sourceInfo.Path[0]); - ripper.DriveOffset = _driveOffset; - ripper.ReadProgress += new EventHandler(CDReadProgress); - audioSource = ripper; - } else - if (_isArchive) - { - RarStream IO = new RarStream(_archivePath, sourceInfo.Path); - IO.PasswordRequired += new PasswordRequiredHandler(unrar_PasswordRequired); - audioSource = AudioReadWrite.GetAudioSource(sourceInfo.Path, IO); - } - else -#endif - audioSource = AudioReadWrite.GetAudioSource(sourceInfo.Path, null); - } - - if (sourceInfo.Offset != 0) - audioSource.Position = sourceInfo.Offset; - - return audioSource; - } - - private void WriteLine(TextWriter sw, int level, CUELine line) { - WriteLine(sw, level, line.ToString()); - } - - private void WriteLine(TextWriter sw, int level, string line) { - sw.Write(new string(' ', level * 2)); - sw.WriteLine(line); - } - - public List Attributes { - get { - return _attributes; - } - } - - public List Tracks { - get { - return _tracks; - } - } - - public bool HasHTOAFilename { - get { - return _hasHTOAFilename; - } - } - - public string HTOAFilename { - get { - return _htoaFilename; - } - set { - _htoaFilename = value; - } - } - - public bool HasTrackFilenames { - get { - return _hasTrackFilenames; - } - } - - public List TrackFilenames { - get { - return _trackFilenames; - } - } - - public bool HasSingleFilename { - get { - return _hasSingleFilename; - } - } - - public string SingleFilename { - get { - return _singleFilename; - } - set { - _singleFilename = value; - } - } - - public string Artist { - get { - CUELine line = General.FindCUELine(_attributes, "PERFORMER"); - return (line == null) ? String.Empty : line.Params[1]; - } - set { - General.SetCUELine(_attributes, "PERFORMER", value, true); - } - } - - public string Title { - get { - CUELine line = General.FindCUELine(_attributes, "TITLE"); - return (line == null) ? String.Empty : line.Params[1]; - } - set { - General.SetCUELine(_attributes, "TITLE", value, true); - } - } - - public int WriteOffset { - get { - return _writeOffset; - } - set { - if (_appliedWriteOffset) { - throw new Exception("Cannot change write offset after audio files have been written."); - } - _writeOffset = value; - } - } - - public bool PaddedToFrame { - get { - return _paddedToFrame; - } - } - - public string DataTrackLength - { - get - { - return CDImageLayout.TimeToString(_dataTrackLength.HasValue ? _dataTrackLength.Value : 0); - } - set - { - uint dtl = (uint)CDImageLayout.TimeFromString(value); - if (dtl != 0) - { - _dataTrackLength = dtl; - CDImageLayout toc2 = new CDImageLayout(_toc); - toc2.AddTrack(new CDTrack((uint)_toc.TrackCount, _toc.Length + 152 * 75, dtl, false, false)); - _accurateRipIdActual = _accurateRipId = AccurateRipVerify.CalculateAccurateRipId(toc2); - } - } - } - - public bool UsePregapForFirstTrackInSingleFile { - get { - return _usePregapForFirstTrackInSingleFile; - } - set{ - _usePregapForFirstTrackInSingleFile = value; - } - } - - public CUEConfig Config - { - get - { - return _config; - } - } - - public AccurateRipMode AccurateRip - { - get - { - return _accurateRipMode; - } - set - { - _accurateRipMode = value; - } - } - - public bool IsCD - { - get - { - return _isCD; - } - } - - private CDImageLayout _toc; - } - - public class CUELine { - private List _params; - private List _quoted; - - public CUELine() { - _params = new List(); - _quoted = new List(); - } - - public CUELine(string line) { - int start, end, lineLen; - bool isQuoted; - - _params = new List(); - _quoted = new List(); - - start = 0; - lineLen = line.Length; - - while (true) { - while ((start < lineLen) && (line[start] == ' ')) { - start++; - } - if (start >= lineLen) { - break; - } - - isQuoted = (line[start] == '"'); - if (isQuoted) { - start++; - } - - end = line.IndexOf(isQuoted ? '"' : ' ', start); - if (end == -1) { - end = lineLen; - } - - _params.Add(line.Substring(start, end - start)); - _quoted.Add(isQuoted); - - start = isQuoted ? end + 1 : end; - } - } - - public List Params { - get { - return _params; - } - } - - public List IsQuoted { - get { - return _quoted; - } - } - - public override string ToString() { - if (_params.Count != _quoted.Count) { - throw new Exception("Parameter and IsQuoted lists must match."); - } - - StringBuilder sb = new StringBuilder(); - int last = _params.Count - 1; - - for (int i = 0; i <= last; i++) { - if (_quoted[i]) sb.Append('"'); - sb.Append(_params[i]); - if (_quoted[i]) sb.Append('"'); - if (i < last) sb.Append(' '); - } - - return sb.ToString(); - } - } - - public class TrackInfo { - private List _attributes; - public NameValueCollection _trackTags; - - public TrackInfo() { - _attributes = new List(); - _trackTags = new NameValueCollection(); - } - - public List Attributes { - get { - return _attributes; - } - } - - public string Artist { - get { - CUELine line = General.FindCUELine(_attributes, "PERFORMER"); - return (line == null) ? String.Empty : line.Params[1]; - } - set - { - General.SetCUELine(_attributes, "PERFORMER", value, true); - } - } - - public string Title { - get { - CUELine line = General.FindCUELine(_attributes, "TITLE"); - return (line == null) ? String.Empty : line.Params[1]; - } - set - { - General.SetCUELine(_attributes, "TITLE", value, true); - } - } - } - - struct IndexInfo { - public int Track; - public int Index; - public int Time; - } - - struct SourceInfo { - public string Path; - public uint Offset; - public uint Length; - } - - public class StopException : Exception { - public StopException() : base() { - } - } -} \ No newline at end of file diff --git a/CUEToolsLib/Properties/AssemblyInfo.cs b/CUEToolsLib/Properties/AssemblyInfo.cs deleted file mode 100644 index c949ad1..0000000 --- a/CUEToolsLib/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("CUEToolsLib")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("CUEToolsLib")] -[assembly: AssemblyCopyright("Copyright © 2006-2008 Moitah, Gregory S. Chudov")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("d3afb938-f35e-4e5a-b650-7d7a4e885aff")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.9.4.0")] -[assembly: AssemblyFileVersion("1.9.4.0")] diff --git a/CUEToolsLib/Settings.cs b/CUEToolsLib/Settings.cs deleted file mode 100644 index 1959fb1..0000000 --- a/CUEToolsLib/Settings.cs +++ /dev/null @@ -1,129 +0,0 @@ -// **************************************************************************** -// -// CUE Tools -// Copyright (C) 2006-2007 Moitah (moitah@yahoo.com) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// **************************************************************************** - -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace CUETools.Processor -{ - static class SettingsShared - { - public static string GetMyAppDataDir(string appName) { - string appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - string myAppDataDir = Path.Combine(appDataDir, appName); - - if (Directory.Exists(myAppDataDir) == false) { - Directory.CreateDirectory(myAppDataDir); - } - - return myAppDataDir; - } - } - - public class SettingsReader { - Dictionary _settings; - - public SettingsReader(string appName, string fileName) { - _settings = new Dictionary(); - - string path = Path.Combine(SettingsShared.GetMyAppDataDir(appName), fileName); - if (!File.Exists(path)) { - return; - } - - using (StreamReader sr = new StreamReader(path, Encoding.UTF8)) { - string line, name, val; - int pos; - - while ((line = sr.ReadLine()) != null) { - pos = line.IndexOf('='); - if (pos != -1) { - name = line.Substring(0, pos); - val = line.Substring(pos + 1); - - if (!_settings.ContainsKey(name)) { - _settings.Add(name, val); - } - } - } - } - } - - public string Load(string name) { - return _settings.ContainsKey(name) ? _settings[name] : null; - } - - public bool? LoadBoolean(string name) { - string val = Load(name); - if (val == "0") return false; - if (val == "1") return true; - return null; - } - - public int? LoadInt32(string name, int? min, int? max) { - int val; - if (!Int32.TryParse(Load(name), out val)) return null; - if (min.HasValue && (val < min.Value)) return null; - if (max.HasValue && (val > max.Value)) return null; - return val; - } - - public uint? LoadUInt32(string name, uint? min, uint? max) { - uint val; - if (!UInt32.TryParse(Load(name), out val)) return null; - if (min.HasValue && (val < min.Value)) return null; - if (max.HasValue && (val > max.Value)) return null; - return val; - } - } - - public class SettingsWriter { - StreamWriter _sw; - - public SettingsWriter(string appName, string fileName) { - string path = Path.Combine(SettingsShared.GetMyAppDataDir(appName), fileName); - - _sw = new StreamWriter(path, false, Encoding.UTF8); - } - - public void Save(string name, string value) { - _sw.WriteLine(name + "=" + value); - } - - public void Save(string name, bool value) { - Save(name, value ? "1" : "0"); - } - - public void Save(string name, int value) { - Save(name, value.ToString()); - } - - public void Save(string name, uint value) { - Save(name, value.ToString()); - } - - public void Close() { - _sw.Close(); - } - } -} \ No newline at end of file diff --git a/FLACDotNet/FLACDotNet.sln b/FLACDotNet/FLACDotNet.sln deleted file mode 100644 index 7a2796c..0000000 --- a/FLACDotNet/FLACDotNet.sln +++ /dev/null @@ -1,36 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FLACDotNet", "FLACDotNet.vcproj", "{E70FA90A-7012-4A52-86B5-362B699D1540}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APEDotNet", "..\APEDotNet\APEDotNet.vcproj", "{9AE965C4-301E-4C01-B90F-297AF341ACC6}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {E70FA90A-7012-4A52-86B5-362B699D1540}.Debug|Win32.ActiveCfg = Debug|Win32 - {E70FA90A-7012-4A52-86B5-362B699D1540}.Debug|Win32.Build.0 = Debug|Win32 - {E70FA90A-7012-4A52-86B5-362B699D1540}.Debug|x64.ActiveCfg = Debug|x64 - {E70FA90A-7012-4A52-86B5-362B699D1540}.Debug|x64.Build.0 = Debug|x64 - {E70FA90A-7012-4A52-86B5-362B699D1540}.Release|Win32.ActiveCfg = Release|Win32 - {E70FA90A-7012-4A52-86B5-362B699D1540}.Release|Win32.Build.0 = Release|Win32 - {E70FA90A-7012-4A52-86B5-362B699D1540}.Release|x64.ActiveCfg = Release|x64 - {E70FA90A-7012-4A52-86B5-362B699D1540}.Release|x64.Build.0 = Release|x64 - {9AE965C4-301E-4C01-B90F-297AF341ACC6}.Debug|Win32.ActiveCfg = Debug|Win32 - {9AE965C4-301E-4C01-B90F-297AF341ACC6}.Debug|Win32.Build.0 = Debug|Win32 - {9AE965C4-301E-4C01-B90F-297AF341ACC6}.Debug|x64.ActiveCfg = Debug|x64 - {9AE965C4-301E-4C01-B90F-297AF341ACC6}.Debug|x64.Build.0 = Debug|x64 - {9AE965C4-301E-4C01-B90F-297AF341ACC6}.Release|Win32.ActiveCfg = Release|Win32 - {9AE965C4-301E-4C01-B90F-297AF341ACC6}.Release|Win32.Build.0 = Release|Win32 - {9AE965C4-301E-4C01-B90F-297AF341ACC6}.Release|x64.ActiveCfg = Release|x64 - {9AE965C4-301E-4C01-B90F-297AF341ACC6}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/HDCDDotNet/HDCDDotNet.csproj b/HDCDDotNet/HDCDDotNet.csproj index 0f25675..f017e79 100644 --- a/HDCDDotNet/HDCDDotNet.csproj +++ b/HDCDDotNet/HDCDDotNet.csproj @@ -85,7 +85,7 @@ - + {6458A13A-30EF-45A9-9D58-E5031B17BEE2} CUETools.Codecs diff --git a/LossyWAVSharp/LossyWAVSharp.csproj b/LossyWAVSharp/LossyWAVSharp.csproj index b4b14e2..9ff38e4 100644 --- a/LossyWAVSharp/LossyWAVSharp.csproj +++ b/LossyWAVSharp/LossyWAVSharp.csproj @@ -81,11 +81,11 @@ - + {6458A13A-30EF-45A9-9D58-E5031B17BEE2} AudioCodecsDotNet - + {8A0426FA-0BC2-4C49-A6E5-1F9A68156F19} LossyWAVDotNet diff --git a/WavPackDotNet/WavPackDotNet.sln b/WavPackDotNet/WavPackDotNet.sln deleted file mode 100644 index 773fcde..0000000 --- a/WavPackDotNet/WavPackDotNet.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WavPackDotNet", "WavPackDotNet.vcproj", "{CC2E74B6-534A-43D8-9F16-AC03FE955000}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CC2E74B6-534A-43D8-9F16-AC03FE955000}.Debug|Win32.ActiveCfg = Debug|Win32 - {CC2E74B6-534A-43D8-9F16-AC03FE955000}.Debug|Win32.Build.0 = Debug|Win32 - {CC2E74B6-534A-43D8-9F16-AC03FE955000}.Release|Win32.ActiveCfg = Release|Win32 - {CC2E74B6-534A-43D8-9F16-AC03FE955000}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal