private static CdItemViewModel[] GetTracksJob(string driveLetter) { using (var cd = new CdReader()) { cd.Open(driveLetter[0]); bool prepare = cd.LoadCD() && cd.LockCD() && cd.Refresh(); if (!prepare) { return(new CdItemViewModel[0]); } List <CdItemViewModel> results = new List <CdItemViewModel>(cd.NumberOfAudioTracks); for (int i = 1; i <= cd.NumberOfTracks; i++) { Domain.Cd.CdTrackInfo?trackInfo = cd.GetTrackInfo(i); if (trackInfo != null && trackInfo.IsAudio) { results.Add(new CdItemViewModel($"Audio Track #{i}") { Length = TimeSpan.FromSeconds(trackInfo.Length), Size = trackInfo.Size, IsSelected = true, Track = i }); } } cd.UnLockCD(); return(results.ToArray()); } }
private void buttonSaveAs_Click(object sender, System.EventArgs e) { if (listViewTracks.SelectedIndices.Count > 0) { int ndx = listViewTracks.SelectedIndices[0]; string title = string.Format("track{0:00}", ndx + 1); saveFileDialog.FileName = string.Format("{0}.wav", title); if (saveFileDialog.ShowDialog() == DialogResult.OK) { ripping = true; try { statusBar.Text = string.Format("Reading track {0}", ndx + 1); UpdateVisualControls(); IntPtr format = CdDrive.GetFormat(); WaveWriter ww = new WaveWriter(File.Create(saveFileDialog.FileName), AudioCompressionManager.FormatBytes(format)); CdReader cr = cda.GetReader(ndx); int durationInMS = cr.GetDurationInMS(); int max = durationInMS / 1000; progressBar1.Minimum = 0; progressBar1.Value = 0; progressBar1.Maximum = max + 1; for (int i = 0; i <= max; i++) { byte[] data = cr.ReadData(i, 1); ww.WriteData(data); progressBar1.Value = i + 1; Application.DoEvents(); } cr.Close(); ww.Close(); DsConvert.ToWma(saveFileDialog.FileName, saveFileDialog.FileName + ".wma", DsConvert.WmaProfile.Stereo128); } finally { ripping = false; } } } UpdateVisualControls(); }
private static bool ReadTracksJob(string driveLetter, IEnumerable <CdItemViewModel> tracks, string outDir, IProgress <long> progress, CancellationToken token) { using (var cd = new CdReader()) { cd.Open(driveLetter[0]); bool prepare = cd.LoadCD() && cd.LockCD() && cd.Refresh(); if (!prepare) { return(false); } foreach (var track in tracks) { progress.Report(0); var outfile = Path.Combine(outDir, $"Track {track.Track}.wav"); using (var file = File.Create(outfile)) { bool result = cd.ReadTrack(track.Track, file, progress, token); if (!result) { return(false); } } } cd.UnLockCD(); } return(true); }