diff --git a/Cargo.lock b/Cargo.lock index 4b69394d60..2882237825 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,7 @@ dependencies = [ "rust-crypto 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", "urlencoded 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -398,6 +399,14 @@ dependencies = [ "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "toml" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "traitobject" version = "0.0.1" diff --git a/Cargo.toml b/Cargo.toml index 46d51e0a6d..51244c76d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,15 +8,16 @@ name = "trumpet" [dependencies] - clap = "1.5.*" # CLI parsing. #cpal = "*" # Hardware audio output (for testing); works well with Hound. + clap = "1.5.*" # CLI parsing. hound = "1.1.0" # WAV codec. hyper = "0.7.*" iron = "0.2.*" log = "0.3.*" router = "0.0.16" - rustc-serialize = "0.3.15" rust-crypto = "0.2.*" + rustc-serialize = "0.3.15" time = "0.1.*" + toml = "0.1.*" urlencoded = "0.2.0" diff --git a/config.toml b/config.toml new file mode 100644 index 0000000000..22b66b89ec --- /dev/null +++ b/config.toml @@ -0,0 +1,6 @@ +# Various configs + +# Sound paths in development and production environments +sound_path_development = "/home/bt/Dropbox/jungle.horse/sounds" +sound_path_production = "./sounds" + diff --git a/src/dictionary.rs b/src/dictionary.rs index ff0f542f00..9c43da6df5 100644 --- a/src/dictionary.rs +++ b/src/dictionary.rs @@ -1,11 +1,11 @@ // Copyright (c) 2016 Brandon Thomas use std::collections::HashMap; -use std::fs::File; use std::fs::DirEntry; +use std::fs::File; use std::fs; -use std::io; use std::io::Read; +use std::io; use std::path::{Path, PathBuf}; pub type VoiceName = String; diff --git a/src/main.rs b/src/main.rs index 9ea12b9ac4..3c3e5117d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2015 Brandon Thomas +// Copyright (c) 2015-2016 Brandon Thomas extern crate clap; extern crate crypto; @@ -9,8 +9,10 @@ extern crate log; extern crate router; extern crate rustc_serialize; extern crate time; +extern crate toml; extern crate urlencoded; +pub mod config; pub mod dictionary; pub mod handlers; pub mod logger; @@ -21,6 +23,7 @@ use std::path::{Path, PathBuf}; use clap::{App, Arg, ArgMatches}; use iron::prelude::*; use router::Router; +use config::Config; use handlers::audio_synth_handler::AudioSynthHandler; use handlers::error_filter::ErrorFilter; @@ -44,10 +47,12 @@ fn main() { let port = get_port(&matches, 9000); + let config = Config::read("./config.toml").unwrap(); - VocabularyLibrary::read_from_directory(Path::new("./sounds")); + VocabularyLibrary::read_from_directory( + Path::new(&config.sound_path_development)); - start_server(port); + start_server(&config, port); } fn get_port(matches: &ArgMatches, default_port: u16) -> u16 { @@ -62,8 +67,8 @@ fn get_port(matches: &ArgMatches, default_port: u16) -> u16 { } } -fn start_server(port: u16) { - let audio_path = "./sounds"; +fn start_server(config: &Config, port: u16) { + let audio_path = &config.sound_path_development; let file_path = "./web"; let index = "index.html";