Skip to content

Commit

Permalink
powershell path
Browse files Browse the repository at this point in the history
  • Loading branch information
cangzhang committed Feb 16, 2024
1 parent 414ce48 commit 4a9c451
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/lcu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ flate2 = "1.0.28"
tar = "0.4.40"
femme = "2.2.1"
kv-log-macro = "1.0.7"
powershell_script = "1.1.0"
47 changes: 19 additions & 28 deletions crates/lcu/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ lazy_static! {
static ref REGION_REGEXP: regex::Regex = regex::Regex::new(r"--region=\S+").unwrap();
static ref DIR_REGEXP: regex::Regex =
regex::Regex::new(r#"--install-directory=(.*?)""#).unwrap();
static ref MAC_DIR_REGEXP: regex::Regex = regex::Regex::new(r"--install-directory=([^\s]+).*?--").unwrap();
static ref MAC_DIR_REGEXP: regex::Regex =
regex::Regex::new(r"--install-directory=([^\s]+).*?--").unwrap();
}

pub fn make_auth_url(token: &String, port: &String) -> String {
Expand All @@ -38,33 +39,23 @@ pub struct CommandLineOutput {

#[cfg(target_os = "windows")]
pub fn get_commandline() -> CommandLineOutput {
use std::{os::windows::process::CommandExt, process::Command};

match Command::new("powershell")
.args([
"-ExecutionPolicy",
"Bypass",
"-NoLogo",
"-NoProfile",
"-NonInteractive",
"-WindowStyle",
"Hidden",
"-Command",
LCU_COMMAND,
])
.creation_flags(0x08000000)
.output()
{
Ok(output) => {
if output.status.success() {
let output = String::from_utf8_lossy(&output.stdout);

#[cfg(not(debug_assertions))]
info!("output: {:?}", &output);

if !output.is_empty() {
return match_stdout(&String::from(output));
}
use powershell_script::PsScriptBuilder;

let ps = PsScriptBuilder::new()
.no_profile(true)
.non_interactive(true)
.hidden(true)
.print_commands(false)
.build();

match ps.run(LCU_COMMAND) {
Ok(out) => {
let output = out.stdout();

#[cfg(not(debug_assertions))]
info!("output: {:?}", &output);
if output.is_some() {
return match_stdout(&String::from(output.unwrap()));
}
}
Err(err) => error!("cmd error: {:?}", err),
Expand Down

0 comments on commit 4a9c451

Please sign in to comment.