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:
Generated
+16
@@ -247,6 +247,7 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"steam_shortcuts_util",
|
"steam_shortcuts_util",
|
||||||
"steamgriddb_api",
|
"steamgriddb_api",
|
||||||
|
"sysinfo",
|
||||||
"tokio",
|
"tokio",
|
||||||
"toml",
|
"toml",
|
||||||
"winreg 0.10.1",
|
"winreg 0.10.1",
|
||||||
@@ -2751,6 +2752,21 @@ dependencies = [
|
|||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sysinfo"
|
||||||
|
version = "0.23.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4eea2ed6847da2e0c7289f72cb4f285f0bd704694ca067d32be811b2a45ea858"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if 1.0.0",
|
||||||
|
"core-foundation-sys 0.8.3",
|
||||||
|
"libc",
|
||||||
|
"ntapi",
|
||||||
|
"once_cell",
|
||||||
|
"rayon",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tempfile"
|
name = "tempfile"
|
||||||
version = "3.3.0"
|
version = "3.3.0"
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ eframe = { version = "0.17.0", optional = true }
|
|||||||
egui = { version = "0.17.0", optional = true }
|
egui = { version = "0.17.0", optional = true }
|
||||||
image = { version = "0.24.1", optional = true, features = ["png"] }
|
image = { version = "0.24.1", optional = true, features = ["png"] }
|
||||||
toml = { version = "^0.5.8", optional = true }
|
toml = { version = "^0.5.8", optional = true }
|
||||||
|
sysinfo = "0.23.10"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
#default = ["ui"]
|
#default = ["ui"]
|
||||||
|
|||||||
@@ -36,4 +36,5 @@ enabled = true
|
|||||||
[steam]
|
[steam]
|
||||||
create_collections = false
|
create_collections = false
|
||||||
optimize_for_big_picture = false
|
optimize_for_big_picture = false
|
||||||
|
stop_steam = false
|
||||||
|
start_steam = false
|
||||||
|
|||||||
@@ -20,10 +20,17 @@ use std::error::Error;
|
|||||||
#[cfg(not(feature = "ui"))]
|
#[cfg(not(feature = "ui"))]
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn Error>> {
|
async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
|
||||||
let settings = settings::Settings::new()?;
|
let settings = settings::Settings::new()?;
|
||||||
|
if settings.steam.stop_steam{
|
||||||
|
crate::steam::ensure_steam_stopped();
|
||||||
|
}
|
||||||
settings::Settings::write_config_if_missing();
|
settings::Settings::write_config_if_missing();
|
||||||
let usersinfo = sync::run_sync(&settings,&mut None).unwrap();
|
let usersinfo = sync::run_sync(&settings,&mut None).unwrap();
|
||||||
sync::download_images(&settings,&usersinfo,&mut None).await;
|
sync::download_images(&settings,&usersinfo,&mut None).await;
|
||||||
|
if settings.steam.start_steam{
|
||||||
|
crate::steam::ensure_steam_started(&settings.steam);
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -2,9 +2,11 @@ mod settings;
|
|||||||
mod utils;
|
mod utils;
|
||||||
mod collections;
|
mod collections;
|
||||||
mod proton_vdf_util;
|
mod proton_vdf_util;
|
||||||
|
mod restarter;
|
||||||
|
|
||||||
|
|
||||||
pub use settings::SteamSettings;
|
pub use settings::SteamSettings;
|
||||||
pub use utils::*;
|
pub use utils::*;
|
||||||
pub use collections::*;
|
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 location: Option<String>,
|
||||||
pub create_collections: bool,
|
pub create_collections: bool,
|
||||||
pub optimize_for_big_picture: 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(
|
pub fn get_shortcuts_paths(
|
||||||
settings: &SteamSettings,
|
settings: &SteamSettings,
|
||||||
) -> Result<Vec<SteamUsersInfo>, Box<dyn Error + Sync + Send>> {
|
) -> Result<Vec<SteamUsersInfo>, Box<dyn Error + Sync + Send>> {
|
||||||
let user_location = settings.location.clone();
|
let steam_path_str = get_steam_path(settings)?;
|
||||||
let steam_path_str = match user_location {
|
|
||||||
Some(location) => location,
|
|
||||||
None => get_default_location()?,
|
|
||||||
};
|
|
||||||
let steam_path = Path::new(&steam_path_str);
|
let steam_path = Path::new(&steam_path_str);
|
||||||
if !steam_path.exists() {
|
if !steam_path.exists() {
|
||||||
return Result::Err(Box::new(SteamFolderNotFound {
|
return Result::Err(Box::new(SteamFolderNotFound {
|
||||||
@@ -107,6 +103,15 @@ pub fn get_shortcuts_paths(
|
|||||||
Ok(users_info)
|
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>> {
|
pub fn get_default_location() -> Result<String, Box<dyn Error + Sync + Send>> {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let path_string = {
|
let path_string = {
|
||||||
@@ -198,3 +203,6 @@ pub fn get_users_images(user: &SteamUsersInfo) -> Result<Vec<String>, Box<dyn Er
|
|||||||
.collect();
|
.collect();
|
||||||
Ok(file_names)
|
Ok(file_names)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ impl MyEguiApp {
|
|||||||
pub fn run_sync(&mut self) {
|
pub fn run_sync(&mut self) {
|
||||||
let (sender,mut reciever ) = watch::channel(SyncProgress::NotStarted);
|
let (sender,mut reciever ) = watch::channel(SyncProgress::NotStarted);
|
||||||
let settings = self.settings.clone();
|
let settings = self.settings.clone();
|
||||||
|
if settings.steam.stop_steam{
|
||||||
|
crate::steam::ensure_steam_stopped();
|
||||||
|
}
|
||||||
|
|
||||||
self.status_reciever = reciever;
|
self.status_reciever = reciever;
|
||||||
self.rt.spawn_blocking(move || {
|
self.rt.spawn_blocking(move || {
|
||||||
|
|
||||||
@@ -55,6 +59,9 @@ impl MyEguiApp {
|
|||||||
if let Some(sender) = some_sender{
|
if let Some(sender) = some_sender{
|
||||||
let _ = sender.send(SyncProgress::Done);
|
let _ = sender.send(SyncProgress::Done);
|
||||||
}
|
}
|
||||||
|
if settings.steam.start_steam{
|
||||||
|
crate::steam::ensure_steam_started(&settings.steam);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,6 +243,8 @@ impl MyEguiApp{
|
|||||||
});
|
});
|
||||||
ui.checkbox(&mut self.settings.steam.create_collections, "Create collections").on_hover_text("Tries to create a games collection for each platform");
|
ui.checkbox(&mut self.settings.steam.create_collections, "Create collections").on_hover_text("Tries to create a games collection for each platform");
|
||||||
ui.checkbox(&mut self.settings.steam.optimize_for_big_picture, "Optimize for big picture").on_hover_text("Set icons to be larger horizontal images, this looks nice in steam big picture mode, but a bit off in desktop mode");
|
ui.checkbox(&mut self.settings.steam.optimize_for_big_picture, "Optimize for big picture").on_hover_text("Set icons to be larger horizontal images, this looks nice in steam big picture mode, but a bit off in desktop mode");
|
||||||
|
ui.checkbox(&mut self.settings.steam.stop_steam, "Stop Steam before import").on_hover_text("Stops Steam if it is running when import starts");
|
||||||
|
ui.checkbox(&mut self.settings.steam.start_steam, "Start Steam after import").on_hover_text("Starts Steam is it is not running after the import");
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user