protected override void WorkerDoWork(DoWorkEventArgs e) { try { using (var logger = OperationLogger.Create(OperationLogger.FFmpegDLogFile)) { var ffmpeg = new FFmpegProcess(logger); if (_end == TimeSpan.MinValue) { ffmpeg.Crop(this.Input, this.Output, _start, this.ReportProgress, _cts.Token); } else { ffmpeg.Crop(this.Input, this.Output, _start, _end, this.ReportProgress, _cts.Token); } } _start = _end = TimeSpan.MinValue; e.Result = this.CancellationPending ? OperationStatus.Canceled : OperationStatus.Success; } catch (Exception ex) { Common.SaveException(ex); Helper.DeleteFiles(this.Output); e.Result = OperationStatus.Failed; } }
protected override void WorkerDoWork(DoWorkEventArgs e) { if (_mode == ConvertingMode.File) { try { using (var logger = OperationLogger.Create(OperationLogger.FFmpegDLogFile)) { var ffmpeg = new FFmpegProcess(logger); ffmpeg.Convert(this.Input, this.Output, this.ReportProgress, _cts.Token); // Crop if not operation wasn't canceled and _start has a valid value if (!this.CancellationPending && _start != TimeSpan.MinValue) { // Crop to end of file, unless _end has a valid value if (_end == TimeSpan.MinValue) { ffmpeg.Crop(this.Output, this.Output, _start, this.ReportProgress, _cts.Token); } else { ffmpeg.Crop(this.Output, this.Output, _start, _end, this.ReportProgress, _cts.Token); } } } // Reset variables _start = _end = TimeSpan.MinValue; } catch (Exception ex) { Common.SaveException(ex); Helper.DeleteFiles(this.Output); e.Result = OperationStatus.Failed; } } else { using (var logger = OperationLogger.Create(OperationLogger.FFmpegDLogFile)) { var ffmpeg = new FFmpegProcess(logger); foreach (string input in Directory.GetFiles(this.Input, _searchPattern)) { if (this.CancellationPending) { break; } _count++; try { string output = string.Format("{0}\\{1}.mp3", this.Output, Path.GetFileNameWithoutExtension(input)); this.ReportProgress(UpdateProperties, new Dictionary <string, object>() { { nameof(Title), Path.GetFileName(input) }, { nameof(Duration), (int)FFmpegProcess.GetDuration(input).Value.TotalSeconds }, { nameof(FileSize), Helper.GetFileSize(input) } }); _currentOutput = output; ffmpeg.Convert(input, output, this.ReportProgress, _cts.Token); _currentOutput = null; this.ProcessedFiles.Add(output); } catch (Exception ex) { _failures++; Common.SaveException(ex); Helper.DeleteFiles(_currentOutput); continue; } } } } // Set operation result e.Result = this.CancellationPending ? OperationStatus.Canceled : OperationStatus.Success; }