Skip to content

Commit

Permalink
修复
Browse files Browse the repository at this point in the history
  • Loading branch information
TC999 committed Nov 27, 2024
1 parent 2f2247c commit 0c32dcd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn delete_folder(folder_path: &str) -> Result<(), String> {
let path = Path::new(folder_path);

if !path.exists() {
//println!("文件夹不存在.".to_string());
println!("文件夹不存在.");
let error_msg = "文件夹不存在.".to_string();
logger::log_error(&error_msg);
return Err(error_msg);
Expand All @@ -23,7 +23,7 @@ pub fn delete_folder(folder_path: &str) -> Result<(), String> {
error_msg
})
} else {
//println!("路径不是目录.".to_string());
println!("路径不是目录.");
let error_msg = "路径不是目录.".to_string();
logger::log_error(&error_msg);
Err(error_msg)
Expand Down
9 changes: 6 additions & 3 deletions src/scanner.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
use std::sync::mpsc::Sender;
use std::thread;
use std::{fs, path::PathBuf};
use std::fs::{self, DirEntry};
use std::path::Path;

use dirs_next as dirs;
use crate::logger; // 引入日志模块

pub fn scan_appdata(tx: Sender<(String, u64)>, folder_type: &str) {
println!("开始扫描 {} 类型的文件夹", folder_type);
// 记录日志
logger::log_info(&format!("开始扫描 {} 类型的文件夹", folder_type));

// 根据 folder_type 确定要扫描的目录
let appdata_dir = match folder_type {
"Roaming" => dirs::data_dir(),
"Local" => dirs::cache_dir(),
"LocalLow" => Some(PathBuf::from("C:/Users/Default/AppData/LocalLow")), // 手动设置路径
_ => None,
};

// 如果找到有效的目录,开始扫描
if let Some(appdata_dir) = appdata_dir {
thread::spawn(move || {
if let Ok(entries) = fs::read_dir(&appdata_dir) {
Expand All @@ -24,7 +28,7 @@ pub fn scan_appdata(tx: Sender<(String, u64)>, folder_type: &str) {
if metadata.is_dir() {
let folder_name = entry.file_name().to_string_lossy().to_string();
let size = calculate_folder_size(&entry.path());
println!("Folder: {:?}, Size: {}", path.display(), size); // 打印文件夹路径和大小
// 发送文件夹大小数据
tx.send((folder_name, size)).unwrap();
}
}
Expand Down Expand Up @@ -56,4 +60,3 @@ fn calculate_folder_size(folder: &Path) -> u64 {

size
}

2 changes: 2 additions & 0 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::confirmation;
use crate::delete;
use crate::scanner;
use crate::utils;
use crate::logger; // 导入 logger 模块
use eframe::egui::{self, Grid, ScrollArea};
use std::sync::mpsc::{Sender, Receiver};

Expand Down Expand Up @@ -69,6 +70,7 @@ impl eframe::App for AppDataCleaner {
if result {
if let Err(err) = delete::delete_folder(&folder) {
eprintln!("删除失败: {}", err);
logger::log_info(&format!("删除失败: {}", err));
}
}
self.confirm_delete = None;
Expand Down

0 comments on commit 0c32dcd

Please sign in to comment.