internal static void SaveControls(string FileOrNull) {
CultureInfo Culture = CultureInfo.InvariantCulture;
System.Text.StringBuilder Builder = new System.Text.StringBuilder();
Builder.AppendLine("; Current control configuration");
Builder.AppendLine("; =============================");
Builder.AppendLine("; This file was automatically generated. Please modify only if you know what you're doing.");
Builder.AppendLine("; This file is INCOMPATIBLE with versions older than 1.4.4.");
Builder.AppendLine();
for (int i = 0; i < CurrentControls.Length; i++) {
CommandInfo Info;
TryGetCommandInfo(CurrentControls[i].Command, out Info);
Builder.Append(Info.Name + ", ");
switch (CurrentControls[i].Method) {
case ControlMethod.Keyboard:
Builder.Append("keyboard, " + CurrentControls[i].Key + ", " + ((int)CurrentControls[i].Modifier).ToString(Culture));
break;
case ControlMethod.Joystick:
Builder.Append("joystick, " + CurrentControls[i].Device.ToString(Culture) + ", ");
switch (CurrentControls[i].Component) {
case JoystickComponent.Axis:
Builder.Append("axis, " + CurrentControls[i].Element.ToString(Culture) + ", " + CurrentControls[i].Direction.ToString(Culture));
break;
case JoystickComponent.Ball:
Builder.Append("ball, " + CurrentControls[i].Element.ToString(Culture) + ", " + CurrentControls[i].Direction.ToString(Culture));
break;
case JoystickComponent.Hat:
Builder.Append("hat, " + CurrentControls[i].Element.ToString(Culture) + ", " + CurrentControls[i].Direction.ToString(Culture));
break;
case JoystickComponent.Button:
Builder.Append("button, " + CurrentControls[i].Element.ToString(Culture));
break;
default:
Builder.Append("invalid");
break;
}
break;
}
Builder.Append("\n");
}
string File;
if (FileOrNull == null) {
File = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "controls.cfg");
} else {
File = FileOrNull;
}
System.IO.File.WriteAllText(File, Builder.ToString(), new System.Text.UTF8Encoding(true));
}