Crates.io | openmw-config |
lib.rs | openmw-config |
version | 0.1.7 |
created_at | 2025-06-17 03:36:57.524859+00 |
updated_at | 2025-07-18 00:53:20.770733+00 |
description | A library for interacting with the Openmw Configuration system. |
homepage | |
repository | https://github.com/DreamWeave-MP/Openmw_Config |
max_upload_size | |
id | 1715162 |
size | 92,964 |
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.
config=
, replace=
, and directory tokens like ?userdata?
.openmw.cfg
files are merged according to OpenMW's rules.openmw.cfg
format.dirs
crate.Modern OpenMW installations often use multiple configuration files, with complex rules for merging and overriding settings. This crate makes it easy to:
openmw.cfg
files.Add to your Cargo.toml
:
openmw-config = "0.1"
use openmw_cfg::OpenMWConfiguration;
fn main() -> Result<(), String> {
// Load the default OpenMW configuration chain
let config = OpenMWConfiguration::new(None)?;
println!("Root config: {:?}", config.root_config());
println!("User config: {:?}", config.user_config_path());
// List all content files (plugins)
for plugin in config.content_files() {
println!("Plugin: {plugin}");
}
// List all data directories
for dir in config.data_directories() {
println!("Data dir: {}", dir.display());
}
Ok(())
}
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 std::path::PathBuf;
use openmw_cfg::OpenMWConfiguration;
fn main() -> Result<(), String> {
// Correct: pass the directory, not the file!
let config_dir = PathBuf::from("/path/to/your/config_dir");
let config = OpenMWConfiguration::new(Some(config_dir))?;
// ... use config as above ...
Ok(())
}
use std::collections::HashMap;
use std::path::PathBuf;
use openmw_cfg::OpenMWConfiguration;
// Assume you have a mutable config instance:
let mut config = OpenMWConfiguration::new(None)?;
// Set content files
config.set_content_files(vec!["MyMod.esp".to_string(), "Another.esp".to_string()]);
// Set data directories
config.set_data_directories(vec![
PathBuf::from("/path/to/DataFiles"),
PathBuf::from("/path/to/OtherData"),
]);
// Set fallback entries
let mut fallbacks = HashMap::new();
fallbacks.insert("Some_Fallback".to_string(), "SomeValue".to_string());
config.set_fallback_entries(fallbacks);
// Set fallback archives
config.set_fallback_archives(vec!["Archive1.bsa".to_string(), "Archive2.bsa".to_string()]);
// Set data-local directory
config.set_data_local(PathBuf::from("/path/to/data-local"));
// Set resources directory
config.set_resources_dir(PathBuf::from("/path/to/resources"));
// Set userdata directory
config.set_userdata_dir(PathBuf::from("/path/to/userdata"));
use std::fs::File;
use std::io::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 = File::create("/path/to/your/openmw.cfg")?;
file.write_all(config_string.as_bytes())?;
println!("{}", config); // Uses the Display trait to print in openmw.cfg format
config.sub_configs()
to inspect the chain and get granular access to the config.replace=content
, replace=data
, etc., as in OpenMW.?userdata?
and ?userconfig?
in directory paths.OpenMWConfiguration::new(path: Option<PathBuf>) -> Result<Self, String>
content_files() -> &Vec<String>
data_directories() -> &Vec<PathBuf>
fallback_archives() -> &Vec<String>
List of Bethesda Archives defined by the current configfallback_entries() -> &HashMap<String, String>
save(dir: Option<PathBuf>) -> Result<(), String>
Display
traitopenmw.cfg
string.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!