mirror of
https://github.com/132nd-vWing/tacview-splitter.git
synced 2026-08-26 13:58:37 +02:00
works now
This commit is contained in:
+34
-24
@@ -4,6 +4,7 @@ pub mod lib {
|
||||
use zip;
|
||||
|
||||
const ERR_CANNOT_WRITE_DATA: &str = "Could not write data";
|
||||
const ERR_CANNOT_OPEN_OUTPUT: &str = "Could not open output file";
|
||||
|
||||
pub struct IDs<'a> {
|
||||
pub blue: Vec<&'a str>,
|
||||
@@ -12,10 +13,10 @@ pub mod lib {
|
||||
pub unknown: Vec<&'a str>,
|
||||
}
|
||||
|
||||
pub struct DescriptorsZip {
|
||||
blue: zip::ZipWriter<fs::File>,
|
||||
red: zip::ZipWriter<fs::File>,
|
||||
violet: zip::ZipWriter<fs::File>,
|
||||
pub struct Descriptors<T: Write> {
|
||||
blue: T,
|
||||
red: T,
|
||||
violet: T,
|
||||
}
|
||||
|
||||
pub struct DescriptorsTxt {
|
||||
@@ -41,11 +42,11 @@ pub mod lib {
|
||||
pub violet: Vec<&'a str>,
|
||||
}
|
||||
|
||||
pub trait WriteData {
|
||||
pub trait Handling {
|
||||
fn write(&mut self, header: Vec<String>, bodies_by_coalition: BodiesByCoalition);
|
||||
}
|
||||
|
||||
impl WriteData for DescriptorsTxt {
|
||||
impl<T: Write> Handling for Descriptors<T> {
|
||||
fn write(&mut self, header: Vec<String>, bodies_by_coalition: BodiesByCoalition) {
|
||||
for line in &header {
|
||||
write!(self.blue, "{}\n", line).expect(ERR_CANNOT_WRITE_DATA);
|
||||
@@ -64,25 +65,34 @@ pub mod lib {
|
||||
}
|
||||
}
|
||||
|
||||
impl WriteData for DescriptorsZip {
|
||||
fn write(&mut self, header: Vec<String>, bodies_by_coalition: BodiesByCoalition) {
|
||||
for line in &header {
|
||||
write!(self.blue, "{}\n", line).expect(ERR_CANNOT_WRITE_DATA);
|
||||
write!(self.red, "{}\n", line).expect(ERR_CANNOT_WRITE_DATA);
|
||||
write!(self.violet, "{}\n", line).expect(ERR_CANNOT_WRITE_DATA);
|
||||
}
|
||||
for line in &bodies_by_coalition.blue {
|
||||
write!(self.blue, "{}\n", line).expect(ERR_CANNOT_WRITE_DATA);
|
||||
}
|
||||
for line in &bodies_by_coalition.red {
|
||||
write!(self.red, "{}\n", line).expect(ERR_CANNOT_WRITE_DATA);
|
||||
}
|
||||
for line in &bodies_by_coalition.violet {
|
||||
write!(self.violet, "{}\n", line).expect(ERR_CANNOT_WRITE_DATA);
|
||||
}
|
||||
|
||||
impl Descriptors<fs::File> {
|
||||
pub fn new_for_file(filenames: OutputFilenames) -> Descriptors<fs::File> {
|
||||
let blue = fs::File::create(&filenames.txt.blue).expect(ERR_CANNOT_OPEN_OUTPUT);
|
||||
let red = fs::File::create(&filenames.txt.red).expect(ERR_CANNOT_OPEN_OUTPUT);
|
||||
let violet = fs::File::create(&filenames.txt.violet).expect(ERR_CANNOT_OPEN_OUTPUT);
|
||||
let descriptors = Descriptors { blue, red, violet };
|
||||
return descriptors
|
||||
}
|
||||
}
|
||||
|
||||
impl Descriptors<zip::ZipWriter<fs::File>> {
|
||||
pub fn new_for_zip(filenames: OutputFilenames) -> Descriptors<zip::ZipWriter<fs::File>> {
|
||||
let options = zip::write::FileOptions::default().compression_method(zip::CompressionMethod::Deflated);
|
||||
|
||||
let file = fs::File::create(&filenames.zip.blue).expect(ERR_CANNOT_OPEN_OUTPUT);
|
||||
let mut blue = zip::ZipWriter::new(file);
|
||||
blue.start_file(&filenames.txt.blue, options).unwrap();
|
||||
|
||||
let file = fs::File::create(&filenames.zip.red).expect(ERR_CANNOT_OPEN_OUTPUT);
|
||||
let mut red = zip::ZipWriter::new(file);
|
||||
red.start_file(&filenames.txt.red, options).unwrap();
|
||||
|
||||
let file = fs::File::create(&filenames.zip.violet).expect(ERR_CANNOT_OPEN_OUTPUT);
|
||||
let mut violet = zip::ZipWriter::new(file);
|
||||
violet.start_file(&filenames.txt.violet, options).unwrap();
|
||||
|
||||
let descriptors = Descriptors{blue, red, violet};
|
||||
descriptors
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user