public void EnableInteractions() { IsIndeterminate = false; IsInputEnabled = true; IsButtonEnabled = true; IsComboBoxEnabled = true; ProgressBarPercent = 0; TaskBarProgressValue = HelpersModel.GetTaskBarProgressValue(100, ProgressBarPercent); TaskbarItemProgressStateModel = TaskbarItemProgressState.Normal; }
public void DisableInteractions() { IsIndeterminate = true; IsInputEnabled = false; IsComboBoxEnabled = false; ProgressBarPercent = 0; _downloadFileSize = 0.0; _audioVideoDownloadCounter = 0; TaskBarProgressValue = HelpersModel.GetTaskBarProgressValue(100, ProgressBarPercent); TaskbarItemProgressStateModel = TaskbarItemProgressState.Indeterminate; }
public (bool measureDownloadTime, string downloadedFileSize, bool isIndeterminate, TaskbarItemProgressState taskbarItemProgressStateModel, int progressBarPercent, double taskBarProgressValue, bool measureProcessingTime, string standardOutputOut) Extract(string standardOutput, string finishedMessage) { int positionFrom; int positionTo; if (standardOutput.Contains(Localization.Properties.Resources.ThreadPoolWorkerDownload) && standardOutput.Contains(Localization.Properties.Resources.ThreadPoolWorkerEta)) { measureDownloadTime = true; positionFrom = standardOutput.IndexOf(Localization.Properties.Resources.ThreadPoolWorkerOf, StringComparison.InvariantCultureIgnoreCase) + Localization.Properties.Resources.ThreadPoolWorkerOf.Length; positionTo = standardOutput.LastIndexOf(Localization.Properties.Resources.ThreadPoolWorkerAt, StringComparison.InvariantCultureIgnoreCase); if ((positionTo - positionFrom) > 0) { downloadedFileSize = standardOutput.Substring(positionFrom, positionTo - positionFrom); } positionFrom = standardOutput.IndexOf("] ", StringComparison.InvariantCultureIgnoreCase) + "] ".Length; positionTo = standardOutput.LastIndexOf("%", StringComparison.InvariantCultureIgnoreCase); if ((positionTo - positionFrom) > 0) { var percent = standardOutput.Substring(positionFrom, positionTo - positionFrom); if (double.TryParse(percent.Trim(), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var downloadedPercent)) { isIndeterminate = false; taskbarItemProgressStateModel = TaskbarItemProgressState.Normal; progressBarPercent = Convert.ToInt32(Math.Round(downloadedPercent)); taskBarProgressValue = HelpersModel.GetTaskBarProgressValue(100, progressBarPercent); } else { isIndeterminate = true; taskbarItemProgressStateModel = TaskbarItemProgressState.Indeterminate; } } standardOutputOut = standardOutput; } if (standardOutput.Contains("has already been")) { standardOutputOut = standardOutput; downloadedFileSize = Localization.Properties.Resources.FileHasAlreadyBeenDownloaded; measureDownloadTime = false; } if (standardOutput.Contains("[ffmpeg]")) { standardOutputOut = finishedMessage; measureProcessingTime = true; measureDownloadTime = false; } return(measureDownloadTime, downloadedFileSize, isIndeterminate, taskbarItemProgressStateModel, progressBarPercent, taskBarProgressValue, measureProcessingTime, standardOutputOut); }
private void SendData(string fileName, string standardOutput) { try { UpdateWebhook(DownloadLink, fileName, standardOutput); } catch (HttpRequestException webhookException) { TaskBarProgressValue = HelpersModel.GetTaskBarProgressValue(100, 100); TaskbarItemProgressStateModel = TaskbarItemProgressState.Error; Thread.Sleep(1000); StandardOutput = Localization.Properties.Resources.ExceptionUpdatingWebhookFailed; Log.Error(webhookException, Localization.Properties.Resources.ExceptionUpdatingWebhookFailed); _informationAndExceptionOutput = webhookException.Message; _downloadedFileSize = null; EnableInteractions(); return; } }
private void ThreadPoolWorker() { _isDownloadRunning = true; string selectedQuality = HelpersModel.GetQuality(SelectedQuality); Log.Information(selectedQuality); DisableInteractions(); Thread.CurrentThread.IsBackground = true; _currentThreadPoolWorker = Thread.CurrentThread; StandardOutput = Localization.Properties.Resources.StartingDownload; var statusWithLink = Localization.Properties.Resources.StatusLogStartingDownloadOfTheLink + DownloadLink; InformationAndExceptionOutput = statusWithLink; Log.Information(statusWithLink); string command; (command, _finishedMessage) = HelpersModel.CreateCommandAndMessage(selectedQuality, DownloadLink); var startinfo = new ProcessStartInfo("CMD.exe", command) { CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, }; var readLineExtractor = new ReadLineExtractorModel(); var process = new Process { StartInfo = startinfo }; process.Start(); var reader = process.StandardOutput; while (!reader.EndOfStream) { StandardOutput = reader.ReadLine(); StandardOutput = HelpersModel.StandardOutputLocalizator(StandardOutput); (_measureDownloadTime, _downloadedFileSize, IsIndeterminate, TaskbarItemProgressStateModel, ProgressBarPercent, TaskBarProgressValue, _measureProcessingTime, StandardOutput) = readLineExtractor.Extract(StandardOutput, _finishedMessage); Thread.Sleep(_timerResolution); } process.WaitForExit(); _measureProcessingTime = false; if (_downloadedFileSize == null || string.IsNullOrWhiteSpace(_downloadedFileSize)) { TimersOutput = string.Empty; TaskBarProgressValue = HelpersModel.GetTaskBarProgressValue(100, 100); TaskbarItemProgressStateModel = TaskbarItemProgressState.Error; Thread.Sleep(1000); if (_isOnline) { if (IsWebsitesUnlockerSelected) { if (!DownloadLink.Contains("https://www.")) { StandardOutput = Localization.Properties.Resources.NotValidLink; Log.Error(StandardOutput); } else { StandardOutput = Localization.Properties.Resources.NoFileDownloadedUnsupportedWebsite; Log.Error(StandardOutput); } } else { StandardOutput = Localization.Properties.Resources.ErrorNoFileDownloadedUpdatesAreNeeded; Log.Error(StandardOutput); } } else { StandardOutput = Localization.Properties.Resources.ErrorNoInternetConnectionNoFileDownloaded; Log.Error(StandardOutput); } ButtonContent = Localization.Properties.Resources.ButtonContentDownload; EnableInteractions(); _isDownloadRunning = false; process.Dispose(); return; } if (_downloadedFileSize == Localization.Properties.Resources.FileHasAlreadyBeenDownloaded) { TimersOutput = string.Empty; TaskBarProgressValue = HelpersModel.GetTaskBarProgressValue(100, 100); TaskbarItemProgressStateModel = TaskbarItemProgressState.Paused; Thread.Sleep(1000); var output = Localization.Properties.Resources.StandardOutputReady + ". " + _downloadedFileSize; StandardOutput = output; Log.Information(output); ButtonContent = Localization.Properties.Resources.ButtonContentDownload; EnableInteractions(); _isDownloadRunning = false; process.Dispose(); return; } else { var processingTimeTimer = (_processingTime * _timerResolution) / 1000.0; var downloadTimeTimer = (_downloadTime * _timerResolution) / 1000.0; (string fileName, double fileSize) = GetFileNameAndSize(selectedQuality); if (_downloadedFileSize.Contains("~")) { _downloadedFileSize = _downloadedFileSize.Substring(1); } TimersOutput = string.Empty; StandardOutput = Localization.Properties.Resources.ProcessingTime + processingTimeTimer.ToString("N0", CultureInfo.InvariantCulture) + "s. " + Localization.Properties.Resources.DownloadTime + downloadTimeTimer.ToString("N0", CultureInfo.InvariantCulture) + "s. " + Localization.Properties.Resources.DownloadedFileSize + _downloadedFileSize + ". " + Localization.Properties.Resources.TranscodedFileSize + fileSize.ToString("F", CultureInfo.InvariantCulture) + "MiB. "; if (double.TryParse(_downloadedFileSize.Remove(_downloadedFileSize.Length - 3), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var downloadedFileSize)) { var ratio = downloadedFileSize / fileSize; StandardOutput += Localization.Properties.Resources.Ratio + ratio.ToString("F", CultureInfo.InvariantCulture) + "."; } SendData(fileName, StandardOutput); _downloadedFileSize = null; _processingTime = 1; _downloadTime = 1; ButtonContent = Localization.Properties.Resources.ButtonContentDownload; EnableInteractions(); _isDownloadRunning = false; process.Dispose(); InformationAndExceptionOutput = Localization.Properties.Resources.StatusLogFinishedDownload; Log.Information(StandardOutput); } }