From 0064d0e1465ded1ad56434e03c7f1c8d6448baa5 Mon Sep 17 00:00:00 2001 From: Neshura Date: Thu, 16 Nov 2023 20:51:15 +0100 Subject: [PATCH] Include Bundle Path contents in bundle cbz Partially implements #2 --- src-tauri/src/main.rs | 16 ++++++++++------ src/lib/MetadataInput.svelte | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index c2b736a..fe8f4f7 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -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 } diff --git a/src/lib/MetadataInput.svelte b/src/lib/MetadataInput.svelte index 96e4e85..d876940 100644 --- a/src/lib/MetadataInput.svelte +++ b/src/lib/MetadataInput.svelte @@ -74,7 +74,7 @@ saveDirectory = downloadDirPath; } - if (bundleDirectory == "") { + if (bundleDirectory == "" && doBundle) { bundleDirectory = downloadDirPath; } }