Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

描述测试 #22

Merged
merged 1 commit into from
Dec 11, 2024
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ log = "0.4"
simplelog = "0.12"
sha2 = "0.10"
native-dialog = "0.7.0"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9.34+deprecated"
23 changes: 23 additions & 0 deletions folders_description.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Roaming:
# 示例:文件夹名: "描述"
Code: "VSCode"
pip: "pip 网络配置文件"
Mozilla: "Firefox"
#firefox: "Mozilla Firefox 浏览器配置文件"
clash_win: "Clash for Windows 配置文件"
VMWare: "VMWare 配置文件"
Motrix: "Motrix 配置文件"
zen: "Zen 网络配置"
Local:
BCUT: "必剪数据"
Temp: "系统临时文件"
myapp: "自定义应用配置文件"
Packages: "UWP 程序数据"
Chromium: "Chromium 用户数据"
Google: "Google 系软件数据"
pip: "pip 下载目录"
Programs: "Python 解释器安装目录"
Obsidian: "Obsidian 安装位置"
zen: "Zen 浏览器用户数据"
rustdesk: "RustDesk 用户数据"
LocalLow:
13 changes: 7 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
mod about; // 关于界面
mod about; // 关于界面
mod confirmation; // 确认删除模块
mod delete; // 引入删除模块
mod scanner; // 引入扫盘模块
mod ui; // 引入 ui 模块
mod utils; // 文件夹大小计算模块
mod logger; // 引入日志模块
mod delete; // 引入删除模块
mod ignore; // 引入忽略模块
mod logger; // 引入日志模块
mod move_module;
mod open;
mod scanner; // 引入扫盘模块
mod ui; // 引入 ui 模块
mod utils; // 文件夹大小计算模块
mod yaml_loader;

use ui::AppDataCleaner;

Expand Down
22 changes: 22 additions & 0 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::move_module; // 导入移动模块
use crate::open;
use crate::scanner;
use crate::utils;
use crate::yaml_loader::FolderDescriptions;
use eframe::egui::{self, Grid, ScrollArea};
use std::collections::HashSet;
use std::sync::mpsc::{Receiver, Sender};
Expand All @@ -24,6 +25,7 @@ pub struct AppDataCleaner {
previous_logging_state: bool, // 记录上一次日志启用状态
ignored_folders: HashSet<String>, // 忽略文件夹集合
move_module: move_module::MoveModule, // 移动模块实例
folder_descriptions: Option<FolderDescriptions>,
}

impl Default for AppDataCleaner {
Expand All @@ -42,6 +44,7 @@ impl Default for AppDataCleaner {
previous_logging_state: false, // 初始时假定日志系统未启用
ignored_folders: ignore::load_ignored_folders(),
move_module: Default::default(),
folder_descriptions: None,
}
}
}
Expand Down Expand Up @@ -73,6 +76,14 @@ impl eframe::App for AppDataCleaner {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
self.setup_custom_fonts(ctx);

// 加载描述文件
if self.folder_descriptions.is_none() {
match FolderDescriptions::load_from_yaml("folders_description.yaml") {
Ok(descriptions) => self.folder_descriptions = Some(descriptions),
Err(e) => eprintln!("加载 YAML 文件失败: {}", e),
}
}

if self.is_logging_enabled != self.previous_logging_state {
logger::init_logger(self.is_logging_enabled); // 初始化日志系统
if self.is_logging_enabled {
Expand Down Expand Up @@ -157,6 +168,7 @@ impl eframe::App for AppDataCleaner {
Grid::new("folders_table").striped(true).show(ui, |ui| {
ui.label("文件夹");
ui.label("大小");
ui.label("描述");
ui.label("操作");
ui.end_row();

Expand All @@ -173,6 +185,16 @@ impl eframe::App for AppDataCleaner {
}
ui.label(utils::format_size(*size));

// 读取描述信息并显示
let description = self.folder_descriptions.as_ref().and_then(|desc| {
desc.get_description(folder, &self.selected_appdata_folder)
});
if let Some(desc) = description {
ui.label(desc);
} else {
ui.label("无描述");
}

if !self.ignored_folders.contains(folder) {
if ui.button("彻底删除").clicked() {
self.confirm_delete = Some((folder.clone(), false));
Expand Down
36 changes: 36 additions & 0 deletions src/yaml_loader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs;
use std::path::Path;

#[derive(Debug, Serialize, Deserialize)]
pub struct FolderDescriptions {
pub Roaming: HashMap<String, String>,
pub Local: HashMap<String, String>,
pub LocalLow: HashMap<String, String>,
}

impl FolderDescriptions {
pub fn load_from_yaml(file_path: &str) -> Result<Self, String> {
let path = Path::new(file_path);
if !path.exists() {
return Err("YAML 文件未找到".to_string());
}

let content = fs::read_to_string(path).map_err(|e| format!("读取 YAML 文件失败: {}", e))?;

let descriptions: FolderDescriptions =
serde_yaml::from_str(&content).map_err(|e| format!("解析 YAML 文件失败: {}", e))?;

Ok(descriptions)
}

pub fn get_description(&self, folder_name: &str, folder_type: &str) -> Option<String> {
match folder_type {
"Roaming" => self.Roaming.get(folder_name).cloned(),
"Local" => self.Local.get(folder_name).cloned(),
"LocalLow" => self.LocalLow.get(folder_name).cloned(),
_ => None,
}
}
}