From c51e7618bd22b3511415bf7cfa04c996e90f0b07 Mon Sep 17 00:00:00 2001 From: quexeky Date: Sat, 26 Oct 2024 15:18:34 +1100 Subject: [PATCH] More progress on checksums --- src-tauri/Cargo.lock | 12 +++--------- src-tauri/Cargo.toml | 6 +++++- src-tauri/src/downloads/download_logic.rs | 13 +++++++++---- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 0a81563..fb66070 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1699,11 +1699,11 @@ dependencies = [ [[package]] name = "gxhash" -version = "3.4.1" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a197c9b654827513cf53842c5c6d3da2b4b35a785f8e0eff78bdf8e445aba1bb" +checksum = "09f0c897148ec6ff3ca864b7c886df75e6ba09972d206bd9a89af0c18c992253" dependencies = [ - "rustversion", + "rand 0.8.5", ] [[package]] @@ -3420,12 +3420,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "rustversion" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" - [[package]] name = "ryu" version = "1.0.18" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 7024860..7b5648d 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -17,6 +17,10 @@ tauri-plugin-single-instance = { version = "2.0.0", features = ["deep-link"] } name = "drop_app_lib" crate-type = ["staticlib", "cdylib", "rlib"] +[build] +rustflags = ["-C", "target-feature=+aes,+sse2"] + + [build-dependencies] tauri-build = { version = "2.0.0", features = [] } @@ -41,7 +45,7 @@ tokio = { version = "1.40.0", features = ["rt", "tokio-macros"] } versions = { version = "6.3.2", features = ["serde"] } urlencoding = "2.1.3" rustix = "0.38.37" -gxhash = "3.4.1" +gxhash = "2.3.0" [dependencies.uuid] version = "1.10.0" diff --git a/src-tauri/src/downloads/download_logic.rs b/src-tauri/src/downloads/download_logic.rs index 06b7641..8826053 100644 --- a/src-tauri/src/downloads/download_logic.rs +++ b/src-tauri/src/downloads/download_logic.rs @@ -2,7 +2,7 @@ use crate::auth::generate_authorization_header; use crate::db::DatabaseImpls; use crate::downloads::manifest::DropDownloadContext; use crate::DB; -use gxhash::GxHasher; +use gxhash::{gxhash128, GxHasher}; use log::info; use std::{fs::{File, OpenOptions}, hash::Hasher, io::{BufWriter, Seek, SeekFrom, Write}, path::PathBuf}; use urlencoding::encode; @@ -61,7 +61,7 @@ pub fn download_game_chunk(ctx: DropDownloadContext) { .send() .unwrap(); - let mut file = FileWriter::new(ctx.path); + let mut file: FileWriter = FileWriter::new(ctx.path); if ctx.offset != 0 { file @@ -73,13 +73,18 @@ pub fn download_game_chunk(ctx: DropDownloadContext) { // Writing directly to disk to avoid write spikes that delay everything - response.copy_to(&mut file).unwrap(); + let data = response.bytes().unwrap(); + let checksum = gxhash128(&*data.clone(), 0); + let res = file.write(&*data).unwrap(); + + //response.copy_to(&mut file).unwrap(); let res = hex::encode(file.finish().to_le_bytes()); if res == ctx.checksum { info!("Matched Checksum {}", res); } else { - info!("Checksum failed {}", res); + info!("Checksum failed. Original: {}, Calculated: {}", ctx.checksum, res); + info!("Other Checksum: {}", hex::encode(checksum.to_le_bytes())); } // stream.flush().unwrap();