Fixed multithreading :)

This commit is contained in:
Kyle Kiteveles 2023-08-04 14:00:18 -04:00
parent 2e8e9cd177
commit cae166bc93

View file

@ -1,5 +1,5 @@
mod oop;
use std::{thread::{self, JoinHandle}, fs::copy, ops::Index, clone, borrow::Cow};
use std::thread::{self, JoinHandle};
use clap::Parser;
use roxmltree::{self, Document};
@ -11,61 +11,45 @@ struct Args {
}
fn main() {
let mut arg = Args::parse();
let arg = Args::parse();
let mut objects_filenames: Vec<String> = Vec::new();
let mut messages_filenames: Vec<String> = Vec::new();
let mut docs: Vec<Document> = Vec::new();
let mut handles: Vec<thread::JoinHandle<()>> = Vec::new();
let mut file_name: Vec<String> = Vec::new();
let handles: Vec<thread::JoinHandle<()>> = Vec::new();
let mut file_names: Vec<String> = Vec::new();
let opt = roxmltree::ParsingOptions {
allow_dtd: true,
..roxmltree::ParsingOptions::default()
};
let paths = std::fs::read_dir(arg.dir).expect("No directory found.");
let mut temp:Vec<JoinHandle<Document>> = Vec::new();
for path in paths {
let paths = std::fs::read_dir(arg.dir.clone()).expect("No directory found.");
let paths2 = std::fs::read_dir(arg.dir.clone()).expect("No directory found.");
let mut temp:Vec<JoinHandle<()>> = Vec::new();
for path in paths2 {
match path {
Ok(real_path) => {
file_name.push(real_path.path().to_string_lossy().to_string());
file_names.push(real_path.path().to_string_lossy().to_string());
},
Err(unreal_path) => {panic!("Bad file path.")}
Err(_) => {panic!("Bad file path.")}
};
objects_filenames.push(file_name.last().unwrap().trim_end_matches(".xml").to_string() + "_objects.rs");
messages_filenames.push(file_name.last().unwrap().trim_end_matches(".xml").to_string() + "_messages.rs");
temp.push(thread::spawn(move || {
let new_file_name = file_name.last().unwrap().to_owned();
roxmltree::Document::parse_with_options(new_file_name.as_str(), opt).unwrap()
}));
objects_filenames.push(file_names.last().unwrap().trim_end_matches(".xml").to_string() + "_objects.rs");
messages_filenames.push(file_names.last().unwrap().trim_end_matches(".xml").to_string() + "_messages.rs");
}
for path in paths {
temp.push(thread::spawn(move || {
let file_name;
temp.push(thread::spawn(move || {
let file_names2;
match path {
Ok(real_path) => {
file_name = real_path.path().to_string_lossy().to_string();
file_names2 = real_path.path().to_string_lossy().to_string();
},
Err(unreal_path) => {panic!("Bad file path.")}
Err(_) => {panic!("Bad file path.")}
};
roxmltree::Document::parse_with_options(&file_name, opt).unwrap()
let doc = roxmltree::Document::parse_with_options(&file_names2.as_str(), opt).unwrap();
output(parse(&doc));
}));
}
/*for arg in 0..args.files.len() {
let temp = args.files.remove(0);
objects_filenames.push(temp.trim_end_matches(".xml").to_string() + "_objects.rs");
messages_filenames.push(temp.trim_end_matches(".xml").to_string() + "_messages.rs");
docs.push(roxmltree::Document::parse_with_options(&temp, opt).unwrap());
}*/
for doc in docs {
}
for handle in handles {
handle.join().unwrap();
}