@@ -10,7 +10,7 @@ use egui::{Context, Slider, TextEdit, Vec2};
1010use std:: thread;
1111use std:: sync:: mpsc;
1212use image_compressor:: FolderCompressor ;
13- use zip_archive:: archive_root_dir_with_sender ;
13+ use zip_archive:: { Archiver , get_dir_list_with_depth } ;
1414
1515use crate :: epi:: { Frame , Storage } ;
1616use 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