Skip to content

Commit

Permalink
support: put installed VCC runtime version in support package (#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
xTVaser authored Oct 3, 2024
1 parent 9edab84 commit 17e2871
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 44 deletions.
50 changes: 9 additions & 41 deletions src-tauri/src/commands/config.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<LauncherConfig>>,
) -> Result<bool, CommandError> {
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")]
Expand Down
12 changes: 10 additions & 2 deletions src-tauri/src/commands/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
};

Expand Down Expand Up @@ -69,6 +70,7 @@ impl PerGameInfo {
#[derive(Default, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SupportPackage {
pub installed_vcc_runtime: Option<String>,
pub total_memory_megabytes: u64,
pub cpu_name: String,
pub cpu_vendor: String,
Expand Down Expand Up @@ -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();
Expand Down
68 changes: 68 additions & 0 deletions src-tauri/src/util/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<semver::Version> {
return None;
}

#[cfg(target_os = "windows")]
pub fn get_installed_vcc_runtime() -> Option<semver::Version> {
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::<u32, _>("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;
}
2 changes: 1 addition & 1 deletion src/routes/Game.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
{$_("gameControls_beta_bugReport_linkPreText")}
<a
class="text-blue-400"
href="https://github.com/open-goal/jak-project/issues/new?assignees=&labels=bug%2Cjak2&projects=&template=jak2-bug-report.yml"
href="https://github.com/open-goal/jak-project/issues/new?template=jak2-bug-report.yml"
target="_blank"
rel="noopener noreferrer"
>{$_("gameControls_beta_bugReport_linkText")}</a
Expand Down

0 comments on commit 17e2871

Please sign in to comment.