diff --git a/ll-core/src/cse.rs b/ll-core/src/cse.rs index 9f9cf4e..206df6e 100644 --- a/ll-core/src/cse.rs +++ b/ll-core/src/cse.rs @@ -49,7 +49,7 @@ impl CSE { if !res.status().is_success() { - return Err(new_err!(format!("Error downloading file: {}", res.status()))) + return Err(new_err!(format!("Error downloading file: {} from {}", res.status(), url))) } else if res_header != "application/x-zip" { diff --git a/ll-core/src/format/extractors/mod.rs b/ll-core/src/format/extractors/mod.rs index bfbda21..0bc6a65 100644 --- a/ll-core/src/format/extractors/mod.rs +++ b/ll-core/src/format/extractors/mod.rs @@ -33,14 +33,14 @@ pub(super) fn generic_extractor(format: &Format, files: &mut Files, file_path: S } - if file_path_lower.contains(&format.match_path.to_lowercase()) { - - let path = PathBuf::from(file_path); - let base_name = path.file_name().unwrap().to_string_lossy().to_string(); - let mut f_data = Vec::::new(); - item.read_to_end(&mut f_data)?; - files.insert(base_name, f_data); - + let path = PathBuf::from(file_path); + for paths_to_extract in &format.match_path { + if file_path_lower.contains(paths_to_extract.to_lowercase().as_str()) { + let base_name = path.file_name().unwrap().to_string_lossy().to_string(); + let mut f_data = Vec::::new(); + item.read_to_end(&mut f_data)?; + files.insert(base_name, f_data); + } } Ok(()) diff --git a/ll-core/src/format/mod.rs b/ll-core/src/format/mod.rs index 2b221d0..ec771dd 100644 --- a/ll-core/src/format/mod.rs +++ b/ll-core/src/format/mod.rs @@ -19,7 +19,7 @@ pub struct Format { pub name: String, pub ecad: ECAD, pub create_folder: bool, - match_path: &'static str, + match_path: Vec<&'static str>, ignore: Vec<&'static str> } @@ -35,35 +35,35 @@ impl Format { name: f, ecad: ECAD::D3, create_folder: true, - match_path: "3D", + match_path: vec!["3D"], ignore: vec![] }, "eagle" => Self { name: f, ecad: ECAD::EAGLE, create_folder: false, - match_path: "EAGLE", + match_path: vec!["EAGLE/", "/3D/"], ignore: vec!["Readme.html"] }, "easyeda" => Self { name: f, ecad: ECAD::EASYEDA, create_folder: false, - match_path: "EasyEDA", + match_path: vec!["EasyEDA/", "/3D/"], ignore: vec!["Readme.html"] }, "kicad" => Self { name: f, ecad: ECAD::KICAD, create_folder: true, - match_path: "KiCad", + match_path: vec!["KiCad/", "/3D/"], ignore: vec![] }, "zip" => Self { name: f, ecad: ECAD::ZIP, create_folder: false, - match_path: "", + match_path: vec![""], ignore: vec![] }, _ => { diff --git a/ll-core/src/watcher.rs b/ll-core/src/watcher.rs index 88caf77..f1b8391 100644 --- a/ll-core/src/watcher.rs +++ b/ll-core/src/watcher.rs @@ -186,12 +186,20 @@ impl Watcher { } - fn handle_file>(&self, path: P) -> LLResult { - - let epw = Epw::from_file(path)?; - let res = &self.cse.get(epw)?; - res.save() - + fn handle_file(&self, path: &PathBuf) -> LLResult { + let extension = path.extension().and_then(|ext| { ext.to_str() }); + match extension { + Some(s) => if s.eq_ignore_ascii_case("zip") { + let epw = Epw::from_file(path)?; + let res = &self.cse.get(epw)?; + res.save() + } else { + Err(new_err!(format!("=> Ignoring non-zip: {}", path.to_str().unwrap()))) + } + None => { + Err(new_err!(format!("=r Ignoring: {}", path.to_str().unwrap()))) + } + } } }