Replace WriteMode with MetadataWriteOptions

This is a breaking API change, but the addition of any future options won't be.
This commit is contained in:
Oliver Hamlet
2026-01-03 13:26:52 +00:00
parent dae06e1f10
commit b7363b0a29
13 changed files with 540 additions and 180 deletions
+58 -17
View File
@@ -3,7 +3,7 @@ use std::{
sync::{Arc, RwLock},
};
use libloot::{EvalMode, MergeMode, WriteMode, error::DatabaseLockPoisonError};
use libloot::{EvalMode, MergeMode, error::DatabaseLockPoisonError};
use libloot_ffi_errors::UnsupportedEnumValueError;
use pyo3::{
Bound, PyResult, pyclass, pymethods,
@@ -15,6 +15,59 @@ use crate::{
metadata::{Group, Message, NONE_REPR, PluginMetadata},
};
#[pyclass(str = "{0:?}")]
#[repr(transparent)]
#[derive(Clone, Debug, Default)]
pub struct MetadataWriteOptions(libloot::MetadataWriteOptions);
#[pymethods]
impl MetadataWriteOptions {
#[new]
pub fn new() -> Self {
MetadataWriteOptions(libloot::MetadataWriteOptions::new())
}
#[setter]
pub fn set_truncate(&mut self, truncate: bool) {
self.0.set_truncate(truncate);
}
#[setter]
pub fn set_write_anchors(&mut self, write_anchors: bool) {
self.0.set_write_anchors(write_anchors);
}
#[setter]
pub fn set_write_common_section(&mut self, write_common_section: bool) {
self.0.set_write_common_section(write_common_section);
}
#[setter]
pub fn set_anchor_file_strings(&mut self, anchor_file_strings: bool) {
self.0.set_anchor_file_strings(anchor_file_strings);
}
#[getter]
pub fn truncate(&self) -> bool {
self.0.truncate()
}
#[getter]
pub fn write_anchors(&self) -> bool {
self.0.write_anchors()
}
#[getter]
pub fn write_common_section(&self) -> bool {
self.0.write_common_section()
}
#[getter]
pub fn anchor_file_strings(&self) -> bool {
self.0.anchor_file_strings()
}
}
#[pyclass]
#[derive(Clone, Debug)]
pub struct Database(Arc<RwLock<libloot::Database>>);
@@ -56,18 +109,12 @@ impl Database {
pub fn write_user_metadata(
&self,
output_path: PathBuf,
overwrite: bool,
options: &MetadataWriteOptions,
) -> Result<(), VerboseError> {
let write_mode = if overwrite {
WriteMode::CreateOrTruncate
} else {
WriteMode::Create
};
self.0
.read()
.map_err(DatabaseLockPoisonError::from)?
.write_user_metadata(&output_path, write_mode)
.write_user_metadata(&output_path, &options.0)
.map_err(Into::into)
}
@@ -75,18 +122,12 @@ impl Database {
pub fn write_minimal_list(
&self,
output_path: PathBuf,
overwrite: bool,
options: &MetadataWriteOptions,
) -> Result<(), VerboseError> {
let write_mode = if overwrite {
WriteMode::CreateOrTruncate
} else {
WriteMode::Create
};
self.0
.read()
.map_err(DatabaseLockPoisonError::from)?
.write_minimal_list(&output_path, write_mode)
.write_minimal_list(&output_path, &options.0)
.map_err(Into::into)
}
+2 -1
View File
@@ -4,7 +4,7 @@ mod game;
mod metadata;
mod plugin;
use database::{Database, EdgeType, Vertex};
use database::{Database, EdgeType, MetadataWriteOptions, Vertex};
use game::{Game, GameType};
use metadata::{
File, Filename, Group, Location, Message, MessageContent, MessageType, PluginCleaningData,
@@ -64,6 +64,7 @@ fn libloot_pyo3(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<TagSuggestion>()?;
m.add_class::<Location>()?;
m.add_class::<PluginMetadata>()?;
m.add_class::<MetadataWriteOptions>()?;
m.add(
"CyclicInteractionError",