|
| 1 | +use std::io::Cursor; |
1 | 2 | use {
|
2 | 3 | crate::error::{Error, Result},
|
3 | 4 | serde::{Deserialize, Serialize},
|
@@ -60,70 +61,59 @@ ecad!([
|
60 | 61 | #[derive(Debug, Clone, PartialEq)]
|
61 | 62 | pub struct Format {
|
62 | 63 | pub output_path: PathBuf,
|
63 |
| - // pub name: String, |
| 64 | + pub name: String, |
64 | 65 | pub ecad: ECAD,
|
65 | 66 | pub create_folder: bool,
|
66 | 67 | match_path: &'static str,
|
67 | 68 | ignore: Vec<&'static str>,
|
68 | 69 | }
|
69 | 70 |
|
70 | 71 | impl Format {
|
71 |
| - pub fn from_ecad<P: Into<PathBuf>>(ecad: ECAD, output_path: P) -> Self { |
72 |
| - // * Keep these in alphabetical order |
73 |
| - match ecad { |
74 |
| - ECAD::D3 => Self { |
75 |
| - output_path: output_path.into(), |
76 |
| - ecad, |
77 |
| - create_folder: true, |
78 |
| - match_path: "3D", |
79 |
| - ignore: vec![], |
| 72 | + pub fn from_ecad<P: Into<PathBuf>>(name: &String, ecad: ECAD, output_path: P) -> Self { |
| 73 | + //defaults |
| 74 | + let mut fmt = Self { |
| 75 | + output_path: output_path.into(), |
| 76 | + name: (*name).clone(), |
| 77 | + ecad, |
| 78 | + create_folder: false, |
| 79 | + match_path: "", |
| 80 | + ignore: vec![], |
| 81 | + }; |
| 82 | + // specific overrides, keep these in alphabetical order |
| 83 | + match fmt.ecad { |
| 84 | + ECAD::D3 => { |
| 85 | + fmt.create_folder = true; |
| 86 | + fmt.match_path = "3D"; |
80 | 87 | },
|
81 |
| - ECAD::DesignSpark => Self { |
82 |
| - output_path: output_path.into(), |
83 |
| - ecad, |
84 |
| - create_folder: false, |
85 |
| - match_path: "DesignSpark PCB", |
86 |
| - ignore: vec![], |
| 88 | + ECAD::DesignSpark => { |
| 89 | + fmt.match_path = "DesignSpark PCB"; |
87 | 90 | },
|
88 |
| - ECAD::Eagle => Self { |
89 |
| - output_path: output_path.into(), |
90 |
| - ecad, |
91 |
| - create_folder: false, |
92 |
| - match_path: "EAGLE", |
93 |
| - ignore: vec!["Readme.html"], |
| 91 | + ECAD::Eagle => { |
| 92 | + fmt.match_path = "EAGLE"; |
| 93 | + fmt.ignore = vec!["Readme.html"]; |
94 | 94 | },
|
95 |
| - ECAD::EasyEDA => Self { |
96 |
| - output_path: output_path.into(), |
97 |
| - ecad, |
98 |
| - create_folder: false, |
99 |
| - match_path: "EasyEDA", |
100 |
| - ignore: vec!["Readme.html"], |
| 95 | + ECAD::EasyEDA => { |
| 96 | + fmt.match_path = "EasyEDA"; |
| 97 | + fmt.ignore = vec!["Readme.html"]; |
101 | 98 | },
|
102 |
| - ECAD::KiCad => Self { |
103 |
| - output_path: output_path.into(), |
104 |
| - ecad, |
105 |
| - create_folder: false, |
106 |
| - match_path: "KiCad", |
107 |
| - ignore: vec![], |
| 99 | + ECAD::KiCad => { |
| 100 | + fmt.match_path = "KiCad"; |
108 | 101 | },
|
109 |
| - ECAD::Zip => Self { |
110 |
| - output_path: output_path.into(), |
111 |
| - ecad, |
112 |
| - create_folder: false, |
113 |
| - match_path: "", |
114 |
| - ignore: vec![], |
| 102 | + ECAD::Zip => { |
| 103 | + //no changes |
115 | 104 | },
|
116 | 105 | }
|
| 106 | + return fmt |
117 | 107 | }
|
118 | 108 |
|
119 |
| - pub fn extract(&self, files: &mut Files, file_path: String, item: &mut ZipFile) -> Result<()> { |
| 109 | + pub fn extract(&self, archive: &mut zip::ZipArchive<Cursor<&Vec<u8>>>) -> Result<()> { |
120 | 110 | match &self.ecad {
|
121 | 111 | // * Keep these in alphabetical order
|
122 | 112 | ECAD::D3 => extractors::d3::extract(&self, files, file_path, item)?,
|
123 | 113 | ECAD::DesignSpark => extractors::designspark::extract(&self, files, file_path, item)?,
|
124 | 114 | ECAD::Eagle => extractors::eagle::extract(&self, files, file_path, item)?,
|
125 | 115 | ECAD::EasyEDA => extractors::easyeda::extract(&self, files, file_path, item)?,
|
126 |
| - ECAD::KiCad => extractors::kicad::extract(&self, files, file_path, item)?, |
| 116 | + ECAD::KiCad => extractors::kicad::extract(&self, archive)?, |
127 | 117 | ECAD::Zip => unreachable!("ZIP not handled!"),
|
128 | 118 | // ! NOTE: DO NOT ADD A _ => {} CATCHER HERE!
|
129 | 119 | };
|
|
0 commit comments