diff --git a/package.json b/package.json index 4f8c70d35a..e9cdf76dda 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "eco-paste", + "description": "一款开源的跨平台剪切板管理工具", "private": true, "version": "0.0.3", "type": "module", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index a90047faee..2153fa1288 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -17,17 +17,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "aes" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" -dependencies = [ - "cfg-if", - "cipher", - "cpufeatures", -] - [[package]] name = "ahash" version = "0.8.11" @@ -103,9 +92,6 @@ name = "arbitrary" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" -dependencies = [ - "derive_arbitrary", -] [[package]] name = "arg_enum_proc_macro" @@ -536,27 +522,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bzip2" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" -dependencies = [ - "bzip2-sys", - "libc", -] - -[[package]] -name = "bzip2-sys" -version = "0.1.11+1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" -dependencies = [ - "cc", - "libc", - "pkg-config", -] - [[package]] name = "cairo-rs" version = "0.15.12" @@ -657,16 +622,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "cipher" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" -dependencies = [ - "crypto-common", - "inout", -] - [[package]] name = "clipboard-rs" version = "0.1.7" @@ -766,12 +721,6 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" -[[package]] -name = "constant_time_eq" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" - [[package]] name = "convert_case" version = "0.4.0" @@ -995,12 +944,6 @@ dependencies = [ "syn 2.0.68", ] -[[package]] -name = "deflate64" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83ace6c86376be0b6cdcf3fb41882e81d94b31587573d1cfa9d01cd06bba210d" - [[package]] name = "der" version = "0.7.9" @@ -1033,17 +976,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "derive_arbitrary" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.68", -] - [[package]] name = "derive_more" version = "0.99.18" @@ -1116,17 +1048,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" -[[package]] -name = "displaydoc" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.68", -] - [[package]] name = "dotenvy" version = "0.15.7" @@ -1159,9 +1080,11 @@ name = "eco-paste" version = "0.0.3" dependencies = [ "clipboard-rs", + "flate2", "mouse_position", "serde", "serde_json", + "tar", "tauri", "tauri-build", "tauri-plugin-autostart", @@ -1169,9 +1092,7 @@ dependencies = [ "tauri-plugin-single-instance", "tauri-plugin-sql", "tauri-plugin-theme", - "walkdir", "window-shadows", - "zip 2.1.3", ] [[package]] @@ -2259,15 +2180,6 @@ dependencies = [ "cfb", ] -[[package]] -name = "inout" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" -dependencies = [ - "generic-array", -] - [[package]] name = "instant" version = "0.1.13" @@ -2535,12 +2447,6 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "lockfree-object-pool" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9374ef4228402d4b7e403e5838cb880d9ee663314b0a900d5a6aabf0c213552e" - [[package]] name = "log" version = "0.4.22" @@ -2571,16 +2477,6 @@ dependencies = [ "imgref", ] -[[package]] -name = "lzma-rs" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "297e814c836ae64db86b36cf2a557ba54368d03f6afcd7d947c266692f71115e" -dependencies = [ - "byteorder", - "crc", -] - [[package]] name = "mac" version = "0.1.1" @@ -3141,16 +3037,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" -[[package]] -name = "pbkdf2" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" -dependencies = [ - "digest", - "hmac", -] - [[package]] name = "pem-rfc7468" version = "0.7.0" @@ -4786,7 +4672,7 @@ dependencies = [ "webkit2gtk", "webview2-com", "windows 0.39.0", - "zip 0.6.6", + "zip", ] [[package]] @@ -6374,20 +6260,6 @@ name = "zeroize" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" -dependencies = [ - "zeroize_derive", -] - -[[package]] -name = "zeroize_derive" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.68", -] [[package]] name = "zip" @@ -6400,77 +6272,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "zip" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "775a2b471036342aa69bc5a602bc889cb0a06cda00477d0c69566757d5553d39" -dependencies = [ - "aes", - "arbitrary", - "bzip2", - "constant_time_eq", - "crc32fast", - "crossbeam-utils", - "deflate64", - "displaydoc", - "flate2", - "hmac", - "indexmap 2.2.6", - "lzma-rs", - "memchr", - "pbkdf2", - "rand 0.8.5", - "sha1", - "thiserror", - "time", - "zeroize", - "zopfli", - "zstd", -] - -[[package]] -name = "zopfli" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5019f391bac5cf252e93bbcc53d039ffd62c7bfb7c150414d61369afe57e946" -dependencies = [ - "bumpalo", - "crc32fast", - "lockfree-object-pool", - "log", - "once_cell", - "simd-adler32", -] - -[[package]] -name = "zstd" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcf2b778a664581e31e389454a7072dab1647606d44f7feea22cd5abb9c9f3f9" -dependencies = [ - "zstd-safe", -] - -[[package]] -name = "zstd-safe" -version = "7.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa556e971e7b568dc775c136fc9de8c779b1c2fc3a63defaafadffdbd3181afa" -dependencies = [ - "zstd-sys", -] - -[[package]] -name = "zstd-sys" -version = "2.0.12+zstd.1.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4e40c320c3cb459d9a9ff6de98cff88f4751ee9275d140e2be94a2b74e4c13" -dependencies = [ - "cc", - "pkg-config", -] - [[package]] name = "zune-core" version = "0.4.12" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index f7f92d2cfe..5448609a86 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "eco-paste" version = "0.0.3" -description = "A Tauri App" -authors = ["you"] +description = "一款开源的跨平台剪切板管理工具" +authors = ["ayangweb", "Azir-11", "orangelckc", "pkptzx", "AuroraTea"] edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -22,8 +22,8 @@ window-shadows = "0.2.2" clipboard-rs = "0.1.7" tauri-plugin-context-menu = { git = "https://github.com/c2r0b/tauri-plugin-context-menu", branch = "main" } mouse_position = "0.1.4" -zip = "2.1.3" -walkdir = "2.5.0" +flate2 = "1.0.30" +tar = "0.4.41" [features] # This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!! diff --git a/src-tauri/src/plugins/backup.rs b/src-tauri/src/plugins/backup.rs index cad7ee66b4..b616705304 100644 --- a/src-tauri/src/plugins/backup.rs +++ b/src-tauri/src/plugins/backup.rs @@ -1,48 +1,37 @@ use super::fs_extra::preview_path; -use std::{ - fs::File, - io::{self, BufReader}, -}; +use flate2::{read::GzDecoder, write::GzEncoder, Compression}; +use std::fs::{read_dir, File}; +use tar::Archive; use tauri::{ api::path::{app_data_dir, download_dir}, command, generate_handler, plugin::{Builder, TauriPlugin}, AppHandle, Result, Wry, }; -use walkdir::WalkDir; -use zip::{read::ZipArchive, write::SimpleFileOptions, CompressionMethod, ZipWriter}; #[command] async fn export_data(app_handle: AppHandle, file_name: String) -> Result<()> { - let entry_dir = app_data_dir(&app_handle.config()).unwrap(); - let output_path = download_dir().unwrap().join(file_name); - - let file = File::create(output_path.clone()).unwrap(); - let mut zip = ZipWriter::new(file); - let walkdir = WalkDir::new(entry_dir.clone()); - let it = walkdir.into_iter(); + let src_dir = app_data_dir(&app_handle.config()).unwrap(); + let dst_path = download_dir().unwrap().join(file_name.clone()); + let dst_file = File::create(dst_path.clone())?; - let options = SimpleFileOptions::default() - .compression_method(CompressionMethod::Deflated) - .unix_permissions(0o755); + let enc = GzEncoder::new(dst_file, Compression::default()); + let mut tar = tar::Builder::new(enc); - for entry in it { - let entry = entry.unwrap(); + for entry in read_dir(&src_dir)? { + let entry = entry?; let path = entry.path(); - let name = path.strip_prefix(entry_dir.clone()).unwrap(); - - if path.is_file() { - zip.start_file(name.to_string_lossy(), options).unwrap(); - let mut f = File::open(path)?; - std::io::copy(&mut f, &mut zip)?; - } else if !name.as_os_str().is_empty() { - zip.add_directory(name.to_string_lossy(), options).unwrap(); + let name = path.strip_prefix(&src_dir).unwrap(); + if path.is_dir() { + tar.append_dir_all(name, path.clone())?; + } else { + tar.append_file(name, &mut File::open(path.clone())?)?; } } - zip.finish().unwrap(); + tar.finish()?; - preview_path(output_path.to_str().unwrap(), true) + preview_path(dst_path.to_str().unwrap(), true) .await .unwrap(); @@ -51,39 +40,20 @@ async fn export_data(app_handle: AppHandle, file_name: String) -> Result<()> { #[command] async fn import_data(app_handle: AppHandle, path: String) -> Result { - let out_dir = app_data_dir(&app_handle.config()).unwrap(); + let dst_dir = app_data_dir(&app_handle.config()).unwrap(); - let zip_file = File::open(path).unwrap(); - let mut archive = ZipArchive::new(BufReader::new(zip_file)).unwrap(); + let file = File::open(path)?; + let decoder = GzDecoder::new(file); + let mut archive = Archive::new(decoder); - for i in 0..archive.len() { - let mut file = archive.by_index(i).unwrap(); - let outpath = match file.enclosed_name() { - Some(path) => out_dir.join(path), - None => continue, - }; + for entry in archive.entries()? { + let mut entry = entry?; + let path = entry.path()?; - if file.is_dir() { - std::fs::create_dir_all(&outpath).unwrap(); - } else { - if let Some(p) = outpath.parent() { - if !p.exists() { - std::fs::create_dir_all(&p).unwrap(); - } - } - let mut outfile = File::create(&outpath).unwrap(); - io::copy(&mut file, &mut outfile)?; - } + #[cfg(target_os = "windows")] + let path = path::Path::new(&path.to_string_lossy().replace("\\", "/")).to_path_buf(); - // 设置解压后的文件的权限 - #[cfg(unix)] - { - use std::os::unix::fs::PermissionsExt; - - if let Some(mode) = file.unix_mode() { - std::fs::set_permissions(&outpath, std::fs::Permissions::from_mode(mode))?; - } - } + entry.unpack(dst_dir.join(path))?; } Ok(true)