Added some fixes for Windows (now the setup command works)
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
004c057a2c
commit
9929db6c5b
10
example.config
Normal file
10
example.config
Normal file
@ -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'
|
@ -2,13 +2,19 @@ use config::Config;
|
|||||||
use crate::settings;
|
use crate::settings;
|
||||||
use crate::transcoder::repository::Repository;
|
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);
|
println!("Initializing video repository at {}...", repository_dir);
|
||||||
|
|
||||||
// create and initialize our config and repository objects
|
// create and initialize our repository object
|
||||||
let c: Config = settings::load_config();
|
let r: Repository = Repository::new(repository_dir);
|
||||||
let r: Repository = Repository::new(&shellexpand::tilde(&c.get_string("transcoder.repository").unwrap()));
|
|
||||||
|
|
||||||
// initialize the video repository
|
// initialize the video repository
|
||||||
r.initialize();
|
r.initialize();
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,6 @@ enum Commands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
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
|
// initialize the log4rs logger
|
||||||
log4rs::init_file("./log4rs.yaml", Default::default()).unwrap();
|
log4rs::init_file("./log4rs.yaml", Default::default()).unwrap();
|
||||||
|
|
||||||
@ -37,7 +31,7 @@ fn main() {
|
|||||||
|
|
||||||
match &cli.command {
|
match &cli.command {
|
||||||
// sub-commands will be handled here
|
// 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
|
// run the main program without any commands
|
||||||
None => {
|
None => {
|
||||||
|
@ -1,12 +1,36 @@
|
|||||||
|
use std::path::Path;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
|
|
||||||
pub fn load_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()
|
let settings = Config::builder()
|
||||||
// Add in `./Settings.toml`
|
// Add in `./Settings.toml`
|
||||||
.add_source(config::File::with_name("/etc/zealot/config.toml").required(false))
|
.add_source(config::File::with_name(&global_config_path).required(false))
|
||||||
.add_source(config::File::with_name(&shellexpand::tilde("~/.config/zealot.toml")).required(false))
|
.add_source(config::File::with_name(&home_config_path).required(false))
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
return settings;
|
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);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user