diff --git a/.gitignore b/.gitignore index 71a1362..3c18a86 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ target release *.dll -*.res \ No newline at end of file +*.res +TestConfig.toml \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 7eda0e4..8302e1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,7 @@ name = "polaris" version = "0.1.0" dependencies = [ + "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "id3 0.1.10 (git+https://github.com/jameshurst/rust-id3)", "iron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -178,6 +179,11 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "getopts" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "hpack" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index d2c5c97..8f4f32c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ authors = ["Antoine Gersant "] ui = [] [dependencies] +getopts = "0.2.14" hyper = "0.9.10" id3 = { git = "https://github.com/jameshurst/rust-id3" } iron = "0.4.0" diff --git a/Polaris.toml b/Polaris.toml deleted file mode 100644 index ccd0e37..0000000 --- a/Polaris.toml +++ /dev/null @@ -1,16 +0,0 @@ -auth_secret = 'Something very secret' - -album_art_pattern = '^Folder\.(png|jpg|jpeg)$' - -[[mount_dirs]] -name = 'root' -source = 'M:/Music/Genres/' - -[[users]] -name = 'agersant' -password = 'test' - -[ydns] -host = 'your_hostname.ydns.eu' -username = 'your_username' -password = 'your_ydns_password' diff --git a/build_release_windows.ps1 b/build_release_windows.ps1 index bb9de2c..bb8e0ac 100644 --- a/build_release_windows.ps1 +++ b/build_release_windows.ps1 @@ -12,6 +12,7 @@ Remove-Item -Recurse .\release\windows\* Copy-Item .\target\release\polaris.exe .\release\windows\ Copy-Item .\res\libeay32.dll .\release\windows\ Copy-Item .\res\libeay32md.dll .\release\windows\ +Copy-Item .\res\SampleConfig.toml .\release\windows\Polaris.toml Copy-Item .\Polaris.toml .\release\windows\ Copy-Item .\web\ .\release\windows\ -recurse diff --git a/res/SampleConfig.toml b/res/SampleConfig.toml new file mode 100644 index 0000000..52c2501 --- /dev/null +++ b/res/SampleConfig.toml @@ -0,0 +1,25 @@ +# Type anything here, don't leave the default +auth_secret = 'Something very secret' + +# Pattern used to match album art matching a file +album_art_pattern = '^Folder\.(png|jpg|jpeg)$' + +# Directories where your music is stored +[[mount_dirs]] +source = 'C:/Users/your_name/Music' # Location of the directory on your computer +name = 'root' # Public-facing name for this directory + +# [[mount_dirs]] +# source = 'D:/more_music' +# name = 'extra' + +# Users having access to the service +[[users]] +name = 'your_first_user' +password = 'your_first_password' # Passwords are stored unencrypted. Do not re-use a sensitive password! + +# Use this section if you want Polaris to broadcast your IP to https://ydns.io +# [ydns] +# host = 'your_hostname.ydns.eu' +# username = 'your_username' +# password = 'your_ydns_password' diff --git a/src/main.rs b/src/main.rs index 9031382..8f0ba58 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ extern crate core; +extern crate getopts; extern crate hyper; extern crate id3; extern crate iron; @@ -22,13 +23,13 @@ extern crate shell32; #[cfg(windows)] extern crate user32; -use std::path::Path; -use std::sync::Arc; -use std::sync::Mutex; - +use getopts::Options; use iron::prelude::*; use mount::Mount; use staticfile::Static; +use std::path; +use std::sync::Arc; +use std::sync::Mutex; mod api; mod collection; @@ -38,10 +39,23 @@ mod error; mod ui; mod vfs; +const DEFAULT_CONFIG_FILE_NAME: &'static str = "Polaris.toml"; + fn main() { + // Parse CLI options + let args: Vec = std::env::args().collect(); + let mut options = Options::new(); + options.optopt("c", "config", "set the configuration file", "FILE"); + let matches = match options.parse(&args[1..]) { + Ok(m) => m, + Err(f) => panic!(f.to_string()), + }; + let config_file_name = matches.opt_str("c").unwrap_or(DEFAULT_CONFIG_FILE_NAME.to_owned()); + // Parse config - let config_file = Path::new("Polaris.toml"); + println!("Reading configuration from {}", config_file_name); + let config_file = path::Path::new(config_file_name.as_str()); let config = config::Config::parse(&config_file).unwrap(); // Start server @@ -64,7 +78,7 @@ fn main() { let mut mount = Mount::new(); mount.mount("/api/", api_chain); - mount.mount("/", Static::new(Path::new("web"))); + mount.mount("/", Static::new(path::Path::new("web"))); let mut server = Iron::new(mount).http(("0.0.0.0", 5050)).unwrap(); // Start DDNS updates