OpenBve.Interface.SaveControls C# (CSharp) Method

SaveControls() static private method

Saves the current control configuration
static private SaveControls ( string FileOrNull ) : void
FileOrNull string An absolute file path if we are exporting the controls, or a null reference to save to the default configuration location
return void
		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));
		}

Usage Example

Esempio n. 1
0
 //
 // SET CONTROL CUSTOM DATA
 //
 internal void SetControlKbdCustomData(Key key, Interface.KeyboardModifier keybMod)
 {
     if (isCustomisingControl)
     {
         Interface.CurrentControls[CustomControlIdx].Method   = Interface.ControlMethod.Keyboard;
         Interface.CurrentControls[CustomControlIdx].Key      = key;
         Interface.CurrentControls[CustomControlIdx].Modifier = keybMod;
         Interface.SaveControls(null);
         PopMenu();
         isCustomisingControl = false;
     }
 }
All Usage Examples Of OpenBve.Interface::SaveControls