Пример #1
0
 public void Close()
 {
     if (_progress != null)
     {
         _progress.cueSheet = null;
         _progress = null;
     }
     if (_archive != null)
         _archive.Close();
     _archive = null;
     if (_ripper != null)
     {
         //_ripper.ReadProgress -= new EventHandler<ReadProgressArgs>(CDReadProgress);
         _ripper.Close();
     }
     _ripper = null;
 }
Пример #2
0
        public void Open(string pathIn)
        {
            _inputPath = pathIn;
            _inputDir = Path.GetDirectoryName(_inputPath) ?? _inputPath;
            if (_inputDir == "") _inputDir = ".";
            if (_inputDir == pathIn && CUEProcessorPlugins.ripper != null)
            {
                ICDRipper ripper = Activator.CreateInstance(CUEProcessorPlugins.ripper) as ICDRipper;
                try
                {
                    ripper.Open(pathIn[0]);
                    if (ripper.TOC.AudioTracks > 0)
                    {
                        OpenCD(ripper);
                        int driveOffset;
                        if (!AccurateRipVerify.FindDriveReadOffset(_ripper.ARName, out driveOffset))
                            throw new Exception("Failed to find drive read offset for drive" + _ripper.ARName);
                        _ripper.DriveOffset = driveOffset;
                        //LookupAlbumInfo();
                        return;
                    }
                }
                catch
                {
                    ripper.Dispose();
                    _ripper = null;
                    throw;
                }
            }

            TextReader sr;

            if (Directory.Exists(pathIn))
                throw new Exception("is a directory");
            //{
            //    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", "*.tta" };
            //    for (i = 0; i < audioExts.Length && cueSheet == null; i++)
            //        cueSheet = CUESheet.CreateDummyCUESheet(pathIn, audioExts[i]);
            //    if (_config.udc1Extension != null && cueSheet == null)
            //        cueSheet = CUESheet.CreateDummyCUESheet(pathIn, "*." + _config.udc1Extension);
            //    if (cueSheet == null)
            //        throw new Exception("Input directory doesn't contain supported audio files.");
            //    sr = new StringReader(cueSheet);

            //    List<CUEToolsSourceFile> logFiles = new List<CUEToolsSourceFile>();
            //    foreach (string logPath in Directory.GetFiles(pathIn, "*.log"))
            //        logFiles.Add(new CUEToolsSourceFile(logPath, new StreamReader(logPath, CUESheet.Encoding)));
            //    CUEToolsSourceFile selectedLogFile = ChooseFile(logFiles, null, false);
            //    _eacLog = selectedLogFile != null ? selectedLogFile.contents : null;
            //} 
            else if (CUEProcessorPlugins.arcp_fmt.Contains(Path.GetExtension(pathIn).ToLower().Trim('.')))
            {
                _archive = null;
                foreach (Type type in CUEProcessorPlugins.arcp)
                {
                    CompressionProviderClass archclass = Attribute.GetCustomAttribute(type, typeof(CompressionProviderClass)) as CompressionProviderClass;
                    if (archclass.Extension == Path.GetExtension(pathIn).ToLower().Trim('.'))
                    {
                        _archive = Activator.CreateInstance(type, pathIn) as ICompressionProvider;
                        break;
                    }
                }
                if (_archive == null)
                    throw new Exception("archive type not supported.");
                _isArchive = true;
                _archiveContents = new List<string>();
                _archive.PasswordRequired += new EventHandler<CompressionPasswordRequiredEventArgs>(unzip_PasswordRequired);
                _archive.ExtractionProgress += new EventHandler<CompressionExtractionProgressEventArgs>(unzip_ExtractionProgress);
                foreach (string f in _archive.Contents)
                    _archiveContents.Add(f);

                _logFiles = new List<CUEToolsSourceFile>();
                List<CUEToolsSourceFile> cueFiles = new List<CUEToolsSourceFile>();
                foreach (string s in _archiveContents)
                {
                    if (Path.GetExtension(s).ToLower() == ".cue" || Path.GetExtension(s).ToLower() == ".log")
                    {
                        Stream archiveStream = OpenArchive(s, false);
                        CUEToolsSourceFile sourceFile = new CUEToolsSourceFile(s, new StreamReader(archiveStream, CUESheet.Encoding));
                        archiveStream.Close();
                        if (Path.GetExtension(s).ToLower() == ".cue")
                            cueFiles.Add(sourceFile);
                        else
                            _logFiles.Add(sourceFile);
                    }
                }
                CUEToolsSourceFile selectedCUEFile = ChooseFile(cueFiles, null, true);
                if (selectedCUEFile == null || selectedCUEFile.contents == "")
                    throw new Exception("Input archive doesn't contain a usable cue sheet.");
                _defaultLog = Path.GetFileNameWithoutExtension(selectedCUEFile.path);
                _archiveCUEpath = Path.GetDirectoryName(selectedCUEFile.path);
                string cueText = selectedCUEFile.contents;
                if (_config.autoCorrectFilenames)
                {
                    string extension;
                    cueText = CorrectAudioFilenames(_config, _archiveCUEpath, cueText, false, _archiveContents, out extension);
                }
                sr = new StringReader(cueText);
                if (_logFiles.Count == 1)
                    _eacLog = _logFiles[0].contents;
            }
            else if (Path.GetExtension(pathIn).ToLower() == ".cue")
            {
                if (_config.autoCorrectFilenames)
                    sr = new StringReader(CorrectAudioFilenames(_config, pathIn, false));
                else
                    sr = new StreamReader(pathIn, CUESheet.Encoding);

                _logFiles = new List<CUEToolsSourceFile>();
                _defaultLog = Path.GetFileNameWithoutExtension(pathIn);
                foreach (string logPath in Directory.GetFiles(_inputDir, "*.log"))
                    try { _logFiles.Add(new CUEToolsSourceFile(logPath, new StreamReader(logPath, CUESheet.Encoding))); }
                    catch { }
            }
            else if (Path.GetExtension(pathIn).ToLower() == ".m3u")
            {
                string cueSheet = CUESheet.CreateDummyCUESheet(_config, pathIn);
                sr = new StringReader(cueSheet);
                _logFiles = new List<CUEToolsSourceFile>();
                _defaultLog = Path.GetFileNameWithoutExtension(pathIn);
                foreach (string logPath in Directory.GetFiles(_inputDir, "*.log"))
                    try { _logFiles.Add(new CUEToolsSourceFile(logPath, new StreamReader(logPath, CUESheet.Encoding))); }
                    catch { }
            }
            else
            {
                string extension = Path.GetExtension(pathIn).ToLower();
                sr = null;
                CUEToolsFormat fmt;
                if (!extension.StartsWith(".") || !_config.formats.TryGetValue(extension.Substring(1), out fmt) || !fmt.allowLossless)
                    throw new Exception("Unknown input format.");
                if (fmt.allowEmbed)
                {
                    string cuesheetTag = null;
                    TagLib.File fileInfo;
                    GetSampleLength(pathIn, out fileInfo);
                    NameValueCollection tags = Tagging.Analyze(fileInfo);
                    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");
                    if (cuesheetTag != null)
                    {
                        sr = new StringReader(cuesheetTag);
                        _hasEmbeddedCUESheet = true;
                    }
                }
                if (!_hasEmbeddedCUESheet)
                {
                    string cueSheet = CUESheet.CreateDummyCUESheet(_config, pathIn);
                    if (cueSheet == null)
                        throw new Exception("Input file doesn't seem to contain a cue sheet or be part of an album.");
                    sr = new StringReader(cueSheet);
                    _logFiles = new List<CUEToolsSourceFile>();
                    foreach (string logPath in Directory.GetFiles(_inputDir, "*.log"))
                        try { _logFiles.Add(new CUEToolsSourceFile(logPath, new StreamReader(logPath, CUESheet.Encoding))); }
                        catch { }
                }
            }

            OpenCUE(sr);
        }
Пример #3
0
 public void OpenCD(ICDRipper ripper)
 {
     _ripper = ripper;
     _toc = (CDImageLayout)_ripper.TOC.Clone();
     for (int iTrack = 0; iTrack < _toc.AudioTracks; iTrack++)
     {
         _trackFilenames.Add(string.Format("{0:00}.wav", iTrack + 1));
         _tracks.Add(new TrackInfo());
     }
     cueMetadata = new CUEMetadata(TOC.TOCID, (int)TOC.AudioTracks);
     _arVerify = new AccurateRipVerify(_toc, proxy);
     _isCD = true;
     SourceInfo cdInfo;
     cdInfo.Path = _ripper.ARName;
     cdInfo.Offset = 0;
     cdInfo.Length = _toc.AudioLength * 588;
     _sources.Add(cdInfo);
     // Causes memory leak, so had to disable!
     //_ripper.ReadProgress += new EventHandler<ReadProgressArgs>(CDReadProgress);
     _padding += TrackCount * 200;
     _padding += _config.embedLog ? 500 + TrackCount * 200 : 0;
 }
Пример #4
0
		private CUEMetadataEntry CreateCUESheet(ICDRipper audioSource)
		{
			CUEMetadataEntry entry = new CUEMetadataEntry(audioSource.TOC, "local");
			entry.metadata.Artist = "Unknown Artist";
			entry.metadata.Title = "Unknown Title";
			for (int i = 0; i < entry.TOC.AudioTracks; i++)
			{
				entry.metadata.Tracks[i].Title = string.Format("Track {0:00}", i + 1);
				entry.metadata.Tracks[i].Artist = entry.metadata.Artist;
			}
			return entry;
		}
Пример #5
0
		//private CUEMetadataEntry CreateCUESheet(ICDRipper audioSource, Release release)
		//{
		//    CUEMetadataEntry entry = new CUEMetadataEntry(audioSource.TOC, "musicbrainz");
		//    entry.metadata.FillFromMusicBrainz(release, entry.TOC.FirstAudio - 1);
		//    return entry;
		//}

		private CUEMetadataEntry CreateCUESheet(ICDRipper audioSource, CDEntry cdEntry)
		{
			CUEMetadataEntry entry = new CUEMetadataEntry(audioSource.TOC, "freedb");
			entry.metadata.FillFromFreedb(cdEntry, entry.TOC.FirstAudio - 1);
			return entry;
		}
Пример #6
0
		private CUEMetadataEntry CreateCUESheet(ICDRipper audioSource, CTDBResponseMeta release)
		{
			CUEMetadataEntry entry = new CUEMetadataEntry(audioSource.TOC, release.source);
			entry.metadata.FillFromCtdb(release, entry.TOC.FirstAudio - 1);
			return entry;
		}
Пример #7
0
		public DriveInfo(CUEControls.IIconManager iconMgr, string path, ICDRipper drive)
		{
			this.iconMgr = iconMgr;
			this.di = new DirectoryInfo(path);
			this.drive = drive;
		}