Include Bundle Path contents in bundle cbz

Partially implements #2
This commit is contained in:
Neshura 2023-11-16 20:51:15 +01:00
parent 25ef82cf2d
commit 0064d0e146
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
2 changed files with 11 additions and 7 deletions

View file

@ -1,9 +1,9 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use std::fs::File;
use std::fs;
use std::fs::{File};
use std::io::{Read, Write};
use serde::{Deserialize, Serialize};
use std::path::MAIN_SEPARATOR_STR;
use crate::metadata::{*};
@ -38,7 +38,7 @@ fn save(metadata: Metadata, path: String) -> String {
#[tauri::command]
fn save_bundle(bundle_dir: String, metadata_file_path: String, save_path: String) -> String {
let comic_book_zip = File::create(&save_path).unwrap();
let mut zip = zip::ZipWriter::new(comic_book_zip);
let mut zip_writer = zip::ZipWriter::new(comic_book_zip);
let options = zip::write::FileOptions::default().compression_method(zip::CompressionMethod::Stored);
@ -46,16 +46,20 @@ fn save_bundle(bundle_dir: String, metadata_file_path: String, save_path: String
file_list.push(metadata_file_path);
let directory_contents = fs::read_dir(bundle_dir.clone()).unwrap();
directory_contents.for_each(|entry| file_list.push(entry.unwrap().path().to_str().unwrap().to_string()));
for file in file_list {
zip.start_file(file.clone().split(MAIN_SEPARATOR_STR).last().unwrap(), options).unwrap();
zip_writer.start_file(file.clone().split(MAIN_SEPARATOR_STR).last().unwrap(), options).unwrap();
let mut file = File::open(file).unwrap();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();
zip.write(&*buffer).unwrap();
zip_writer.write(&*buffer).unwrap();
}
zip.finish().unwrap();
zip_writer.finish().unwrap();
return bundle_dir
}

View file

@ -74,7 +74,7 @@
saveDirectory = downloadDirPath;
}
if (bundleDirectory == "") {
if (bundleDirectory == "" && doBundle) {
bundleDirectory = downloadDirPath;
}
}