diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 549844c..90d0977 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -10,17 +10,18 @@ edition = "2018" build = "src/build.rs" [dependencies] -attohttpc = { version = "0.16", features = [ "json" ] } +attohttpc = { version = "0.18", features = [ "json" ] } chrono = "0.4" crossbeam-channel = "0.5" -dirs = "3.0" +dirs = "4.0" log = "0.4" -serde_json = "1.0" serde = { version = "1.0", features = [ "derive" ] } -simplelog = "0.8" -tauri = { version = "0.9", features = [ "all-api" ] } +serde_json = "1.0" +simconnect = "0.1" +simplelog = "0.11" +tauri = { version = "0.11", features = [ "all-api" ] } winapi = "0.3" -winreg = "0.7" +winreg = "0.10" zip = "0.5" [target."cfg(windows)".build-dependencies] diff --git a/src-tauri/src/installer.rs b/src-tauri/src/installer.rs index 7527c9d..ddd3aa7 100644 --- a/src-tauri/src/installer.rs +++ b/src-tauri/src/installer.rs @@ -297,6 +297,16 @@ impl Installer { Ok(()) } + pub fn error_for_sim_running(&self) -> Result<(), Error> { + let mut conn = simconnect::SimConnector::new(); + + if conn.connect("YourControlsInstaller") { + return Err(Error::SimRunning); + } + + Ok(()) + } + pub fn install_sequence( &mut self, contents: &mut ZipArchive>>, diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 6827849..dbf37b9 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -216,7 +216,10 @@ fn main() { } } // Download and install - let result = match downloader.download_release() { + let result = match installer + .error_for_sim_running() + .and_then(|_| downloader.download_release()) + { Ok(mut zip) => installer.install_sequence( &mut zip, &selected_features, diff --git a/src-tauri/src/util.rs b/src-tauri/src/util.rs index 3411033..d3484cd 100644 --- a/src-tauri/src/util.rs +++ b/src-tauri/src/util.rs @@ -13,6 +13,7 @@ pub enum Error { ReleaseError, WebError(attohttpc::Error), ZipError(zip::result::ZipError), + SimRunning, } impl std::error::Error for Error {} @@ -34,6 +35,10 @@ impl Display for Error { Error::ReleaseError => write!(f, "Could not fetch release data."), Error::ZipError(e) => write!(f, "Could not read release ZIP file. Reason: {}", e), Error::IOError(e) => write!(f, "An IO error occured. Error: {}", e), + Error::SimRunning => write!( + f, + "Sim is running! Please close the sim to proceed with the install." + ), } } }