0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-22 05:58:21 -05:00

chore: make websurfx directory and config file names as constants

This commit is contained in:
neon_arch 2023-05-24 12:01:36 +03:00
parent ea3f21139f
commit a7a28ed8c6

View File

@ -5,6 +5,10 @@ use super::parser_models::Style;
use rlua::Lua; use rlua::Lua;
use std::{format, fs, path::Path}; use std::{format, fs, path::Path};
// ------- Constants --------
static COMMON_DIRECTORY_NAME: &str = "websurfx";
static CONFIG_FILE_NAME: &str = "config.lua";
/// A named struct which stores the parsed config file options. /// A named struct which stores the parsed config file options.
/// ///
/// # Fields /// # Fields
@ -67,20 +71,29 @@ impl Config {
fn handle_different_config_file_path() -> Result<String, Box<dyn std::error::Error>> { fn handle_different_config_file_path() -> Result<String, Box<dyn std::error::Error>> {
if Path::new( if Path::new(
format!( format!(
"{}/.config/websurfx/config.lua", "{}/.config/{}/config.lua",
std::env::var("HOME").unwrap() std::env::var("HOME").unwrap(),
COMMON_DIRECTORY_NAME
) )
.as_str(), .as_str(),
) )
.exists() .exists()
{ {
Ok(format!( Ok(format!(
"{}/.config/websurfx/config.lua", "{}/.config/{}/{}",
std::env::var("HOME").unwrap() std::env::var("HOME").unwrap(),
COMMON_DIRECTORY_NAME,
CONFIG_FILE_NAME
)) ))
} else if Path::new("/etc/xdg/websurfx/config.lua").exists() { } else if Path::new(
format!("/etc/xdg/{}/{}", COMMON_DIRECTORY_NAME, CONFIG_FILE_NAME).as_str(),
)
.exists()
{
Ok("/etc/xdg/websurfx/config.lua".to_string()) Ok("/etc/xdg/websurfx/config.lua".to_string())
} else if Path::new("./websurfx/config.lua").exists() { } else if Path::new(format!("./{}/{}", COMMON_DIRECTORY_NAME, CONFIG_FILE_NAME).as_str())
.exists()
{
Ok("./websurfx/config.lua".to_string()) Ok("./websurfx/config.lua".to_string())
} else { } else {
Err(format!("Config file not found!!").into()) Err(format!("Config file not found!!").into())