private void WriteCaptureDataToFile()
 {
     // explicit hook, only one process
     if (!string.IsNullOrWhiteSpace(SelectedProcessToCapture))
     {
         Task.Run(() => WriteExtractedCaptureDataToFileAsync(SelectedProcessToCapture));
     }
     // auto hook with filtered process list
     else
     {
         var process = ProcessesToCapture.FirstOrDefault();
         Task.Run(() => WriteExtractedCaptureDataToFileAsync(process));
     }
 }
Пример #2
0
        private void WriteCaptureDataToFile()
        {
            // explicit hook, only one process
            if (!string.IsNullOrWhiteSpace(SelectedProcessToCapture))
            {
                Task.Run(() => WriteExtractedCaptureDataToFile(SelectedProcessToCapture));
            }
            // auto hook with filtered process list
            else
            {
                var filter  = CaptureServiceConfiguration.GetProcessIgnoreList();
                var process = ProcessesToCapture.FirstOrDefault();

                Task.Run(() => WriteExtractedCaptureDataToFile(process));
            }
        }
Пример #3
0
        private void SetCaptureMode()
        {
            if (!ProcessesToCapture.Any())
            {
                _soundPlayer.Open(new Uri("Sounds/no_process.mp3", UriKind.Relative));
                _soundPlayer.Volume = VoiceSoundLevel;
                _soundPlayer.Play();
                return;
            }

            if (ProcessesToCapture.Count > 1 && string.IsNullOrWhiteSpace(SelectedProcessToCapture))
            {
                _soundPlayer.Open(new Uri("Sounds/more_than_one_process.mp3", UriKind.Relative));
                _soundPlayer.Volume = VoiceSoundLevel;
                _soundPlayer.Play();
                return;
            }

            if (!IsCapturing)
            {
                if (SelectedProcessToCapture != null)
                {
                    _lastCapturedProcess = SelectedProcessToCapture;
                }
                else
                {
                    _lastCapturedProcess = ProcessesToCapture.FirstOrDefault();
                }

                _ = QueryPerformanceCounter(out long startCounter);
                AddLoggerEntry($"Performance counter on start capturing: {startCounter}");
                _qpcTimeStart = startCounter;

                _timestampStartCapture = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();

                // none -> do nothing
                // simple sounds
                if (SelectedSoundMode == _soundModes[1])
                {
                    _soundPlayer.Open(new Uri("Sounds/simple_start_sound.mp3", UriKind.Relative));
                    _soundPlayer.Volume = SimpleSoundLevel;
                    _soundPlayer.Play();
                }
                // voice response
                else if (SelectedSoundMode == _soundModes[2])
                {
                    _soundPlayer.Open(new Uri("Sounds/capture_started.mp3", UriKind.Relative));
                    _soundPlayer.Volume = VoiceSoundLevel;
                    _soundPlayer.Play();
                }

                StartCaptureDataFromStream();

                IsCapturing = !IsCapturing;
                _disposableHeartBeat?.Dispose();
                IsAddToIgnoreListButtonActive = false;

                if (CaptureTimeString == "0" && CaptureStartDelayString == "0")
                {
                    CaptureStateInfo = "Capturing in progress..." + Environment.NewLine + $"Press {CaptureHotkeyString} to stop capture.";
                }

                if (CaptureTimeString != "0" && CaptureStartDelayString == "0")
                {
                    CaptureStateInfo = $"Capturing in progress (Set Time: {CaptureTimeString} seconds)..." + Environment.NewLine
                                       + $"Press {CaptureHotkeyString} to stop capture.";
                }

                if (CaptureTimeString != "0" && CaptureStartDelayString != "0")
                {
                    CaptureStateInfo = $"Capturing starts with delay of {CaptureStartDelayString} seconds. " +
                                       $"Capture will stop after {CaptureTimeString} seconds." + Environment.NewLine + $"Press {CaptureHotkeyString} to stop capture.";
                }
            }
            else
            {
                // manual termination (hotkey triggered)
                // turn locking on
                _dataOffsetRunning = true;

                _timestampStopCapture = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
                _cancellationTokenSource?.Cancel();

                // none -> do nothing
                // simple sounds
                if (SelectedSoundMode == _soundModes[1])
                {
                    _soundPlayer.Open(new Uri("Sounds/simple_stop_sound.mp3", UriKind.Relative));
                    _soundPlayer.Volume = SimpleSoundLevel;
                    _soundPlayer.Play();
                }
                // voice response
                else if (SelectedSoundMode == _soundModes[2])
                {
                    _soundPlayer.Open(new Uri("Sounds/capture_finished.mp3", UriKind.Relative));
                    _soundPlayer.Volume = VoiceSoundLevel;
                    _soundPlayer.Play();
                }

                var context = TaskScheduler.FromCurrentSynchronizationContext();

                CaptureStateInfo = "Creating capture file...";
                _overlayService.StopCaptureTimer();
                _overlayService.SetCaptureServiceStatus("Processing data");

                // offset timer
                Task.Run(async() =>
                {
                    await SetTaskDelayOffset().ContinueWith(_ =>
                    {
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            FinishCapturingAndUpdateUi();
                        }));
                    }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, context);
                });
            }
        }