mirror of
https://github.com/alterware/alterware-launcher.git
synced 2025-12-04 15:27:48 +00:00
replace sh1 file hashes with blake3
This commit is contained in:
39
Cargo.lock
generated
39
Cargo.lock
generated
@@ -21,6 +21,7 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
|||||||
name = "alterware-launcher"
|
name = "alterware-launcher"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"blake3",
|
||||||
"colored",
|
"colored",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
@@ -33,7 +34,6 @@ dependencies = [
|
|||||||
"semver",
|
"semver",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sha1_smol",
|
|
||||||
"simple-log",
|
"simple-log",
|
||||||
"static_vcruntime",
|
"static_vcruntime",
|
||||||
"steamlocate",
|
"steamlocate",
|
||||||
@@ -62,6 +62,18 @@ version = "0.4.8"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dabe5a181f83789739c194cbe5a897dde195078fac08568d09221fd6137a7ba8"
|
checksum = "dabe5a181f83789739c194cbe5a897dde195078fac08568d09221fd6137a7ba8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayref"
|
||||||
|
version = "0.3.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayvec"
|
||||||
|
version = "0.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@@ -101,6 +113,19 @@ version = "2.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "blake3"
|
||||||
|
version = "1.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e9ec96fe9a81b5e365f9db71fe00edc4fe4ca2cc7dcb7861f0603012a7caa210"
|
||||||
|
dependencies = [
|
||||||
|
"arrayref",
|
||||||
|
"arrayvec",
|
||||||
|
"cc",
|
||||||
|
"cfg-if",
|
||||||
|
"constant_time_eq",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "block-buffer"
|
name = "block-buffer"
|
||||||
version = "0.10.4"
|
version = "0.10.4"
|
||||||
@@ -177,6 +202,12 @@ dependencies = [
|
|||||||
"windows-sys 0.45.0",
|
"windows-sys 0.45.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "constant_time_eq"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "convert_case"
|
name = "convert_case"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@@ -1468,12 +1499,6 @@ dependencies = [
|
|||||||
"yaml-rust",
|
"yaml-rust",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "sha1_smol"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.10.7"
|
version = "0.10.7"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ panic = "abort"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
sha1_smol = "1.0.0"
|
blake3 = "1.5.3"
|
||||||
serde = { version = "1.0.204", features = ["derive"] }
|
serde = { version = "1.0.204", features = ["derive"] }
|
||||||
serde_json = "1.0.120"
|
serde_json = "1.0.120"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
|||||||
25
src/main.rs
25
src/main.rs
@@ -202,17 +202,17 @@ async fn update_dir(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sha1_remote = file.hash.to_lowercase();
|
let hash_remote = file.blake3.to_lowercase();
|
||||||
let file_name = &file.name.replace(remote_dir_pre.as_str(), "");
|
let file_name = &file.name.replace(remote_dir_pre.as_str(), "");
|
||||||
let file_path = dir.join(file_name);
|
let file_path = dir.join(file_name);
|
||||||
if file_path.exists() {
|
if file_path.exists() {
|
||||||
let sha1_local = hashes
|
let hash_local = hashes
|
||||||
.get(file_name)
|
.get(file_name)
|
||||||
.map(Cow::Borrowed)
|
.map(Cow::Borrowed)
|
||||||
.unwrap_or_else(|| Cow::Owned(misc::get_file_sha1(&file_path)))
|
.unwrap_or_else(|| Cow::Owned(misc::file_blake3(&file_path).unwrap()))
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
if sha1_local != sha1_remote {
|
if hash_local != hash_remote {
|
||||||
files_to_download.push(file.clone());
|
files_to_download.push(file.clone());
|
||||||
} else {
|
} else {
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
@@ -222,7 +222,7 @@ async fn update_dir(
|
|||||||
);
|
);
|
||||||
pb.println(&msg);
|
pb.println(&msg);
|
||||||
info!("{}", msg);
|
info!("{}", msg);
|
||||||
hashes.insert(file_name.to_owned(), file.hash.to_lowercase());
|
hashes.insert(file_name.to_owned(), file.blake3.to_lowercase());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
files_to_download.push(file.clone());
|
files_to_download.push(file.clone());
|
||||||
@@ -269,7 +269,7 @@ async fn update_dir(
|
|||||||
{
|
{
|
||||||
panic!("{err}");
|
panic!("{err}");
|
||||||
};
|
};
|
||||||
let hash = misc::get_file_sha1(&file_path);
|
let hash = misc::file_blake3(&file_path).unwrap();
|
||||||
hashes.insert(file_name.to_owned(), hash.to_lowercase());
|
hashes.insert(file_name.to_owned(), hash.to_lowercase());
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
if file_name.ends_with(".exe") {
|
if file_name.ends_with(".exe") {
|
||||||
@@ -308,8 +308,17 @@ async fn update(
|
|||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dir.join(".sha-sums").exists() {
|
||||||
|
match fs::remove_file(dir.join(".sha-sums")) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(error) => {
|
||||||
|
crate::println_error!("Error removing .sha-sums: {:#?}", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut hashes = HashMap::new();
|
let mut hashes = HashMap::new();
|
||||||
let hash_file = dir.join(".sha-sums");
|
let hash_file = dir.join(".hashes");
|
||||||
if hash_file.exists() && !force {
|
if hash_file.exists() && !force {
|
||||||
let hash_file = fs::read_to_string(hash_file).unwrap();
|
let hash_file = fs::read_to_string(hash_file).unwrap();
|
||||||
for line in hash_file.lines() {
|
for line in hash_file.lines() {
|
||||||
@@ -445,7 +454,7 @@ async fn update(
|
|||||||
for (file, hash) in hashes.iter() {
|
for (file, hash) in hashes.iter() {
|
||||||
hash_file_content.push_str(&format!("{} {}\n", hash, file));
|
hash_file_content.push_str(&format!("{} {}\n", hash, file));
|
||||||
}
|
}
|
||||||
fs::write(dir.join(".sha-sums"), hash_file_content).unwrap();
|
fs::write(dir.join(".hashes"), hash_file_content).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
|||||||
16
src/misc.rs
16
src/misc.rs
@@ -6,10 +6,18 @@ use std::{
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
|
|
||||||
pub fn get_file_sha1(path: &PathBuf) -> String {
|
pub fn file_blake3(file: &std::path::Path) -> std::io::Result<String> {
|
||||||
let mut sha1 = sha1_smol::Sha1::new();
|
let mut blake3 = blake3::Hasher::new();
|
||||||
sha1.update(&fs::read(path).unwrap());
|
let mut file = std::fs::File::open(file)?;
|
||||||
sha1.digest().to_string()
|
let mut buffer = [0; 1024];
|
||||||
|
loop {
|
||||||
|
let n = std::io::Read::read(&mut file, &mut buffer)?;
|
||||||
|
if n == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
blake3.update(&buffer[..n]);
|
||||||
|
}
|
||||||
|
Ok(blake3.finalize().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stdin() -> String {
|
pub fn stdin() -> String {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use std::path::Path;
|
|||||||
pub struct CdnFile {
|
pub struct CdnFile {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub size: u32,
|
pub size: u32,
|
||||||
pub hash: String,
|
pub blake3: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
|
|||||||
Reference in New Issue
Block a user