private void Button_Click(object sender, RoutedEventArgs e) { if (System.IO.File.Exists(FinalFileLocation.Text)) { W("clean_output_msg", FinalFileLocation.Text + " exists; cleaning"); try { System.IO.File.Delete(FinalFileLocation.Text); W("clean_output_msg", FinalFileLocation.Text + " successfully deleted"); } catch (Exception exc) { W("clean_output_err", exc.ToString()); } } else { W("clean_output_msg", FinalFileLocation.Text + " does not exist"); } dl = new YTDLInteract.Download(URL.Text, "bestaudio", FinalFileLocation.Text); dl.TrimmedErrorDataReceived += (obj, dt) => { W("err", dt.FullData); }; dl.TrimmedOutputDataReceived += (obj, dt) => { W("out", dt.FullData); }; dl.ProgressReported += (obj, dt) => { Progress.Value = dt.Percent; Percent.Text = dt.Percent.ToString(); TotalSize.Text = dt.Size; Speed.Text = dt.Speed; ETA.Text = dt.Time.ToString(); }; dl.Finished += (obj, dt) => { W("Finished!"); }; }
private void Gm_Finished(object sender, EventArgs e) { gm.Finished -= Gm_Finished; PartialProgress.Value = 0; OnProgressReported(25); if (gm.Status != WorkerStatus.Successful) { OnFinished(false); return; } try { if (TempDirInfo.Exists) { TempDirInfo.Delete(true); OnTrimmedOutputDataReceived("TempDirInfo deleted preexistent directory:" + TempDirInfo.FullName); } TempDirInfo.Create(); OnTrimmedOutputDataReceived("TempDirInfo created:" + TempDirInfo.FullName); } catch (Exception exc) { OnTrimmedErrorDataReceived("TempDirInfo error operating with directory:" + exc.ToString()); OnFinished(false); return; } if (FinalFileInfo.Name == "default.mp3") { FinalFileInfo = new System.IO.FileInfo(FinalFileInfo.DirectoryName + @"\" + SafeTitle + ".mp3"); } OnTrimmedOutputDataReceived("FinalFileInfo location:" + FinalFileInfo.FullName); dl = new YTDLInteract.Download(URL.Text, "bestaudio", TempDirInfo.FullName + @"\audio"); dl.TrimmedOutputDataReceived += (s2, e2) => OnTrimmedOutputDataReceived(e2); dl.TrimmedErrorDataReceived += (s2, e2) => OnTrimmedErrorDataReceived(e2); dl.ProgressReported += (s2, e2) => { PartialProgress.Value = e2.Percent; OnProgressReported(25 + 0.25 * e2.Percent); if (e2.Percent > 100) { MessageBox.Show("e"); } }; dl.Finished += Dl_Finished; dl.Ready(); dl.Start(); }