Mountain/Binary/Extension/ScanPathConfigure.rs
1//! # Extension Scan Path Configure Module
2//!
3//! Configures extension scan paths from the executable directory.
4
5use std::path::PathBuf;
6
7use log::{debug, info};
8
9use crate::ApplicationState::{ApplicationState, MapLockError};
10
11/// Configures extension scan paths by resolving paths from the executable
12/// directory.
13///
14/// # Arguments
15///
16/// * `AppState` - The application state containing ExtensionScanPaths
17///
18/// # Returns
19///
20/// A `Result` indicating success or failure.
21///
22/// # Scan Path Configuration
23///
24/// This function adds the following default scan paths:
25/// - `../Resources/extensions` - Bundled extensions in app resources directory
26/// - `extensions` - Local extensions directory relative to executable
27///
28/// # Errors
29///
30/// Returns an error if ExtensionScanPaths mutex lock fails.
31pub fn ScanPathConfigure(AppState:&std::sync::Arc<ApplicationState>) -> Result<Vec<PathBuf>, String> {
32 debug!("[Extensions] [ScanPaths] Locking ExtensionScanPaths...");
33
34 let mut ScanPathsGuard = AppState
35 .Extension
36 .Registry
37 .ExtensionScanPaths
38 .lock()
39 .map_err(MapLockError)
40 .map_err(|e| format!("Failed to lock ExtensionScanPaths: {}", e))?;
41
42 debug!("[Extensions] [ScanPaths] Adding default scan paths...");
43
44 // Resolve paths from executable directory
45 if let Ok(ExecutableDirectory) = std::env::current_exe() {
46 if let Some(Parent) = ExecutableDirectory.parent() {
47 let ResourcesPath = Parent.join("../Resources/extensions");
48
49 let LocalPath = Parent.join("extensions");
50
51 debug!("[Extensions] [ScanPaths] + {}", ResourcesPath.display());
52
53 ScanPathsGuard.push(ResourcesPath);
54
55 debug!("[Extensions] [ScanPaths] + {}", LocalPath.display());
56
57 ScanPathsGuard.push(LocalPath);
58 }
59 }
60
61 let ScanPaths = ScanPathsGuard.clone();
62
63 info!("[Extensions] [ScanPaths] Configured: {:?}", ScanPaths);
64
65 Ok(ScanPaths)
66}