mirror of
https://github.com/132nd-vWing/tacview-splitter.git
synced 2026-08-26 07:48:37 +02:00
replaced all unwrap with expect
This commit is contained in:
+4
-3
@@ -5,6 +5,7 @@ pub mod lib {
|
|||||||
|
|
||||||
const ERR_CANNOT_WRITE_DATA: &str = "Could not write data";
|
const ERR_CANNOT_WRITE_DATA: &str = "Could not write data";
|
||||||
const ERR_CANNOT_OPEN_OUTPUT: &str = "Could not open output file";
|
const ERR_CANNOT_OPEN_OUTPUT: &str = "Could not open output file";
|
||||||
|
const ERR_CANNOT_BEGIN_FILE: &str = "Could not begin file in zip archive";
|
||||||
|
|
||||||
pub struct IDs<'a> {
|
pub struct IDs<'a> {
|
||||||
pub blue: Vec<&'a str>,
|
pub blue: Vec<&'a str>,
|
||||||
@@ -81,15 +82,15 @@ pub mod lib {
|
|||||||
|
|
||||||
let file = fs::File::create(&filenames.zip.blue).expect(ERR_CANNOT_OPEN_OUTPUT);
|
let file = fs::File::create(&filenames.zip.blue).expect(ERR_CANNOT_OPEN_OUTPUT);
|
||||||
let mut blue = zip::ZipWriter::new(file);
|
let mut blue = zip::ZipWriter::new(file);
|
||||||
blue.start_file(&filenames.txt.blue, options).unwrap();
|
blue.start_file(&filenames.txt.blue, options).expect(ERR_CANNOT_BEGIN_FILE);
|
||||||
|
|
||||||
let file = fs::File::create(&filenames.zip.red).expect(ERR_CANNOT_OPEN_OUTPUT);
|
let file = fs::File::create(&filenames.zip.red).expect(ERR_CANNOT_OPEN_OUTPUT);
|
||||||
let mut red = zip::ZipWriter::new(file);
|
let mut red = zip::ZipWriter::new(file);
|
||||||
red.start_file(&filenames.txt.red, options).unwrap();
|
red.start_file(&filenames.txt.red, options).expect(ERR_CANNOT_BEGIN_FILE);
|
||||||
|
|
||||||
let file = fs::File::create(&filenames.zip.violet).expect(ERR_CANNOT_OPEN_OUTPUT);
|
let file = fs::File::create(&filenames.zip.violet).expect(ERR_CANNOT_OPEN_OUTPUT);
|
||||||
let mut violet = zip::ZipWriter::new(file);
|
let mut violet = zip::ZipWriter::new(file);
|
||||||
violet.start_file(&filenames.txt.violet, options).unwrap();
|
violet.start_file(&filenames.txt.violet, options).expect(ERR_CANNOT_BEGIN_FILE);
|
||||||
|
|
||||||
let descriptors = Descriptors{blue, red, violet};
|
let descriptors = Descriptors{blue, red, violet};
|
||||||
descriptors
|
descriptors
|
||||||
|
|||||||
+17
-6
@@ -101,10 +101,12 @@ fn will_line_continue(line: &String) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_id_from_line(line: &String) -> &str {
|
fn get_id_from_line(line: &String) -> &str {
|
||||||
let id = line
|
let result = line.split_once(',');
|
||||||
.split_once(',') // TODO catch the None
|
let split = match result {
|
||||||
.unwrap()
|
Some(t) => t,
|
||||||
.0;
|
None => panic!("Could not get ID from line!")
|
||||||
|
};
|
||||||
|
let id = split.0;
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,17 +143,26 @@ fn get_output_filenames(input_filename: &String) -> lib::OutputFilenames {
|
|||||||
let red = input_filename.replace(".zip", "_red.zip");
|
let red = input_filename.replace(".zip", "_red.zip");
|
||||||
let violet = input_filename.replace(".zip", "_violet.zip");
|
let violet = input_filename.replace(".zip", "_violet.zip");
|
||||||
let output_filenames_zip = lib::FilenamesVariant{blue, red, violet};
|
let output_filenames_zip = lib::FilenamesVariant{blue, red, violet};
|
||||||
|
sanity_check_output_filenames(input_filename, &output_filenames_zip);
|
||||||
|
|
||||||
// TODO make sure the replace was successful
|
|
||||||
let blue = input_filename.replace(".txt", "_blue.txt");
|
let blue = input_filename.replace(".txt", "_blue.txt");
|
||||||
let red = input_filename.replace(".txt", "_red.txt");
|
let red = input_filename.replace(".txt", "_red.txt");
|
||||||
let violet = input_filename.replace(".txt", "_violet.txt");
|
let violet = input_filename.replace(".txt", "_violet.txt");
|
||||||
let output_filenames_txt = lib::FilenamesVariant{blue, red, violet};
|
let output_filenames_txt = lib::FilenamesVariant{blue, red, violet};
|
||||||
|
sanity_check_output_filenames(input_filename, &output_filenames_txt);
|
||||||
|
|
||||||
let output_filenames = lib::OutputFilenames{txt: output_filenames_txt, zip: output_filenames_zip};
|
let output_filenames = lib::OutputFilenames{txt: output_filenames_txt, zip: output_filenames_zip};
|
||||||
output_filenames
|
output_filenames
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sanity_check_output_filenames(input_filename: &String, output_filenames: &lib::FilenamesVariant) {
|
||||||
|
if input_filename == &output_filenames.blue ||
|
||||||
|
input_filename == &output_filenames.red ||
|
||||||
|
input_filename == &output_filenames.violet {
|
||||||
|
panic!("Output filenames were the same as input filenames")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn find_input_file() -> (String, bool) {
|
fn find_input_file() -> (String, bool) {
|
||||||
let read_dir = fs::read_dir(".").expect("Could not read current directory");
|
let read_dir = fs::read_dir(".").expect("Could not read current directory");
|
||||||
for entry_result in read_dir {
|
for entry_result in read_dir {
|
||||||
@@ -174,7 +185,7 @@ fn read_data(filename: &String, is_zip: bool) -> Vec<String> {
|
|||||||
let buf = BufReader::new(file);
|
let buf = BufReader::new(file);
|
||||||
return if is_zip {
|
return if is_zip {
|
||||||
let mut archive = zip::ZipArchive::new(buf).expect("Could not read zip data");
|
let mut archive = zip::ZipArchive::new(buf).expect("Could not read zip data");
|
||||||
let inner_file = archive.by_index(0).unwrap();
|
let inner_file = archive.by_index(0).expect("Could not read telemetry file from zip archive");
|
||||||
let inner_buf = BufReader::new(inner_file);
|
let inner_buf = BufReader::new(inner_file);
|
||||||
let lines: Vec<String> = inner_buf.lines()
|
let lines: Vec<String> = inner_buf.lines()
|
||||||
.map(|l| l.expect("Could not parse line"))
|
.map(|l| l.expect("Could not parse line"))
|
||||||
|
|||||||
Reference in New Issue
Block a user