From 286d8d92fa4bc734d704a0578efc0f31f5add35f Mon Sep 17 00:00:00 2001 From: Wolfgang Jung Date: Sun, 12 Jan 2020 18:25:49 +0100 Subject: [PATCH 1/6] Ignoring temporary files during download --- src/watcher.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/watcher.rs b/src/watcher.rs index f651211..8c222a6 100644 --- a/src/watcher.rs +++ b/src/watcher.rs @@ -140,12 +140,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(LLError::new(format!("=> Ignoring non-zip: {}", path.to_str().unwrap()))) + } + None => { + Err(LLError::new(format!("=> Ignoring: {}", path.to_str().unwrap()))) + } + } } } From 0763e1d45de76d85ac9291bac51034c05ad56902 Mon Sep 17 00:00:00 2001 From: Wolfgang Jung Date: Sun, 12 Jan 2020 18:29:30 +0100 Subject: [PATCH 2/6] Extracting 3D Models from download --- src/format/extractors/mod.rs | 16 ++++++++-------- src/format/mod.rs | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/format/extractors/mod.rs b/src/format/extractors/mod.rs index 97c8257..4772338 100644 --- a/src/format/extractors/mod.rs +++ b/src/format/extractors/mod.rs @@ -27,14 +27,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/src/format/mod.rs b/src/format/mod.rs index 1206b72..dc2b21e 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -17,7 +17,7 @@ pub enum ECAD { pub struct Format { pub ecad: ECAD, pub create_folder: bool, - match_path: &'static str, + match_path: Vec<&'static str>, ignore: Vec<&'static str> } @@ -32,25 +32,25 @@ impl Format { "eagle" => Self { ecad: ECAD::EAGLE, create_folder: false, - match_path: "EAGLE", + match_path: vec!["EAGLE/", "/3D/"], ignore: vec!["Readme.html"] }, "easyeda" => Self { ecad: ECAD::EASYEDA, create_folder: false, - match_path: "EasyEDA", + match_path: vec!["EasyEDA/", "/3D/"], ignore: vec!["Readme.html"] }, "kicad" => Self { ecad: ECAD::KICAD, create_folder: true, - match_path: "KiCad", + match_path: vec!["KiCad/", "/3D/"], ignore: vec![] }, "zip" => Self { ecad: ECAD::ZIP, create_folder: false, - match_path: "", + match_path: vec![""], ignore: vec![] }, _ => { From fcbe5807d08961917e1a9caf4e369af765bb60b4 Mon Sep 17 00:00:00 2001 From: Wolfgang Jung Date: Sun, 31 Oct 2021 13:45:30 +0100 Subject: [PATCH 3/6] Adds URL to error message --- src/cse.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cse.rs b/src/cse.rs index 7ef3922..68ff2f4 100644 --- a/src/cse.rs +++ b/src/cse.rs @@ -41,7 +41,7 @@ impl CSE { if !res.status().is_success() { - return Err(LLError::new(format!("Error downloading file: {}", res.status()))) + return Err(LLError::new(format!("Error downloading file: {} from {}", res.status(), url))) } else if res_header != "application/x-zip" { From 7b28aa57da3a3a26f2e34165ea6746c4d3569117 Mon Sep 17 00:00:00 2001 From: Wolfgang Jung Date: Sun, 31 Oct 2021 13:47:24 +0100 Subject: [PATCH 4/6] Changes download-url to https --- src/consts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/consts.rs b/src/consts.rs index c01baa1..de6e345 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -1,5 +1,5 @@ // Component Search Enginge Url -pub const COMPONENT_SEARCH_ENGINE_URL: &str = "http://componentsearchengine.com/ga/model.php?partID="; +pub const COMPONENT_SEARCH_ENGINE_URL: &str = "https://componentsearchengine.com/ga/model.php?partID="; // Main config file to look for in working dir pub const LL_CONFIG: &str = "LibraryLoader.toml"; From 28f0c625c46c40ebff6d5232a8a0cf39f9306cb0 Mon Sep 17 00:00:00 2001 From: Wolfgang Jung Date: Sun, 31 Oct 2021 13:56:54 +0100 Subject: [PATCH 5/6] Use new error macro --- ll-core/src/watcher.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ll-core/src/watcher.rs b/ll-core/src/watcher.rs index 933ccd0..f1b8391 100644 --- a/ll-core/src/watcher.rs +++ b/ll-core/src/watcher.rs @@ -194,10 +194,10 @@ impl Watcher { let res = &self.cse.get(epw)?; res.save() } else { - Err(LLError::new(format!("=> Ignoring non-zip: {}", path.to_str().unwrap()))) + Err(new_err!(format!("=> Ignoring non-zip: {}", path.to_str().unwrap()))) } None => { - Err(LLError::new(format!("=> Ignoring: {}", path.to_str().unwrap()))) + Err(new_err!(format!("=r Ignoring: {}", path.to_str().unwrap()))) } } } From dbed0b74265dc2954b495051732f55c38322bf09 Mon Sep 17 00:00:00 2001 From: Wolfgang Jung Date: Sun, 31 Oct 2021 13:57:50 +0100 Subject: [PATCH 6/6] Use vec for match_path --- ll-core/src/format/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ll-core/src/format/mod.rs b/ll-core/src/format/mod.rs index 1774fae..ec771dd 100644 --- a/ll-core/src/format/mod.rs +++ b/ll-core/src/format/mod.rs @@ -35,7 +35,7 @@ impl Format { name: f, ecad: ECAD::D3, create_folder: true, - match_path: "3D", + match_path: vec!["3D"], ignore: vec![] }, "eagle" => Self {