diff --git a/Cargo.lock b/Cargo.lock index 6281efd..3891b93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,18 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "arrayref" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" - -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - [[package]] name = "atty" version = "0.2.14" @@ -31,29 +19,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "base64" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" - [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -[[package]] -name = "blake2b_simd" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" -dependencies = [ - "arrayref", - "arrayvec", - "constant_time_eq", -] - [[package]] name = "cfg-if" version = "1.0.0" @@ -62,9 +33,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.0.0-beta.2" +version = "3.0.0-beta.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142" +checksum = "feff3878564edb93745d58cf63e17b63f24142506e7a20c87a5521ed7bfb1d63" dependencies = [ "atty", "bitflags", @@ -75,15 +46,14 @@ dependencies = [ "strsim", "termcolor", "textwrap", - "unicode-width", - "vec_map", + "unicase", ] [[package]] name = "clap_derive" -version = "3.0.0-beta.2" +version = "3.0.0-beta.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "370f715b81112975b1b69db93e0b56ea4cd4e5002ac43b2da8474106a54096a1" +checksum = "8b15c6b4f786ffb6192ffe65a36855bc1fc2444bcd0945ae16748dcd6ed7d0d3" dependencies = [ "heck", "proc-macro-error", @@ -92,37 +62,20 @@ dependencies = [ "syn", ] -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - -[[package]] -name = "crossbeam-utils" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" -dependencies = [ - "autocfg", - "cfg-if", - "lazy_static", -] - [[package]] name = "dirs" -version = "3.0.1" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "142995ed02755914747cc6ca76fc7e4583cd18578746716d0508ea6ed558b9ff" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" dependencies = [ "dirs-sys", ] [[package]] name = "dirs-sys" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a" +checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780" dependencies = [ "libc", "redox_users", @@ -135,17 +88,6 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.2" @@ -154,7 +96,7 @@ checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ "cfg-if", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -203,11 +145,20 @@ version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + [[package]] name = "os_str_bytes" -version = "2.4.0" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85" +checksum = "addaa943333a514159c80c97ff4a93306530d965d27e139188283cd13e06a799" +dependencies = [ + "memchr", +] [[package]] name = "ppv-lite86" @@ -241,18 +192,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.28" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" +checksum = "edc3358ebc67bc8b7fa0c007f945b0b18226f78437d61bec735a9eb96b61ee70" dependencies = [ "unicode-xid", ] [[package]] name = "quote" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" dependencies = [ "proc-macro2", ] @@ -285,7 +236,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" dependencies = [ - "getrandom 0.2.2", + "getrandom", ] [[package]] @@ -299,36 +250,26 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" - -[[package]] -name = "redox_users" -version = "0.3.5" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" dependencies = [ - "getrandom 0.1.16", - "redox_syscall", - "rust-argon2", + "bitflags", ] [[package]] -name = "rust-argon2" -version = "0.8.3" +name = "redox_users" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" +checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ - "base64", - "blake2b_simd", - "constant_time_eq", - "crossbeam-utils", + "getrandom", + "redox_syscall", ] [[package]] name = "steam_randomiser" -version = "0.2.0" +version = "0.4.0" dependencies = [ "clap", "dirs", @@ -344,9 +285,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.74" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c" +checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194" dependencies = [ "proc-macro2", "quote", @@ -364,13 +305,22 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.12.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789" +checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" dependencies = [ "unicode-width", ] +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-segmentation" version = "1.8.0" @@ -379,9 +329,9 @@ checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-width" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "unicode-xid" @@ -389,24 +339,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 28855f6..1cd942b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "steam_randomiser" -version = "0.2.0" +version = "0.4.0" authors = ["Dimitri Belopopsky "] -edition = "2018" +edition = "2021" license = "MIT" -description = "Randomly pick an installed Steam game!" +description = "Randomly picks an installed Steam game!" readme = "README.md" homepage = "https://github.com/ShadowMitia/steam_randomiser" repository = "https://github.com/ShadowMitia/steam_randomiser" @@ -15,10 +15,11 @@ categories = ["command-line-utilities"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dirs = "3.0.1" +dirs = "4.0.0" rand = "0.8.3" which = "4.1.0" -clap = "3.0.0-beta.2" +clap = "3.0.0-beta.5" + [profile.release] lto = true diff --git a/README.md b/README.md index 3a5016d..68a9464 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,11 @@ # Steam Randomiser -[![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=shadowmitia&repo=steam_randomiser)](https://github.com/anuraghazra/github-readme-stats) +[![license shields.io](https://img.shields.io/github/license/shadowMitia/steam_randomiser)](https://github.com/ShadowMitia/steam_randomiser/blob/master/LICENSE.txt) +[![GitHub stars badge shields.io](https://img.shields.io/github/stars/shadowMitia/steam_randomiser)](https://github.com/shadowMitia/steam_randomiser) Don't know what to play on [Steam](https://store.steampowered.com/)? -Just run `Steam Randomiser` and it will randomly choose from one of your **installed** games! - -Perfect when you don't know which game to play from all of those bundles you've bought all these years! +Just run [`Steam Randomiser`](https://github.com/shadowMitia/steam_randomiser) and it will randomly choose from one of your (numerous) **installed** games! ### Installation @@ -29,11 +28,11 @@ And then play your awesome and randomly picked game! #### Supported systems -| | Vanilla | Flatpak | -| ------- | :-----: | ------: | -| Windows | ✅ | N/A | -| MacOS | ❌ | N/A | -| Linux | ✅ | ✅ | +| | Vanilla | Flatpak | +| ------- | :---------------------: | ------: | +| Windows | ✅ | N/A | +| MacOS | ❌ (experimental build) | N/A | +| Linux | ✅ | ✅ | ## Development diff --git a/src/main.rs b/src/main.rs index 542ad6d..d40a819 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,19 +1,19 @@ -use clap::{AppSettings, Clap}; +use clap::Parser; use rand::seq::SliceRandom; -use std::{ - fs::DirEntry, - path::{Path, PathBuf}, - process::{Child, Command, Stdio}, -}; +use std::{fs::DirEntry, path::{Path, PathBuf}, process::{Child, Command, Stdio}}; const FLATPAK_APPLICATIONS_PATH: &str = ".var/app/com.valvesoftware.Steam/data/Steam"; #[cfg(target_os = "linux")] -const VANILLA_APPLICATIONS_PATH: &str = r#".local/share/Steam"#; +const VANILLA_APPLICATIONS_PATHS: [&str; 2] = [ + r#".local/share/steam"#, + r#".steam/steam"# +]; #[cfg(target_os = "windows")] const VANILLA_APPLICATIONS_PATH: &str = r#"C:\Program Files (x86)\Steam"#; #[cfg(target_os = "macos")] const VANILLA_APPLICATIONS_PATH: &str = r#"Library/Application Support/Steam"#; +const VERSION: &str = env!("CARGO_PKG_VERSION"); const MANIFEST_DIR: &str = "steamapps/"; @@ -45,33 +45,53 @@ fn is_blacklisted(app_name: &str) -> bool { ]; steam_libs.iter().any(|&b| b == app_name) - || app_name.ends_with("Soundtrack") // This **should** deal with downloaded albums + || app_name.ends_with("Soundtrack") // This **should** deal with downloaded albums, and ignore them || is_proton(app_name) || app_name.starts_with("Steam Linux Runtime") } +// fn parse_vdf(path_to_vdf: &Path) -> HashMap { +// let mut res = HashMap::new(); + +// let contents = std::fs::read_to_string(path_to_vdf); +// let lines = contents.unwrap(); +// let lines:Vec<&str> = lines.lines().collect(); + +// for line in 0..lines.len() { +// println!("Working on {:?}", lines[line]); +// if line+1 < lines.len() && lines[line+1].trim() == "{" { + +// } else{ +// let key_value:Vec<&str> = lines[line].split_whitespace().collect(); +// if key_value.len() < 2 { +// continue; +// } +// println!("splitted {:?}", key_value); +// res.insert(key_value[0].to_string(), key_value[1].to_string()); + +// } +// } + +// res +// } + /// Find other install directories which are not the default one fn get_other_install_dirs(path: &Path) -> Vec { let mut path = path.to_path_buf(); path.push("libraryfolders.vdf"); + let path = path.as_path(); + let contents = std::fs::read_to_string(path); let lines = contents.unwrap(); let mut libs = Vec::new(); - // NOTE: I'm assuming that after the "TimeNextStatsReport" and "ContentStatsID" come the alternative paths - let lines = lines.lines().skip(2).collect::>(); - for line in lines.iter().take(lines.len() - 1) { - let path = line - .split('\t') - .filter(|s| !s.is_empty()) - .collect::>(); - - let tag = path[0].replace("\"", ""); - let path = path[1].trim().replace("\"", ""); - if tag.chars().all(|c| c.is_digit(10)) { - libs.push(path.to_string()); + let lines = lines.lines(); + for line in lines { + if line.contains("path") { + let splitted:Vec<&str> = line.split_whitespace().collect(); + libs.push(splitted[1][1..splitted[1].len()-1].to_string()); } } libs @@ -234,11 +254,10 @@ fn run(steam_type: SteamKind, id: &str) -> std::io::Result { } /// Randomly picks an installed game from your Steam library and launches it. -#[derive(Clap)] +#[derive(Parser)] #[clap( - version = "0.2.0" + version = VERSION )] -#[clap(setting = AppSettings::ColoredHelp)] struct Opts { /// Show short message telling which game is being launched #[clap(short, long, parse(from_occurrences))] @@ -262,6 +281,13 @@ fn main() { let mut home = dirs::home_dir().unwrap(); match steam_type { SteamKind::Flatpak => home.push(FLATPAK_APPLICATIONS_PATH), + #[cfg(target_os = "linux")] + SteamKind::Vanilla => home.push(VANILLA_APPLICATIONS_PATHS.iter().find(|&&p| { + let mut test_path = home.to_path_buf(); + test_path.push(p); + test_path.exists() && test_path.is_dir() + }).unwrap()), + #[cfg(not(target_os = "linux"))] SteamKind::Vanilla => home.push(VANILLA_APPLICATIONS_PATH), _ => {} }