Skip to content

Commit

Permalink
Merge pull request #21 from lanyeeee/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
lanyeeee authored Aug 4, 2024
2 parents 1606244 + ef561aa commit dacc6f2
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 29 deletions.
Binary file modified src-tauri/icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/128x128@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square107x107Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square142x142Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square150x150Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square284x284Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square30x30Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square310x310Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square44x44Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square71x71Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square89x89Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/icon.icns
Binary file not shown.
Binary file modified src-tauri/icons/icon.ico
Binary file not shown.
Binary file modified src-tauri/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 29 additions & 18 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,26 @@ pub fn get_manga_dir_data(
// 用于存储不同尺寸的图片的数量
let mut size_count: HashMap<(u32, u32), u32> = HashMap::new();
// 遍历漫画目录下的所有文件,统计不同尺寸的图片的数量
for entry in WalkDir::new(PathBuf::from_slash(manga_dir))
WalkDir::new(PathBuf::from_slash(manga_dir))
.max_depth(2) // 一般第一层目录是章节目录,第二层目录是图片文件
.into_iter()
.filter_map(Result::ok)
{
let path = entry.into_path();
if path.is_file() && path.extension().map_or(false, |e| e == "jpg") {
let Ok(size) = imagesize::size(&path) else {
continue;
};
.filter_map(|entry| {
let path = entry.into_path();
if !path.is_file() {
return None;
}
let ext = path.extension()?;
if ext != "jpg" && ext != "jpeg" {
return None;
}
imagesize::size(&path).ok()
})
.for_each(|size| {
let key = (size.width as u32, size.height as u32);
let count = size_count.entry(key).or_insert(0);
*count += 1;
}
}
});
// 将统计结果转换为Vec<MangaDirData>
let mut manga_dir_data: Vec<MangaDirData> = size_count
.into_iter()
Expand Down Expand Up @@ -165,23 +170,29 @@ pub fn get_jpg_image_infos(manga_dir: &str) -> CommandResponse<Vec<JpgImageInfo>
// 用于存储jpg图片的信息
let mut jpg_image_infos = vec![];
// 遍历漫画目录下的所有文件,获取jpg图片的信息
for entry in WalkDir::new(PathBuf::from_slash(manga_dir))
WalkDir::new(PathBuf::from_slash(manga_dir))
.max_depth(2) // 一般第一层目录是章节目录,第二层目录是图片文件
.into_iter()
.filter_map(Result::ok)
{
let path = entry.into_path();
if path.is_file() && path.extension().map_or(false, |e| e == "jpg") {
let Ok(size) = imagesize::size(&path) else {
continue;
};
.filter_map(|entry| {
let path = entry.into_path();
if !path.is_file() {
return None;
}
let ext = path.extension()?;
if ext != "jpg" && ext != "jpeg" {
return None;
}
let size = imagesize::size(&path).ok()?;
Some((path, size))
})
.for_each(|(path, size)| {
jpg_image_infos.push(JpgImageInfo {
width: size.width as u32,
height: size.height as u32,
path,
});
}
}
});
CommandResponse {
code: 0,
msg: String::new(),
Expand Down
32 changes: 21 additions & 11 deletions src-tauri/src/watermark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
};
use tauri::AppHandle;
use tauri_specta::Event;
use walkdir::{DirEntry, WalkDir};
use walkdir::WalkDir;

/// 生成黑色背景和白色背景的水印图片
pub fn generate_background(
Expand Down Expand Up @@ -101,7 +101,11 @@ fn create_image_paths(manga_dir: &str, width: u32, height: u32) -> Vec<PathBuf>
.filter_map(Result::ok)
.filter_map(|entry| {
let path = entry.into_path();
if !path.is_file() || path.extension()? != "jpg" {
if !path.is_file() {
return None;
}
let ext = path.extension()?;
if ext != "jpg" && ext != "jpeg" {
return None;
}
let size = imagesize::size(&path).ok()?;
Expand Down Expand Up @@ -233,16 +237,22 @@ fn create_dir_progress<'a>(
fn create_dir_map(manga_dir: &PathBuf) -> HashMap<PathBuf, Vec<PathBuf>> {
let mut dir_map: HashMap<PathBuf, Vec<PathBuf>> = HashMap::new();
// 遍历manga_dir目录下的所有文件和子目录
for entry in WalkDir::new(manga_dir).into_iter().filter_map(Result::ok) {
let entry: DirEntry = entry;
let path = entry.into_path();
// 如果是文件且是jpg文件则添加到directory_map中
if path.is_file() && path.extension().map_or(false, |e| e == "jpg") {
if let Some(parent) = path.parent() {
dir_map.entry(parent.to_path_buf()).or_default().push(path);
WalkDir::new(manga_dir)
.into_iter()
.filter_map(Result::ok)
.filter_map(|entry| {
let path = entry.into_path();
if !path.is_file() {
return None;
}
}
}
let ext = path.extension()?;
if ext != "jpg" && ext != "jpeg" {
return None;
}
let parent = path.parent()?.to_path_buf();
Some((path, parent))
})
.for_each(|(path, parent)| dir_map.entry(parent).or_default().push(path));
dir_map
}

Expand Down

0 comments on commit dacc6f2

Please # to comment.