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:
		
							
								
								
									
										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::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(); | ||||
| } | ||||
|   | ||||
| @@ -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 => { | ||||
|   | ||||
| @@ -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); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user