mirror of
https://github.com/italicsjenga/ableton-rack-converter.git
synced 2024-11-22 07:01:30 +11:00
work begins...
This commit is contained in:
parent
e2641154d2
commit
97ee7f249e
|
@ -1,9 +1,9 @@
|
|||
use ableton_rack_converter;
|
||||
use xml_dom::level2::RefNode;
|
||||
use ableton_rack_converter::{self, fixers};
|
||||
|
||||
fn main() {
|
||||
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 device: RefNode = ableton_rack_converter::load_adg(&file_load);
|
||||
ableton_rack_converter::save_adg(&device, &file_save);
|
||||
let file_save = String::from("C:\\Users\\janka\\Documents\\Projects\\Programming\\ableton-rack-converter\\validation\\Utility10_save.xml");
|
||||
let mut device = ableton_rack_converter::load_adg(&file_load);
|
||||
fixers::traverse_children(&mut device);
|
||||
ableton_rack_converter::save_uncompressed(&device, &file_save);
|
||||
}
|
||||
|
|
18
src/fixers.rs
Normal file
18
src/fixers.rs
Normal 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);
|
||||
}
|
|
@ -6,6 +6,8 @@ use std::{
|
|||
};
|
||||
use xml_dom::{level2::RefNode, parser};
|
||||
|
||||
pub mod fixers;
|
||||
|
||||
pub fn load_adg(filename: &str) -> RefNode {
|
||||
let contents = File::open(filename).expect("failed to load file");
|
||||
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");
|
||||
}
|
||||
|
||||
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> {
|
||||
let mut encoder = GzEncoder::new(Vec::new(), Compression::default());
|
||||
encoder
|
||||
|
|
Loading…
Reference in a new issue