Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Version 2 (modified by landauf, 16 years ago) (diff)

ConfigFileManager

TracNav(TracNav/TOC_Development)?

Description

The ConfigFileManager loads and saves config-files. Config-files are a list of config-values divided into sections. Usually one section corresponds to une class and one config-value corresponds to one variable of this class. Read this guide to learn more about how to edit the config-file.

General structure of a config-file:

[Section1]
variable1=value
variable2=value

[Section2]
other_variable1=value
other_variable2=value
other_variable3=value

...

Types

There are several types of config-files, denoted by an enum:

  • CFT_Settings: Normal config file, usually orxonox.ini
  • CFT_Keybindings: Keybinding file, usually keybindings.ini
  • CFT_JoyStickCalibration: Special file for joystick callibration

Usage

Load

  • setFile(type, filename): Sets the path to the config-file of the given type (CFT_Settings, CFT_Keybindings, CFT_JoyStickCalibration) and loads the file.
  • load(type): Reloads the config-file of the given type if the path was already set by setFile, else loads the default file.

When loading a config-file, the file is parsed into sections and values. Each value belongs to a section, each section usually belongs to a class. For every value a ConfigValueContainer is created to store the value. The container is then stored in the Identifier of the corresponding class (usually denoted by the section). This allows new instances of a class to get the loaded config-values without parsing the file every time.

Save

  • load(type): Saves the config-file of the given type if the path was already set by setFile, else saves the default file.

When saving a config-file, every existing ConfigValueContainer writes it's value into the file, grouped into sections (where a section usually corresponds to a class). New config-values and sections are automatically added to the file.

A config-file is usually saved after a config-value has changed (for example by using the config or keybind commands) except for temporary changes (for example by using tconfig or tkeybind).