96 lines
2.9 KiB
Rust
96 lines
2.9 KiB
Rust
//! Synchronizes a [GOG](https://www.gog.com/) library with a local folder.
|
|
//!
|
|
//! ```
|
|
//! USAGE:
|
|
//! gog-sync [OPTIONS]
|
|
//!
|
|
//! FLAGS:
|
|
//! -h, --help Prints help information
|
|
//! -V, --version Prints version information
|
|
//!
|
|
//! OPTIONS:
|
|
//! -l, --language <FILTER> Only sync files for this comma seperated list of languages.
|
|
//! -o, --os <FILTER> Only sync files for this comma seperated list of operating systems.
|
|
//! Valid values are 'linux', 'mac' and 'windows'.
|
|
//! -s, --storage <FOLDER> Sets the download folder (defaults to the working directory).
|
|
//! ```
|
|
|
|
extern crate chrono;
|
|
extern crate clap;
|
|
extern crate curl;
|
|
extern crate env_logger;
|
|
#[macro_use]
|
|
extern crate log;
|
|
extern crate serde;
|
|
extern crate serde_json;
|
|
#[macro_use]
|
|
extern crate serde_derive;
|
|
extern crate url;
|
|
extern crate xdg;
|
|
|
|
pub mod configfiles;
|
|
pub mod gog;
|
|
pub mod http;
|
|
mod models;
|
|
|
|
use configfiles::ConfigFiles;
|
|
use clap::{Arg, App};
|
|
use gog::Gog;
|
|
use http::Http;
|
|
use models::Config;
|
|
|
|
fn main() {
|
|
env_logger::init().unwrap();
|
|
|
|
let matches = App::new("Gog Synchronizer")
|
|
.version("0.1.0")
|
|
.author("Sebastian Hugentobler <sebastian@vanwa.ch>")
|
|
.about("Synchronizes your gog library to a local folder.")
|
|
.arg(Arg::with_name("storage")
|
|
.short("s")
|
|
.long("storage")
|
|
.value_name("FOLDER")
|
|
.help("Sets the download folder (defaults to the working directory).")
|
|
.takes_value(true))
|
|
.arg(Arg::with_name("os")
|
|
.short("o")
|
|
.long("os")
|
|
.value_name("FILTER")
|
|
.help("Only sync files for this comma seperated list of operating systems.\n\
|
|
Valid values are 'linux', 'mac' and 'windows'.")
|
|
.takes_value(true))
|
|
.arg(Arg::with_name("language")
|
|
.short("l")
|
|
.long("language")
|
|
.value_name("FILTER")
|
|
.help("Only sync files for this comma seperated list of languages.")
|
|
.takes_value(true))
|
|
.get_matches();
|
|
|
|
let configfiles = ConfigFiles::new();
|
|
let config: Config = match configfiles.load("config.json") {
|
|
Ok(value) => value,
|
|
Err(_) => Config::new(),
|
|
};
|
|
|
|
let download_folder: &str = match matches.value_of("storage") {
|
|
Some(value) => value,
|
|
None => config.storage.as_str(),
|
|
};
|
|
|
|
let os_filters: Vec<String> = match matches.value_of("os") {
|
|
Some(value) => value.split(',').map(String::from).collect(),
|
|
None => config.os_filters,
|
|
};
|
|
|
|
let language_filters: Vec<String> = match matches.value_of("language") {
|
|
Some(value) => value.split(',').map(String::from).collect(),
|
|
None => config.language_filters,
|
|
};
|
|
|
|
let mut http_client = Http::new();
|
|
let mut gog = Gog::new(&mut http_client);
|
|
gog.login().unwrap();
|
|
gog.sync(download_folder, &os_filters, &language_filters).unwrap();
|
|
}
|