mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Restart steam option (#82)
Adds options to start and stop steam when importing
This commit is contained in:
+3
-1
@@ -2,9 +2,11 @@ mod settings;
|
||||
mod utils;
|
||||
mod collections;
|
||||
mod proton_vdf_util;
|
||||
mod restarter;
|
||||
|
||||
|
||||
pub use settings::SteamSettings;
|
||||
pub use utils::*;
|
||||
pub use collections::*;
|
||||
pub use proton_vdf_util::*;
|
||||
pub use proton_vdf_util::*;
|
||||
pub use restarter::*;
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -5,4 +5,6 @@ pub struct SteamSettings {
|
||||
pub location: Option<String>,
|
||||
pub create_collections: bool,
|
||||
pub optimize_for_big_picture: bool,
|
||||
pub stop_steam: bool,
|
||||
pub start_steam: bool,
|
||||
}
|
||||
|
||||
+13
-5
@@ -53,11 +53,7 @@ pub struct SteamUsersInfo {
|
||||
pub fn get_shortcuts_paths(
|
||||
settings: &SteamSettings,
|
||||
) -> Result<Vec<SteamUsersInfo>, Box<dyn Error + Sync + Send>> {
|
||||
let user_location = settings.location.clone();
|
||||
let steam_path_str = match user_location {
|
||||
Some(location) => location,
|
||||
None => get_default_location()?,
|
||||
};
|
||||
let steam_path_str = get_steam_path(settings)?;
|
||||
let steam_path = Path::new(&steam_path_str);
|
||||
if !steam_path.exists() {
|
||||
return Result::Err(Box::new(SteamFolderNotFound {
|
||||
@@ -107,6 +103,15 @@ pub fn get_shortcuts_paths(
|
||||
Ok(users_info)
|
||||
}
|
||||
|
||||
pub fn get_steam_path(settings: &SteamSettings) -> Result<String, Box<dyn Error + Sync + Send>> {
|
||||
let user_location = settings.location.clone();
|
||||
let steam_path_str = match user_location {
|
||||
Some(location) => location,
|
||||
None => get_default_location()?,
|
||||
};
|
||||
Ok(steam_path_str)
|
||||
}
|
||||
|
||||
pub fn get_default_location() -> Result<String, Box<dyn Error + Sync + Send>> {
|
||||
#[cfg(target_os = "windows")]
|
||||
let path_string = {
|
||||
@@ -198,3 +203,6 @@ pub fn get_users_images(user: &SteamUsersInfo) -> Result<Vec<String>, Box<dyn Er
|
||||
.collect();
|
||||
Ok(file_names)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user