Skip to content

Commit

Permalink
feat: detect sim running
Browse files Browse the repository at this point in the history
  • Loading branch information
Sequal32 committed Nov 25, 2021
1 parent ee42436 commit 5ffae3c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 10 additions & 0 deletions src-tauri/src/installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cursor<Vec<u8>>>,
Expand Down
5 changes: 4 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src-tauri/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub enum Error {
ReleaseError,
WebError(attohttpc::Error),
ZipError(zip::result::ZipError),
SimRunning,
}

impl std::error::Error for Error {}
Expand All @@ -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."
),
}
}
}
Expand Down

0 comments on commit 5ffae3c

Please sign in to comment.