Skip to content

Commit

Permalink
feat(weidu): Auto detect weidu bin
Browse files Browse the repository at this point in the history
Signed-off-by: dark0dave <dark0dave@mykolab.com>
  • Loading branch information
dark0dave committed Jan 11, 2025
1 parent 5d19a99 commit bbeb5b4
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 21 deletions.
188 changes: 171 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,22 @@ Let's break down what each part means:

* --game-directory <GAME_DIRECTORY>: This is where you tell the program where your game is installed.

* --weidu-binary <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 <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 <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.
Expand Down
Empty file modified fixtures/weidu
100644 → 100755
Empty file.
28 changes: 27 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env::{split_paths, var_os};
use std::path::PathBuf;

use clap::{builder::BoolishValueParser, Parser};
Expand All @@ -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 {
Expand All @@ -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 = WEIDU_FILE_NAME,
required = weidu_bin_on_path()
)]
pub weidu_binary: PathBuf,

/// Path to mod directories
Expand Down Expand Up @@ -128,6 +142,18 @@ fn parse_absolute_path(arg: &str) -> Result<PathBuf, String> {
}
}

fn weidu_bin_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 true;
}
}
}
false
}

#[cfg(test)]
mod tests {

Expand Down
Loading

0 comments on commit bbeb5b4

Please sign in to comment.