Skip to content

Commit

Permalink
fix(bgt): BGT and EET installs now work
Browse files Browse the repository at this point in the history
Signed-off-by: dark0dave <dark0dave@mykolab.com>
  • Loading branch information
dark0dave committed Apr 14, 2024
1 parent c476620 commit 2bb63a6
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/weidu_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@ use std::{

use crate::{state::State, utils::sleep};

const WEIDU_USEFUL_STATUS: [&str; 8] = [
"copying",
const WEIDU_USEFUL_STATUS: [&str; 9] = [
"copied",
"installing",
"copying",
"creating",
"installed",
"patching",
"installing",
"patched",
"processing",
"patching",
"processed",
"processing",
];

const WEIDU_CHOICE: [&str; 6] = [
const WEIDU_CHOICE: [&str; 7] = [
"choice",
"choose",
"select",
"do you want",
"would you like",
"enter",
"the full path",
];

const WEIDU_CHOICE_SYMBOL: [char; 2] = ['?', ':'];
Expand Down Expand Up @@ -131,10 +133,19 @@ pub fn parse_raw_output(
}

fn string_looks_like_question(weidu_output: &str) -> bool {
let comparable_output = weidu_output.trim().to_lowercase();
if comparable_output.contains("installing") || comparable_output.contains("creating") {
let comparable_output = weidu_output.trim().to_ascii_lowercase();
// installing|creating
if comparable_output.contains(WEIDU_USEFUL_STATUS[2])
|| comparable_output.contains(WEIDU_USEFUL_STATUS[4])
{
return false;
}
// enter.*the full path.*
if comparable_output.contains(WEIDU_CHOICE[WEIDU_CHOICE.len() - 1])
&& comparable_output.starts_with(WEIDU_CHOICE[WEIDU_CHOICE.len() - 2])
{
return true;
}
(WEIDU_CHOICE.contains(&comparable_output.as_str()))
|| WEIDU_CHOICE_SYMBOL.contains(
&comparable_output
Expand Down Expand Up @@ -168,6 +179,7 @@ mod tests {
#[test]
fn test_exit_warnings() {
let test = "INSTALLED WITH WARNINGS Additional equipment for Thieves and Bards";
assert_eq!(string_looks_like_question(test), false);
assert_eq!(
detect_weidu_finished_state(test),
Some(State::CompletedWithWarnings)
Expand All @@ -176,6 +188,7 @@ mod tests {
#[test]
fn test_exit_success() {
let test = "SUCCESSFULLY INSTALLED Jan's Extended Quest";
assert_eq!(string_looks_like_question(test), false);
assert_eq!(detect_weidu_finished_state(test), Some(State::Completed))
}

Expand All @@ -184,4 +197,13 @@ mod tests {
let test = "Creating epilogues. Too many epilogues... Why are there so many options here?";
assert_eq!(string_looks_like_question(test), false)
}

#[test]
fn is_a_question() {
let test = "Enter the full path to your Baldur's Gate installation then press Enter.";
assert_eq!(string_looks_like_question(test), true);
let test = "Enter the full path to your BG:EE+SoD installation then press Enter.\
Example: C:\\Program Files (x86)\\BeamDog\\Games\\00806";
assert_eq!(string_looks_like_question(test), true)
}
}

0 comments on commit 2bb63a6

Please sign in to comment.