diff --git a/Cargo.lock b/Cargo.lock index 8af871c..0a50d85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "gog-sync" -version = "0.2.1" +version = "0.2.2" dependencies = [ "chrono 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.21.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/gog.rs b/src/gog.rs index edbeab0..06d520e 100644 --- a/src/gog.rs +++ b/src/gog.rs @@ -325,12 +325,15 @@ impl<'a> Gog<'a> { language_filters: &Vec) -> Result { let game_uri = self.game_uri(game_id); + debug!("looking for information at {}...", &game_uri); let response = self.http_client.get(game_uri.as_str())?; + let game_raw: Value = serde_json::from_str(response.as_str())?; + debug!("found {:?}", &game_raw); + let mut game: Game = serde_json::from_str(&response)?; - let game_raw: Value = serde_json::from_str(response.as_str())?; let downloads = &game_raw["downloads"]; if game_raw.is_object() && !game_raw.as_object().unwrap().contains_key("forumLink") { @@ -344,6 +347,7 @@ impl<'a> Gog<'a> { game.is_movie = is_movie; + debug!("processing installer fields: {:?}", &downloads); for languages in downloads.as_array() { for language in languages { if !language.is_array() || language.as_array().unwrap().len() < 2 { diff --git a/src/http.rs b/src/http.rs index a43b262..a4b40ca 100644 --- a/src/http.rs +++ b/src/http.rs @@ -92,20 +92,22 @@ impl Http { /// http_client.get("https://discworld.com/"); /// ``` pub fn get(&mut self, uri: &str) -> Result { - let mut response_body = String::new(); - + let mut data = Vec::new(); self.curl.url(uri)?; { let mut transfer = self.curl.transfer(); - transfer.write_function(|data| { - response_body = String::from(str::from_utf8(data).unwrap()); - Ok(data.len()) + transfer.write_function(|new_data| { + data.extend_from_slice(new_data); + Ok(new_data.len()) })?; transfer.perform()?; } - Ok(response_body) + match str::from_utf8(data.as_slice()) { + Ok(value) => Ok(value.to_owned()), + Err(error) => Err(HttpError::Utf8Error(error)), + } } /// Add a header to all future requests. diff --git a/src/main.rs b/src/main.rs index 7ba17c0..9ae3ee8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,9 +11,11 @@ //! OPTIONS: //! -l, --language Only sync files for this comma seperated list of languages. //! -o, --os Only sync files for this comma seperated list of operating systems. -//! Valid values are 'linux', 'mac' and 'windows'. +//! Valid values are linux, mac and windows. //! -s, --storage Sets the download folder (defaults to the working directory). //! ``` +//! +//! An incomplete list of languages on gog: `english, český, deutsch, español, français, magyar, polski, русский, 中文` extern crate chrono; extern crate clap;