chore: remove more iw4x stuff

This commit is contained in:
alterware
2025-06-30 18:27:03 +02:00
parent 6f241dffe2
commit a30d6950c8
9 changed files with 16 additions and 147 deletions

2
Cargo.lock generated
View File

@@ -19,7 +19,7 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "alterware-launcher"
version = "0.11.2"
version = "0.11.3"
dependencies = [
"blake3",
"colored",

View File

@@ -1,6 +1,6 @@
[package]
name = "alterware-launcher"
version = "0.11.2"
version = "0.11.3"
edition = "2021"
build = "res/build.rs"

View File

@@ -15,7 +15,7 @@ pub fn save_cache(dir: &Path, cache: Cache) {
let cache_path = dir.join("awcache.json");
let cache_serialized = serde_json::to_string_pretty(&cache).unwrap();
fs::write(cache_path, cache_serialized).unwrap_or_else(|e| {
error!("Failed to save cache: {}", e);
error!("Failed to save cache: {e}");
});
}

View File

@@ -284,7 +284,7 @@ pub async fn rate_cdns_and_display() {
"Unknown".bright_red()
);
} else {
println!("User region: {:?}", user_region);
println!("User region: {user_region:?}");
}
println!("Rating CDNs...");

View File

@@ -17,17 +17,13 @@ pub async fn latest_tag_full(
repo: &str,
) -> Result<String, Box<dyn std::error::Error>> {
let github_body = crate::http_async::get_body_string(
format!(
"https://api.github.com/repos/{}/{}/releases/latest",
owner, repo
)
.as_str(),
format!("https://api.github.com/repos/{owner}/{repo}/releases/latest").as_str(),
)
.await
.map_err(|e| format!("Failed to fetch GitHub API: {}", e))?;
.map_err(|e| format!("Failed to fetch GitHub API: {e}"))?;
let github_json: serde_json::Value = serde_json::from_str(&github_body)
.map_err(|e| format!("Failed to parse GitHub API response: {}", e))?;
.map_err(|e| format!("Failed to parse GitHub API response: {e}"))?;
let tag_name = github_json
.get("tag_name")
@@ -43,13 +39,13 @@ pub async fn latest_tag_prerelease(
repo: &str,
) -> Result<String, Box<dyn std::error::Error>> {
let github_body = crate::http_async::get_body_string(
format!("https://api.github.com/repos/{}/{}/releases", owner, repo).as_str(),
format!("https://api.github.com/repos/{owner}/{repo}/releases").as_str(),
)
.await
.map_err(|e| format!("Failed to fetch GitHub API: {}", e))?;
.map_err(|e| format!("Failed to fetch GitHub API: {e}"))?;
let github_json: serde_json::Value = serde_json::from_str(&github_body)
.map_err(|e| format!("Failed to parse GitHub API response: {}", e))?;
.map_err(|e| format!("Failed to parse GitHub API response: {e}"))?;
let latest_release = github_json.get(0).ok_or("No releases found")?;

View File

@@ -10,8 +10,6 @@ use crate::cdn::{Hosts, Region, Server};
pub const GH_OWNER: &str = "alterware";
pub const GH_REPO: &str = "alterware-launcher";
pub const GH_IW4X_OWNER: &str = "iw4x";
pub const GH_IW4X_REPO: &str = "iw4x-client";
pub const DEFAULT_MASTER: &str = "https://cdn.alterware.ovh";
pub const CDN_HOSTS: [Server; 2] = [

View File

@@ -1,46 +0,0 @@
use crate::extend::*;
use crate::github;
use crate::global::*;
use crate::http_async;
use crate::misc;
use crate::structs;
use std::path::Path;
pub async fn remote_revision(prerelease: Option<bool>) -> u16 {
match github::latest_tag(GH_IW4X_OWNER, GH_IW4X_REPO, prerelease).await {
Ok(tag) => misc::rev_to_int(&tag),
Err(_) => {
crate::println_error!("Failed to get latest version for {GH_IW4X_OWNER}/{GH_IW4X_REPO}, assuming we are up to date.");
0
}
}
}
pub async fn update(dir: &Path, cache: &mut structs::Cache, prerelease: Option<bool>) {
let remote = remote_revision(prerelease).await;
let local = misc::rev_to_int(&cache.iw4x_revision);
if remote <= local && dir.join("iw4x.dll").exists() {
crate::println_info!("No files to download for IW4x");
return;
}
crate::println_info!("Downloading outdated or missing files for IW4x",);
println!(
"{}{}",
misc::prefix("downloading"),
dir.join("iw4x.dll").cute_path()
);
http_async::download_file(
&format!(
"{}/iw4x.dll",
github::download_url(GH_IW4X_OWNER, GH_IW4X_REPO, Some(&format!("r{remote}")))
),
&dir.join("iw4x.dll"),
)
.await
.unwrap();
cache.iw4x_revision = format!("r{remote}");
}

View File

@@ -6,7 +6,6 @@ mod github;
mod global;
mod http;
mod http_async;
mod iw4x;
mod misc;
mod self_update;
mod structs;
@@ -28,7 +27,7 @@ use mslnk::ShellLink;
use simple_log::LogConfigBuilder;
use std::{
borrow::Cow,
collections::{HashMap, HashSet},
collections::HashMap,
env, fs,
path::{Path, PathBuf},
};
@@ -117,7 +116,7 @@ fn setup_desktop_links(path: &Path, game: &Game) {
async fn auto_install(path: &Path, game: &Game<'_>) {
setup_client_links(game, path);
setup_desktop_links(path, game);
update(game, path, false, false, None, None, None).await;
update(game, path, false, false, None).await;
}
#[cfg(windows)]
@@ -187,7 +186,7 @@ fn total_download_size(cdn_info: &Vec<CdnFile>, remote_dir: &str) -> u64 {
let remote_dir = format!("{remote_dir}/");
let mut size: u64 = 0;
for file in cdn_info {
if !file.name.starts_with(&remote_dir) || file.name == "iw4/iw4x.dll" {
if !file.name.starts_with(&remote_dir) {
continue;
}
size += file.size as u64;
@@ -201,7 +200,6 @@ async fn update_dir(
dir: &Path,
hashes: &mut HashMap<String, String>,
pb: &ProgressBar,
skip_iw4x_sp: bool,
) {
misc::pb_style_download(pb, false);
@@ -210,10 +208,7 @@ async fn update_dir(
let mut files_to_download: Vec<CdnFile> = vec![];
for file in cdn_info {
if !file.name.starts_with(&remote_dir_pre) || file.name == "iw4/iw4x.dll" {
continue;
}
if skip_iw4x_sp && file.name == "iw4/iw4x-sp.exe" {
if !file.name.starts_with(&remote_dir_pre) {
continue;
}
@@ -337,15 +332,12 @@ async fn update(
dir: &Path,
bonus_content: bool,
force: bool,
skip_iw4x_sp: Option<bool>,
ignore_required_files: Option<bool>,
prerelease: Option<bool>,
) {
info!("Starting update for game engine: {}", game.engine);
info!("Update path: {}", dir.display());
debug!("Bonus content: {}, Force update: {}", bonus_content, force);
let skip_iw4x_sp = skip_iw4x_sp.unwrap_or(false);
let ignore_required_files = ignore_required_files.unwrap_or(false);
let res =
@@ -405,66 +397,12 @@ async fn update(
}
}
if game.engine == "iw4" {
iw4x::update(dir, &mut cache, prerelease).await;
let scan_dirs = ["iw4x", "zone/patch"];
let valid_files: HashSet<_> = cdn_info
.iter()
.filter_map(|cdn_file| {
if cdn_file.name.starts_with("iw4/") || cdn_file.name.starts_with("iw4-dlc/") {
Some(Path::new(&cdn_file.name).to_path_buf())
} else {
None
}
})
.collect();
for scan_dir in scan_dirs.iter() {
let full_scan_dir = dir.join(scan_dir);
if !full_scan_dir.exists() || !full_scan_dir.is_dir() {
continue;
}
for entry in walkdir::WalkDir::new(&full_scan_dir)
.into_iter()
.filter_map(Result::ok)
.filter(|e| e.file_type().is_file())
{
let rel_path = entry.path().strip_prefix(dir).unwrap_or(entry.path());
let cdn_paths = [
Path::new("iw4").join(rel_path),
Path::new("iw4-dlc").join(rel_path),
];
if !cdn_paths.iter().any(|path| valid_files.contains(path)) {
crate::println_info!("{}{}", misc::prefix("removed"), entry.path().cute_path());
if std::fs::remove_file(entry.path()).is_err() {
crate::println_error!(
"{}Couldn't delete {}",
misc::prefix("error"),
entry.path().cute_path()
);
}
}
}
}
}
let pb = ProgressBar::new(0);
update_dir(
&cdn_info,
game.engine,
dir,
&mut cache.hashes,
&pb,
skip_iw4x_sp,
)
.await;
update_dir(&cdn_info, game.engine, dir, &mut cache.hashes, &pb).await;
if bonus_content && !game.bonus.is_empty() {
for bonus in game.bonus.iter() {
update_dir(&cdn_info, bonus, dir, &mut cache.hashes, &pb, skip_iw4x_sp).await;
update_dir(&cdn_info, bonus, dir, &mut cache.hashes, &pb).await;
}
}
@@ -953,14 +891,6 @@ async fn main() {
"engine",
cfg.engine.clone(),
);
if cfg.engine == "iw4" && cfg.args.is_empty() {
cfg.args = String::from("-stdout");
config::save_value_s(
install_path.join("alterware-launcher.json"),
"args",
cfg.args.clone(),
);
}
#[cfg(windows)]
if !cfg.skip_redist {
@@ -989,9 +919,7 @@ async fn main() {
install_path.as_path(),
cfg.download_bonus_content,
cfg.force_update,
Some(&game != "iw4x-sp"),
Some(ignore_required_files),
Some(cfg.prerelease),
)
.await;
if !cfg.update_only {

View File

@@ -12,13 +12,6 @@ pub fn stdin() -> String {
input.trim().to_string()
}
pub fn rev_to_int(rev: &str) -> u16 {
rev.strip_prefix('r')
.unwrap_or("0")
.parse::<u16>()
.unwrap_or(0)
}
pub fn human_readable_bytes(bytes: u64) -> String {
let mut bytes = bytes as f64;
let mut i = 0;