private void applyKeyButton_Click(object sender, EventArgs e) { bool inputsOk = KeybindInterpreter.validateInput(); if (inputsOk) { Program.MyFactory.writeInputFile(); applyKeyButton.Enabled = false; } else { MessageBox.Show(@"All keys have to be bound!", @"Unbound Key found", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Reads the UserInput file and saves the lines to a string list. /// Overwrites pre-existing file if it's not created by Launcher. /// </summary> public void readInputFile() { // creates file if it doesn't exist if (!File.Exists(InputFile)) { logger.Warn("readInputFile - UserInput not found at {0}. Generating it now.", InputFile); File.Create(InputFile).Dispose(); using (StreamWriter file = new StreamWriter(InputFile)) { file.Write(UserInputPremade); } logger.Debug("readInputFile - generated UserInput at: {0}", InputFile); } InputFileInfo.IsReadOnly = false; string[] inputLines = File.ReadAllLines(InputFile); // if-condition only relevant if UserInput was not created by the Launcher. Will overwrite existing file if (!inputLines.Last().Equals("[Generated by Batman: Arkham Asylum - Advanced Launcher]")) { File.Delete(InputFile); using (StreamWriter file = new StreamWriter(InputFile)) { file.Write(UserInputPremade); } logger.Debug("readInputFile - replaced UserInput with custom made Advanced Launcher files."); inputLines = File.ReadAllLines(InputFile); } logger.Debug("readInputFile - starting interpretKeys reading process."); kInterpreter = new KeybindInterpreter(); for (int i = 0; i < inputLines.Length; i++) { InputList.Add(inputLines[i]); if (i < 51) { kInterpreter.interpretKeys(inputLines[i], true); } } logger.Info("readInputFile - processed UserInput."); }