work begins...

This commit is contained in:
Alex Janka 2021-07-10 13:58:09 +10:00
parent e2641154d2
commit 97ee7f249e
3 changed files with 30 additions and 5 deletions

View file

@ -1,9 +1,9 @@
use ableton_rack_converter; use ableton_rack_converter::{self, fixers};
use xml_dom::level2::RefNode;
fn main() { fn main() {
let file_load = String::from("C:\\Users\\janka\\Documents\\Projects\\Programming\\ableton-rack-converter\\validation\\Utility10.adg"); let file_load = String::from("C:\\Users\\janka\\Documents\\Projects\\Programming\\ableton-rack-converter\\validation\\Utility10.adg");
let file_save = String::from("C:\\Users\\janka\\Documents\\Projects\\Programming\\ableton-rack-converter\\validation\\Utility10_save.adg"); let file_save = String::from("C:\\Users\\janka\\Documents\\Projects\\Programming\\ableton-rack-converter\\validation\\Utility10_save.xml");
let device: RefNode = ableton_rack_converter::load_adg(&file_load); let mut device = ableton_rack_converter::load_adg(&file_load);
ableton_rack_converter::save_adg(&device, &file_save); fixers::traverse_children(&mut device);
ableton_rack_converter::save_uncompressed(&device, &file_save);
} }

18
src/fixers.rs Normal file
View file

@ -0,0 +1,18 @@
use xml_dom::level2::{Element, Node, RefNode};
pub fn traverse_children(node: &mut RefNode) {
match node.node_name().to_string().as_str() {
"OverwriteProtectionNumber" => fix_overwrite_protection(node),
_ => {
for mut e in node.child_nodes() {
traverse_children(&mut e);
}
}
}
}
fn fix_overwrite_protection(node: &mut RefNode) {
node.set_attribute("Value", "FINDABLE")
.expect("couldnt set node value");
println!("{}", node);
}

View file

@ -6,6 +6,8 @@ use std::{
}; };
use xml_dom::{level2::RefNode, parser}; use xml_dom::{level2::RefNode, parser};
pub mod fixers;
pub fn load_adg(filename: &str) -> RefNode { pub fn load_adg(filename: &str) -> RefNode {
let contents = File::open(filename).expect("failed to load file"); let contents = File::open(filename).expect("failed to load file");
let xml = decompress(contents); let xml = decompress(contents);
@ -31,6 +33,11 @@ pub fn save_adg(dom: &RefNode, filename: &str) {
fs::write(filename, compressed).expect("could not write file"); fs::write(filename, compressed).expect("could not write file");
} }
pub fn save_uncompressed(dom: &RefNode, filename: &str) {
let xml = encode(dom);
fs::write(filename, xml.as_bytes()).expect("could not write file");
}
fn compress(xml: &str) -> Vec<u8> { fn compress(xml: &str) -> Vec<u8> {
let mut encoder = GzEncoder::new(Vec::new(), Compression::default()); let mut encoder = GzEncoder::new(Vec::new(), Compression::default());
encoder encoder