diff --git a/src-tauri/src/commands/config.rs b/src-tauri/src/commands/config.rs index d212876..091b190 100644 --- a/src-tauri/src/commands/config.rs +++ b/src-tauri/src/commands/config.rs @@ -1,5 +1,6 @@ use std::path::Path; +use crate::util::os::get_installed_vcc_runtime; use crate::{config::LauncherConfig, util::file::delete_dir}; use semver::Version; use sysinfo::Disks; @@ -118,48 +119,15 @@ pub async fn is_diskspace_requirement_met( pub async fn is_minimum_vcc_runtime_installed( _config: tauri::State<'_, tokio::sync::Mutex>, ) -> Result { - use log::info; - use winreg::{ - enums::{HKEY_LOCAL_MACHINE, KEY_READ}, - RegKey, - }; - let hklm = RegKey::predef(HKEY_LOCAL_MACHINE); - let path = r"SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64"; - - if let Ok(key) = hklm.open_subkey_with_flags(path, KEY_READ) { - let installed_value: u32 = key.get_value("Installed").map_err(|err| { - log::error!("Couldn't locate VCC runtime registry entry: {}", err); - CommandError::Configuration("Unable to check if VCC runtime is installed".to_owned()) - })?; - let is_installed = installed_value == 1; - if !is_installed { - return Ok(false); - } - let minimum_version = semver::Version::new(14, 40, 33810); - let patch_version: u32 = key.get_value("Bld").map_err(|err| { - log::error!("Couldn't locate VCC runtime registry entry: {}", err); - CommandError::Configuration("Unable to check if VCC runtime is installed".to_owned()) - })?; - let minor_version: u32 = key.get_value("Minor").map_err(|err| { - log::error!("Couldn't locate VCC runtime registry entry: {}", err); - CommandError::Configuration("Unable to check if VCC runtime is installed".to_owned()) - })?; - let major_version: u32 = key.get_value("Major").map_err(|err| { - log::error!("Couldn't locate VCC runtime registry entry: {}", err); - CommandError::Configuration("Unable to check if VCC runtime is installed".to_owned()) - })?; - let installed_version = semver::Version::new( - major_version.into(), - minor_version.into(), - patch_version.into(), - ); - info!("Detected VCC Runtime: {major_version}.{minor_version}.{patch_version}"); - return Ok(installed_version >= minimum_version); + let minimum_version = semver::Version::new(14, 40, 33810); + let installed_vcc_runtime_version = get_installed_vcc_runtime(); + if installed_vcc_runtime_version.is_none() { + Err(CommandError::Configuration( + "Unable to check if VCC runtime is installed".to_owned(), + )) + } else { + Ok(installed_vcc_runtime_version.unwrap() >= minimum_version) } - - return Err(CommandError::Configuration( - "Unable to check if minimum VCC runtime is installed".to_owned(), - )); } #[cfg(target_os = "linux")] diff --git a/src-tauri/src/commands/support.rs b/src-tauri/src/commands/support.rs index 718bbfd..884176f 100644 --- a/src-tauri/src/commands/support.rs +++ b/src-tauri/src/commands/support.rs @@ -14,8 +14,9 @@ use tauri::api::path::config_dir; use crate::{ config::LauncherConfig, - util::zip::{ - append_dir_contents_to_zip, append_file_to_zip, check_if_zip_contains_top_level_file, + util::{ + os::get_installed_vcc_runtime, + zip::{append_dir_contents_to_zip, append_file_to_zip, check_if_zip_contains_top_level_file}, }, }; @@ -69,6 +70,7 @@ impl PerGameInfo { #[derive(Default, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct SupportPackage { + pub installed_vcc_runtime: Option, pub total_memory_megabytes: u64, pub cpu_name: String, pub cpu_vendor: String, @@ -283,6 +285,12 @@ pub async fn generate_support_package( // System Information let mut system_info = System::new_all(); system_info.refresh_all(); + let installed_vcc_runtime_version = get_installed_vcc_runtime(); + if installed_vcc_runtime_version.is_none() { + package.installed_vcc_runtime = None; + } else { + package.installed_vcc_runtime = Some(installed_vcc_runtime_version.unwrap().to_string()); + } package.total_memory_megabytes = system_info.total_memory() / 1024 / 1024; package.cpu_name = system_info.cpus()[0].name().to_string(); package.cpu_vendor = system_info.cpus()[0].vendor_id().to_string(); diff --git a/src-tauri/src/util/os.rs b/src-tauri/src/util/os.rs index 318ea95..2011f85 100644 --- a/src-tauri/src/util/os.rs +++ b/src-tauri/src/util/os.rs @@ -11,3 +11,71 @@ pub fn open_dir_in_os(dir: String) -> Result<(), std::io::Error> { Command::new(FILE_OPENING_PROGRAM).arg(dir).spawn()?; Ok(()) } + +#[cfg(not(target_os = "windows"))] +pub fn get_installed_vcc_runtime() -> Option { + return None; +} + +#[cfg(target_os = "windows")] +pub fn get_installed_vcc_runtime() -> Option { + use winreg::{ + enums::{HKEY_LOCAL_MACHINE, KEY_READ}, + RegKey, + }; + let hklm = RegKey::predef(HKEY_LOCAL_MACHINE); + let path = r"SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64"; + + if let Ok(key) = hklm.open_subkey_with_flags(path, KEY_READ) { + match key.get_value::("Installed") { + Ok(val) => { + if val != 1 { + log::error!("VCC runtime exists in the registry but is not marked as installed"); + return None; + } + } + Err(err) => { + log::error!("Couldn't determine if VCC runtime was installed: {}", err); + return None; + } + }; + let patch_version: u32 = match key.get_value("Bld") { + Ok(val) => val, + Err(err) => { + log::error!( + "Couldn't determine installed VCC runtime patch version: {}", + err + ); + return None; + } + }; + let minor_version: u32 = match key.get_value("Minor") { + Ok(val) => val, + Err(err) => { + log::error!( + "Couldn't determine installed VCC runtime minor version: {}", + err + ); + return None; + } + }; + let major_version: u32 = match key.get_value("Major") { + Ok(val) => val, + Err(err) => { + log::error!( + "Couldn't determine installed VCC runtime major version: {}", + err + ); + return None; + } + }; + let installed_version = semver::Version::new( + major_version.into(), + minor_version.into(), + patch_version.into(), + ); + log::info!("Detected VCC Runtime: {major_version}.{minor_version}.{patch_version}"); + return Some(installed_version); + } + return None; +} diff --git a/src/routes/Game.svelte b/src/routes/Game.svelte index 483a8fa..949cdde 100644 --- a/src/routes/Game.svelte +++ b/src/routes/Game.svelte @@ -237,7 +237,7 @@ {$_("gameControls_beta_bugReport_linkPreText")} {$_("gameControls_beta_bugReport_linkText")}