Converted to md5

This commit is contained in:
quexeky
2024-10-26 22:22:10 +11:00
parent ddc585dc23
commit 706f525ae7
3 changed files with 18 additions and 11 deletions

7
src-tauri/Cargo.lock generated
View File

@ -1025,6 +1025,7 @@ dependencies = [
"hex",
"http",
"log",
"md5",
"openssl",
"rayon",
"reqwest",
@ -2283,6 +2284,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5"
[[package]]
name = "md5"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771"
[[package]]
name = "memchr"
version = "2.7.4"

View File

@ -46,6 +46,7 @@ versions = { version = "6.3.2", features = ["serde"] }
urlencoding = "2.1.3"
rustix = "0.38.37"
gxhash = "2.3.0"
md5 = "0.7.0"
[dependencies.uuid]
version = "1.10.0"

View File

@ -4,23 +4,24 @@ use crate::downloads::manifest::DropDownloadContext;
use crate::DB;
use gxhash::{gxhash128, GxHasher};
use log::info;
use std::{fs::{File, OpenOptions}, hash::Hasher, io::{BufWriter, Seek, SeekFrom, Write}, path::PathBuf};
use md5::{Context, Digest};
use std::{fs::{File, OpenOptions}, hash::Hasher, io::{Seek, SeekFrom, Write}, path::PathBuf};
use urlencoding::encode;
pub struct FileWriter {
file: File,
hasher: GxHasher
hasher: Context
}
impl FileWriter {
fn new(path: PathBuf) -> Self {
Self {
file: OpenOptions::new().write(true).open(path).unwrap(),
hasher: GxHasher::with_seed(0)
hasher: Context::new()
}
}
fn finish(mut self) -> u128 {
fn finish(mut self) -> Digest {
self.flush();
self.hasher.finish_u128()
self.hasher.compute()
}
}
impl Write for FileWriter {
@ -30,6 +31,7 @@ impl Write for FileWriter {
}
fn flush(&mut self) -> std::io::Result<()> {
self.hasher.flush()?;
self.file.flush()
}
}
@ -73,18 +75,15 @@ pub fn download_game_chunk(ctx: DropDownloadContext) {
// Writing directly to disk to avoid write spikes that delay everything
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());
response.copy_to(&mut file).unwrap();
let res = hex::encode(file.finish().0);
if res == ctx.checksum {
info!("Matched Checksum {}", res);
}
else {
info!("Checksum failed. Original: {}, Calculated: {} for {}", ctx.checksum, res, ctx.file_name);
info!("Other Checksum: {}", hex::encode(checksum.to_le_bytes()));
//info!("Other Checksum: {}", hex::encode(checksum));
}
// stream.flush().unwrap();