Add functional bundling of ComicInfo File with static test name
This commit is contained in:
parent
b5812fa32c
commit
25ef82cf2d
4 changed files with 368 additions and 5 deletions
src-tauri/src
|
@ -1,6 +1,8 @@
|
|||
// 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::io::{Read, Write};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::MAIN_SEPARATOR_STR;
|
||||
|
||||
|
@ -15,7 +17,7 @@ fn greet(name: &str) -> String {
|
|||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![greet, save])
|
||||
.invoke_handler(tauri::generate_handler![greet, save, save_bundle])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -32,3 +34,28 @@ fn save(metadata: Metadata, path: String) -> String {
|
|||
metadata.save_to_xml(&file_path);
|
||||
file_path
|
||||
}
|
||||
|
||||
#[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 options = zip::write::FileOptions::default().compression_method(zip::CompressionMethod::Stored);
|
||||
|
||||
let mut file_list: Vec<String> = Vec::new();
|
||||
|
||||
file_list.push(metadata_file_path);
|
||||
|
||||
for file in file_list {
|
||||
zip.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.finish().unwrap();
|
||||
return bundle_dir
|
||||
}
|
||||
|
|
Reference in a new issue