Skip to content
This repository was archived by the owner on Dec 29, 2024. It is now read-only.

Commit

Permalink
feat: can now wait for login, added README.md
Browse files Browse the repository at this point in the history
misc: renamed to steamed
  • Loading branch information
Fodor Levente committed Dec 31, 2021
1 parent 7bcbe05 commit 61962b1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 37 deletions.
28 changes: 14 additions & 14 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,5 +1,5 @@
[package]
name = "learn-rust"
name = "steamed"
description = "Awesomeness"
version = "0.1.0"
edition = "2021"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Steamed
37 changes: 24 additions & 13 deletions src/auto_steam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ pub mod auto_steam {

pub(super) trait MyPrivateRegTraits {
fn get_running_appid(&self) -> u32;
fn get_current_userid(&self) -> u32;
fn get_steam_pid(&self) -> usize;
fn get_app_running_value(&self, app_reg: &RegKey) -> u32;
fn get_app_updating_value(&self, app_reg: &RegKey) -> u32;
fn get_app_installed_value(&self, app_reg: &RegKey) -> u32;
fn get_app_name_value(&self, app_reg: &RegKey) -> u32;
fn create_new_command(&self) -> Command;
fn create_new_steam_command(&self) -> Command;
fn handle_a_game_is_already_running(&self);
}
}
Expand All @@ -58,6 +59,11 @@ pub mod auto_steam {
return running;
}

fn get_current_userid(&self) -> u32 {
let userid: u32 = self.active_process_reg_key.get_value("ActiveUser").unwrap();
return userid;
}

fn get_steam_pid(&self) -> usize {
let pid: u32 = self.active_process_reg_key.get_value("pid").unwrap();
return pid as usize;
Expand All @@ -83,7 +89,7 @@ pub mod auto_steam {
return name;
}

fn create_new_command(&self) -> Command {
fn create_new_steam_command(&self) -> Command {
let mut command = Command::new(&self.steam_path);
command.stdin(Stdio::null())
.stdout(Stdio::null())
Expand All @@ -107,6 +113,7 @@ pub mod auto_steam {
}

pub trait MyRegTraits {
fn wait_for_login(&self) -> bool;
fn wait_for_game_start(&self, app_id: &str) -> bool;
fn wait_for_game_exit(&self, app_id: &str) -> ();
fn list_installed_and_choose(&self) -> String;
Expand All @@ -118,6 +125,17 @@ pub mod auto_steam {
}

impl MyRegTraits for MyRegVars {
fn wait_for_login(&self) -> bool {
if self.get_current_userid() != 0 { return true; }

let now = Instant::now();
loop {
watch_reg(&self.active_process_reg_key, 3000);
if self.get_current_userid() != 0 { return true; }
if now.elapsed().as_secs() > 60 { return false; }
}
}

fn wait_for_game_start(&self, appid: &str) -> bool {
let app_reg_key = self.apps_reg_key
.open_subkey(appid)
Expand Down Expand Up @@ -193,7 +211,7 @@ pub mod auto_steam {
}

fn shut_down_steam(&self) -> Child {
return self.create_new_command()
return self.create_new_steam_command()
.arg("-shutdown")
.spawn()
.expect("Something went wrong when shutting down steam.exe");
Expand Down Expand Up @@ -222,21 +240,14 @@ pub mod auto_steam {
}

fn start_steam_login(&self, user: &str, pass: &str, appid: &str) -> Child {
return self.create_new_command()
.args([
"-silent",
"-login",
user,
pass,
"-applaunch",
appid
])
return self.create_new_steam_command()
.args(["-silent", "-login", user, pass, "-applaunch", appid])
.spawn()
.expect("Something went wrong when starting steam.exe");
}

fn start_steam(&self) -> Child {
return self.create_new_command()
return self.create_new_steam_command()
.spawn()
.expect("Something went wrong when starting steam.exe");
}
Expand Down
22 changes: 13 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,22 @@ fn main() {
// I could shut down asynchronously, make choice and then await the async shutdown
auto_steam.shutdown_steam_if_running();

// todo: check if login successful, by registry attribute of CurrentUserID or something
let mut main_child = auto_steam.start_steam_login(&user, &pass, &appid);

if auto_steam.wait_for_game_start(&appid) {
auto_steam.wait_for_game_exit(&appid);
auto_steam.shut_down_steam()
.wait()
.expect("failed to wait on child");
main_child.wait().expect("failed to wait on child");
auto_steam.start_steam();
if auto_steam.wait_for_login() {
if auto_steam.wait_for_game_start(&appid) {
auto_steam.wait_for_game_exit(&appid);
auto_steam.shut_down_steam()
.wait()
.expect("failed to wait on child");
main_child.wait().expect("failed to wait on child");
auto_steam.start_steam();
} else {
println!("wait_for_game_start was false");
main_child.wait().expect("failed to wait on child");
}
} else {
println!("wait_for_game_start was false");
println!("wait_for_login was false");
main_child.wait().expect("failed to wait on child");
}
}

0 comments on commit 61962b1

Please sign in to comment.