diff --git a/fixtures/test.log b/fixtures/test.log index a983acf..950c33b 100644 --- a/fixtures/test.log +++ b/fixtures/test.log @@ -2,4 +2,7 @@ // The top of the file is the 'oldest' mod // ~TP2_File~ #language_number #component_number // [Subcomponent Name -> ] Component Name [ : Version] ~TEST_MOD_NAME_1/TEST.TP2~ #0 #0 // test mod one -~TEST_MOD_NAME_2/TEST.TP2~ #0 #0 // test mod two +~TEST_MOD_NAME_1/TEST.TP2~ #0 #1 // test mod two +~TEST_MOD_NAME_2/END.TP2~ #0 #0 // test mod with subcomponent information -> Standard installation +~TEST_MOD_NAME_3/END.TP2~ #0 #0 // test mod with version: 1.02 +~TEST_MOD_NAME_4/TWEAKS.TP2~ #0 #3346 // test mod with both subcomponent information and version -> Casting speed only: v16 diff --git a/src/main.rs b/src/main.rs index 705133c..28a0dc8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,6 +41,7 @@ fn main() { mods.iter() .filter_map(|weidu_mod| { if !installed_mods.contains(weidu_mod) { + log::debug!("Mod to be installed {:?}", weidu_mod); Some(weidu_mod.clone()) } else { None @@ -51,7 +52,7 @@ fn main() { mods }; - log::debug!( + log::info!( "Number of mods found: {}, Number of mods to be installed: {}", number_of_mods_found, mods_to_be_installed.len() diff --git a/src/mod_component.rs b/src/mod_component.rs index 96e54c8..1185848 100644 --- a/src/mod_component.rs +++ b/src/mod_component.rs @@ -4,12 +4,15 @@ use std::{ path::{PathBuf, MAIN_SEPARATOR}, }; -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, PartialOrd, Clone)] pub struct ModComponent { pub tp_file: String, pub name: String, pub lang: String, pub component: String, + pub component_name: String, + pub sub_component: String, + pub version: String, } impl From for ModComponent { @@ -33,10 +36,12 @@ impl From for ModComponent { .unwrap_or_else(|| panic!("Could not split {} into mod into name and component", line)) .to_ascii_lowercase(); - let mut lang_and_component = parts + let mut tail = parts .next() .unwrap_or_else(|| panic!("Could not find lang and component, from {}", line)) - .split(' '); + .split("//"); + + let mut lang_and_component = tail.next().unwrap_or_default().split(' '); let lang = lang_and_component .nth(1) @@ -48,11 +53,39 @@ impl From for ModComponent { .unwrap_or_else(|| panic!("Could not find component, from {}", line)) .replace('#', ""); + let mut component_name_sub_component_version = tail.next().unwrap_or_default().split(':'); + + let mut component_name_sub_component = component_name_sub_component_version + .next() + .unwrap_or_default() + .split("->"); + + let component_name = component_name_sub_component + .next() + .unwrap_or_default() + .trim() + .to_string(); + + let sub_component = component_name_sub_component + .next() + .unwrap_or_default() + .trim() + .to_string(); + + let version = component_name_sub_component_version + .next() + .unwrap_or_default() + .trim() + .to_string(); + ModComponent { tp_file, name, lang, component, + component_name, + sub_component, + version, } } } @@ -88,22 +121,55 @@ mod tests { let test_log = Path::new("fixtures/test.log"); let logs = parse_weidu_log(test_log.to_path_buf()); assert_eq!( - logs.first(), - Some(&ModComponent { - tp_file: "TEST.TP2".to_string(), - name: "test_mod_name_1".to_string(), - lang: "0".to_string(), - component: "0".to_string() - }) - ); - assert_eq!( - logs.last(), - Some(&ModComponent { - tp_file: "TEST.TP2".to_string(), - name: "test_mod_name_2".to_string(), - lang: "0".to_string(), - component: "0".to_string() - }) + logs, + vec![ + ModComponent { + tp_file: "TEST.TP2".to_string(), + name: "test_mod_name_1".to_string(), + lang: "0".to_string(), + component: "0".to_string(), + component_name: "test mod one".to_string(), + sub_component: "".to_string(), + version: "".to_string() + }, + ModComponent { + tp_file: "TEST.TP2".to_string(), + name: "test_mod_name_1".to_string(), + lang: "0".to_string(), + component: "1".to_string(), + component_name: "test mod two".to_string(), + sub_component: "".to_string(), + version: "".to_string() + }, + ModComponent { + tp_file: "END.TP2".to_string(), + name: "test_mod_name_2".to_string(), + lang: "0".to_string(), + component: "0".to_string(), + component_name: "test mod with subcomponent information".to_string(), + sub_component: "Standard installation".to_string(), + version: "".to_string() + }, + ModComponent { + tp_file: "END.TP2".to_string(), + name: "test_mod_name_3".to_string(), + lang: "0".to_string(), + component: "0".to_string(), + component_name: "test mod with version".to_string(), + sub_component: "".to_string(), + version: "1.02".to_string() + }, + ModComponent { + tp_file: "TWEAKS.TP2".to_string(), + name: "test_mod_name_4".to_string(), + lang: "0".to_string(), + component: "3346".to_string(), + component_name: "test mod with both subcomponent information and version" + .to_string(), + sub_component: "Casting speed only".to_string(), + version: "v16".to_string() + } + ] ); } } diff --git a/src/utils.rs b/src/utils.rs index d47ca7e..28ab6d2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -88,6 +88,9 @@ mod tests { name: "test_mod_name_1".to_string(), lang: "0".to_string(), component: "0".to_string(), + component_name: "".to_string(), + sub_component: "".to_string(), + version: "".to_string(), }; let mod_folder = find_mod_folder(&mod_component, Path::new("fixtures/mods"), 3);