openmw_config
openmw_config is a lightweight Rust crate that provides a simple, idiomatic API for reading, composing, and writing OpenMW configuration files. It closely matches OpenMW's own configuration parser, supporting advanced features such as configuration chains, directory tokens, and value replacement semantics. For comprehensive coverage of OpenMW's configuration and filesystem, combine this crate with vfstool_lib.
Features
- Accurate Parsing: Mirrors OpenMW's config resolution, including support for
config=,replace=, and directory tokens like?userdata?. - Multi-file Support: Handles configuration chains, where multiple
openmw.cfgfiles are merged according to OpenMW's rules. - Simple API: Access content files, data directories, fallback entries, and more with ergonomic Rust methods.
- Serialization: Easily write out a configuration in valid
openmw.cfgformat. - No heavy dependencies: Only depends on the Rust standard library and the
dirscrate.
Why use openmw-config?
Modern OpenMW installations often use multiple configuration files, with complex rules for merging and overriding settings. This crate makes it easy to:
- Inspect and modify the effective configuration as seen by OpenMW.
- Build tools for mod management, diagnostics, or launcher frontends.
- Programmatically generate or edit
openmw.cfgfiles.
Quick Start
Add to your Cargo.toml:
= "0.1"
Basic Usage
Load the active OpenMW configuration
use OpenMWConfiguration;
Load a specific config file
Note:
The argument toOpenMWConfiguration::new(Some(path))must be the directory containingopenmw.cfg, not the path to the file itself.
For example, if your config is at/home/user/.config/openmw/openmw.cfg, you should pass/home/user/.config/openmw.
use PathBuf;
use OpenMWConfiguration;
Accessing and Modifying Configuration
use HashMap;
use PathBuf;
use OpenMWConfiguration;
// Assume you have a mutable config instance:
let mut config = new?;
// Set content files
config.set_content_files;
// Set data directories
config.set_data_directories;
// Set fallback entries
let mut fallbacks = new;
fallbacks.insert;
config.set_fallback_entries;
// Set fallback archives
config.set_fallback_archives;
// Set data-local directory
config.set_data_local;
// Set resources directory
config.set_resources_dir;
// Set userdata directory
config.set_userdata_dir;
Manually Serializing and Saving to a File
use File;
use Write;
// Serialize the config to a string in openmw.cfg format
let config_string = config.display;
// Write to a file of your choice
let mut file = create?;
file.write_all?;
Serialize to String (openmw.cfg format)
println!; // Uses the Display trait to print in openmw.cfg format
Advanced Features
- Config Chains:
OpenMW can load multiple config files in a chain. Useconfig.sub_configs()to inspect the chain and get granular access to the config. - Replace Semantics:
Handlesreplace=content,replace=data, etc., as in OpenMW. - Token Expansion:
Supports tokens like?userdata?and?userconfig?in directory paths.
API Overview
OpenMWConfiguration::new(path: Option<PathBuf>) -> Result<Self, String>
Load a configuration, optionally from a specific directory.content_files() -> &Vec<String>
List of plugin files.data_directories() -> &Vec<PathBuf>
List of data directories.fallback_archives() -> &Vec<String>List of Bethesda Archives defined by the current configfallback_entries() -> &HashMap<String, String>
Fallback key-value pairs.save(dir: Option<PathBuf>) -> Result<(), String>
Save the configuration to a directory.Displaytrait
Serialize the configuration to a validopenmw.cfgstring.
Reference
See OpenMW documentation for details on configuration file semantics.
openmw-config is not affiliated with the OpenMW project, but aims to be a faithful and practical Rust implementation of its configuration logic.
PRs and issues welcome!