Fix sqlite db wrong path
This commit is contained in:
11
src/app.rs
11
src/app.rs
@@ -14,12 +14,7 @@ use ratatui::prelude::{Widget};
|
|||||||
use ratatui::style::{Color, Style};
|
use ratatui::style::{Color, Style};
|
||||||
use ratatui::text::{Line, Span, Text};
|
use ratatui::text::{Line, Span, Text};
|
||||||
use crate::config::types::ApplicationConfig;
|
use crate::config::types::ApplicationConfig;
|
||||||
use crate::constants::{APP_CONFIG_DIR, APP_DATA_DIR};
|
use crate::constants::{APP_CONFIG_DIR, APP_CONIFG_FILE_PATH, APP_DATA_DIR};
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
static ref APP_CONIFG_FILE_PATH: PathBuf = APP_CONFIG_DIR.clone()
|
|
||||||
.join("config.ini");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) struct App {
|
pub(crate) struct App {
|
||||||
running: bool,
|
running: bool,
|
||||||
@@ -33,8 +28,8 @@ impl App {
|
|||||||
let app_conf =
|
let app_conf =
|
||||||
if APP_CONIFG_FILE_PATH.exists() { ApplicationConfig::from_file(&APP_CONIFG_FILE_PATH) }
|
if APP_CONIFG_FILE_PATH.exists() { ApplicationConfig::from_file(&APP_CONIFG_FILE_PATH) }
|
||||||
else { ApplicationConfig::new() };
|
else { ApplicationConfig::new() };
|
||||||
|
Self::initialize();
|
||||||
let db_conn = Self::establish_db_connection(app_conf.clone());
|
let db_conn = Self::establish_db_connection(app_conf.clone());
|
||||||
Self::initialize(&db_conn);
|
|
||||||
App {
|
App {
|
||||||
running: true,
|
running: true,
|
||||||
events: EventHandler::new(Duration::from_millis(app_conf.basic_config.tick_rate)),
|
events: EventHandler::new(Duration::from_millis(app_conf.basic_config.tick_rate)),
|
||||||
@@ -43,7 +38,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initialize(db_conn: &SqliteConnection) {
|
fn initialize() {
|
||||||
if !APP_CONFIG_DIR.exists() {
|
if !APP_CONFIG_DIR.exists() {
|
||||||
std::fs::create_dir_all(APP_CONFIG_DIR.as_path()).unwrap();
|
std::fs::create_dir_all(APP_CONFIG_DIR.as_path()).unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::path::{PathBuf};
|
use std::path::{PathBuf};
|
||||||
use ini::Ini;
|
use ini::Ini;
|
||||||
use crate::config::types::{ApplicationConfig, BasicConfig};
|
use crate::config::types::{ApplicationConfig, BasicConfig};
|
||||||
use crate::constants::APP_CONFIG_DIR;
|
use crate::constants::{APP_CONFIG_DIR, APP_CONIFG_FILE_PATH};
|
||||||
|
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
@@ -19,12 +19,14 @@ impl ApplicationConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
let conf = Self {
|
||||||
basic_config: BasicConfig {
|
basic_config: BasicConfig {
|
||||||
db_path: APP_CONFIG_DIR.clone().to_str().unwrap().to_string(),
|
db_path: APP_CONFIG_DIR.clone().join("games.db").to_str().unwrap().to_string(),
|
||||||
tick_rate: 250
|
tick_rate: 250
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
conf.clone().write_to_file(APP_CONIFG_FILE_PATH.to_path_buf());
|
||||||
|
conf
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_to_file(self, path: PathBuf) {
|
pub fn write_to_file(self, path: PathBuf) {
|
||||||
|
|||||||
@@ -9,4 +9,6 @@ lazy_static!(
|
|||||||
.join(APP_DIR_NAME);
|
.join(APP_DIR_NAME);
|
||||||
pub static ref APP_DATA_DIR: PathBuf = BASE_DIRS.data_dir().to_path_buf()
|
pub static ref APP_DATA_DIR: PathBuf = BASE_DIRS.data_dir().to_path_buf()
|
||||||
.join(APP_DIR_NAME);
|
.join(APP_DIR_NAME);
|
||||||
|
pub static ref APP_CONIFG_FILE_PATH: PathBuf = APP_CONFIG_DIR.clone()
|
||||||
|
.join("config.ini");
|
||||||
);
|
);
|
||||||
Reference in New Issue
Block a user