Exemple #1
0
        private void OnBuildDriveButtonMenu(object sender, EventArgs e)
        {
            try
            {
                System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();

                tsbDrives.DropDownItems.Clear();
                ilDrives.Images.Clear();

                tsbDrives.DropDown.BackColor = ThemeManager.WndValidColor;

                foreach (System.IO.DriveInfo di in drives)
                {
                    DriveInfoItem dii = new DriveInfoItem(di);
                    OPMToolStripDropDownMenuItem tsi = new OPMToolStripDropDownMenuItem(tsbDrives);
                    tsi.ImageScaling = ToolStripItemImageScaling.None;

                    tsi.Text  = dii.ToString();
                    tsi.Tag   = dii.Path;
                    tsi.Image = dii.Image;

                    tsbDrives.DropDownItems.Add(tsi);
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
        }
        private void PopulateAudioCDDrives()
        {
            cmbAudioCDDrives.Items.Clear();
            lvTracks.Items.Clear();

            DriveInfoItem selected = null;

            btnRefresh.Enabled = false;
            pbWaiting.Visible  = true;
            Application.DoEvents();

            ThreadPool.QueueUserWorkItem((c) =>
            {
                try
                {
                    DriveInfo[] audioCDs = CDDrive.GetAllAudioCDDrives();
                    foreach (DriveInfo di in audioCDs)
                    {
                        DriveInfoItem item = new DriveInfoItem(di);

                        MainThread.Post((d) => { cmbAudioCDDrives.Items.Add(item); });

                        if ((BkgTask as Task).DrivePath == null)
                        {
                            (BkgTask as Task).DrivePath = di.RootDirectory.FullName;
                        }

                        if (Path.Equals(di.RootDirectory.FullName, (BkgTask as Task).DrivePath))
                        {
                            selected = item;
                        }
                    }

                    MainThread.Post((d) =>
                    {
                        cmbAudioCDDrives.SelectedItem = selected;
                    });
                }
                finally
                {
                    MainThread.Post((d) =>
                    {
                        pbWaiting.Visible  = false;
                        btnRefresh.Enabled = true;
                    });
                }
            });
        }
        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))
                {
                    (BkgTask as Task).DrivePath = 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();
        }