use std::path::{Path, PathBuf}; const MODEL_LIBRARY_DIR: &str = "model-library"; const INDEX_FILE: &str = "index.json"; const MANAGED_MODELS_DIR: &str = "managed-models"; const DEFAULT_MODELS_DIR: &str = "models"; /// Resolves the models directory from the user-configured `models_dir`. /// - `None` → `./models` (relative to the app's working directory) /// - `Some("")` → `./models` /// - `Some(path)` → that exact path pub fn resolve_models_dir(models_dir: Option<&str>) -> PathBuf { match models_dir { None | Some("") => PathBuf::from(DEFAULT_MODELS_DIR), Some(path) => PathBuf::from(path), } } pub fn model_library_dir(app_data_dir: &Path) -> PathBuf { app_data_dir.join(MODEL_LIBRARY_DIR) } pub fn model_library_index_path(app_data_dir: &Path) -> PathBuf { model_library_dir(app_data_dir).join(INDEX_FILE) } /// Legacy path for the managed-models location inside AppData. /// Used only for index persistence — downloads now go to the user-configured /// `models_dir` (defaults to `./models` in the project root). pub fn managed_models_dir(app_data_dir: &Path) -> PathBuf { model_library_dir(app_data_dir).join(MANAGED_MODELS_DIR) } #[cfg(test)] mod tests { use super::{managed_models_dir, model_library_dir, model_library_index_path}; #[test] fn model_library_paths_live_under_app_data_dir() { let root = std::path::Path::new("C:/Users/demo/AppData/Roaming/ForgeLM"); assert_eq!(model_library_dir(root), root.join("model-library")); assert_eq!( model_library_index_path(root), root.join("model-library").join("index.json") ); assert_eq!( managed_models_dir(root), root.join("model-library").join("managed-models") ); } }