Also use connectr.ini in cwd if it exists.
use std::fs;
use std::path;
-const INIFILE: &'static str = ".connectr.ini";
+const INIFILE: &'static str = "connectr.ini";
pub struct Settings {
pub port: u32,
fn inifile() -> String {
// Try to load INI file from home directory
- let path = format!("{}/{}", env::home_dir().unwrap().display(), INIFILE);
+ let path = format!("{}/.{}", env::home_dir().unwrap().display(), INIFILE);
if path::Path::new(&path).exists() {
info!("Found config: {}", path);
- return path
+ return path;
}
// If it doesn't exist, try to copy the template from the app bundle, if
if path::Path::new(&bundle_ini).exists() {
info!("Copied config: {}", bundle_ini);
let _ = fs::copy(bundle_ini, path.clone());
+ return path;
}
- path
+
+ let path = INIFILE.to_string();
+ if path::Path::new(&path).exists() {
+ info!("Found config: {}", path);
+ return path;
+ }
+
+ // Default to looking in current working directory
+ String::new()
}
pub fn read_settings() -> Option<Settings> {
info!("Attempting to read config file.");
let conf = match Ini::load_from_file(&inifile()) {
Ok(c) => c,
- Err(_) => {
+ Err(e) => {
+ info!("Load file error: {}", e);
// No connectr.ini found. Generate a junk one in-memory, which
// will fail shortly after with the nice error message.
let mut c = Ini::new();
let secret = section.get("secret").unwrap();
let client_id = section.get("client_id").unwrap();
if client_id.starts_with('<') || secret.starts_with('<') {
- error!("No config file found. Exiting.");
+ error!("Invalid or missing configuration. Cannot continue.");
println!("");
println!("ERROR: Spotify Client ID or Secret not set in connectr.ini!");
println!("");