mirror of
https://github.com/132nd-vWing/tacview-splitter.git
synced 2026-08-26 10:28:36 +02:00
fix clippy warnings
This commit is contained in:
+72
-57
@@ -1,7 +1,5 @@
|
||||
use std::{fs, str};
|
||||
use std::io::{BufRead, BufReader};
|
||||
|
||||
use zip;
|
||||
use std::{fs, str};
|
||||
|
||||
use tacview_splitter::lib;
|
||||
use tacview_splitter::lib::Handling;
|
||||
@@ -17,7 +15,7 @@ enum LineType {
|
||||
Unknown,
|
||||
Timestamp,
|
||||
Destruction,
|
||||
Telemetry
|
||||
Telemetry,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -38,21 +36,30 @@ fn main() {
|
||||
}
|
||||
|
||||
fn split_into_header_and_body(lines: Vec<String>) -> (Vec<String>, Vec<String>) {
|
||||
let mut i=0;
|
||||
let mut i = 0;
|
||||
for line in &lines {
|
||||
if line.chars().nth(0).expect("malformed line") == COMMENT {
|
||||
break
|
||||
if line.chars().next().expect("malformed line") == COMMENT {
|
||||
break;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
return (lines[..i].to_vec(), lines[i..].to_vec());
|
||||
(lines[..i].to_vec(), lines[i..].to_vec())
|
||||
}
|
||||
|
||||
fn divide_body_by_coalition(body: &Vec<String>) -> lib::BodiesByCoalition {
|
||||
let mut bbc = lib::BodiesByCoalition{blue: Vec::new(), red: Vec::new(), violet: Vec::new()};
|
||||
let mut bbc = lib::BodiesByCoalition {
|
||||
blue: Vec::new(),
|
||||
red: Vec::new(),
|
||||
violet: Vec::new(),
|
||||
};
|
||||
let mut continued = false;
|
||||
let mut line_type = LineType::Unknown;
|
||||
let mut coalitions = lib::IDs{blue: Vec::new(), red: Vec::new(), violet: Vec::new(), unknown: Vec::new()};
|
||||
let mut coalitions = lib::IDs {
|
||||
blue: Vec::new(),
|
||||
red: Vec::new(),
|
||||
violet: Vec::new(),
|
||||
unknown: Vec::new(),
|
||||
};
|
||||
for line in body {
|
||||
let result = process_line(continued, &mut coalitions, line, line_type);
|
||||
line_type = result.0;
|
||||
@@ -62,7 +69,8 @@ fn divide_body_by_coalition(body: &Vec<String>) -> lib::BodiesByCoalition {
|
||||
bbc.blue.push(line);
|
||||
bbc.red.push(line);
|
||||
bbc.violet.push(line);
|
||||
} else { // destruction or telemetry
|
||||
} else {
|
||||
// destruction or telemetry
|
||||
if coalitions.blue.contains(&id) {
|
||||
bbc.blue.push(line);
|
||||
} else if coalitions.red.contains(&id) {
|
||||
@@ -75,7 +83,12 @@ fn divide_body_by_coalition(body: &Vec<String>) -> lib::BodiesByCoalition {
|
||||
bbc
|
||||
}
|
||||
|
||||
fn process_line<'a>(continued: bool, coalitions: &mut lib::IDs<'a>, line: &'a String, last_line_type: LineType) -> (LineType, bool, &'a str) {
|
||||
fn process_line<'a>(
|
||||
continued: bool,
|
||||
coalitions: &mut lib::IDs<'a>,
|
||||
line: &'a str,
|
||||
last_line_type: LineType,
|
||||
) -> (LineType, bool, &'a str) {
|
||||
let mut id = "";
|
||||
let line_type;
|
||||
if !continued {
|
||||
@@ -91,27 +104,20 @@ fn process_line<'a>(continued: bool, coalitions: &mut lib::IDs<'a>, line: &'a St
|
||||
(line_type, line_will_continue, id)
|
||||
}
|
||||
|
||||
fn will_line_continue(line: &String) -> bool {
|
||||
let line_will_continue: bool;
|
||||
if line.ends_with("\\") {
|
||||
line_will_continue = true;
|
||||
} else {
|
||||
line_will_continue = false;
|
||||
}
|
||||
line_will_continue
|
||||
fn will_line_continue(line: &str) -> bool {
|
||||
line.ends_with('\\')
|
||||
}
|
||||
|
||||
fn get_id_from_line(line: &String) -> &str {
|
||||
fn get_id_from_line(line: &str) -> &str {
|
||||
let result = line.split_once(',');
|
||||
let split = match result {
|
||||
Some(t) => t,
|
||||
None => panic!("Could not get ID from line!")
|
||||
None => panic!("Could not get ID from line!"),
|
||||
};
|
||||
let id = split.0;
|
||||
id
|
||||
split.0 as _
|
||||
}
|
||||
|
||||
fn assign_id_to_coalitions<'a>(coalitions: &mut lib::IDs<'a>, line: &'a String, id: &'a str) {
|
||||
fn assign_id_to_coalitions<'a>(coalitions: &mut lib::IDs<'a>, line: &'a str, id: &'a str) {
|
||||
if line.contains("Color=") {
|
||||
if line.contains("Color=Blue") {
|
||||
coalitions.blue.push(id);
|
||||
@@ -125,18 +131,15 @@ fn assign_id_to_coalitions<'a>(coalitions: &mut lib::IDs<'a>, line: &'a String,
|
||||
}
|
||||
}
|
||||
|
||||
fn determine_line_type(line: &String) -> LineType {
|
||||
let line_type: LineType;
|
||||
|
||||
let first_char = line.chars().nth(0).expect("malformed line");
|
||||
fn determine_line_type(line: &str) -> LineType {
|
||||
let first_char = line.chars().next().expect("malformed line");
|
||||
if first_char == COMMENT {
|
||||
line_type = LineType::Timestamp;
|
||||
LineType::Timestamp
|
||||
} else if first_char == MINUS {
|
||||
line_type = LineType::Destruction;
|
||||
LineType::Destruction
|
||||
} else {
|
||||
line_type = LineType::Telemetry;
|
||||
LineType::Telemetry
|
||||
}
|
||||
return line_type
|
||||
}
|
||||
|
||||
fn get_output_filenames(input_filename: &String, is_zip: bool) -> lib::OutputFilenames {
|
||||
@@ -144,36 +147,45 @@ fn get_output_filenames(input_filename: &String, is_zip: bool) -> lib::OutputFil
|
||||
let output_filenames_txt: lib::FilenamesVariant;
|
||||
|
||||
if is_zip {
|
||||
output_filenames_zip = get_output_filenames_for_extension(
|
||||
input_filename, EXTENSION_ZIP, EXTENSION_ZIP
|
||||
);
|
||||
output_filenames_txt = get_output_filenames_for_extension(
|
||||
input_filename, EXTENSION_ZIP, EXTENSION_TXT
|
||||
);
|
||||
output_filenames_zip =
|
||||
get_output_filenames_for_extension(input_filename, EXTENSION_ZIP, EXTENSION_ZIP);
|
||||
output_filenames_txt =
|
||||
get_output_filenames_for_extension(input_filename, EXTENSION_ZIP, EXTENSION_TXT);
|
||||
} else {
|
||||
output_filenames_zip = get_output_filenames_dummy();
|
||||
output_filenames_txt = get_output_filenames_for_extension(
|
||||
input_filename, EXTENSION_TXT, EXTENSION_TXT
|
||||
);
|
||||
output_filenames_txt =
|
||||
get_output_filenames_for_extension(input_filename, EXTENSION_TXT, EXTENSION_TXT);
|
||||
}
|
||||
|
||||
let output_filenames = lib::OutputFilenames{txt: output_filenames_txt, zip: output_filenames_zip};
|
||||
output_filenames
|
||||
lib::OutputFilenames {
|
||||
txt: output_filenames_txt,
|
||||
zip: output_filenames_zip,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_output_filenames_dummy() -> lib::FilenamesVariant {
|
||||
let blue = "".to_string();
|
||||
let red = "".to_string();
|
||||
let violet = "".to_string();
|
||||
let output_filenames = lib::FilenamesVariant{blue, red, violet};
|
||||
output_filenames
|
||||
lib::FilenamesVariant { blue, red, violet }
|
||||
}
|
||||
|
||||
fn get_output_filenames_for_extension(input_filename: &String, old_extension: &str, new_extension: &str) -> lib::FilenamesVariant {
|
||||
let blue = lib::get_output_filenames_individual(input_filename, old_extension, new_extension, "_blue");
|
||||
let red = lib::get_output_filenames_individual(input_filename, old_extension, new_extension,"_red");
|
||||
let violet = lib::get_output_filenames_individual(input_filename, old_extension, new_extension,"_violet");
|
||||
let output_filenames_zip = lib::FilenamesVariant{blue, red, violet};
|
||||
fn get_output_filenames_for_extension(
|
||||
input_filename: &String,
|
||||
old_extension: &str,
|
||||
new_extension: &str,
|
||||
) -> lib::FilenamesVariant {
|
||||
let blue =
|
||||
lib::get_output_filenames_individual(input_filename, old_extension, new_extension, "_blue");
|
||||
let red =
|
||||
lib::get_output_filenames_individual(input_filename, old_extension, new_extension, "_red");
|
||||
let violet = lib::get_output_filenames_individual(
|
||||
input_filename,
|
||||
old_extension,
|
||||
new_extension,
|
||||
"_violet",
|
||||
);
|
||||
let output_filenames_zip = lib::FilenamesVariant { blue, red, violet };
|
||||
lib::sanity_check_output_filenames(input_filename, &output_filenames_zip);
|
||||
output_filenames_zip
|
||||
}
|
||||
@@ -189,27 +201,30 @@ fn find_input_file() -> (String, bool) {
|
||||
} else if filename.ends_with(EXTENSION_ZIP) {
|
||||
return (filename, true);
|
||||
}
|
||||
};
|
||||
}
|
||||
println!("No tacview input file found in current directory.");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
|
||||
fn read_data(filename: &String, is_zip: bool) -> Vec<String> {
|
||||
let file = fs::File::open(filename).expect("Could not read from input file");
|
||||
let buf = BufReader::new(file);
|
||||
return if is_zip {
|
||||
let mut archive = zip::ZipArchive::new(buf).expect("Could not read zip data");
|
||||
let inner_file = archive.by_index(0).expect("Could not read telemetry file from zip archive");
|
||||
let inner_file = archive
|
||||
.by_index(0)
|
||||
.expect("Could not read telemetry file from zip archive");
|
||||
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"))
|
||||
.collect();
|
||||
lines
|
||||
} else {
|
||||
let lines: Vec<String> = buf.lines()
|
||||
let lines: Vec<String> = buf
|
||||
.lines()
|
||||
.map(|l| l.expect("Could not parse line"))
|
||||
.collect();
|
||||
lines
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user