mirror of
https://github.com/pcvolkmer/osc-variant.git
synced 2025-04-19 19:56:50 +00:00
feat: check file extension before reading OSC files
This commit is contained in:
parent
2358f6410f
commit
dcfc50878e
26
src/main.rs
26
src/main.rs
@ -31,7 +31,6 @@ use std::ops::Add;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use crate::checks::{check_file, print_checks, CheckNotice};
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use console::style;
|
use console::style;
|
||||||
use dialoguer::Confirm;
|
use dialoguer::Confirm;
|
||||||
@ -39,6 +38,7 @@ use quick_xml::se::Serializer;
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use sha256::digest;
|
use sha256::digest;
|
||||||
|
|
||||||
|
use crate::checks::{check_file, print_checks, CheckNotice};
|
||||||
use crate::cli::{Cli, SubCommand};
|
use crate::cli::{Cli, SubCommand};
|
||||||
use crate::model::onkostar_editor::OnkostarEditor;
|
use crate::model::onkostar_editor::OnkostarEditor;
|
||||||
use crate::profile::Profile;
|
use crate::profile::Profile;
|
||||||
@ -83,13 +83,25 @@ impl Display for FileError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read_inputfile(inputfile: String) -> Result<OnkostarEditor, FileError> {
|
fn read_inputfile(inputfile: String) -> Result<OnkostarEditor, FileError> {
|
||||||
return match fs::read_to_string(inputfile.clone()) {
|
let filename = Path::new(&inputfile);
|
||||||
Ok(content) => match OnkostarEditor::from_str(content.as_str()) {
|
|
||||||
Ok(data) => Ok(data),
|
match filename.extension() {
|
||||||
Err(err) => Err(FileError::Parsing(inputfile, err)),
|
Some(extension) => match extension.to_ascii_lowercase().to_str() {
|
||||||
|
Some("osc") => {
|
||||||
|
return match fs::read_to_string(filename) {
|
||||||
|
Ok(content) => match OnkostarEditor::from_str(content.as_str()) {
|
||||||
|
Ok(data) => Ok(data),
|
||||||
|
Err(err) => Err(FileError::Parsing(inputfile, err)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(FileError::Reading(inputfile, err.to_string())),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
},
|
},
|
||||||
Err(err) => Err(FileError::Reading(inputfile, err.to_string())),
|
None => {}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
return Err(FileError::Reading(inputfile, "Keine OSC-Datei".into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_outputfile(filename: String, content: &String) -> Result<(), FileError> {
|
fn write_outputfile(filename: String, content: &String) -> Result<(), FileError> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user