1
0
mirror of https://github.com/pcvolkmer/osc-variant.git synced 2025-04-19 19:56:50 +00:00

chore: code cleanup

This commit is contained in:
Paul-Christian Volkmer 2025-01-08 20:49:45 +01:00
parent ea47b101f2
commit b055146c8f
4 changed files with 38 additions and 34 deletions

View File

@ -32,7 +32,7 @@ pub fn check_file(file: &Path, password: &str) -> Result<Vec<CheckNotice>, Check
Ok(file) => file, Ok(file) => file,
Err(err) => { Err(err) => {
return Err(CheckNotice::Error { return Err(CheckNotice::Error {
description: format!("Kann Datei nicht lesen: {}", err), description: format!("Kann Datei nicht lesen: {err}"),
line: None, line: None,
}); });
} }
@ -42,7 +42,7 @@ pub fn check_file(file: &Path, password: &str) -> Result<Vec<CheckNotice>, Check
Ok(file) => file, Ok(file) => file,
Err(err) => { Err(err) => {
return Err(CheckNotice::Error { return Err(CheckNotice::Error {
description: format!("Kann Datei nicht lesen: {}", err), description: format!("Kann Datei nicht lesen: {err}"),
line: None, line: None,
}); });
} }
@ -73,9 +73,9 @@ pub fn check_file(file: &Path, password: &str) -> Result<Vec<CheckNotice>, Check
result.push(CheckNotice::Ok(format!( result.push(CheckNotice::Ok(format!(
"Keine Probleme in '{}' erkannt", "Keine Probleme in '{}' erkannt",
zip_file.name() zip_file.name()
))) )));
} }
result.append(check_result) result.append(check_result);
} }
Err(_) => result.push(CheckNotice::Warning { Err(_) => result.push(CheckNotice::Warning {
description: format!( description: format!(
@ -94,7 +94,7 @@ pub fn check_file(file: &Path, password: &str) -> Result<Vec<CheckNotice>, Check
zip_file.name() zip_file.name()
), ),
line: None, line: None,
}) });
} }
} else { } else {
return Err(CheckNotice::Error { return Err(CheckNotice::Error {

View File

@ -550,7 +550,7 @@ mod tests {
assert_eq!( assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[2].default_value, onkostar_editor.editor.data_form[0].entries.entry[2].default_value,
"B" "B"
) );
} }
#[test] #[test]
@ -586,7 +586,7 @@ mod tests {
assert_eq!( assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[2].default_value, onkostar_editor.editor.data_form[0].entries.entry[2].default_value,
"" ""
) );
} }
#[test] #[test]
@ -883,7 +883,7 @@ mod tests {
assert_eq!( assert_eq!(
onkostar_editor.editor.unterformular[0].entries.entry[1].default_value, onkostar_editor.editor.unterformular[0].entries.entry[1].default_value,
"2024-03-18" "2024-03-18"
) );
} }
#[test] #[test]
@ -919,7 +919,7 @@ mod tests {
assert_eq!( assert_eq!(
onkostar_editor.editor.unterformular[0].entries.entry[1].default_value, onkostar_editor.editor.unterformular[0].entries.entry[1].default_value,
"" ""
) );
} }
#[test] #[test]

View File

@ -141,9 +141,9 @@ mod tests {
assert_eq!(profile.forms[0].name, "DNPM Therapieplan"); assert_eq!(profile.forms[0].name, "DNPM Therapieplan");
assert!(profile.forms[0].menu_category.is_some()); assert!(profile.forms[0].menu_category.is_some());
assert_eq!(profile.forms[0].form_references.len(), 1); assert_eq!(profile.forms[0].form_references.len(), 1);
assert_eq!(profile.forms[0].form_fields.len(), 1) assert_eq!(profile.forms[0].form_fields.len(), 1);
} }
Err(e) => panic!("Cannot deserialize profile: {}", e), Err(e) => panic!("Cannot deserialize profile: {e}"),
} }
} }
@ -186,7 +186,7 @@ mod tests {
Some("// Example code&#10;console.log(42);".to_string()) Some("// Example code&#10;console.log(42);".to_string())
); );
} }
Err(e) => panic!("Cannot deserialize profile: {}", e), Err(e) => panic!("Cannot deserialize profile: {e}"),
} }
} }
@ -215,7 +215,7 @@ mod tests {
true true
})); }));
} }
Err(e) => panic!("Cannot deserialize profile: {}", e), Err(e) => panic!("Cannot deserialize profile: {e}"),
} }
} }
@ -240,7 +240,7 @@ mod tests {
assert_eq!(profile.forms[0].form_references[0].anzeige, None); assert_eq!(profile.forms[0].form_references[0].anzeige, None);
assert_eq!(profile.forms[0].form_references[0].anzeige_auswahl, None); assert_eq!(profile.forms[0].form_references[0].anzeige_auswahl, None);
} }
Err(e) => panic!("Cannot deserialize profile: {}", e), Err(e) => panic!("Cannot deserialize profile: {e}"),
} }
} }
@ -289,7 +289,7 @@ mod tests {
Some("// Example code&#10;console.log(42);".to_string()) Some("// Example code&#10;console.log(42);".to_string())
); );
} }
Err(e) => panic!("Cannot deserialize profile: {}", e), Err(e) => panic!("Cannot deserialize profile: {e}"),
} }
} }
@ -312,7 +312,7 @@ mod tests {
Some("X".to_string()) Some("X".to_string())
); );
} }
Err(e) => panic!("Cannot deserialize profile: {}", e), Err(e) => panic!("Cannot deserialize profile: {e}"),
} }
} }
@ -336,7 +336,7 @@ mod tests {
); );
assert!(profile.forms[0].form_references[0].remove_filter); assert!(profile.forms[0].form_references[0].remove_filter);
} }
Err(e) => panic!("Cannot deserialize profile: {}", e), Err(e) => panic!("Cannot deserialize profile: {e}"),
} }
} }
@ -357,7 +357,7 @@ mod tests {
assert_eq!(profile.forms[0].form_fields[0].name, "formularfeld_to_mod"); assert_eq!(profile.forms[0].form_fields[0].name, "formularfeld_to_mod");
assert!(profile.forms[0].form_fields[0].remove_filter); assert!(profile.forms[0].form_fields[0].remove_filter);
} }
Err(e) => panic!("Cannot deserialize profile: {}", e), Err(e) => panic!("Cannot deserialize profile: {e}"),
} }
} }
} }

View File

@ -75,9 +75,7 @@ pub fn unzip_osb(path: &str, dir: &str, password: Option<String>) {
}; };
for i in 0..archive.len() { for i in 0..archive.len() {
let mut file = if let Ok(file) = archive.by_index_decrypt(i, password.as_bytes()) { let Ok(mut file) = archive.by_index_decrypt(i, password.as_bytes()) else {
file
} else {
println!( println!(
"{: <6}Abbruch! - Kann Datei nicht entpacken", "{: <6}Abbruch! - Kann Datei nicht entpacken",
style("[ERR]").red() style("[ERR]").red()
@ -92,10 +90,27 @@ pub fn unzip_osb(path: &str, dir: &str, password: Option<String>) {
started!(outpath.display()); started!(outpath.display());
if !file.is_dir() { if file.is_dir() {
if !outpath.exists() {
match fs::create_dir_all(&outpath) {
Ok(()) => {}
Err(err) => {
error!(outpath.display(), err);
continue;
}
}
}
ok!(outpath.display());
} else {
if let Some(p) = outpath.parent() { if let Some(p) = outpath.parent() {
if !p.exists() { if !p.exists() {
fs::create_dir_all(p).unwrap(); match fs::create_dir_all(p) {
Ok(()) => {}
Err(err) => {
error!(outpath.display(), err);
continue;
}
}
} }
} }
let mut outfile = match fs::File::create(&outpath) { let mut outfile = match fs::File::create(&outpath) {
@ -113,17 +128,6 @@ pub fn unzip_osb(path: &str, dir: &str, password: Option<String>) {
} }
} }
ok!(outpath.display()); ok!(outpath.display());
} else {
if !outpath.exists() {
match fs::create_dir_all(&outpath) {
Ok(_) => {}
Err(err) => {
error!(outpath.display(), err);
continue;
}
}
}
ok!(outpath.display());
} }
} }
} }