aboutsummaryrefslogtreecommitdiff
path: root/src-tauri
diff options
context:
space:
mode:
authorGeckoEidechse <gecko.eidechse+git@pm.me>2023-07-23 17:23:51 +0200
committerGeckoEidechse <gecko.eidechse+git@pm.me>2023-07-23 17:23:51 +0200
commite42f0db4cc81549e25f9e663e307606eff75ce53 (patch)
tree91e0d6faf6e02b6d982e9948730b45e2e86acd90 /src-tauri
parent031ced476c38d08f7bec5312c16d1343a24e2469 (diff)
downloadFlightCore-e42f0db4cc81549e25f9e663e307606eff75ce53.tar.gz
FlightCore-e42f0db4cc81549e25f9e663e307606eff75ce53.zip
feat: Add button to DevView to calculate checksums
of files in game install location
Diffstat (limited to 'src-tauri')
-rw-r--r--src-tauri/Cargo.lock44
-rw-r--r--src-tauri/Cargo.toml4
-rw-r--r--src-tauri/src/development/mod.rs78
-rw-r--r--src-tauri/src/main.rs1
4 files changed, 124 insertions, 3 deletions
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index e8ac30cc..dca74714 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -87,6 +87,7 @@ dependencies = [
"async-recursion",
"chrono",
"const_format",
+ "crypto-hash",
"dirs",
"glob",
"json5",
@@ -108,6 +109,7 @@ dependencies = [
"tauri-plugin-store",
"tokio",
"ts-rs",
+ "walkdir",
"winapi",
"winreg 0.11.0",
"zip",
@@ -596,6 +598,24 @@ dependencies = [
]
[[package]]
+name = "commoncrypto"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d056a8586ba25a1e4d61cb090900e495952c7886786fc55f909ab2f819b69007"
+dependencies = [
+ "commoncrypto-sys",
+]
+
+[[package]]
+name = "commoncrypto-sys"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fed34f46747aa73dfaa578069fd8279d2818ade2b55f38f22a9401c7f4083e2"
+dependencies = [
+ "libc",
+]
+
+[[package]]
name = "concurrent-queue"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -748,6 +768,18 @@ dependencies = [
]
[[package]]
+name = "crypto-hash"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8a77162240fd97248d19a564a565eb563a3f592b386e4136fb300909e67dddca"
+dependencies = [
+ "commoncrypto",
+ "hex 0.3.2",
+ "openssl",
+ "winapi",
+]
+
+[[package]]
name = "cssparser"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1598,6 +1630,12 @@ checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b"
[[package]]
name = "hex"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77"
+
+[[package]]
+name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
@@ -3465,7 +3503,7 @@ checksum = "360ee3270f7a4a1eee6c667f7d38360b995431598a73b740dfe420da548d9cc9"
dependencies = [
"debugid",
"getrandom 0.2.10",
- "hex",
+ "hex 0.4.3",
"serde",
"serde_json",
"thiserror",
@@ -3545,7 +3583,7 @@ checksum = "21e47d95bc83ed33b2ecf84f4187ad1ab9685d18ff28db000c99deac8ce180e3"
dependencies = [
"base64 0.21.2",
"chrono",
- "hex",
+ "hex 0.4.3",
"indexmap 1.9.3",
"serde",
"serde_json",
@@ -5331,7 +5369,7 @@ dependencies = [
"futures-core",
"futures-sink",
"futures-util",
- "hex",
+ "hex 0.4.3",
"nix",
"once_cell",
"ordered-stream",
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index d2f1e87e..50e75987 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -65,6 +65,10 @@ semver = "1.0"
# simplified filesystem access
glob = "0.3.1"
dirs = "5"
+# Walk directories
+walkdir = "2.3"
+# Crypto stuff like checksum calculation
+crypto-hash = "0.3"
[target.'cfg(windows)'.dependencies]
# Windows API stuff
diff --git a/src-tauri/src/development/mod.rs b/src-tauri/src/development/mod.rs
index be02966d..cb2aeec9 100644
--- a/src-tauri/src/development/mod.rs
+++ b/src-tauri/src/development/mod.rs
@@ -3,6 +3,9 @@ use crate::github::{
pull_requests::{check_github_api, download_zip_into_memory, get_launcher_download_link},
CommitInfo,
};
+use crate::GameInstall;
+use serde::{Deserialize, Serialize};
+use std::io::Read;
#[tauri::command]
pub async fn install_git_main(game_install_path: &str) -> Result<String, String> {
@@ -82,3 +85,78 @@ pub async fn install_git_main(game_install_path: &str) -> Result<String, String>
);
Ok(latest_commit_sha)
}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct Checksum {
+ path: String,
+ checksum: String,
+}
+
+impl ToString for Checksum {
+ fn to_string(&self) -> String {
+ format!("{} {}", self.checksum, self.path)
+ }
+}
+
+/// Computes the checksum of a given file
+fn compute_checksum<P: AsRef<std::path::Path>>(
+ path: P,
+) -> Result<Checksum, Box<dyn std::error::Error>> {
+ dbg!(path.as_ref().to_string_lossy().into_owned());
+ let mut file = std::fs::File::open(&path)?;
+ let mut buffer = Vec::new();
+ file.read_to_end(&mut buffer)?;
+
+ let checksum = crypto_hash::hex_digest(crypto_hash::Algorithm::SHA256, &buffer);
+ Ok(Checksum {
+ path: path.as_ref().to_string_lossy().into_owned(),
+ checksum,
+ })
+}
+
+fn convert_to_string(checksums: Vec<Checksum>) -> String {
+ let mut result = String::new();
+
+ for entry in checksums {
+ result.push_str(&entry.to_string());
+ result.push('\n');
+ }
+ result
+}
+
+#[tauri::command]
+/// Calculates checksums over the passed game_install folder and returns results
+pub async fn calculate_checksums_gameinstall(game_install: GameInstall) -> Result<String, String> {
+ log::info!("Computing checksums");
+
+ let path = game_install.game_path;
+ let mut checksums = Vec::new();
+
+ // Iterate over folder
+ for entry in walkdir::WalkDir::new(path.clone()) {
+ let entry = entry.unwrap();
+ if !entry.file_type().is_file() {
+ continue;
+ }
+
+ match compute_checksum(entry.path()) {
+ Ok(mut checksum) => {
+ checksum.path = checksum
+ .path
+ .strip_prefix(&path.clone())
+ .unwrap()
+ .to_string();
+ checksums.push(checksum)
+ }
+ Err(err) => log::warn!("Failed to compute checksum for {:?}: {:?}", entry, err),
+ }
+ }
+
+ for checksum in &checksums {
+ println!("{:?}", checksum);
+ }
+
+ log::info!("Done calculating");
+ let s = convert_to_string(checksums);
+ Ok(s)
+}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 1067f5d3..db0fd3bd 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -156,6 +156,7 @@ fn main() {
github::pull_requests::get_launcher_download_link,
close_application,
development::install_git_main,
+ development::calculate_checksums_gameinstall,
get_available_northstar_versions,
])
.run(tauri::generate_context!())