public void WriteRecordedDataToFile(List <KeysData> listOfKeysData, string filepath, IEncryptor encryptor) { List <string> textToWrite = new List <string>(); foreach (KeysData data in listOfKeysData) { textToWrite.Add(DataFormatter.GetFormattedDataLine(data) + Environment.NewLine); } using (StreamWriter sw = fileSystem.File.AppendText(filepath)) { foreach (string line in textToWrite) { string encryptedLine = encryptor.Encrypt(line); WriteEncryptorIV(encryptor, sw); sw.Write(encryptedLine + Environment.NewLine); } } }
private void TimerCountdown(object sender, EventArgs e) { string filepath = Path.Combine(ConstantValues.KEYBOARD_DATA_FILEPATH, ConstantValues.KEYBOARD_FILE_NAME); dataFormatter.RemoveLastDataItem(); List <KeysData> dataToWriteToFile = dataFormatter.DataRecorded; if (dataToWriteToFile.Count != 0) { PythonInterface pi = new PythonInterface(); List <string> formattedData = new List <string>(); foreach (KeysData keysData in dataToWriteToFile) { formattedData.Add(DataFormatter.GetFormattedDataLine(keysData)); } if (ModelFileExists()) { pi.TestUserInput(formattedData, health, ConstantValues.KEYBOARD_DATA_FILEPATH); } if (recordingEnabled.Checked) { WriteEncryptedDataToFile(filepath, dataToWriteToFile); } } PossiblyShuffleLines(filepath); if (health.GetValue() < ConstantValues.HEALTH_VALUE_THRESHOLD) { // Uncomment to lock user out of computer //Process.Start(@"C:\WINDOWS\system32\rundll32.exe", "user32.dll,LockWorkStation"); health.SetValue(ConstantValues.DEFAULT_HEALTH_VALUE); } dataFormatter.End(); }