From 9929db6c5b0790e5710198a55792f53792dab645 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Mon, 24 Oct 2022 23:42:45 -0400 Subject: [PATCH] Added some fixes for Windows (now the setup command works) --- example.config | 10 ++++++++++ src/cmd/core.rs | 16 +++++++++++----- src/main.rs | 8 +------- src/settings.rs | 28 ++++++++++++++++++++++++++-- 4 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 example.config diff --git a/example.config b/example.config new file mode 100644 index 0000000..9fe6d19 --- /dev/null +++ b/example.config @@ -0,0 +1,10 @@ +[transcoder] +repo_path = '~/zealot' +interval = 15 +video_format = 'mov' +video_codec = 'dnxhd' +video_profile = 'dnxhr_hq' +video_resolution = '1920x1080' +video_framerate = '60' +video_color = 'yuv422p' +audio_codec = 'pcm_s16le' diff --git a/src/cmd/core.rs b/src/cmd/core.rs index b4d56b2..0ff44bd 100644 --- a/src/cmd/core.rs +++ b/src/cmd/core.rs @@ -2,13 +2,19 @@ use config::Config; use crate::settings; use crate::transcoder::repository::Repository; -pub fn setup_command(repository_dir: &str) { +pub fn setup_command() { + // load configuration + let c: Config = settings::load_config(); + + // resolve repository path + let repository_dir_raw: &str = &c.get_string("transcoder.repository").unwrap(); + let repository_dir: &str = &shellexpand::tilde(repository_dir_raw); + + // alert the user to what's happening println!("Initializing video repository at {}...", repository_dir); - // create and initialize our config and repository objects - let c: Config = settings::load_config(); - let r: Repository = Repository::new(&shellexpand::tilde(&c.get_string("transcoder.repository").unwrap())); - + // create and initialize our repository object + let r: Repository = Repository::new(repository_dir); // initialize the video repository r.initialize(); } diff --git a/src/main.rs b/src/main.rs index 9fde30e..93093b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,12 +23,6 @@ enum Commands { } fn main() { - // set the configuration file path depending on the OS - let mut config_path: &str = "/etc/zealot/config.toml"; - if cfg!(windows) { - config_path = "C:\\Program Files\\Zealot\\config.toml"; - } - // initialize the log4rs logger log4rs::init_file("./log4rs.yaml", Default::default()).unwrap(); @@ -37,7 +31,7 @@ fn main() { match &cli.command { // sub-commands will be handled here - Some(Commands::Setup {}) => cmd::core::setup_command(config_path), + Some(Commands::Setup {}) => cmd::core::setup_command(), // run the main program without any commands None => { diff --git a/src/settings.rs b/src/settings.rs index 8ed06dc..4ccf1a2 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,12 +1,36 @@ +use std::path::Path; use config::Config; pub fn load_config() -> Config { + let global_config_path: String = find_global_config_path(); + let home_config_path: String = find_home_config_path(); + + println!("{}", Path::new(&global_config_path).exists()); + let settings = Config::builder() // Add in `./Settings.toml` - .add_source(config::File::with_name("/etc/zealot/config.toml").required(false)) - .add_source(config::File::with_name(&shellexpand::tilde("~/.config/zealot.toml")).required(false)) + .add_source(config::File::with_name(&global_config_path).required(false)) + .add_source(config::File::with_name(&home_config_path).required(false)) .build() .unwrap(); return settings; } + +fn find_global_config_path() -> String { + if cfg!(windows) { + return String::from("C:\\Program Files\\Zealot\\config.toml"); + } + + return String::from("/etc/zealot/config.toml"); +} + +fn find_home_config_path() -> String { + let home_path: &str = &shellexpand::tilde("~/.config/zealot.toml"); + + if cfg!(windows) { + return String::from(home_path.replace("/", "\\")); + } + + return String::from(home_path); +}