From 438bac39a24c152d456c9427b100086f06ff20b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lidwin?= Date: Sun, 18 Aug 2024 20:45:45 +0200 Subject: [PATCH] feat: support wyvern as auth source --- Cargo.lock | 53 ++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + README.md | 17 ++++++++++-- src/import_parsers.rs | 10 +++++++ src/import_parsers/wyvern.rs | 40 +++++++++++++++++++++++++++ src/main.rs | 9 ++++++ 6 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 src/import_parsers/wyvern.rs diff --git a/Cargo.lock b/Cargo.lock index a3df4cf..9340e34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -337,6 +337,7 @@ dependencies = [ "tokio", "tokio-tungstenite", "tokio-util", + "toml", ] [[package]] @@ -1723,6 +1724,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -2233,6 +2243,40 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "tower" version = "0.4.13" @@ -2697,6 +2741,15 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index 5804b6b..28b5073 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ rustls-pemfile = "2.1.1" async_zip = { version = "0.0.17", features = ["tokio", "deflate"] } base64 = "0.22.0" serde_ini = "0.2.0" +toml = "0.8.19" [build-dependencies] protobuf-codegen = "3.4.0" diff --git a/README.md b/README.md index 0626655..0427008 100644 --- a/README.md +++ b/README.md @@ -58,11 +58,19 @@ You need to obtain `access_token`, `refresh_token` and `user_id` either manually #### Via [Heroic Games Launcher](https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher) -Log in to GOG within the launcher. +Log in to GOG within the launcher. +Use `--from-heroic` for automatic import. #### Via [Lutris](https://github.com/lutris/lutris) -Log in to Lutris's GOG source. +Log in to Lutris's GOG source. +Use `--from-lutris` for automatic import. + +### Via [wyvern](https://github.com/nicohman/wyvern) (CLI) + +Log in to GOG in wyvern +Use `--from-wyvern` for automatic import. + #### Via [gogdl](https://github.com/Heroic-Games-Launcher/heroic-gogdl) (CLI) @@ -99,6 +107,11 @@ Or Lutris comet --from-lutris --username ``` +Or wyvern +``` +comet --from-wyvern --username +``` + Or use the shortcut script provided for non-Steam shortcuts. See the [Steam Deck Usage Guide](docs/steamdeck/USAGE.md). ## Contributing diff --git a/src/import_parsers.rs b/src/import_parsers.rs index 93903b0..0f064eb 100644 --- a/src/import_parsers.rs +++ b/src/import_parsers.rs @@ -3,6 +3,8 @@ use crate::constants; mod heroic; #[cfg(target_os = "linux")] mod lutris; +#[cfg(target_os = "linux")] +mod wyvern; pub fn handle_credentials_import(args: &crate::Args) -> (String, String, String) { if args.heroic { @@ -58,6 +60,14 @@ pub fn handle_credentials_import(args: &crate::Args) -> (String, String, String) return (access_token, refresh_token, galaxy_user_id); } + #[cfg(target_os = "linux")] + if args.wyvern { + let config = wyvern::load_tokens(); + let token = config.token; + + return token.dissolve(); + } + let access_token = args.access_token.clone().expect("Access token is required"); let refresh_token = args .refresh_token diff --git a/src/import_parsers/wyvern.rs b/src/import_parsers/wyvern.rs new file mode 100644 index 0000000..eafd19f --- /dev/null +++ b/src/import_parsers/wyvern.rs @@ -0,0 +1,40 @@ +use derive_getters::Dissolve; +use serde::Deserialize; +use std::env; +use std::fs::read_to_string; +use std::path; + +#[derive(Deserialize, Dissolve)] +pub struct WyvernTokenData { + pub access_token: String, + pub refresh_token: String, + pub user_id: String, +} + +#[derive(Deserialize)] +pub struct WyvernConfig { + pub token: WyvernTokenData, +} + +fn get_config_path() -> Option { + let home_dir = env::var("HOME").unwrap(); + let home_dir = path::Path::new(&home_dir); + + let config_path: path::PathBuf = env::var("XDG_CONFIG_HOME") + .unwrap_or_else(|_e| home_dir.join(".config").to_str().unwrap().to_string()) + .into(); + + let wyvern_config_path = config_path.join("wyvern/wyvern.toml"); + + if wyvern_config_path.exists() { + Some(wyvern_config_path) + } else { + None + } +} + +pub fn load_tokens() -> WyvernConfig { + let config_path = get_config_path().expect("Wyvern toml doesn't exist"); + let data = read_to_string(config_path).expect("Failed to read wyvern.toml"); + toml::from_str(&data).expect("Failed to parse wyvern config") +} diff --git a/src/main.rs b/src/main.rs index 4c550ed..8b5e0bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,6 +62,15 @@ struct Args { #[cfg(target_os = "linux")] lutris: bool, + #[arg( + long = "from-wyvern", + help = "Load tokens from wyvern", + global = true, + group = "import" + )] + #[cfg(target_os = "linux")] + wyvern: bool, + #[arg( short, long,