aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan <sentrycraft123@gmail.com>2023-07-18 14:26:20 +0200
committerGitHub <noreply@github.com>2023-07-18 14:26:20 +0200
commit9dccdb0b0335f82aa9f2e63642f16ff0f2699528 (patch)
tree22c4651dd5cafc4375e4cd2a76dccf5e389388c5
parentdfa5af1746546d388a85081fae499c28521a20ea (diff)
downloadFlightCore-9dccdb0b0335f82aa9f2e63642f16ff0f2699528.tar.gz
FlightCore-9dccdb0b0335f82aa9f2e63642f16ff0f2699528.zip
feat: Add basic Proton management (#383)
Adds logic to install, remove, and check existing install of NorthstarProton.
-rw-r--r--src-tauri/Cargo.lock3
-rw-r--r--src-tauri/Cargo.toml4
-rw-r--r--src-tauri/src/main.rs32
-rw-r--r--src-tauri/src/platform_specific/linux.rs75
-rw-r--r--src-vue/src/views/DeveloperView.vue28
5 files changed, 141 insertions, 1 deletions
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index 77064841..968d523b 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -83,6 +83,7 @@ dependencies = [
"chrono",
"const_format",
"dirs",
+ "glob",
"json5",
"libthermite",
"log",
@@ -1987,9 +1988,11 @@ version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27cd844bbc25676cd14fa9ad04cc40e0f3c4d5c66107ef3a99896db1f81324c0"
dependencies = [
+ "flate2",
"json5",
"serde",
"serde_json",
+ "tar",
"thiserror",
"tracing",
"ureq",
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index ed523a4b..63ff51f7 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -33,7 +33,7 @@ steamlocate = "1.2"
# Error messages
anyhow = "1.0"
# libthermite for Northstar/mod install handling
-libthermite = "0.6.5"
+libthermite = { version = "0.6.5", features = ["proton"] }
# zip stuff
zip = "0.6.2"
# Regex
@@ -62,6 +62,8 @@ zip-extract = "0.1.2"
# open urls
open = "3.2.0"
semver = "1.0"
+# simplified filesystem access
+glob = "0.3.1"
dirs = "5"
[target.'cfg(windows)'.dependencies]
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index a584eea9..a295f322 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -144,6 +144,9 @@ fn main() {
mod_management::delete_northstar_mod,
util::get_server_player_count,
mod_management::delete_thunderstore_mod,
+ install_northstar_proton_wrapper,
+ uninstall_northstar_proton_wrapper,
+ get_local_northstar_proton_wrapper_version,
open_repair_window,
thunderstore::query_thunderstore_packages_api,
github::get_list_of_tags,
@@ -525,3 +528,32 @@ pub fn check_is_valid_game_path(game_install_path: &str) -> Result<(), String> {
fn get_host_os() -> String {
env::consts::OS.to_string()
}
+
+/// On Linux attempts to install NorthstarProton
+/// On Windows simply returns an error message
+#[tauri::command]
+async fn install_northstar_proton_wrapper() -> Result<(), String> {
+ #[cfg(target_os = "linux")]
+ return linux::install_ns_proton().map_err(|err| err.to_string());
+
+ #[cfg(target_os = "windows")]
+ Err("Not supported on Windows".to_string())
+}
+
+#[tauri::command]
+async fn uninstall_northstar_proton_wrapper() -> Result<(), String> {
+ #[cfg(target_os = "linux")]
+ return linux::uninstall_ns_proton();
+
+ #[cfg(target_os = "windows")]
+ Err("Not supported on Windows".to_string())
+}
+
+#[tauri::command]
+async fn get_local_northstar_proton_wrapper_version() -> Result<String, String> {
+ #[cfg(target_os = "linux")]
+ return linux::get_local_ns_proton_version();
+
+ #[cfg(target_os = "windows")]
+ Err("Not supported on Windows".to_string())
+}
diff --git a/src-tauri/src/platform_specific/linux.rs b/src-tauri/src/platform_specific/linux.rs
index 4b9964e9..674f384b 100644
--- a/src-tauri/src/platform_specific/linux.rs
+++ b/src-tauri/src/platform_specific/linux.rs
@@ -3,6 +3,81 @@
use regex::Regex;
use std::process::Command;
+fn get_proton_dir() -> Option<String> {
+ let steam_dir = steamlocate::SteamDir::locate()?;
+ let compat_dir = format!("{}/compatibilitytools.d/", steam_dir.path.display());
+
+ Some(compat_dir)
+}
+
+/// Downloads and installs NS proton
+/// Assumes Steam install
+pub fn install_ns_proton() -> Result<(), thermite::prelude::ThermiteError> {
+ // Get latest NorthstarProton release
+ let latest = thermite::core::latest_release()?;
+
+ let temp_dir = std::env::temp_dir();
+ let path = format!("{}/nsproton-{}.tar.gz", temp_dir.display(), latest);
+ let archive = std::fs::File::create(path.clone())?;
+
+ // Download the latest Proton release
+ log::info!("Downloading NorthstarProton to {}", path);
+ thermite::core::download_ns_proton(latest, archive)?;
+ log::info!("Finished Download");
+
+ let compat_dir = get_proton_dir().unwrap();
+ std::fs::create_dir_all(compat_dir.clone())?;
+
+ let finished = std::fs::File::open(path.clone())?;
+
+ // Extract to Proton dir
+ log::info!("Installing NorthstarProton to {}", compat_dir);
+ thermite::core::install_ns_proton(&finished, compat_dir)?;
+ log::info!("Finished Installation");
+ drop(finished);
+
+ std::fs::remove_file(path)?;
+
+ Ok(())
+}
+
+/// Remove NS Proton
+pub fn uninstall_ns_proton() -> Result<(), String> {
+ let compat_dir = get_proton_dir().unwrap();
+ let pattern = format!("{}/NorthstarProton-*", compat_dir);
+ for e in glob::glob(&pattern).expect("Failed to read glob pattern") {
+ std::fs::remove_dir_all(e.unwrap()).unwrap();
+ }
+
+ Ok(())
+}
+
+/// Get the latest installed NS Proton version
+pub fn get_local_ns_proton_version() -> Result<String, String> {
+ let compat_dir = get_proton_dir().unwrap();
+ let ns_prefix = "NorthstarProton-";
+ let pattern = format!("{}/{}*/version", compat_dir, ns_prefix);
+
+ let mut version: String = "".to_string();
+
+ for e in glob::glob(&pattern).expect("Failed to read glob pattern") {
+ let version_content = std::fs::read_to_string(e.unwrap()).unwrap();
+ let version_string = version_content.split(' ').nth(1).unwrap();
+
+ if version_string.starts_with(ns_prefix) {
+ version = version_string[ns_prefix.len()..version_string.len() - 1]
+ .to_string()
+ .clone();
+ }
+ }
+
+ if version.is_empty() {
+ return Err("Northstar Proton is not installed".to_string());
+ }
+
+ Ok(version)
+}
+
pub fn check_glibc_v() -> f32 {
let out = Command::new("/bin/ldd")
.arg("--version")
diff --git a/src-vue/src/views/DeveloperView.vue b/src-vue/src/views/DeveloperView.vue
index 500c9c35..28ab3892 100644
--- a/src-vue/src/views/DeveloperView.vue
+++ b/src-vue/src/views/DeveloperView.vue
@@ -21,6 +21,18 @@
Check NSProton Compatibility
</el-button>
+ <el-button type="primary" @click="installNSProton">
+ Install NSProton
+ </el-button>
+
+ <el-button type="primary" @click="uninstallNSProton">
+ Remove NSProton
+ </el-button>
+
+ <el-button type="primary" @click="getLocalNSProtonVersion">
+ Get local NSProton Version
+ </el-button>
+
<h3>Testing:</h3>
<el-button type="primary" @click="launchGameWithoutChecks">
@@ -308,6 +320,22 @@ export default defineComponent({
notification.close();
});
},
+ async installNSProton() {
+ showNotification(`Started NSProton install`);
+ await invoke("install_northstar_proton_wrapper")
+ .then((message) => { showNotification(`Done`); })
+ .catch((error) => { showNotification(`Error`, error, "error"); })
+ },
+ async uninstallNSProton() {
+ await invoke("uninstall_northstar_proton_wrapper")
+ .then((message) => { showNotification(`Done`); })
+ .catch((error) => { showNotification(`Error`, error, "error"); })
+ },
+ async getLocalNSProtonVersion() {
+ await invoke("get_local_northstar_proton_wrapper_version")
+ .then((message) => { showNotification(`NSProton Version`, message as string); })
+ .catch((error) => { showNotification(`Error`, error, "error"); })
+ },
}
});
</script>