summary history branches tags files
commit:f96a193dc91060e100faaf089a520166c71b1537
author:Trevor Bentley
committer:Trevor Bentley
date:Sat Apr 22 19:48:06 2017 +0200
parents:2a24bf1711b031ac3c8ed2a576501bd4caff4c8f
Also use connectr.ini in cwd if it exists.
diff --git a/src/settings/mod.rs b/src/settings/mod.rs
line changes: +16/-6
index 88777fa..07877cc
--- a/src/settings/mod.rs
+++ b/src/settings/mod.rs
@@ -10,7 +10,7 @@ use std::env;
 use std::fs;
 use std::path;
 
-const INIFILE: &'static str = ".connectr.ini";
+const INIFILE: &'static str = "connectr.ini";
 
 pub struct Settings {
     pub port: u32,
@@ -37,10 +37,10 @@ fn bundled_ini() -> String {
 
 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
@@ -49,15 +49,25 @@ fn inifile() -> String {
     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();
@@ -78,7 +88,7 @@ pub fn read_settings() -> Option<Settings> {
     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!("");