private void UpdateCaptureStateInfo() { if (string.IsNullOrWhiteSpace(SelectedProcessToCapture)) { if (!ProcessesToCapture.Any()) { CaptureStateInfo = "Process list clear." + Environment.NewLine + $"Start any game / application and press {CaptureHotkeyString} to start capture."; _overlayService.SetCaptureServiceStatus("Scanning for process..."); } else if (ProcessesToCapture.Count == 1) { CaptureStateInfo = "Process auto-detected." + Environment.NewLine + $"Press {CaptureHotkeyString} to start capture."; _overlayService.SetCaptureServiceStatus("Ready to capture..."); } else if (ProcessesToCapture.Count > 1) { //Multiple processes detected, select the one to capture or move unwanted processes to ignore list. CaptureStateInfo = "Multiple processes detected." + Environment.NewLine + "Select one or move unwanted processes to ignore list."; _overlayService.SetCaptureServiceStatus("Multiple processes detected"); } return; } CaptureStateInfo = $"{SelectedProcessToCapture} selected." + Environment.NewLine + $"Press {CaptureHotkeyString} to start capture."; }
private void UpdateProcessToCaptureList() { var selectedProcessToCapture = SelectedProcessToCapture; var backupProcessList = new List <string>(ProcessesToCapture); ProcessesToCapture.Clear(); var filter = CaptureServiceConfiguration.GetProcessIgnoreList(); var processList = _captureService.GetAllFilteredProcesses(filter).Distinct(); ProcessesToCapture.AddRange(processList); if (ProcessesToCapture.Any() && !string.IsNullOrWhiteSpace(_lastCapturedProcess)) { if (!ProcessesToCapture.Contains(_lastCapturedProcess) || (selectedProcessToCapture != null && selectedProcessToCapture != _lastCapturedProcess)) { _overlayService.ResetHistory(); } } // fire update global hook if new process is detected if (backupProcessList.Count != ProcessesToCapture.Count) { UpdateGlobalCaptureHookEvent(); } if (!processList.Contains(selectedProcessToCapture)) { SelectedProcessToCapture = null; } else { SelectedProcessToCapture = selectedProcessToCapture; } Application.Current.Dispatcher.Invoke(new Action(() => { UpdateCaptureStateInfo(); })); }
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); }); } }