2025-09-11 14:08:46 -04:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
use std::fs;
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
|
|
|
pub struct Config {
|
|
|
|
|
pub paths: PathConfig,
|
2025-09-11 16:32:21 -04:00
|
|
|
pub processing: ProcessingConfig,
|
2025-09-11 14:08:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
|
|
|
pub struct PathConfig {
|
|
|
|
|
pub default_indexing_path: String,
|
|
|
|
|
pub database_path: String,
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-21 02:34:40 -04:00
|
|
|
fn default_fts_update_batch_size() -> usize {
|
|
|
|
|
1000
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-11 16:32:21 -04:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
|
|
|
pub struct ProcessingConfig {
|
|
|
|
|
pub hash_length: usize,
|
|
|
|
|
pub maximum_text_size: usize,
|
2026-04-21 02:34:40 -04:00
|
|
|
pub maximum_text_file_size: u64,
|
2025-09-11 16:32:21 -04:00
|
|
|
pub batch_size: usize,
|
2026-04-21 02:34:40 -04:00
|
|
|
#[serde(default = "default_fts_update_batch_size")]
|
|
|
|
|
pub fts_update_batch_size: usize,
|
2025-09-11 18:36:42 -04:00
|
|
|
pub tokenize: String,
|
2026-04-21 02:34:40 -04:00
|
|
|
#[serde(default)]
|
|
|
|
|
pub precount_files_for_progress: bool,
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub follow_symlinks: bool,
|
2026-04-21 03:43:28 -04:00
|
|
|
#[serde(default)]
|
|
|
|
|
pub include_hidden: bool,
|
2025-09-11 16:32:21 -04:00
|
|
|
}
|
|
|
|
|
|
2025-09-11 14:08:46 -04:00
|
|
|
impl Default for Config {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Config {
|
|
|
|
|
paths: PathConfig {
|
|
|
|
|
default_indexing_path: "C:\\".to_string(),
|
|
|
|
|
database_path: "QuickSearch.db".to_string(),
|
|
|
|
|
},
|
2025-09-11 16:32:21 -04:00
|
|
|
processing: ProcessingConfig {
|
|
|
|
|
hash_length: 1024 * 8,
|
2026-04-21 02:34:40 -04:00
|
|
|
maximum_text_size: 1024 * 256,
|
|
|
|
|
maximum_text_file_size: 1024 * 1024 * 2,
|
2025-09-11 16:32:21 -04:00
|
|
|
batch_size: 200,
|
2026-04-21 02:34:40 -04:00
|
|
|
fts_update_batch_size: 1000,
|
2025-09-11 18:36:42 -04:00
|
|
|
tokenize: "trigram".to_string(),
|
2026-04-21 02:34:40 -04:00
|
|
|
precount_files_for_progress: false,
|
|
|
|
|
follow_symlinks: false,
|
2026-04-21 03:43:28 -04:00
|
|
|
include_hidden: false,
|
2025-09-11 16:32:21 -04:00
|
|
|
},
|
2025-09-11 14:08:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Config {
|
|
|
|
|
pub fn load() -> Result<Self, String> {
|
|
|
|
|
let config_path = "config.toml";
|
|
|
|
|
|
|
|
|
|
if Path::new(config_path).exists() {
|
|
|
|
|
let content = fs::read_to_string(config_path)
|
|
|
|
|
.map_err(|e| format!("Failed to read config file: {}", e))?;
|
|
|
|
|
|
|
|
|
|
toml::from_str(&content)
|
|
|
|
|
.map_err(|e| format!("Failed to parse config file: {}", e))
|
|
|
|
|
} else {
|
|
|
|
|
let default_config = Config::default();
|
|
|
|
|
default_config.save()?;
|
|
|
|
|
Ok(default_config)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn save(&self) -> Result<(), String> {
|
|
|
|
|
let content = toml::to_string_pretty(self)
|
|
|
|
|
.map_err(|e| format!("Failed to serialize config: {}", e))?;
|
|
|
|
|
|
|
|
|
|
fs::write("config.toml", content)
|
|
|
|
|
.map_err(|e| format!("Failed to write config file: {}", e))?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|