#![allow(dead_code)]
use super::constants;
use std::{fmt::Display, path::PathBuf};
#[derive(Debug, Clone)]
enum VFxPRConfigType {
Local,
Sourced,
Unknown,
}
#[derive(Debug, Clone)]
pub struct VFxPRConfigFile {
pub config_path: Option<PathBuf>,
config_type: VFxPRConfigType,
}
impl Default for VFxPRConfigFile {
fn default() -> Self {
if let Some(cf) = get_default_config() {
//println!("Seeking file at: {:?}", );
cf
} else {
Self {
config_path: None,
config_type: VFxPRConfigType::Unknown,
}
}
}
}
impl Display for VFxPRConfigFile {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(file_path) = &self.config_path {
write!(f, "{:?}", file_path)
} else {
write!(f, "No file found")
}
}
}
impl VFxPRConfigFile {
pub fn new(s: &str) -> Self {
if PathBuf::from(s).is_file() {
Self {
config_path: Some(PathBuf::from(s)),
config_type: VFxPRConfigType::Sourced,
}
} else {
Self {
config_path: None,
..Default::default()
}
}
}
// pub fn seek_default(&self)->Self {
// }
}
fn get_default_path() -> PathBuf {
if let Some(c_path) = dirs::config_dir() {
let mut file_path = std::path::PathBuf::new();
file_path.push(c_path);
file_path.push(constants::VFXPRNAME);
file_path.push(constants::VFXPRCONFIGFILENAME);
file_path
} else {
PathBuf::new()
}
}
fn get_default_config() -> Option<VFxPRConfigFile> {
let file_path = get_default_path();
if file_path.is_file() {
let cf = VFxPRConfigFile {
config_path: Some(file_path),
config_type: VFxPRConfigType::Local,
};
// println!("found config file at {:?}", &file_path);
return Some(cf);
}
None
}
pub fn check_config(cp: &VFxPRConfigFile, dd: bool) {
if dd {
println!("Config file set at ");
}
// None => {
// // let l = match
// println!("No config file!");
// // std::process::exit(1)
// }
// }
}
pub fn create_config_file() -> bool {
// let file_path = get_default_path();
false
}