示例#1
0
 private void TimerClipper()
 {
     if (IsClipboardCaptureSelected)
     {
         Application.Current.Dispatcher.Invoke(() =>
         {
             if (DownloadLink == null)
             {
                 DownloadLink = Clipboard.GetText();
             }
             if (!DownloadLink.Contains(Clipboard.GetText()))
             {
                 DownloadLink = Clipboard.GetText();
             }
         }, System.Windows.Threading.DispatcherPriority.Send);
     }
 }
示例#2
0
        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);
            }
        }