/// <summary> /// Postprocesses the given job according to the JobPostProcessors in the mainForm's PackageSystem /// </summary> /// <param name="job"></param> private void postprocessJob(Job job) { LogItem i = log.LogEvent("Postprocessing"); foreach (JobPostProcessor pp in mainForm.PackageSystem.JobPostProcessors.Values) { LogItem plog = pp.PostProcessor(mainForm, job); if (plog != null) { i.Add(plog); } } }
void run() { su.Status = "Cleanup files..."; Thread.Sleep(2000); // just so that the job has properly registered as starting log.LogValue("Delete Intermediate Files option set", mf.Settings.DeleteIntermediateFiles); if (mf.Settings.DeleteIntermediateFiles) { log.Add(FileUtil.DeleteIntermediateFiles(files, true)); } su.IsComplete = true; statusUpdate(su); }
/// <summary> /// marks job currently marked as processing as aborted /// </summary> private void markJobAborted() { if (currentJob == null) { return; } TaggedJob job = currentJob; job.Status = JobStatus.ABORTED; job.End = DateTime.Now; long iCounter = 0; LogItem i = new LogItem("Deleting aborted output"); i.LogValue("Delete aborted ouptut set", mainForm.Settings.DeleteAbortedOutput); if (mainForm.Settings.DeleteAbortedOutput) { i.LogValue("File to delete", job.Job.Output); while (File.Exists(job.Job.Output)) { try { File.Delete(job.Job.Output); } catch (Exception e) { if (++iCounter >= 10) { i.LogValue("Error deleting file", e, ImageType.Warning); break; } else { i.LogEvent("Error deleting file - trying again", ImageType.Information); System.Threading.Thread.Sleep(1000); } } } if (!File.Exists(job.Job.Output)) { i.LogEvent("File deleted"); } } log.Add(i); }
/// <summary> /// marks job currently marked as processing as aborted /// </summary> private void MarkJobAborted() { if (currentJob == null) { return; } TaggedJob job = currentJob; job.Status = JobStatus.ABORTED; job.End = DateTime.Now; LogItem i = new LogItem(string.Format("[{0:G}] {1}", DateTime.Now, "Deleting aborted output")); i.LogValue("Delete aborted output set", mainForm.Settings.DeleteAbortedOutput); if (mainForm.Settings.DeleteAbortedOutput && File.Exists(job.Job.Output)) { // delete outout file and temporary files if (File.Exists(job.Job.Output)) { FileUtil.DeleteFile(job.Job.Output, i); if (!File.Exists(job.Job.Output)) { i.LogValue("File deleted", job.Job.Output); } } foreach (string strFile in job.Job.FilesToDelete) { if (!File.Exists(strFile)) { continue; } FileUtil.DeleteFile(strFile, i); if (!File.Exists(strFile)) { i.LogValue("File deleted", strFile); } } } log.Add(i); }
public void StartWrite(string message, LogItem item) { depth++; item.Add(message, depth); }
private void reallyDeleteJob(TaggedJob job) { if (job.Status == JobStatus.PROCESSING || job.Status == JobStatus.ABORTING) { return; } if (job.Status != JobStatus.DONE && MainForm.Instance.Settings.DeleteIntermediateFiles) { List <string> filesToDelete = new List <string>(); if (job.Job.FilesToDelete.Count > 0) { filesToDelete.AddRange(job.Job.FilesToDelete); } if (job.Job is CleanupJob && ((CleanupJob)job.Job).files.Count > 0) { filesToDelete.AddRange(((CleanupJob)job.Job).files); } if (filesToDelete.Count > 0) { LogItem oLog = FileUtil.DeleteIntermediateFiles(filesToDelete, false, true); if (oLog != null) { LogItem log = mainForm.Log.Info(string.Format("Log for {0} ({1}, {2} -> {3})", job.Name, job.Job.EncodingMode, job.InputFileName, job.OutputFileName)); log.Add(oLog); } } } mainForm.Jobs.ResourceLock.WaitOne(10000, false); if (job.OwningWorker != null && workers.ContainsKey(job.OwningWorker)) { workers[job.OwningWorker].RemoveJobFromQueue(job); } if (jobQueue.HasJob(job)) { jobQueue.removeJobFromQueue(job); } foreach (TaggedJob p in job.RequiredJobs) { p.EnabledJobs.Remove(job); } foreach (TaggedJob j in job.EnabledJobs) { j.RequiredJobs.Remove(job); } string fileName = Path.Combine(mainForm.MeGUIPath, "jobs"); fileName = Path.Combine(fileName, job.Name + ".xml"); if (File.Exists(fileName)) { File.Delete(fileName); } allJobs.Remove(job.Name); mainForm.Jobs.ResourceLock.Release(); }
public JobChain GenerateJobSeries(VideoStream video, string muxedOutput, AudioJob[] audioStreams, MuxStream[] subtitles, string chapters, FileSize?desiredSize, FileSize?splitSize, ContainerType container, bool prerender, MuxStream[] muxOnlyAudio, LogItem log, string deviceType, Zone[] zones, string videoFileToMux, OneClickAudioTrack[] audioTracks) { if (desiredSize.HasValue && String.IsNullOrEmpty(videoFileToMux)) { if (video.Settings.EncodingMode != 4 && video.Settings.EncodingMode != 8) // no automated 2/3 pass { if (this.mainForm.Settings.NbPasses == 2) { video.Settings.EncodingMode = 4; // automated 2 pass } else if (video.Settings.MaxNumberOfPasses == 3) { video.Settings.EncodingMode = 8; } } } fixFileNameExtensions(video, audioStreams, container); string videoOutput = video.Output; log.Add(eliminatedDuplicateFilenames(ref videoOutput, ref muxedOutput, audioStreams)); JobChain vjobs = null; if (!String.IsNullOrEmpty(videoFileToMux)) { video.Output = videoFileToMux; } else { video.Output = videoOutput; vjobs = jobUtil.prepareVideoJob(video.Input, video.Output, video.Settings, video.DAR, prerender, true, zones); if (vjobs == null) { return(null); } } /* Here, we guess the types of the files based on extension. * This is guaranteed to work with MeGUI-encoded files, because * the extension will always be recognised. For non-MeGUI files, * we can only ever hope.*/ List <MuxStream> allAudioToMux = new List <MuxStream>(); List <MuxableType> allInputAudioTypes = new List <MuxableType>(); if (audioTracks != null) { // OneClick mode foreach (OneClickAudioTrack ocAudioTrack in audioTracks) { if (ocAudioTrack.DirectMuxAudio != null) { if (VideoUtil.guessAudioMuxableType(ocAudioTrack.DirectMuxAudio.path, true) != null) { allInputAudioTypes.Add(VideoUtil.guessAudioMuxableType(ocAudioTrack.DirectMuxAudio.path, true)); allAudioToMux.Add(ocAudioTrack.DirectMuxAudio); } } if (ocAudioTrack.AudioJob != null) { allAudioToMux.Add(ocAudioTrack.AudioJob.ToMuxStream()); allInputAudioTypes.Add(ocAudioTrack.AudioJob.ToMuxableType()); } } } else { // AutoEncode mode foreach (AudioJob stream in audioStreams) { allAudioToMux.Add(stream.ToMuxStream()); allInputAudioTypes.Add(stream.ToMuxableType()); } foreach (MuxStream muxStream in muxOnlyAudio) { if (VideoUtil.guessAudioMuxableType(muxStream.path, true) != null) { allInputAudioTypes.Add(VideoUtil.guessAudioMuxableType(muxStream.path, true)); allAudioToMux.Add(muxStream); } } } List <MuxableType> allInputSubtitleTypes = new List <MuxableType>(); foreach (MuxStream muxStream in subtitles) { if (VideoUtil.guessSubtitleType(muxStream.path) != null) { allInputSubtitleTypes.Add(new MuxableType(VideoUtil.guessSubtitleType(muxStream.path), null)); } } MuxableType chapterInputType = null; if (!String.IsNullOrEmpty(chapters)) { ChapterType type = VideoUtil.guessChapterType(chapters); if (type != null) { chapterInputType = new MuxableType(type, null); } } MuxableType deviceOutputType = null; if (!String.IsNullOrEmpty(deviceType)) { DeviceType type = VideoUtil.guessDeviceType(deviceType); if (type != null) { deviceOutputType = new MuxableType(type, null); } } List <string> inputsToDelete = new List <string>(); if (String.IsNullOrEmpty(videoFileToMux)) { inputsToDelete.Add(video.Output); } inputsToDelete.AddRange(Array.ConvertAll <AudioJob, string>(audioStreams, delegate(AudioJob a) { return(a.Output); })); JobChain muxJobs = jobUtil.GenerateMuxJobs(video, video.Framerate, allAudioToMux.ToArray(), allInputAudioTypes.ToArray(), subtitles, allInputSubtitleTypes.ToArray(), chapters, chapterInputType, container, muxedOutput, splitSize, inputsToDelete, deviceType, deviceOutputType); if (desiredSize.HasValue && String.IsNullOrEmpty(videoFileToMux)) { BitrateCalculationInfo b = new BitrateCalculationInfo(); List <string> audiofiles = new List <string>(); foreach (MuxStream s in allAudioToMux) { audiofiles.Add(s.path); } b.AudioFiles = audiofiles; b.Container = container; b.VideoJobs = new List <TaggedJob>(vjobs.Jobs); b.DesiredSize = desiredSize.Value; ((VideoJob)vjobs.Jobs[0].Job).BitrateCalculationInfo = b; } if (!String.IsNullOrEmpty(videoFileToMux)) { return(new SequentialChain(new SequentialChain((Job[])audioStreams), new SequentialChain(muxJobs))); } else { return(new SequentialChain( new SequentialChain((Job[])audioStreams), new SequentialChain(vjobs), new SequentialChain(muxJobs))); } }