-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds options to start and stop steam when importing
- Loading branch information
Showing
9 changed files
with
110 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use std::{path::Path, process::Command, thread::sleep, time::Duration}; | ||
|
||
use sysinfo::{ProcessExt, System, SystemExt}; | ||
|
||
pub fn ensure_steam_stopped() { | ||
#[cfg(target_os = "windows")] | ||
let steam_name = "steam.exe"; | ||
#[cfg(target_family = "unix")] | ||
let steam_name = "steam"; | ||
|
||
let s = System::new_all(); | ||
let processes = s.processes_by_name(&steam_name); | ||
for process in processes { | ||
let mut s = System::new(); | ||
process.kill_with(sysinfo::Signal::Quit); | ||
process.kill_with(sysinfo::Signal::Kill); | ||
while s.refresh_process(process.pid()) { | ||
println!("Waiting for steam to stop"); | ||
sleep(Duration::from_millis(500)); | ||
process.kill_with(sysinfo::Signal::Quit); | ||
process.kill_with(sysinfo::Signal::Kill); | ||
} | ||
} | ||
} | ||
#[cfg(target_os = "windows")] | ||
pub fn ensure_steam_started(settings: &super::SteamSettings) { | ||
let steam_name = "steam.exe"; | ||
let s = System::new_all(); | ||
let mut processes = s.processes_by_name(&steam_name); | ||
if processes.next().is_none() { | ||
//no steam, we need to start it | ||
println!("Starting steam"); | ||
let folder = super::get_steam_path(settings); | ||
if let Ok(folder) = folder { | ||
let path = Path::new(&folder).join(steam_name); | ||
let mut command = Command::new(&path); | ||
if let Err(e) = command.spawn() { | ||
println!("Failed to start steam: {:?}", e); | ||
}; | ||
} | ||
} | ||
} | ||
|
||
#[cfg(target_family = "unix")] | ||
pub fn ensure_steam_started(_settings: &super::SteamSettings) { | ||
let steam_name = "steam"; | ||
let s = System::new_all(); | ||
let mut processes = s.processes_by_name(&steam_name); | ||
if processes.next().is_none() { | ||
//no steam, we need to start it | ||
println!("Starting steam"); | ||
let mut command = Command::new(&steam_name); | ||
if let Err(e) = command.spawn() { | ||
println!("Failed to start steam: {:?}", e); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters