mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-06-29 01:45:54 +08:00
bfd114d80f
架构重构: - StringList 类替换为不可变 string[](消除 dataVersion hack,Zustand 自然检测变化) - UndoRedoManager.undo/redo 返回新数组而非原地修改 - 删除 dataVersion 字段和 _bumpVersion() - 启用 TypeScript strict 模式 死代码清理: - 删除 string-list.ts, string-list.test.ts, use-path-validation.ts - Rust AppError 保留供未来使用 功能修复: - importFromJson 添加 try/catch - handleClean 使用真实格式验证替代 () => true - savePaths 保存前调用 backup_registry,处理部分保存失败 - importFromJson 校验非 object 类型输入 i18n 完善: - MergePreview/StatusBar 硬编码中文 → t() 调用 - 新增 merge.* 和 status.* 翻译键 Rust 改进: - registry.rs 抽取 load_paths/save_paths 通用函数,消除重复 - registry 新增 6 个单元测试(split/join/roundtrip) - backup.rs 时间戳加毫秒防覆盖,回退路径改为 home_dir 元数据: - package.json 名称→patheditor, 版本→4.0.0 - 新增 CHANGELOG.md - 移除 UndoRedoButtons 废弃注释 - tsconfig 添加 strict:true Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
60 lines
1.9 KiB
Rust
60 lines
1.9 KiB
Rust
use chrono::Local;
|
|
use std::fs;
|
|
use std::path::PathBuf;
|
|
|
|
/// 获取 APPDATA 路径下的备份目录
|
|
#[tauri::command]
|
|
pub fn get_appdata_dir() -> String {
|
|
dirs::data_dir()
|
|
.or_else(dirs::home_dir)
|
|
.unwrap_or_else(|| PathBuf::from("."))
|
|
.join("PathEditor")
|
|
.join("backups")
|
|
.to_string_lossy()
|
|
.to_string()
|
|
}
|
|
|
|
/// 备份当前注册表中的系统 PATH 和用户 PATH
|
|
/// 返回备份文件的路径
|
|
#[tauri::command]
|
|
pub fn backup_registry(custom_dir: Option<String>, sys_paths: Vec<String>, user_paths: Vec<String>) -> Result<String, String> {
|
|
// 确定备份目录
|
|
let backup_dir = match custom_dir {
|
|
Some(ref dir) if !dir.is_empty() => PathBuf::from(dir),
|
|
_ => {
|
|
dirs::data_dir()
|
|
.unwrap_or_else(|| PathBuf::from("C:\\"))
|
|
.join("PathEditor")
|
|
.join("backups")
|
|
}
|
|
};
|
|
|
|
// 创建目录
|
|
fs::create_dir_all(&backup_dir)
|
|
.map_err(|e| format!("无法创建备份目录: {}", e))?;
|
|
|
|
// 生成带时间戳的文件名
|
|
let timestamp = Local::now().format("%Y%m%d_%H%M%S_%3f");
|
|
let filename = format!("path_backup_{}.txt", timestamp);
|
|
let filepath = backup_dir.join(&filename);
|
|
|
|
// 写入备份内容
|
|
let mut content = String::new();
|
|
content.push_str(&format!("PathEditor Backup - {}\n", Local::now().format("%Y-%m-%d %H:%M:%S")));
|
|
content.push_str("\n[System PATH]\n");
|
|
for path in &sys_paths {
|
|
content.push_str(&format!("{}\n", path));
|
|
}
|
|
content.push_str("\n[User PATH]\n");
|
|
for path in &user_paths {
|
|
content.push_str(&format!("{}\n", path));
|
|
}
|
|
|
|
fs::write(&filepath, &content)
|
|
.map_err(|e| format!("无法写入备份文件: {}", e))?;
|
|
|
|
let result = filepath.to_string_lossy().to_string();
|
|
log::info!("备份已保存到: {}", result);
|
|
Ok(result)
|
|
}
|