From 6ff44a8137de7870509f0837d3e149aa13c79d3e Mon Sep 17 00:00:00 2001 From: dark0dave Date: Sat, 11 Jan 2025 13:23:05 +0000 Subject: [PATCH] feat(weidu): Auto detect weidu bin Signed-off-by: dark0dave --- Cargo.lock | 188 ++++++++++++++++++++++++++++++++++++++++++++----- Cargo.toml | 4 +- README.md | 14 +++- fixtures/weidu | 0 src/args.rs | 42 ++++++++++- src/main.rs | 8 ++- 6 files changed, 233 insertions(+), 23 deletions(-) mode change 100644 => 100755 fixtures/weidu diff --git a/Cargo.lock b/Cargo.lock index 94d2427..809d777 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,9 +62,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "1be3f42a67d6d345ecd59f675f3f012d6974981560836e938c22b424b85ce1be" [[package]] name = "cfg-if" @@ -74,9 +74,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.5.23" +version = "4.5.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" +checksum = "a8eb5e908ef3a6efbe1ed62520fb7287959888c88485abe072543190ecc66783" dependencies = [ "clap_builder", "clap_derive", @@ -84,9 +84,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.23" +version = "4.5.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" +checksum = "96b01801b5fc6a0a232407abc821660c9c6d25a1cafc0d4f85f29fb8d9afc121" dependencies = [ "anstream", "anstyle", @@ -96,9 +96,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.18" +version = "4.5.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c" dependencies = [ "heck", "proc-macro2", @@ -186,6 +186,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "erased-serde" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24e2389d65ab4fab27dc2a5de7b191e1f6617d1f1c8855c0dc569c94a4cbb18d" +dependencies = [ + "serde", + "typeid", +] + [[package]] name = "fs_extra" version = "1.3.0" @@ -237,6 +247,12 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itoa" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" + [[package]] name = "libc" version = "0.2.169" @@ -255,9 +271,12 @@ dependencies = [ [[package]] name = "log" -version = "0.4.22" +version = "0.4.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "3d6ea2a48c204030ee31a7d7fc72c93294c92fe87ecb1789881c9543516e1a0d" +dependencies = [ + "value-bag", +] [[package]] name = "memchr" @@ -267,7 +286,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mod_installer" -version = "9.0.2" +version = "9.1.0" dependencies = [ "clap", "confy", @@ -298,9 +317,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" dependencies = [ "unicode-ident", ] @@ -354,6 +373,12 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + [[package]] name = "same-file" version = "1.0.6" @@ -383,6 +408,15 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_fmt" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d4ddca14104cd60529e8c7f7ba71a2c8acd8f7f5cfcdc2faf97eeb7c3010a4" +dependencies = [ + "serde", +] + [[package]] name = "serde_spanned" version = "0.6.8" @@ -398,11 +432,89 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "sval" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6dc0f9830c49db20e73273ffae9b5240f63c42e515af1da1fceefb69fceafd8" + +[[package]] +name = "sval_buffer" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "429922f7ad43c0ef8fd7309e14d750e38899e32eb7e8da656ea169dd28ee212f" +dependencies = [ + "sval", + "sval_ref", +] + +[[package]] +name = "sval_dynamic" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f16ff5d839396c11a30019b659b0976348f3803db0626f736764c473b50ff4" +dependencies = [ + "sval", +] + +[[package]] +name = "sval_fmt" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c01c27a80b6151b0557f9ccbe89c11db571dc5f68113690c1e028d7e974bae94" +dependencies = [ + "itoa", + "ryu", + "sval", +] + +[[package]] +name = "sval_json" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0deef63c70da622b2a8069d8600cf4b05396459e665862e7bdb290fd6cf3f155" +dependencies = [ + "itoa", + "ryu", + "sval", +] + +[[package]] +name = "sval_nested" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a39ce5976ae1feb814c35d290cf7cf8cd4f045782fe1548d6bc32e21f6156e9f" +dependencies = [ + "sval", + "sval_buffer", + "sval_ref", +] + +[[package]] +name = "sval_ref" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb7c6ee3751795a728bc9316a092023529ffea1783499afbc5c66f5fabebb1fa" +dependencies = [ + "sval", +] + +[[package]] +name = "sval_serde" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a5572d0321b68109a343634e3a5d576bf131b82180c6c442dee06349dfc652a" +dependencies = [ + "serde", + "sval", + "sval_nested", +] + [[package]] name = "syn" -version = "2.0.94" +version = "2.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "987bc0be1cdea8b10216bd06e2ca407d40b9543468fafd3ddfb02f36e77f71f3" +checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" dependencies = [ "proc-macro2", "quote", @@ -463,6 +575,12 @@ dependencies = [ "winnow", ] +[[package]] +name = "typeid" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e13db2e0ccd5e14a544e8a246ba2312cd25223f616442d7f2cb0e3db614236e" + [[package]] name = "unicode-ident" version = "1.0.14" @@ -475,6 +593,42 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "value-bag" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ef4c4aa54d5d05a279399bfa921ec387b7aba77caf7a682ae8d86785b8fdad2" +dependencies = [ + "value-bag-serde1", + "value-bag-sval2", +] + +[[package]] +name = "value-bag-serde1" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bb773bd36fd59c7ca6e336c94454d9c66386416734817927ac93d81cb3c5b0b" +dependencies = [ + "erased-serde", + "serde", + "serde_fmt", +] + +[[package]] +name = "value-bag-sval2" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a916a702cac43a88694c97657d449775667bcd14b70419441d05b7fea4a83a" +dependencies = [ + "sval", + "sval_buffer", + "sval_dynamic", + "sval_fmt", + "sval_json", + "sval_ref", + "sval_serde", +] + [[package]] name = "walkdir" version = "2.5.0" @@ -641,9 +795,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.22" +version = "0.6.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39281189af81c07ec09db316b302a3e67bf9bd7cbf6c820b50e35fee9c2fa980" +checksum = "c8d71a593cc5c42ad7876e2c1fda56f314f3754c084128833e64f1345ff8a03a" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index d770d0c..e7d0ee2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mod_installer" -version = "9.0.2" +version = "9.1.0" edition = "2021" authors = [ "dark0dave" ] documentation = "https://raw.githubusercontent.com/dark0dave/mod_installer/main/README.md" @@ -20,7 +20,7 @@ keywords = [ [dependencies] confy = "^0.6" -clap = { version = "^4.5.9", features = ["derive", "env"] } +clap = { version = "^4.5.9", features = ["derive", "env", "string"] } env_logger = "^0.11.1" fs_extra = "^1.3.0" log = "^0.4.22" diff --git a/README.md b/README.md index eacf0af..7d72ddf 100644 --- a/README.md +++ b/README.md @@ -43,10 +43,22 @@ Let's break down what each part means: * --game-directory : This is where you tell the program where your game is installed. -* --weidu-binary : This is where you tell the program where to find the WeiDU program (WeiDU is a tool used to install mods). +* --weidu-binary : This is where you tell the program where to find the WeiDU program (WeiDU is a tool used to install mods). This binary can be auto detected (alpha feature). * --mod-directories : This is where you tell the program where to find the mod files. +### Example Run + +With binary or installed from cargo +```sh +mod_installer(.exe) --log-file dark0dave_weidu.log --game-directory ~/.steam/steam/steamapps/common/Baldur\'s\ Gate\ Enhanced\ Edition/ --mod-directories ~/Downloads/my_mods/ +``` + +With cargo: +```sh +cargo run -- --log-file dark0dave_weidu.log --game-directory ~/.steam/steam/steamapps/common/Baldur\'s\ Gate\ Enhanced\ Edition/ --mod-directories ~/Downloads/my_mods/ +``` + ## FAQ The Infinity Engine Mod Installer looks at a "weidu.log" file that you provide. This file contains information about mods you want to install. The tool then goes through this list and installs each mod automatically. This saves you time and effort, as you don't have to manually install each mod one by one. diff --git a/fixtures/weidu b/fixtures/weidu old mode 100644 new mode 100755 diff --git a/src/args.rs b/src/args.rs index 8a00593..3e6049c 100644 --- a/src/args.rs +++ b/src/args.rs @@ -1,6 +1,7 @@ +use std::env::{split_paths, var_os}; use std::path::PathBuf; -use clap::{builder::BoolishValueParser, Parser}; +use clap::{builder::BoolishValueParser, builder::OsStr, Parser}; pub(crate) const CARGO_PKG_NAME: &str = env!("CARGO_PKG_NAME"); @@ -12,6 +13,12 @@ Please provide a valid weidu logging setting, options are: --weidu-log-mode log-extern also log output from commands invoked by WeiDU "; +#[cfg(not(target_os = "windows"))] +pub(crate) const WEIDU_FILE_NAME: &str = "weidu"; +#[cfg(target_os = "windows")] +pub(crate) const WEIDU_FILE_NAME: &str = "weidu.exe"; + +// https://docs.rs/clap/latest/clap/_derive/index.html#arg-attributes #[derive(Parser, Debug, PartialEq)] #[clap(author, version, about, long_about = None)] pub struct Args { @@ -24,7 +31,14 @@ pub struct Args { pub game_directory: PathBuf, /// Absolute Path to weidu binary - #[clap(env, short, long, value_parser = parse_absolute_path, required = true)] + #[clap( + env, + short, + long, + value_parser = parse_absolute_path, + default_missing_value = find_weidu_bin_on_path(), + required = weidu_bin_not_on_path() + )] pub weidu_binary: PathBuf, /// Path to mod directories @@ -128,6 +142,30 @@ fn parse_absolute_path(arg: &str) -> Result { } } +fn weidu_bin_not_on_path() -> bool { + if let Some(paths) = var_os("PATH") { + for path in split_paths(&paths) { + let full_path = path.join(WEIDU_FILE_NAME); + if full_path.is_file() { + return false; + } + } + } + true +} + +fn find_weidu_bin_on_path() -> OsStr { + if let Some(paths) = var_os("PATH") { + for path in split_paths(&paths) { + let full_path = path.join(WEIDU_FILE_NAME); + if full_path.is_file() { + return OsStr::from(full_path.into_os_string()); + } + } + } + OsStr::from("") +} + #[cfg(test)] mod tests { diff --git a/src/main.rs b/src/main.rs index 4801ff2..c4200d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,13 @@ fn main() -> ExitCode { \/ \/\___/ \__,_| |_|_| |_|___/\__\__,_|_|_|\___|_| " ); - let args = Args::parse(); + let args = match Args::try_parse() { + Ok(args) => args, + Err(err) => { + log::error!("Could not parse args, {}", err); + return ExitCode::FAILURE; + } + }; let parser_config: Arc = match confy::load(CARGO_PKG_NAME, "config") { Ok(config) => Arc::new(config), Err(err) => {