update all game-specific files, add iw6
This commit is contained in:
parent
4a488abb8e
commit
d587553845
@ -3,3 +3,7 @@
|
|||||||
1. Download [latest release](https://github.com/mxve/alterware-launcher/releases/latest/download/alterware-launcher-x86_64-pc-windows-msvc.zip)
|
1. Download [latest release](https://github.com/mxve/alterware-launcher/releases/latest/download/alterware-launcher-x86_64-pc-windows-msvc.zip)
|
||||||
2. Unpack the archive and place alterware-launcher.exe in MW2/MW3 game directory
|
2. Unpack the archive and place alterware-launcher.exe in MW2/MW3 game directory
|
||||||
3. Run alterware-launcher.exe
|
3. Run alterware-launcher.exe
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
- Passing iw4-sp, iw5-mod or iw6-mod as the first argument will skip automatic game detection
|
111
src/main.rs
111
src/main.rs
@ -15,7 +15,7 @@ struct Game<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const MASTER: &str = "https://master.alterware.dev";
|
const MASTER: &str = "https://master.alterware.dev";
|
||||||
const GAMES: [Game; 2] = [
|
const GAMES: [Game; 3] = [
|
||||||
Game {
|
Game {
|
||||||
engine: "iw4",
|
engine: "iw4",
|
||||||
client: "iw4-sp",
|
client: "iw4-sp",
|
||||||
@ -26,6 +26,11 @@ const GAMES: [Game; 2] = [
|
|||||||
client: "iw5-mod",
|
client: "iw5-mod",
|
||||||
references: &["iw5sp.exe", "iw5mp.exe", "iw5mp_server.exe"],
|
references: &["iw5sp.exe", "iw5mp.exe", "iw5mp_server.exe"],
|
||||||
},
|
},
|
||||||
|
Game {
|
||||||
|
engine: "iw6",
|
||||||
|
client: "iw6-mod",
|
||||||
|
references: &["iw6sp64_ship.exe", "iw6mp64_ship.exe"],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
fn file_get_sha1(path: &PathBuf) -> String {
|
fn file_get_sha1(path: &PathBuf) -> String {
|
||||||
@ -34,41 +39,7 @@ fn file_get_sha1(path: &PathBuf) -> String {
|
|||||||
sha1.digest().to_string()
|
sha1.digest().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn download_and_launch(url: &str, file_path: &PathBuf, hash: Option<String>) {
|
fn update(game: &Game) {
|
||||||
if let Some(parent) = file_path.parent() {
|
|
||||||
if !parent.exists() {
|
|
||||||
fs::create_dir_all(parent).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// clippy will suggest using if let or match, but i prefer it being somewhat readable
|
|
||||||
#[allow(clippy::unnecessary_unwrap)]
|
|
||||||
if file_path.exists() && hash.is_some() {
|
|
||||||
let sha1_local = file_get_sha1(file_path).to_lowercase();
|
|
||||||
let sha1_remote = hash.unwrap().to_lowercase();
|
|
||||||
if sha1_local != sha1_remote {
|
|
||||||
println!(
|
|
||||||
"Updating {}...\nLocal hash: {}\nRemote hash: {}",
|
|
||||||
file_path.display(),
|
|
||||||
sha1_local,
|
|
||||||
sha1_remote
|
|
||||||
);
|
|
||||||
http::download_file(url, file_path);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println!("Downloading {}...", file_path.display());
|
|
||||||
http::download_file(url, file_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Launching {}...", file_path.display());
|
|
||||||
std::process::Command::new(file_path)
|
|
||||||
.spawn()
|
|
||||||
.unwrap()
|
|
||||||
.wait()
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_hash(game: &Game) -> Option<String> {
|
|
||||||
let cdn_info: Vec<CdnFile> = serde_json::from_str(&http::get_body_string(
|
let cdn_info: Vec<CdnFile> = serde_json::from_str(&http::get_body_string(
|
||||||
format!(
|
format!(
|
||||||
"{}/files.json?{}",
|
"{}/files.json?{}",
|
||||||
@ -79,13 +50,62 @@ fn get_hash(game: &Game) -> Option<String> {
|
|||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let mut files_to_update: Vec<CdnFile> = Vec::new();
|
||||||
for file in cdn_info {
|
for file in cdn_info {
|
||||||
if file.name == format!("{}/{}.exe", game.engine, game.client) {
|
if file.name.starts_with(game.engine) {
|
||||||
return Some(file.hash);
|
files_to_update.push(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
for file in files_to_update {
|
||||||
|
let file_path = PathBuf::from(&file.name.replace(&format!("{}/", game.engine), ""));
|
||||||
|
if file_path.exists() {
|
||||||
|
let sha1_local = file_get_sha1(&file_path).to_lowercase();
|
||||||
|
let sha1_remote = file.hash.to_lowercase();
|
||||||
|
if sha1_local != sha1_remote {
|
||||||
|
println!(
|
||||||
|
"Updating {}...\nLocal hash: {}\nRemote hash: {}",
|
||||||
|
file_path.display(),
|
||||||
|
sha1_local,
|
||||||
|
sha1_remote
|
||||||
|
);
|
||||||
|
http::download_file(
|
||||||
|
&format!(
|
||||||
|
"{}/{}?{}",
|
||||||
|
MASTER,
|
||||||
|
file.name,
|
||||||
|
rand::Rng::gen_range(&mut rand::thread_rng(), 0..1000)
|
||||||
|
),
|
||||||
|
&file_path,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Downloading {}...", file_path.display());
|
||||||
|
if let Some(parent) = file_path.parent() {
|
||||||
|
if !parent.exists() {
|
||||||
|
fs::create_dir_all(parent).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
http::download_file(
|
||||||
|
&format!(
|
||||||
|
"{}/{}?{}",
|
||||||
|
MASTER,
|
||||||
|
file.name,
|
||||||
|
rand::Rng::gen_range(&mut rand::thread_rng(), 0..1000)
|
||||||
|
),
|
||||||
|
&file_path,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn launch(file_path: &PathBuf) {
|
||||||
|
println!("Launching {}...", file_path.display());
|
||||||
|
std::process::Command::new(file_path)
|
||||||
|
.spawn()
|
||||||
|
.unwrap()
|
||||||
|
.wait()
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -106,17 +126,8 @@ fn main() {
|
|||||||
|
|
||||||
for g in GAMES.iter() {
|
for g in GAMES.iter() {
|
||||||
if g.client == game {
|
if g.client == game {
|
||||||
download_and_launch(
|
update(&g);
|
||||||
&format!(
|
launch(&PathBuf::from(format!("{}.exe", g.client)));
|
||||||
"{}/{}/{}.exe?{}",
|
|
||||||
MASTER,
|
|
||||||
g.engine,
|
|
||||||
g.client,
|
|
||||||
rand::Rng::gen_range(&mut rand::thread_rng(), 0..1000)
|
|
||||||
),
|
|
||||||
&PathBuf::from(format!("{}.exe", g.client)),
|
|
||||||
get_hash(g),
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user