public async Task Run(FFmpegCmdOptions FFmpegOptions) { if (FFmpegOptions.Install != null) { var downloadFolder = FFmpegOptions.Install; if (!Directory.Exists(downloadFolder)) { Directory.CreateDirectory(downloadFolder); } _ffmpegSettings.FolderPath = downloadFolder; var progress = new Progress <FFmpegDownloaderProgress>(FFmpegProgressHandler); Console.Write(nameof(FFmpegDownloaderState.Ready)); var cts = new CancellationTokenSource(); Console.CancelKeyPress += (S, E) => { cts.Cancel(); // Prevent abrupt exit E.Cancel = true; }; await _downloadModel.Start(progress, cts.Token); } }
public async Task Run(FFmpegCmdOptions FFmpegOptions) { if (FFmpegOptions.Install != null) { var downloadFolder = FFmpegOptions.Install; if (!Directory.Exists(downloadFolder)) { Directory.CreateDirectory(downloadFolder); } _ffmpegSettings.FolderPath = downloadFolder; var progress = new Progress <FFmpegDownloaderProgress>(FFmpegProgressHandler); Console.Write(nameof(FFmpegDownloaderState.Ready)); await _downloadModel.Start(progress); } }
public FFmpegDownloadViewModel(FFmpegSettings FFmpegSettings, FFmpegDownloadModel DownloadModel, IFFmpegViewsProvider FFmpegViewsProvider, IMessageProvider MessageProvider) { this.FFmpegSettings = FFmpegSettings; _downloadModel = DownloadModel; _messageProvider = MessageProvider; StartCommand = _downloaderProgress .Select(M => M.State) .Select(M => M == FFmpegDownloaderState.Ready) .ToReactiveCommand() .WithSubscribe(async() => { var progress = new Progress <FFmpegDownloaderProgress>(M => _downloaderProgress.Value = M); _downloadTask = DownloadModel.Start(progress, _cancellationTokenSource.Token); var result = await _downloadTask; AfterDownload?.Invoke(result); }); CanCancel = _downloaderProgress .Select(M => M.State) .Select(M => M == FFmpegDownloaderState.Downloading) .ToReadOnlyReactivePropertySlim(); SelectFolderCommand = _downloaderProgress .Select(M => M.State) .Select(M => M == FFmpegDownloaderState.Ready) .ToReactiveCommand() .WithSubscribe(FFmpegViewsProvider.PickFolder); OpenFolderCommand = new ReactiveCommand() .WithSubscribe(() => { var path = FFmpegSettings.GetFolderPath(); if (Directory.Exists(path)) { Process.Start(path); } }); Status = _downloaderProgress .Select(M => { switch (M.State) { case FFmpegDownloaderState.Error: return(M.ErrorMessage); case FFmpegDownloaderState.Downloading: return($"{FFmpegDownloaderState.Downloading} ({M.DownloadProgress}%)"); default: return(M.State.ToString()); } }) .ToReadOnlyReactivePropertySlim(); Progress = _downloaderProgress .Where(M => M.State == FFmpegDownloaderState.Downloading) .Select(M => M.DownloadProgress) .ToReadOnlyReactivePropertySlim(); Progress.Subscribe(M => ProgressChanged?.Invoke(M)); InProgress = _downloaderProgress .Select(M => M.State) .Select(M => M == FFmpegDownloaderState.Downloading || M == FFmpegDownloaderState.Extracting) .ToReadOnlyReactivePropertySlim(); IsDone = _downloaderProgress .Select(M => M.State) .Select(M => M == FFmpegDownloaderState.Done || M == FFmpegDownloaderState.Cancelled || M == FFmpegDownloaderState.Error) .ToReadOnlyReactivePropertySlim(); }