Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
7zz
7zzs
.DS_Store
*.iml
Cargo.lock
/packages/
/packages/
/original_images/
/dest/
/arc/
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ImageCompressor"
version = "1.0.1"
version = "1.0.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -18,5 +18,5 @@ rfd = "0.8.1"
serde = { version = "1.0.136", default-features = false, features = ["derive"]}
serde_json = "1.0.79"
atomic_refcell = "0.1.8"
image_compressor = "1.1.1"
zip_archive = "0.1.1"
image_compressor = "1.2.0"
zip_archive = "1.0.0"
19 changes: 0 additions & 19 deletions ImageCompressor.iml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ A rust GUI image compressing program.

Compress original directory

![compress_demo](./examples/compress_demo.webp)
![compress_demo](./demo/compress_demo.webp)


Compress and archive original directory

![compress_and_archive_demo](./examples/compress_and_archive_demo.webp)
![compress_and_archive_demo](./demo/compress_and_archive_demo.webp)

## Supported Image Formats

Expand Down
File renamed without changes
42 changes: 29 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use egui::{Context, Slider, TextEdit, Vec2};
use std::thread;
use std::sync::mpsc;
use image_compressor::FolderCompressor;
use zip_archive::archive_root_dir_with_sender;
use zip_archive::{Archiver, get_dir_list_with_depth};

use crate::epi::{Frame, Storage};
use crate::file_io::{ProgramData, DataType};
Expand Down Expand Up @@ -51,8 +51,10 @@ impl epi::App for App {
None => {}
}

let version = env!("CARGO_PKG_VERSION");

// Title
ui.vertical_centered(|ui| ui.heading("Image Compress and Archive Program"));
ui.vertical_centered(|ui| ui.heading(format!("Image Compress and Archive Program v{}", version)));
ui.add_space(10.);

// UI group
Expand Down Expand Up @@ -140,14 +142,14 @@ impl epi::App for App {
ui.group(|ui| {

// Condition for compress
match *(*self.origin_dir).borrow() {
Some(_) => {
match *(*self.dest_dir).borrow() {
Some(_) => {
match &*(*self.origin_dir).borrow() {
Some(p) if !p.as_os_str().is_empty() => {
match &*(*self.dest_dir).borrow() {
Some(p) if !p.as_os_str().is_empty() => {
match self.to_zip {
true => {
match *(*self.archive_dir).borrow() {
Some(_) => ui.set_enabled(true),
match &*(*self.archive_dir).borrow() {
Some(p) if !p.as_os_str().is_empty() => ui.set_enabled(true),
_ => ui.set_enabled(false),
}
}
Expand All @@ -173,11 +175,14 @@ impl epi::App for App {
let th_count = self.thread_count;
let z = self.to_zip;
let to_del_origin = self.to_del_origin_files;
let origin_dir_list = get_dir_list_with_depth((*origin).as_ref().unwrap().to_path_buf(), 1).unwrap();

thread::spawn(move || {
let mut compressor = FolderCompressor::new((*origin).as_ref().unwrap().to_path_buf(), (*dest).as_ref().unwrap().to_path_buf());
compressor.set_thread_count(th_count);
compressor.set_delelte_origin(to_del_origin);
match compressor.compress_with_sender(compressor_tx.unwrap()) {
compressor.set_sender(compressor_tx.unwrap());
match compressor.compress() {
Ok(_) => {
if !z {
is_ui_enable.swap(true, Ordering::Relaxed);
Expand All @@ -188,10 +193,21 @@ impl epi::App for App {
}
};
if z {
match archive_root_dir_with_sender((*dest).as_ref().unwrap().to_path_buf(),
(*archive).as_ref().unwrap().to_path_buf(),
th_count,
archive_tx.unwrap()) {
let mut archive_dir_list = Vec::new();
let dest_dir_list = get_dir_list_with_depth((*dest).as_ref().unwrap(), 1).unwrap();
for o_dir in origin_dir_list{
for d_dir in &dest_dir_list{
if o_dir.file_name().unwrap().eq(d_dir.file_name().unwrap()){
archive_dir_list.push(d_dir.to_path_buf());
}
}
}
let mut archiver = Archiver::new();
archiver.set_destination((*archive).as_ref().unwrap().to_path_buf());
archiver.set_thread_count(th_count);
archiver.push_from_iter(archive_dir_list.iter());
archiver.set_sender(archive_tx.unwrap());
match archiver.archive() {
Ok(_) => { is_ui_enable.swap(true, Ordering::Relaxed); }
Err(e) => {
println!("Cannot archive the folder!: {}", e);
Expand Down