Пример #1
0
        public static DriveInfo[] GetAllAudioCDDrives()
        {
            List <DriveInfo> drives = new List <DriveInfo>();

            foreach (DriveInfo di in DriveInfo.GetDrives())
            {
                if (di.DriveType != DriveType.CDRom)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(di.RootDirectory.FullName))
                {
                    char letter = di.RootDirectory.FullName.ToUpperInvariant()[0];
                    using (CDDrive cd = new CDDrive())
                    {
                        if (cd.Open(letter) && cd.Refresh() && cd.HasAudioTracks())
                        {
                            drives.Add(di);
                        }
                    }
                }
            }

            return(drives.ToArray());
        }
Пример #2
0
      public static DriveInfo[] GetAllAudioCDDrives()
      {
          List<DriveInfo> drives = new List<DriveInfo>();

          foreach (DriveInfo di in DriveInfo.GetDrives())
          {
              if (di.DriveType != DriveType.CDRom)
                  continue;

              if (!string.IsNullOrEmpty(di.RootDirectory.FullName))
              {
                  char letter = di.RootDirectory.FullName.ToUpperInvariant()[0];
                  using (CDDrive cd = new CDDrive())
                  {
                      if (cd.Open(letter) && cd.Refresh() && cd.HasAudioTracks())
                      {
                        drives.Add(di);
                      }
                  }
              }
          }

          return drives.ToArray();
      }
Пример #3
0
        private void OnDriveSelected(object sender, EventArgs e)
        {
            Wizard.CanMoveNext = false;
            lvTracks.Items.Clear();

            DriveInfoItem item = cmbAudioCDDrives.SelectedItem as DriveInfoItem;
            if (item != null)
            {
                string rootPath = System.IO.Path.GetPathRoot(item.Path);
                if (!string.IsNullOrEmpty(rootPath))
                {
                    CDEntry cdEntry = null;
                    char letter = rootPath.ToUpperInvariant()[0];
                    using (CDDrive cd = new CDDrive())
                    {
                        if (cd.Open(letter) && cd.Refresh())
                        {
                            // Check whether the disc is already added to our persistent storage
                            string discId = cd.GetCDDBDiskID();
                            cdEntry = CDEntry.LoadPersistentDisc(discId);

                            if (cdEntry == null)
                            {
                                switch (ProTONEConfig.AudioCdInfoSource)
                                {
                                    case CddaInfoSource.CdText:
                                        cdEntry = CDAFileInfo.BuildCdEntryByCdText(cd, cd.GetCDDBDiskID());
                                        break;

                                    case CddaInfoSource.Cddb:
                                        cdEntry = CDAFileInfo.BuildCdEntryByCddb(cd, cd.GetCDDBDiskID());
                                        break;

                                    case CddaInfoSource.CdText_Cddb:
                                        {
                                            cdEntry = CDAFileInfo.BuildCdEntryByCdText(cd, cd.GetCDDBDiskID());
                                            CDEntry cde = CDAFileInfo.BuildCdEntryByCddb(cd, cd.GetCDDBDiskID());
                                            cdEntry = CDAFileInfo.Merge(cdEntry, cde);
                                        }
                                        break;

                                    case CddaInfoSource.Cddb_CdText:
                                        {
                                            cdEntry = CDAFileInfo.BuildCdEntryByCddb(cd, cd.GetCDDBDiskID());
                                            CDEntry cde = CDAFileInfo.BuildCdEntryByCdText(cd, cd.GetCDDBDiskID());
                                            cdEntry = CDAFileInfo.Merge(cdEntry, cde);
                                        }
                                        break;

                                    default:
                                        break;
                                }

                                if (cdEntry != null)
                                {
                                   // Cache the disk to persistent storage for retrieving it faster later on
                                   cdEntry.PersistDisc();
                               }
                           }
                        }

                        if (cdEntry != null)
                        {
                            for (int i = 1; i <= cdEntry.NumberOfTracks; i++)
                            {
                                double size = cd.TrackSize(i);
                                int duration = cd.GetSeconds(i);
    
                                ListViewItem lvItem = new ListViewItem(i.ToString());
    
                                lvItem.SubItems.Add(TimeSpan.FromSeconds(duration).ToString());
                                lvItem.SubItems.Add(((size / (1024 * 1024)).ToString("F")) + " MB");
    
                                OPMListViewSubItem subItem = new OPMListViewSubItem(tbEditAlbum, lvItem,
                                    cdEntry.Tracks[i - 1].Album ?? string.Empty);
                                subItem.ReadOnly = false;
                                lvItem.SubItems.Add(subItem);
    
                                subItem = new OPMListViewSubItem(tbEditArtist, lvItem,
                                    cdEntry.Tracks[i - 1].Artist ?? string.Empty);
                                subItem.ReadOnly = false;
                                lvItem.SubItems.Add(subItem);
    
                                subItem = new OPMListViewSubItem(tbEditTitle, lvItem,
                                    cdEntry.Tracks[i - 1].Title ?? string.Empty);
                                subItem.ReadOnly = false;
                                lvItem.SubItems.Add(subItem);
    
                                subItem = new OPMListViewSubItem(cmbEditgenre, lvItem,
                                    cdEntry.Tracks[i - 1].Genre ?? string.Empty);
                                subItem.ReadOnly = false;
                                lvItem.SubItems.Add(subItem);
    
                                if (Wizard.RepeatCount == 0)
                                {
                                    lvItem.ImageIndex = 1;
                                }
                                else
                                {
                                    //lvItem.ImageIndex = ((BkgTask as Task).Tracks.Contains(i)) ? 1 : 0;
                                }
    
                                lvItem.Tag = cdEntry.Tracks[i - 1];
    
                                lvTracks.Items.Add(lvItem);
                            }
                        }
                    }
                }
            }

            CheckNextButton();
        }
Пример #4
0
        private StepDetail ProcessTrack(Track track)
        {
            string newFileName = string.Format("{0}.{1}",
                CdRipper.GetFileName(WordCasing.KeepCase, track, OutputFilePattern),
                this.EncoderSettings.AudioMediaFormatType.ToString().ToLowerInvariant());

            StepDetail detail = new StepDetail();
            detail.Description = Translator.Translate("TXT_PROCESSING_TRACK", track, newFileName);
            RaiseTaskStepInitEvent(detail);

            detail.Results = Translator.Translate("TXT_UNHANDLED");
            detail.IsSuccess = false;

            try
            {
                _grabber = CdRipper.CreateGrabber(this.EncoderSettings.AudioMediaFormatType);
                char letter = Drive.RootDirectory.FullName.ToUpperInvariant()[0];
                using (CDDrive cd = new CDDrive())
                {
                    if (cd.Open(letter) && cd.Refresh() && cd.HasAudioTracks())
                    {
                        string destFile = Path.Combine(OutputFolder, newFileName);

                        bool generateTagsFromMetadata = false;

                        switch (this.EncoderSettings.AudioMediaFormatType)
                        {
                            case AudioMediaFormatType.WAV:
                                break;

                            case AudioMediaFormatType.MP3:
                                (_grabber as GrabberToMP3).Mp3ConversionOptions = this.EncoderSettings.Mp3EncoderSettings.Mp3ConversionOptions;
                                generateTagsFromMetadata = this.EncoderSettings.Mp3EncoderSettings.GenerateTagsFromTrackMetadata;
                                break;
                        }

                        _grabber.Grab(cd, track, destFile, generateTagsFromMetadata);
                    }
                }

                detail.IsSuccess = true;
            }
            catch (Exception ex)
            {
                detail.Results = ex.Message;
            }

            return detail;
        }
Пример #5
0
        public void RefreshDisk()
        {
            string rootPath = System.IO.Path.GetPathRoot(this.Path);
            if (!string.IsNullOrEmpty(rootPath))
            {
                char letter = rootPath.ToUpperInvariant()[0];
                {
                    using (CDDrive cd = new CDDrive())
                    {
                        if (cd.Open(letter) && cd.Refresh())
                        {
                            switch (ProTONEConfig.AudioCdInfoSource)
                            {
                                case CddaInfoSource.CdText:
                                    _cdEntry = BuildCdEntryByCdText(cd, _discId);
                                    break;

                                case CddaInfoSource.Cddb:
                                    _cdEntry = BuildCdEntryByCddb(cd, _discId);
                                    break;

                                case CddaInfoSource.CdText_Cddb:
                                    {
                                        _cdEntry = BuildCdEntryByCdText(cd, _discId);
                                        CDEntry cde = BuildCdEntryByCddb(cd, _discId);
                                        _cdEntry = Merge(_cdEntry, cde);
                                    }
                                    break;

                                case CddaInfoSource.Cddb_CdText:
                                    {
                                        _cdEntry = BuildCdEntryByCddb(cd, _discId);
                                        CDEntry cde = BuildCdEntryByCdText(cd, _discId);
                                        _cdEntry = Merge(_cdEntry, cde);
                                    }
                                    break;

                                default:
                                    break;
                            }

                            if (_cdEntry != null)
                            {
                                _cdEntry.PersistDisc();
                            }
                        }
                    }
                }
            }
        }
Пример #6
0
        public CDAFileInfo(string path, bool deepLoad)
            : base(path, false)
        {
            try
            {
                string rootPath = System.IO.Path.GetPathRoot(path);
                if (!string.IsNullOrEmpty(rootPath))
                {
                    char letter = rootPath.ToUpperInvariant()[0];
                    using (CDDrive cd = new CDDrive())
                    {
                        if (cd.Open(letter) && cd.Refresh())
                        {
                            string trackStr = path.Replace(rootPath, "").ToLowerInvariant().Replace("track", "").Replace(".cda", "");
                            _track = -1;
                            if (int.TryParse(trackStr, out _track) && _track > 0)
                            {
                                if (cd.IsAudioTrack(_track))
                                {
                                    _duration = cd.GetSeconds(_track);

                                    _discId = cd.GetCDDBDiskID();

                                    // Check whether the disc is already added to our FreeDb lite database
                                    _cdEntry = CDEntry.LoadPersistentDisc(_discId);
                                    if (_cdEntry == null)
                                    {
                                        RefreshDisk();
                                    }

                                    return;
                                }
                            }
                        }
                    }

                    _cdEntry = null;
                }
            }
            catch(Exception ex) 
            {
                Logger.LogException(ex);
                _cdEntry = null;
            }
        }