Added config file
This commit is contained in:
parent
8248517d42
commit
3e3369ba27
7 changed files with 78 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
||||||
/target
|
/target
|
||||||
*.db
|
*.db
|
||||||
|
config.toml
|
||||||
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -3082,8 +3082,10 @@ dependencies = [
|
||||||
"dpc-pariter",
|
"dpc-pariter",
|
||||||
"quick-xml",
|
"quick-xml",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
|
"serde",
|
||||||
"sha2",
|
"sha2",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"toml",
|
||||||
"tqdm",
|
"tqdm",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
"zip",
|
"zip",
|
||||||
|
|
|
||||||
|
|
@ -14,3 +14,5 @@ walkdir = "2.5.0"
|
||||||
zip = "0.6"
|
zip = "0.6"
|
||||||
quick-xml = "0.31"
|
quick-xml = "0.31"
|
||||||
tokio = { version = "1.0", features = ["time"] }
|
tokio = { version = "1.0", features = ["time"] }
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
toml = "0.8"
|
||||||
|
|
|
||||||
3
config_example.toml
Normal file
3
config_example.toml
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
[paths]
|
||||||
|
default_indexing_path = "C:\\"
|
||||||
|
database_path = "QuickSearch.db"
|
||||||
53
src/config.rs
Normal file
53
src/config.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||||
|
pub struct Config {
|
||||||
|
pub paths: PathConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||||
|
pub struct PathConfig {
|
||||||
|
pub default_indexing_path: String,
|
||||||
|
pub database_path: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Config {
|
||||||
|
fn default() -> Self {
|
||||||
|
Config {
|
||||||
|
paths: PathConfig {
|
||||||
|
default_indexing_path: "C:\\".to_string(),
|
||||||
|
database_path: "QuickSearch.db".to_string(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,21 +3,23 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use crate::indexing::{IndexingService, IndexingStatus};
|
use crate::indexing::{IndexingService, IndexingStatus};
|
||||||
|
use crate::config::Config;
|
||||||
|
|
||||||
#[derive(Props, Clone)]
|
#[derive(Props, Clone)]
|
||||||
pub struct AppProps {
|
pub struct AppProps {
|
||||||
pub indexing_service: Arc<IndexingService>,
|
pub indexing_service: Arc<IndexingService>,
|
||||||
|
pub config: Config,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for AppProps {
|
impl PartialEq for AppProps {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
Arc::ptr_eq(&self.indexing_service, &other.indexing_service)
|
Arc::ptr_eq(&self.indexing_service, &other.indexing_service) && self.config.paths.default_indexing_path == other.config.paths.default_indexing_path && self.config.paths.database_path == other.config.paths.database_path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn App(props: AppProps) -> Element {
|
pub fn App(props: AppProps) -> Element {
|
||||||
let mut indexing_path = use_signal(|| "C:\\".to_string());
|
let mut indexing_path = use_signal(|| props.config.paths.default_indexing_path.clone());
|
||||||
let mut db_path = use_signal(|| "QuickSearch.db".to_string());
|
let mut db_path = use_signal(|| props.config.paths.database_path.clone());
|
||||||
let mut status_text = use_signal(|| "Idle".to_string());
|
let mut status_text = use_signal(|| "Idle".to_string());
|
||||||
|
|
||||||
let indexing_service_for_start = props.indexing_service.clone();
|
let indexing_service_for_start = props.indexing_service.clone();
|
||||||
|
|
|
||||||
13
src/main.rs
13
src/main.rs
|
|
@ -5,18 +5,27 @@ mod frontend;
|
||||||
mod file_handling;
|
mod file_handling;
|
||||||
mod document_extraction;
|
mod document_extraction;
|
||||||
mod indexing;
|
mod indexing;
|
||||||
|
mod config;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Launch the frontend with the indexing service
|
|
||||||
launch(app);
|
launch(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn app() -> Element {
|
fn app() -> Element {
|
||||||
|
let config = match config::Config::load() {
|
||||||
|
Ok(config) => config,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Failed to load config: {}", e);
|
||||||
|
return rsx! { div { "Failed to load configuration" } };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let indexing_service = Arc::new(indexing::IndexingService::new());
|
let indexing_service = Arc::new(indexing::IndexingService::new());
|
||||||
|
|
||||||
rsx! {
|
rsx! {
|
||||||
frontend::App {
|
frontend::App {
|
||||||
indexing_service: indexing_service
|
indexing_service: indexing_service,
|
||||||
|
config: config
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue