From f42ee4ec9ec5263e0466b95d5587c182e98fa5ee Mon Sep 17 00:00:00 2001 From: Julian Freeman Date: Sun, 7 Dec 2025 20:27:00 -0400 Subject: [PATCH] check page --- src-tauri/src/lib.rs | 96 +++++++++++++++++++++++++- src/App.vue | 158 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 227 insertions(+), 27 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 620478d..3147004 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -250,6 +250,96 @@ fn rename_videos(files: Vec, prefix: String, base_name: String) -> Resul Ok(format!("Successfully renamed {} files.", renamed_count)) } +// --- Check Logic --- + +fn remove_empty_dirs_recursive(path: &Path, deleted_list: &mut Vec) -> std::io::Result<()> { + if path.is_dir() { + let read_dir = fs::read_dir(path)?; + for entry in read_dir { + let entry = entry?; + let child_path = entry.path(); + if child_path.is_dir() { + remove_empty_dirs_recursive(&child_path, deleted_list)?; + } + } + + // Re-check if empty after processing children + // Use read_dir again to check if it's empty now + let mut is_empty = true; + let read_dir_check = fs::read_dir(path)?; + for _ in read_dir_check { + is_empty = false; + break; + } + + if is_empty { + fs::remove_dir(path)?; + deleted_list.push(path.to_string_lossy().to_string()); + } + } + Ok(()) +} + +#[tauri::command] +fn delete_empty_dirs(path: String) -> Result, String> { + let root_path = Path::new(&path); + if !root_path.exists() || !root_path.is_dir() { + return Err("Path is not a valid directory".to_string()); + } + + let mut deleted = Vec::new(); + + // We cannot delete the root path itself even if empty, per logic usually expected in tools. + // So we iterate children and call recursive function. + let read_dir = fs::read_dir(root_path).map_err(|e| e.to_string())?; + + for entry in read_dir { + let entry = entry.map_err(|e| e.to_string())?; + let child_path = entry.path(); + if child_path.is_dir() { + remove_empty_dirs_recursive(&child_path, &mut deleted).map_err(|e| e.to_string())?; + } + } + + Ok(deleted) +} + +#[tauri::command] +fn check_file_naming(path: String, prefix: String) -> Result, String> { + let root_path = Path::new(&path); + if !root_path.exists() || !root_path.is_dir() { + return Err("Path is not a valid directory".to_string()); + } + + let mut mismatches = Vec::new(); + let mut stack = vec![root_path.to_path_buf()]; + + while let Some(current_dir) = stack.pop() { + let read_dir = fs::read_dir(¤t_dir).map_err(|e| e.to_string())?; + + for entry in read_dir { + let entry = entry.map_err(|e| e.to_string())?; + let path = entry.path(); + if path.is_dir() { + stack.push(path); + } else { + if let Some(name) = path.file_name().and_then(|n| n.to_str()) { + // Check against prefix + // NOTE: Should we check hidden files? Assuming ignoring hidden files for now if starting with dot? + // Or just check everything. Let's check everything visible. + if !name.starts_with(".") { + if !name.starts_with(&prefix) { + mismatches.push(path.to_string_lossy().to_string()); + } + } + } + } + } + } + + Ok(mismatches) +} + #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { @@ -265,8 +355,10 @@ pub fn run() { save_history_item, remove_history_item, check_dir_exists, - rename_videos + rename_videos, + delete_empty_dirs, + check_file_naming ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); -} \ No newline at end of file +} diff --git a/src/App.vue b/src/App.vue index c875c1d..2d556df 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,9 +1,9 @@