support fast clean options
This commit is contained in:
@@ -174,11 +174,12 @@ pub struct CleaningConfig {
|
||||
pub name: String,
|
||||
pub path: String,
|
||||
pub filter_days: Option<u64>,
|
||||
pub default_enabled: bool,
|
||||
}
|
||||
|
||||
impl CleaningConfig {
|
||||
fn new(name: &str, path: &str, filter_days: Option<u64>) -> Self {
|
||||
Self { name: name.into(), path: path.into(), filter_days }
|
||||
fn new(name: &str, path: &str, filter_days: Option<u64>, default_enabled: bool) -> Self {
|
||||
Self { name: name.into(), path: path.into(), filter_days, default_enabled }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,33 +189,32 @@ fn get_fast_cleaning_configs() -> Vec<CleaningConfig> {
|
||||
|
||||
// 1. 用户临时文件
|
||||
if let Ok(t) = std::env::var("TEMP") {
|
||||
configs.push(CleaningConfig::new("用户临时文件", &t, None));
|
||||
configs.push(CleaningConfig::new("用户临时文件", &t, None, true));
|
||||
}
|
||||
|
||||
// 2. 系统临时文件
|
||||
configs.push(CleaningConfig::new("系统临时文件", "C:\\Windows\\Temp", None));
|
||||
configs.push(CleaningConfig::new("系统临时文件", "C:\\Windows\\Temp", None, true));
|
||||
|
||||
// 3. Windows 更新残留 (通常建议清理 10 天前的)
|
||||
configs.push(CleaningConfig::new("Windows 更新残留", "C:\\Windows\\SoftwareDistribution\\Download", Some(10)));
|
||||
configs.push(CleaningConfig::new("Windows 更新残留", "C:\\Windows\\SoftwareDistribution\\Download", Some(10), true));
|
||||
|
||||
// 4. 传递优化缓存
|
||||
// configs.push(CleaningConfig::new(
|
||||
// "传递优化缓存",
|
||||
// "C:\\Windows\\ServiceProfiles\\NetworkService\\AppData\\Local\\Microsoft\\Windows\\DeliveryOptimization",
|
||||
// None
|
||||
// ));
|
||||
|
||||
// 以后要添加新目录,只需在此处追加一行:
|
||||
// configs.push(CleaningConfig::new("新目录名称", "C:\\路径", None));
|
||||
// 4. 内核转储文件
|
||||
configs.push(CleaningConfig::new("内核转储文件", "C:\\Windows\\LiveKernelReports", None, false));
|
||||
|
||||
configs
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
pub struct ScanItem { pub name: String, pub path: String, pub size: u64, pub count: u32 }
|
||||
pub struct ScanItem {
|
||||
pub name: String,
|
||||
pub path: String,
|
||||
pub size: u64,
|
||||
pub count: u32,
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct FastScanResult { pub items: Vec<ScanItem>, pub total_size: String, pub total_count: u32 }
|
||||
pub struct FastScanResult { pub items: Vec<ScanItem>, total_size: String, total_count: u32 }
|
||||
|
||||
pub async fn run_fast_scan() -> FastScanResult {
|
||||
let configs = get_fast_cleaning_configs();
|
||||
@@ -228,7 +228,8 @@ pub async fn run_fast_scan() -> FastScanResult {
|
||||
name: config.name,
|
||||
path: config.path,
|
||||
size,
|
||||
count
|
||||
count,
|
||||
enabled: config.default_enabled,
|
||||
});
|
||||
total_bytes += size;
|
||||
total_count += count;
|
||||
@@ -274,27 +275,21 @@ pub struct CleanResult {
|
||||
pub fail_count: u32,
|
||||
}
|
||||
|
||||
pub async fn run_fast_clean(is_simulation: bool) -> Result<CleanResult, String> {
|
||||
if is_simulation {
|
||||
return Ok(CleanResult {
|
||||
total_freed: "0 B".into(),
|
||||
success_count: 0,
|
||||
fail_count: 0,
|
||||
});
|
||||
}
|
||||
|
||||
pub async fn run_fast_clean(selected_paths: Vec<String>) -> Result<CleanResult, String> {
|
||||
let configs = get_fast_cleaning_configs();
|
||||
let mut success_count = 0;
|
||||
let mut fail_count = 0;
|
||||
let mut total_freed: u64 = 0;
|
||||
|
||||
for config in configs {
|
||||
let path = Path::new(&config.path);
|
||||
if path.exists() {
|
||||
let (freed, s, f) = clean_directory_contents(path, config.filter_days);
|
||||
total_freed += freed;
|
||||
success_count += s;
|
||||
fail_count += f;
|
||||
if selected_paths.contains(&config.path) {
|
||||
let path = Path::new(&config.path);
|
||||
if path.exists() {
|
||||
let (freed, s, f) = clean_directory_contents(path, config.filter_days);
|
||||
total_freed += freed;
|
||||
success_count += s;
|
||||
fail_count += f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user