2024-11-08 07:46:25 +02:00
|
|
|
mod database;
|
|
|
|
pub use database::Database;
|
|
|
|
|
|
|
|
use gtk::glib::user_config_dir;
|
|
|
|
use std::{
|
|
|
|
fs::create_dir_all,
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
};
|
|
|
|
|
2024-11-08 08:43:02 +02:00
|
|
|
const VENDOR: &str = "YGGverse";
|
|
|
|
const APP_ID: &str = "Yoda";
|
|
|
|
const BRANCH: &str = "master";
|
|
|
|
|
2024-11-08 07:46:25 +02:00
|
|
|
const DB_NAME: &str = "profile.sqlite3";
|
|
|
|
|
|
|
|
pub struct Profile {
|
|
|
|
database: Database,
|
|
|
|
config_path: PathBuf,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Profile {
|
|
|
|
// Constructors
|
|
|
|
|
2024-11-08 08:43:02 +02:00
|
|
|
pub fn new() -> Self {
|
2024-11-08 07:46:25 +02:00
|
|
|
// Init profile path
|
|
|
|
let mut config_path = user_config_dir();
|
|
|
|
|
2024-11-08 08:43:02 +02:00
|
|
|
config_path.push(VENDOR);
|
|
|
|
config_path.push(APP_ID);
|
|
|
|
config_path.push(BRANCH);
|
|
|
|
config_path.push(format!(
|
|
|
|
"{}.{}",
|
|
|
|
env!("CARGO_PKG_VERSION_MAJOR"),
|
|
|
|
env!("CARGO_PKG_VERSION_MINOR")
|
|
|
|
)); // @TODO remove after auto-migrate feature implementation
|
2024-11-08 07:46:25 +02:00
|
|
|
|
|
|
|
if let Err(e) = create_dir_all(&config_path) {
|
|
|
|
panic!("Failed to create profile directory: {e}")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init database path
|
|
|
|
let mut database_path = config_path.clone();
|
|
|
|
database_path.push(DB_NAME);
|
|
|
|
|
|
|
|
// Result
|
|
|
|
Self {
|
|
|
|
database: Database::new(database_path.as_path()),
|
|
|
|
config_path,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Getters
|
|
|
|
|
|
|
|
pub fn database(&self) -> &Database {
|
|
|
|
&self.database
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn config_path(&self) -> &Path {
|
|
|
|
self.config_path.as_path()
|
|
|
|
}
|
|
|
|
}
|