private async Task WriteExtractedCaptureDataToFileAsync() { try { if (string.IsNullOrWhiteSpace(_currentCaptureOptions.ProcessName)) { PrepareForNextCapture(); return; } var adjustedCaptureData = GetAdjustedCaptureData(); PrepareForNextCapture(); if (!adjustedCaptureData.Any()) { AddLoggerEntry("Error while extracting capture data. No file will be written."); return; } // Skip first line to compensate the first frametime being one frame before original capture start point. var normalizedAdjustedCaptureData = NormalizeTimes(adjustedCaptureData.Skip(1)); var sessionRun = _recordManager.ConvertPresentDataLinesToSessionRun(normalizedAdjustedCaptureData); sessionRun.SensorData = _sensorService.GetSessionSensorData(); if (_appConfiguration.UseRunHistory) { await Task.Factory.StartNew(() => _overlayService.AddRunToHistory(sessionRun, _currentCaptureOptions.ProcessName, _currentCaptureOptions.RecordDirectory)); } // if aggregation mode is active and "Save aggregated result only" is checked, don't save single history items if (_appConfiguration.UseAggregation && _appConfiguration.SaveAggregationOnly) { return; } if (_currentCaptureOptions.CaptureFileMode == Enum.GetName(typeof(ECaptureFileMode), ECaptureFileMode.JsonCsv)) { await _recordManager.SavePresentmonRawToFile(normalizedAdjustedCaptureData, _currentCaptureOptions.ProcessName, _currentCaptureOptions.RecordDirectory); } bool checkSave = await _recordManager.SaveSessionRunsToFile(new ISessionRun[] { sessionRun }, _currentCaptureOptions.ProcessName, _currentCaptureOptions.RecordDirectory); if (!checkSave) { AddLoggerEntry("Error while saving capture data."); } else { AddLoggerEntry("Capture file is successfully written into directory."); } } catch (Exception e) { _logger.LogError(e, "Error writing capture data"); PrepareForNextCapture(); } }