Skip to content

Commit fe16487

Browse files
authored
Merge pull request #2 from altair823/nightly
Nightly
2 parents ee2ae68 + 9111cd5 commit fe16487

File tree

7 files changed

+39
-38
lines changed

7 files changed

+39
-38
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@
1212
7zz
1313
7zzs
1414
.DS_Store
15+
*.iml
1516
Cargo.lock
16-
/packages/
17+
/packages/
18+
/original_images/
19+
/dest/
20+
/arc/

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ImageCompressor"
3-
version = "1.0.1"
3+
version = "1.0.3"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -18,5 +18,5 @@ rfd = "0.8.1"
1818
serde = { version = "1.0.136", default-features = false, features = ["derive"]}
1919
serde_json = "1.0.79"
2020
atomic_refcell = "0.1.8"
21-
image_compressor = "1.1.1"
22-
zip_archive = "0.1.1"
21+
image_compressor = "1.2.0"
22+
zip_archive = "1.0.0"

ImageCompressor.iml

Lines changed: 0 additions & 19 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ A rust GUI image compressing program.
1313

1414
Compress original directory
1515

16-
![compress_demo](./examples/compress_demo.webp)
16+
![compress_demo](./demo/compress_demo.webp)
1717

1818

1919
Compress and archive original directory
2020

21-
![compress_and_archive_demo](./examples/compress_and_archive_demo.webp)
21+
![compress_and_archive_demo](./demo/compress_and_archive_demo.webp)
2222

2323
## Supported Image Formats
2424

File renamed without changes.
File renamed without changes.

src/lib.rs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use egui::{Context, Slider, TextEdit, Vec2};
1010
use std::thread;
1111
use std::sync::mpsc;
1212
use image_compressor::FolderCompressor;
13-
use zip_archive::archive_root_dir_with_sender;
13+
use zip_archive::{Archiver, get_dir_list_with_depth};
1414

1515
use crate::epi::{Frame, Storage};
1616
use crate::file_io::{ProgramData, DataType};
@@ -51,8 +51,10 @@ impl epi::App for App {
5151
None => {}
5252
}
5353

54+
let version = env!("CARGO_PKG_VERSION");
55+
5456
// Title
55-
ui.vertical_centered(|ui| ui.heading("Image Compress and Archive Program"));
57+
ui.vertical_centered(|ui| ui.heading(format!("Image Compress and Archive Program v{}", version)));
5658
ui.add_space(10.);
5759

5860
// UI group
@@ -140,14 +142,14 @@ impl epi::App for App {
140142
ui.group(|ui| {
141143

142144
// Condition for compress
143-
match *(*self.origin_dir).borrow() {
144-
Some(_) => {
145-
match *(*self.dest_dir).borrow() {
146-
Some(_) => {
145+
match &*(*self.origin_dir).borrow() {
146+
Some(p) if !p.as_os_str().is_empty() => {
147+
match &*(*self.dest_dir).borrow() {
148+
Some(p) if !p.as_os_str().is_empty() => {
147149
match self.to_zip {
148150
true => {
149-
match *(*self.archive_dir).borrow() {
150-
Some(_) => ui.set_enabled(true),
151+
match &*(*self.archive_dir).borrow() {
152+
Some(p) if !p.as_os_str().is_empty() => ui.set_enabled(true),
151153
_ => ui.set_enabled(false),
152154
}
153155
}
@@ -173,11 +175,14 @@ impl epi::App for App {
173175
let th_count = self.thread_count;
174176
let z = self.to_zip;
175177
let to_del_origin = self.to_del_origin_files;
178+
let origin_dir_list = get_dir_list_with_depth((*origin).as_ref().unwrap().to_path_buf(), 1).unwrap();
179+
176180
thread::spawn(move || {
177181
let mut compressor = FolderCompressor::new((*origin).as_ref().unwrap().to_path_buf(), (*dest).as_ref().unwrap().to_path_buf());
178182
compressor.set_thread_count(th_count);
179183
compressor.set_delelte_origin(to_del_origin);
180-
match compressor.compress_with_sender(compressor_tx.unwrap()) {
184+
compressor.set_sender(compressor_tx.unwrap());
185+
match compressor.compress() {
181186
Ok(_) => {
182187
if !z {
183188
is_ui_enable.swap(true, Ordering::Relaxed);
@@ -188,10 +193,21 @@ impl epi::App for App {
188193
}
189194
};
190195
if z {
191-
match archive_root_dir_with_sender((*dest).as_ref().unwrap().to_path_buf(),
192-
(*archive).as_ref().unwrap().to_path_buf(),
193-
th_count,
194-
archive_tx.unwrap()) {
196+
let mut archive_dir_list = Vec::new();
197+
let dest_dir_list = get_dir_list_with_depth((*dest).as_ref().unwrap(), 1).unwrap();
198+
for o_dir in origin_dir_list{
199+
for d_dir in &dest_dir_list{
200+
if o_dir.file_name().unwrap().eq(d_dir.file_name().unwrap()){
201+
archive_dir_list.push(d_dir.to_path_buf());
202+
}
203+
}
204+
}
205+
let mut archiver = Archiver::new();
206+
archiver.set_destination((*archive).as_ref().unwrap().to_path_buf());
207+
archiver.set_thread_count(th_count);
208+
archiver.push_from_iter(archive_dir_list.iter());
209+
archiver.set_sender(archive_tx.unwrap());
210+
match archiver.archive() {
195211
Ok(_) => { is_ui_enable.swap(true, Ordering::Relaxed); }
196212
Err(e) => {
197213
println!("Cannot archive the folder!: {}", e);

0 commit comments

Comments
 (0)