use crate::{
architecture::Architecture, registry_comparator::RegistryComparator, registry_key::KeyNode,
registry_parser::{LoadResult, RegistryParser}, registry_writer::RegistryWriter,
};
#[derive(Debug, Clone)]
pub struct EditorOptions {
pub relative_base: String,
pub architecture: Architecture,
}
impl Default for EditorOptions {
fn default() -> Self {
Self {
relative_base: String::new(),
architecture: Architecture::Unknown,
}
}
}
pub struct RegistryEditor;
impl RegistryEditor {
pub fn load_from_file(filename: &str) -> Result<LoadResult, crate::registry_parser::ParseError> {
let parser = RegistryParser;
parser.load_from_file(filename)
}
pub fn load_from_text(text: &str) -> Result<LoadResult, crate::registry_parser::ParseError> {
let parser = RegistryParser;
parser.load_from_text(text)
}
pub fn write_to_file_with_options(
key: &KeyNode,
filename: &str,
options: EditorOptions,
) -> std::io::Result<()> {
let writer = RegistryWriter {
relative_base: options.relative_base,
architecture: options.architecture,
};
writer.write_to_file(key, filename)
}
pub fn write_to_file_default(key: &KeyNode, filename: &str) -> std::io::Result<()> {
Self::write_to_file_with_options(key, filename, EditorOptions::default())
}
pub fn write_to_string_with_options(key: &KeyNode, options: EditorOptions) -> String {
let writer = RegistryWriter {
relative_base: options.relative_base,
architecture: options.architecture,
};
writer.write_to_string(key)
}
pub fn write_to_string_default(key: &KeyNode) -> String {
Self::write_to_string_with_options(key, EditorOptions::default())
}
pub fn compare_registries(key1: &KeyNode, key2: &KeyNode) -> crate::registry_comparator::DiffResult {
let comparator = RegistryComparator;
comparator.compare_registries(key1, key2)
}
}