private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { ScanMultipleDialogViewModel viewModel = this.DataContext as ScanMultipleDialogViewModel; if (!viewModel.ScanFinished) { e.Cancel = true; viewModel.CancelPending = true; } }
/// <summary> /// Adds the given source to the encode queue. /// </summary> /// <param name="source">The path to the source file to encode.</param> /// <param name="destination">The destination path for the encoded file.</param> /// <param name="presetName">The name of the preset to use to encode.</param> /// <returns>True if the item was successfully queued for processing.</returns> public void Process(string source, string destination, string presetName) { if (string.IsNullOrWhiteSpace(source)) { throw new ArgumentException("source cannot be null or empty."); } if (string.IsNullOrWhiteSpace(destination) && !this.EnsureDefaultOutputFolderSet()) { throw new ArgumentException("If destination is not set, the default output folder must be set."); } if (destination != null && !Utilities.IsValidFullPath(destination)) { throw new ArgumentException("Destination path is not valid: " + destination); } VCProfile profile = this.presetsViewModel.GetProfileByName(presetName); if (profile == null) { throw new ArgumentException("Cannot find preset: " + presetName); } var jobVM = new EncodeJobViewModel(new VCJob { SourcePath = source, SourceType = Utilities.GetSourceType(source), Title = 1, RangeType = VideoRangeType.All, EncodingProfile = profile, ChosenAudioTracks = new List<int> { 1 }, OutputPath = destination, UseDefaultChapterNames = true }); jobVM.PresetName = presetName; jobVM.ManualOutputPath = !string.IsNullOrWhiteSpace(destination); var scanMultipleDialog = new ScanMultipleDialogViewModel(new List<EncodeJobViewModel>{ jobVM }); WindowManager.OpenDialog(scanMultipleDialog, this.main); VCJob job = jobVM.Job; Title title = jobVM.HandBrakeInstance.Titles.SingleOrDefault(t => t.TitleNumber == job.Title); if (title == null) { title = jobVM.HandBrakeInstance.Titles[0]; } // Choose the correct audio/subtitle tracks based on settings this.AutoPickAudio(job, title); this.AutoPickSubtitles(job, title); // Now that we have the title and subtitles we can determine the final output file name if (string.IsNullOrWhiteSpace(destination)) { // Exclude all current queued files if overwrite is disabled HashSet<string> excludedPaths; if (CustomConfig.WhenFileExistsBatch == WhenFileExists.AutoRename) { excludedPaths = this.GetQueuedFiles(); } else { excludedPaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase); } string pathToQueue = job.SourcePath; excludedPaths.Add(pathToQueue); string outputFolder = this.outputVM.GetOutputFolder(pathToQueue); string outputFileName = this.outputVM.BuildOutputFileName(pathToQueue, Utilities.GetSourceName(pathToQueue), job.Title, title.Duration, title.Chapters.Count, usesScan: false); string outputExtension = this.outputVM.GetOutputExtension(); string queueOutputPath = Path.Combine(outputFolder, outputFileName + outputExtension); queueOutputPath = this.outputVM.ResolveOutputPathConflicts(queueOutputPath, excludedPaths, isBatch: true); job.OutputPath = queueOutputPath; } this.Queue(jobVM); if (!this.Encoding) { this.StartEncodeQueue(); } }
// Queues a list of files or video folders. public void QueueMultiple(IEnumerable<SourcePath> sourcePaths) { if (!this.EnsureDefaultOutputFolderSet()) { return; } // Exclude all current queued files if overwrite is disabled HashSet<string> excludedPaths; if (CustomConfig.WhenFileExistsBatch == WhenFileExists.AutoRename) { excludedPaths = this.GetQueuedFiles(); } else { excludedPaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase); } var itemsToQueue = new List<EncodeJobViewModel>(); foreach (SourcePath sourcePath in sourcePaths) { var job = new VCJob { SourcePath = sourcePath.Path, EncodingProfile = this.presetsViewModel.SelectedPreset.Preset.EncodingProfile.Clone(), Title = 1, RangeType = VideoRangeType.All, UseDefaultChapterNames = true }; if (sourcePath.SourceType == SourceType.None) { if (Directory.Exists(sourcePath.Path)) { job.SourceType = SourceType.VideoFolder; } else if (File.Exists(sourcePath.Path)) { job.SourceType = SourceType.File; } } else { job.SourceType = sourcePath.SourceType; } if (job.SourceType != SourceType.None) { var jobVM = new EncodeJobViewModel(job); jobVM.SourceParentFolder = sourcePath.ParentFolder; jobVM.ManualOutputPath = false; jobVM.PresetName = this.presetsViewModel.SelectedPreset.DisplayName; itemsToQueue.Add(jobVM); } } // This dialog will scan the items in the list, calculating length. var scanMultipleDialog = new ScanMultipleDialogViewModel(itemsToQueue); WindowManager.OpenDialog(scanMultipleDialog, this.main); var failedFiles = new List<string>(); foreach (EncodeJobViewModel jobVM in itemsToQueue) { // Skip over any cancelled jobs if (jobVM.HandBrakeInstance == null) { continue; } // Only queue items with a successful scan if (jobVM.HandBrakeInstance.Titles.Count > 0) { VCJob job = jobVM.Job; Title title = jobVM.HandBrakeInstance.Titles.SingleOrDefault(t => t.TitleNumber == job.Title); if (title == null) { title = jobVM.HandBrakeInstance.Titles[0]; } // Choose the correct audio/subtitle tracks based on settings this.AutoPickAudio(job, title); this.AutoPickSubtitles(job, title); // Now that we have the title and subtitles we can determine the final output file name string fileToQueue = job.SourcePath; excludedPaths.Add(fileToQueue); string outputFolder = this.outputVM.GetOutputFolder(fileToQueue, jobVM.SourceParentFolder); string outputFileName = this.outputVM.BuildOutputFileName(fileToQueue, Utilities.GetSourceNameFile(fileToQueue), job.Title, title.Duration, title.Chapters.Count, usesScan: false); string outputExtension = this.outputVM.GetOutputExtension(); string queueOutputPath = Path.Combine(outputFolder, outputFileName + outputExtension); queueOutputPath = this.outputVM.ResolveOutputPathConflicts(queueOutputPath, excludedPaths, isBatch: true); job.OutputPath = queueOutputPath; excludedPaths.Add(queueOutputPath); this.Queue(jobVM); } else { failedFiles.Add(jobVM.Job.SourcePath); } } if (failedFiles.Count > 0) { Utilities.MessageBox.Show( string.Format(MainRes.QueueMultipleScanErrorMessage, string.Join(Environment.NewLine, failedFiles)), MainRes.QueueMultipleScanErrorTitle, MessageBoxButton.OK, MessageBoxImage.Warning); } }