private ListViewItem AddToQueue(JobInfo jobInfo) { ListViewItem item = new ListViewItem { Group = listView1.Groups[(int) jobInfo.Task], Tag = jobInfo.Process, Text = jobInfo.Input }; item.SubItems.Add(jobInfo.Output); if (listView1.InvokeRequired) { listView1.Invoke((MethodInvoker) delegate { listView1.Items.Add(item); }); } else { listView1.Items.Add(item); } processes.Add(jobInfo.Process); return item; }
private void RunAsync(JobInfo jobInfo) { if (File.Exists(ffmpeg)) { tabControl1.SelectTab(queueTab); BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (obj, ea) => bw_DoWork(ea, jobInfo); bw.RunWorkerCompleted += bw_RunWorkerCompleted; bw.RunWorkerAsync(); } else { Log(ffmpeg + " not found"); OnError(); } }
private void OnSuccess(JobInfo jobInfo) { if (OpenExplorer && !Utility.LaunchExplorer(jobInfo.Output)) { SystemSounds.Hand.Play(); } }
private void OnError(JobInfo jobInfo = null) { SystemSounds.Hand.Play(); if (jobInfo != null) OnCancel(jobInfo); }
private void OnCancel(JobInfo jobInfo) { Utility.RemovePath(jobInfo.Output); }
private void bw_DoWork(DoWorkEventArgs e, JobInfo jobInfo) { Process p = jobInfo.CreateProcess(ffmpeg); p.OutputDataReceived += (s, ea) => Log(ea.Data); p.ErrorDataReceived += (s, ea) => Log(ea.Data); var item = AddToQueue(jobInfo); logger.Log(p.StartInfo.FileName + " " + p.StartInfo.Arguments); p.Start(); p.BeginOutputReadLine(); p.BeginErrorReadLine(); p.WaitForExit(); RemoveFromQueue(item); switch (p.ExitCode) { // Kill() case -1: jobInfo.Result = JobInfo.EResult.Cancel; break; // OK case 0: jobInfo.Result = JobInfo.EResult.Success; break; // ffmpeg error default: jobInfo.Result = JobInfo.EResult.Error; break; } e.Result = jobInfo; p.Dispose(); }