1 Commits

Author SHA1 Message Date
dependabot[bot]
a2432f57ef Bump steamlocate from 2.0.0-beta.2 to 2.0.1
Bumps [steamlocate](https://github.com/WilliamVenner/steamlocate-rs) from 2.0.0-beta.2 to 2.0.1.
- [Release notes](https://github.com/WilliamVenner/steamlocate-rs/releases)
- [Changelog](https://github.com/WilliamVenner/steamlocate-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/WilliamVenner/steamlocate-rs/commits/2.0.1)

---
updated-dependencies:
- dependency-name: steamlocate
  dependency-version: 2.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-06-12 20:06:36 +00:00
16 changed files with 728 additions and 658 deletions

View File

@@ -15,7 +15,7 @@ jobs:
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
@@ -23,7 +23,7 @@ jobs:
target: ${{ matrix.target }}
- name: Cache dependencies
uses: actions/cache@v5
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
@@ -46,7 +46,7 @@ jobs:
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
@@ -54,7 +54,7 @@ jobs:
target: ${{ matrix.target }}
- name: Cache dependencies
uses: actions/cache@v5
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
@@ -77,7 +77,7 @@ jobs:
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
@@ -86,7 +86,7 @@ jobs:
components: rustfmt, clippy
- name: Cache dependencies
uses: actions/cache@v5
uses: actions/cache@v4
with:
path: |
~/.cargo/registry

View File

@@ -9,8 +9,8 @@ jobs:
create-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1.9.2
- uses: actions/checkout@v4
- uses: taiki-e/create-gh-release-action@v1.9.1
with:
draft: true
token: ${{ secrets.GITHUB_TOKEN }}
@@ -29,8 +29,8 @@ jobs:
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1.28.0
- uses: actions/checkout@v4
- uses: taiki-e/upload-rust-binary-action@v1.26.0
with:
target: ${{ matrix.target }}
bin: alterware-launcher

816
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
[package]
name = "alterware-launcher"
version = "0.11.6"
version = "0.11.1"
edition = "2021"
build = "res/build.rs"
@@ -18,12 +18,12 @@ rand = "0.9"
semver = "1.0"
colored = "3.0"
once_cell = "1.21"
reqwest = { version = "0.13", features = ["stream"] }
reqwest = { version = "0.12", features = ["stream"] }
futures-util = "0.3"
futures = "0.3"
indicatif = "0.18"
tokio = { version="1.47", features = ["rt-multi-thread", "macros"] }
simple-log = "2.4"
indicatif = "0.17"
tokio = { version="1.45", features = ["rt-multi-thread", "macros"] }
simple-log = "2.3"
walkdir = "2.5"
[target.'cfg(unix)'.dependencies]
@@ -31,17 +31,17 @@ openssl = { version = "0.10", default-features = false, features = ["vendored"]
[target.'cfg(windows)'.dependencies]
# todo: update to 2.0.x; needs testing on windows
steamlocate = "=2.0.0-beta.2"
steamlocate = "=2.0.1"
mslnk = "0.1"
self-replace = "1.5"
[build-dependencies]
winresource = "0.1"
static_vcruntime = "3.0"
static_vcruntime = "2.0"
[dev-dependencies]
strip-ansi-escapes = "0.2"
serial_test = "3.4"
serial_test = "3.2"
[package.metadata.winresource]
OriginalFilename = "alterware-launcher.exe"

View File

@@ -146,8 +146,11 @@
- Install or reinstall redistributables
- ```--prerelease```
- Update to prerelease version of the launcher
- ```--rate```
- Rate and display CDN servers
- ```--cdn-url```
- ```--offline```
- ```--skip-connectivity-check```
##### Example:
@@ -172,6 +175,7 @@ alterware-launcher.exe iw6 --bonus -u --path "C:\Games\IW6x" --pass "-headless"
- `prerelease`: Update to prerelease version of clients and launcher. Default: `false`.
- `cdn_url`
- `offline`
- `skip-connectivity-check`
---

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

@@ -6,19 +6,93 @@ use std::time::Duration;
static CURRENT_CDN: Mutex<Option<Arc<Server>>> = Mutex::new(None);
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Region {
Africa,
Asia,
Europe,
NorthAmerica,
Oceania,
SouthAmerica,
Global,
Unknown,
}
impl Region {
pub fn from_str(region_str: &str) -> Self {
match region_str {
"Africa" => Region::Africa,
"Asia" => Region::Asia,
"Europe" => Region::Europe,
"NorthAmerica" => Region::NorthAmerica,
"Oceania" => Region::Oceania,
"SouthAmerica" => Region::SouthAmerica,
_ => Region::Unknown,
}
}
pub fn coordinates(&self) -> Option<(f64, f64)> {
match self {
Region::Europe => Some((54.0, 15.0)),
Region::Asia => Some((35.0, 105.0)),
Region::NorthAmerica => Some((45.0, -100.0)),
Region::SouthAmerica => Some((-15.0, -60.0)),
Region::Africa => Some((0.0, 20.0)),
Region::Oceania => Some((-25.0, 140.0)),
Region::Global => None,
Region::Unknown => None,
}
}
pub fn distance_to(&self, other: Region) -> f64 {
if *self == Region::Global || other == Region::Global {
return 0.0;
}
if *self == other {
return 0.0;
}
let (lat1, lon1) = match self.coordinates() {
Some(coords) => coords,
None => return 20000.0,
};
let (lat2, lon2) = match other.coordinates() {
Some(coords) => coords,
None => return 20000.0,
};
// haversine
let r = 6371.0;
let d_lat = (lat2 - lat1).to_radians();
let d_lon = (lon2 - lon1).to_radians();
let lat1_rad = lat1.to_radians();
let lat2_rad = lat2.to_radians();
let a = (d_lat / 2.0).sin().powi(2)
+ lat1_rad.cos() * lat2_rad.cos() * (d_lon / 2.0).sin().powi(2);
let c = 2.0 * a.sqrt().atan2((1.0 - a).sqrt());
r * c
}
}
#[derive(Clone, Copy, Debug)]
pub struct Server {
pub host: &'static str,
pub rating: u8,
pub latency: Option<std::time::Duration>,
pub region: Region,
}
impl Server {
pub const fn new(host: &'static str) -> Self {
pub const fn new(host: &'static str, region: Region) -> Self {
Server {
host,
rating: 255,
latency: None,
region,
}
}
@@ -26,7 +100,7 @@ impl Server {
format!("https://{}/", self.host)
}
async fn rate(&mut self, asn: u32, is_initial: bool) {
async fn rate(&mut self, asn: u32, user_region: Region, is_initial: bool) {
let timeout = if is_initial {
Duration::from_millis(1000)
} else {
@@ -35,15 +109,16 @@ impl Server {
match http::rating_request(&self.url(), timeout).await {
Ok((latency, is_cloudflare)) => {
self.latency = Some(latency);
self.rating = self.calculate_rating(latency, is_cloudflare, asn);
self.rating = self.calculate_rating(latency, is_cloudflare, asn, user_region);
info!(
"Server {} rated {} ({}ms, rating: {}, cloudflare: {})",
"Server {} rated {} ({}ms, rating: {}, cloudflare: {}, region: {:?})",
self.host,
self.rating,
latency.as_millis(),
self.rating,
is_cloudflare,
self.region
);
}
Err(e) => {
@@ -72,7 +147,13 @@ impl Server {
rating.clamp(1.0, 255.0) as u8
}
fn calculate_rating(&self, latency: std::time::Duration, is_cloudflare: bool, asn: u32) -> u8 {
fn calculate_rating(
&self,
latency: std::time::Duration,
is_cloudflare: bool,
asn: u32,
user_region: Region,
) -> u8 {
let mut rating = self.rate_latency(latency);
// Additional factors for full rating
@@ -84,6 +165,25 @@ impl Server {
}
}
let distance_km = user_region.distance_to(self.region);
let region_multiplier = if self.region == Region::Global {
1.4
} else if distance_km == 0.0 {
1.3
} else if user_region == Region::Unknown {
1.0
} else if distance_km <= 2000.0 {
1.25
} else if distance_km <= 5000.0 {
1.15
} else if distance_km <= 10000.0 {
1.05
} else {
1.0
};
rating = (rating as f32 * region_multiplier).min(255.0) as u8;
rating
}
}
@@ -98,13 +198,23 @@ impl Hosts {
pub async fn new() -> Self {
let cdn_hosts = crate::global::CDN_HOSTS.to_vec();
let hosts = Hosts {
let mut hosts = Hosts {
servers: cdn_hosts,
active_index: RwLock::new(None),
};
let (asn, region_str) = crate::http::get_location_info().await;
let user_region = Region::from_str(&region_str);
info!(
"Detected user region as {:?} (region: {})",
user_region, region_str
);
hosts.rate(asn, user_region, true).await;
if hosts.servers.iter().all(|server| server.rating == 0) {
info!("All CDN servers failed with 1000ms timeout, retrying with 5000ms timeout");
hosts.rate(asn, user_region, false).await;
}
hosts
@@ -140,11 +250,11 @@ impl Hosts {
}
/// rate and order all servers, then select the best one
pub async fn rate(&mut self, asn: u32, is_initial: bool) {
pub async fn rate(&mut self, asn: u32, user_region: Region, is_initial: bool) {
let rating_futures: Vec<_> = self
.servers
.iter_mut()
.map(|server| server.rate(asn, is_initial))
.map(|server| server.rate(asn, user_region, is_initial))
.collect();
join_all(rating_futures).await;
@@ -160,3 +270,61 @@ impl Hosts {
self.active_url()
}
}
/// CDN rating function for --rate flag
pub async fn rate_cdns_and_display() {
use colored::Colorize;
let (asn, region_str) = crate::http::get_location_info().await;
let user_region = Region::from_str(&region_str);
if user_region == Region::Unknown {
println!(
"User region: {} (using Global server preference)",
"Unknown".bright_red()
);
} else {
println!("User region: {:?}", user_region);
}
println!("Rating CDNs...");
let cdn_hosts = crate::global::CDN_HOSTS.to_vec();
let mut hosts = Hosts {
servers: cdn_hosts,
active_index: RwLock::new(None),
};
hosts.rate(asn, user_region, true).await;
if hosts.servers.iter().all(|server| server.rating == 0) {
println!("Retrying with longer timeout...");
hosts.rate(asn, user_region, false).await;
}
println!();
for server in hosts.servers.iter() {
let latency_str = server
.latency
.map_or("timeout".to_string(), |l| format!("{} ms", l.as_millis()));
println!(
"{}: rating {}, latency {}",
server.host.bright_white(),
server.rating.to_string().bright_cyan(),
latency_str
);
}
// Show selected CDN
if hosts.next() {
if let Some(best_url) = hosts.active_url() {
println!();
println!("Selected: {}", best_url.bright_green());
}
} else {
println!();
println!("{}", "No available CDN servers".bright_red());
}
}

View File

@@ -17,13 +17,17 @@ 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/{owner}/{repo}/releases/latest").as_str(),
format!(
"https://api.github.com/repos/{}/{}/releases/latest",
owner, repo
)
.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")
@@ -39,13 +43,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/{owner}/{repo}/releases").as_str(),
format!("https://api.github.com/repos/{}/{}/releases", owner, repo).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")?;
@@ -66,7 +70,7 @@ pub async fn latest_version(
let tag = latest_tag(owner, repo, prerelease).await?;
let cleaned_tag = tag.replace('v', "");
Version::parse(&cleaned_tag)
.map_err(|e| format!("Failed to parse version '{cleaned_tag}': {e}").into())
.map_err(|e| format!("Failed to parse version '{}': {}", cleaned_tag, e).into())
}
pub fn download_url(owner: &str, repo: &str, tag: Option<&str>) -> String {

View File

@@ -6,13 +6,20 @@ use std::future::Future;
use std::pin::Pin;
use std::sync::Mutex;
use crate::cdn::{Hosts, Server};
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; 1] = [Server::new("cdn.alterware.ovh")];
pub const CDN_HOSTS: [Server; 2] = [
Server::new("cdn.alterware.ovh", Region::Global),
Server::new("us-cdn.alterware.ovh", Region::NorthAmerica),
];
pub const IP2ASN: &str = "https://ip2asn.getserve.rs/v1/as/ip/self";
pub static USER_AGENT: Lazy<String> = Lazy::new(|| {
format!(
@@ -26,6 +33,8 @@ pub static USER_AGENT: Lazy<String> = Lazy::new(|| {
pub static MASTER_URL: Lazy<Mutex<String>> = Lazy::new(|| Mutex::new(String::from(DEFAULT_MASTER)));
pub static IS_OFFLINE: Lazy<Mutex<bool>> = Lazy::new(|| Mutex::new(false));
pub static PREFIXES: Lazy<HashMap<&'static str, PrintPrefix>> = Lazy::new(|| {
HashMap::from([
(
@@ -72,3 +81,54 @@ pub static PREFIXES: Lazy<HashMap<&'static str, PrintPrefix>> = Lazy::new(|| {
),
])
});
pub async fn check_connectivity_and_rate_cdns() -> Pin<Box<dyn Future<Output = bool> + Send>> {
Box::pin(async move {
crate::println_info!("Initializing CDN rating system...");
let hosts = Hosts::new().await;
let best_cdn = hosts.get_master_url();
if let Some(cdn_url) = best_cdn {
let cdn_url = cdn_url.trim_end_matches('/');
*MASTER_URL.lock().unwrap() = cdn_url.to_string();
crate::println_info!("Selected CDN: {}", cdn_url);
match crate::http_async::get_body_string(cdn_url).await {
Ok(_) => {
info!("Successfully connected to CDN: {}", cdn_url);
true
}
Err(e) => {
error!("Failed to connect to selected CDN {}: {}", cdn_url, e);
*IS_OFFLINE.lock().unwrap() = true;
false
}
}
} else {
crate::println_error!("No CDN hosts are available");
*IS_OFFLINE.lock().unwrap() = true;
false
}
})
}
pub fn check_connectivity(
master_url: Option<String>,
) -> Pin<Box<dyn Future<Output = bool> + Send>> {
Box::pin(async move {
if let Some(url) = master_url {
*MASTER_URL.lock().unwrap() = url.clone();
crate::println_info!("Using fallback connectivity check on {}", url);
match crate::http_async::get_body_string(&url).await {
Ok(_) => true,
Err(_) => {
*IS_OFFLINE.lock().unwrap() = true;
false
}
}
} else {
check_connectivity_and_rate_cdns().await.await
}
})
}

View File

@@ -1,4 +1,5 @@
use reqwest::header::HeaderMap;
use serde_json::Value;
use simple_log::*;
use std::time::{Duration, Instant};
@@ -16,18 +17,18 @@ pub async fn quick_request(url: &str) -> Result<String, Box<dyn std::error::Erro
.await;
if let Err(e) = &res {
error!("Failed to get {url}: {e}");
return Err(format!("Failed to get {url} {e}").into());
error!("Failed to get {}: {}", url, e);
return Err(format!("Failed to get {} {}", url, e).into());
}
let res = res.unwrap();
match res.text().await {
Ok(text) => {
info!("Successfully received response from: {url}");
info!("Successfully received response from: {}", url);
Ok(text)
}
Err(e) => {
warn!("Failed to get response text from {url}: {e}");
warn!("Failed to get response text from {}: {}", url, e);
Err(e.into())
}
}
@@ -63,8 +64,8 @@ pub async fn rating_request(
let latency = start.elapsed();
if let Err(e) = &res {
error!("Failed to get {url}: {e} (after {latency:?})");
return Err(format!("Failed to get {url} {e} (after {latency:?})").into());
error!("Failed to get {}: {} (after {:?})", url, e, latency);
return Err(format!("Failed to get {} {} (after {:?})", url, e, latency).into());
}
let res = res.unwrap();
@@ -73,10 +74,36 @@ pub async fn rating_request(
// We don't need the response body for rating
if let Err(e) = res.text().await {
warn!("Failed to get response text from {url}: {e} (after {latency:?})");
warn!(
"Failed to get response text from {}: {} (after {:?})",
url, e, latency
);
return Err(e.into());
}
info!("Successfully rated {url} in {latency:?} (cloudflare: {is_cloudflare})");
info!(
"Successfully rated {} in {:?} (cloudflare: {})",
url, latency, is_cloudflare
);
Ok((latency, is_cloudflare))
}
/// Retrieve client ASN and region
pub async fn get_location_info() -> (u32, String) {
let response = quick_request(crate::global::IP2ASN).await;
if let Ok(as_data_str) = response {
if let Ok(as_data) = serde_json::from_str::<Value>(&as_data_str) {
let as_number = as_data
.get("as_number")
.and_then(|v| v.as_u64())
.unwrap_or(0) as u32;
let region = as_data
.get("region")
.and_then(|v| v.as_str())
.unwrap_or("Unknown")
.to_string();
return (as_number, region);
}
}
(0, "Unknown".to_string())
}

View File

@@ -32,14 +32,10 @@ pub async fn download_file_progress(
.send()
.await
.map_err(|e| {
error!("Failed to GET from '{url}': {e}");
error!("Failed to GET from '{}': {}", url, e);
format!("Failed to GET from '{url}'")
})?;
if !res.status().is_success() {
return Err(format!("Request failed with status: {}", res.status()));
}
let total_size = res.content_length().unwrap_or(size);
debug!("Download size: {}", misc::human_readable_bytes(total_size));
pb.set_length(total_size);
@@ -93,18 +89,14 @@ pub async fn get_body(url: &str) -> Result<Vec<u8>, String> {
)
.send()
.await
.map_err(|e| format!("Failed to send request: {e}"))?;
.map_err(|e| format!("Failed to send request: {}", e))?;
debug!("{} {url}", res.status());
if !res.status().is_success() {
return Err(format!("Request failed with status: {}", res.status()));
}
res.bytes()
.await
.map(|b| b.to_vec())
.map_err(|e| format!("Failed to get body: {e}"))
.map_err(|e| format!("Failed to get body: {}", e))
}
pub async fn get_body_string(url: &str) -> Result<String, String> {
@@ -127,7 +119,7 @@ pub async fn get_json<T: serde::de::DeserializeOwned>(url: &str) -> Result<T, St
.header("Accept", "application/json")
.send()
.await
.map_err(|e| format!("Failed to send request: {e}"))?;
.map_err(|e| format!("Failed to send request: {}", e))?;
debug!("{} {}", res.status(), url);
@@ -138,7 +130,7 @@ pub async fn get_json<T: serde::de::DeserializeOwned>(url: &str) -> Result<T, St
let body = res
.bytes()
.await
.map_err(|e| format!("Failed to read response body: {e}"))?;
.map_err(|e| format!("Failed to read response body: {}", e))?;
serde_json::from_slice::<T>(&body).map_err(|e| format!("Failed to parse JSON: {e}"))
serde_json::from_slice::<T>(&body).map_err(|e| format!("Failed to parse JSON: {}", e))
}

46
src/iw4x.rs Normal file
View File

@@ -0,0 +1,46 @@
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,6 +6,7 @@ mod github;
mod global;
mod http;
mod http_async;
mod iw4x;
mod misc;
mod self_update;
mod structs;
@@ -27,7 +28,7 @@ use mslnk::ShellLink;
use simple_log::LogConfigBuilder;
use std::{
borrow::Cow,
collections::HashMap,
collections::{HashMap, HashSet},
env, fs,
path::{Path, PathBuf},
};
@@ -116,7 +117,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).await;
update(game, path, false, false, None, None, None).await;
}
#[cfg(windows)]
@@ -186,7 +187,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) {
if !file.name.starts_with(&remote_dir) || file.name == "iw4/iw4x.dll" {
continue;
}
size += file.size as u64;
@@ -200,6 +201,7 @@ async fn update_dir(
dir: &Path,
hashes: &mut HashMap<String, String>,
pb: &ProgressBar,
skip_iw4x_sp: bool,
) {
misc::pb_style_download(pb, false);
@@ -208,7 +210,10 @@ 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) {
if !file.name.starts_with(&remote_dir_pre) || file.name == "iw4/iw4x.dll" {
continue;
}
if skip_iw4x_sp && file.name == "iw4/iw4x-sp.exe" {
continue;
}
@@ -332,12 +337,15 @@ 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 =
@@ -397,12 +405,66 @@ 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).await;
update_dir(
&cdn_info,
game.engine,
dir,
&mut cache.hashes,
&pb,
skip_iw4x_sp,
)
.await;
if bonus_content && !game.bonus.is_empty() {
for bonus in game.bonus.iter() {
update_dir(&cdn_info, bonus, dir, &mut cache.hashes, &pb).await;
update_dir(&cdn_info, bonus, dir, &mut cache.hashes, &pb, skip_iw4x_sp).await;
}
}
@@ -487,18 +549,9 @@ fn launch(file_path: &PathBuf, args: &str) {
fn launch(file_path: &PathBuf, args: &str) {
println!("\n\nJoin the AlterWare Discord server:\nhttps://discord.gg/2ETE8engZM\n\n");
crate::println_info!("Launching {} {args}", file_path.display());
let launcher = if misc::is_program_in_path("umu-run") {
Some("umu-run")
} else if misc::is_program_in_path("wine") {
Some("wine")
} else {
None
};
let exit_status = if let Some(launcher) = launcher {
println!("Found {launcher}, launching game using {launcher}.\nIf you run into issues or want to launch a different way, run {} manually.", file_path.display());
std::process::Command::new(launcher)
let exit_status = if misc::is_program_in_path("wine") {
println!("Found wine, launching game using wine.\nIf you run into issues or want to launch a different way, run {} manually.", file_path.display());
std::process::Command::new("wine")
.args([file_path.to_str().unwrap(), args.trim()])
.current_dir(file_path.parent().unwrap())
.spawn()
@@ -574,7 +627,7 @@ fn show_iw4x_info() {
"{}",
"IW4x is not provided through AlterWare anymore.".bright_red()
);
println!("Please visit https://aka.alterware.dev/iw4x for more information");
println!("Please use iw4x-launcher.exe instead or visit www.iw4x.dev/install");
misc::stdin();
std::process::exit(0);
}
@@ -626,6 +679,8 @@ async fn main() {
println!(" --redist: (Re-)Install redistributables");
println!(" --prerelease: Update to prerelease version of clients and launcher");
println!(" --offline: Run in offline mode");
println!(" --skip-connectivity-check: Don't check connectivity");
println!(" --rate: Display CDN rating information and exit");
println!("\nExample:\n alterware-launcher.exe iw6 --pass \"-headless\"");
return;
}
@@ -661,6 +716,11 @@ async fn main() {
install_path = env::current_dir().unwrap();
}
if arg_bool(&args, "--rate") {
cdn::rate_cdns_and_display().await;
return;
}
let mut cfg = config::load(install_path.join("alterware-launcher.json"));
if let Some(cdn_url) = arg_value(&args, "--cdn-url") {
@@ -673,6 +733,11 @@ async fn main() {
arg_remove(&mut args, "--offline");
}
if arg_bool(&args, "--skip-connectivity-check") {
cfg.skip_connectivity_check = true;
arg_remove(&mut args, "--skip-connectivity-check");
}
let initial_cdn = if !cfg.cdn_url.is_empty() {
info!("Using custom CDN URL: {}", cfg.cdn_url);
Some(cfg.cdn_url.clone())
@@ -680,6 +745,14 @@ async fn main() {
None
};
if !cfg.offline && !cfg.skip_connectivity_check {
if initial_cdn.is_some() {
cfg.offline = !global::check_connectivity(initial_cdn).await;
} else {
cfg.offline = !global::check_connectivity_and_rate_cdns().await.await;
}
}
if cfg.offline {
// Check if this is a first-time run (no stored data)
let stored_data = cache::get_stored_data();
@@ -743,9 +816,9 @@ async fn main() {
std::process::exit(1);
};
info!("Launching game in offline mode with client: {client}");
info!("Launching game in offline mode with client: {}", client);
// Launch game without updates
launch(&install_path.join(format!("{client}.exe")), &cfg.args);
launch(&install_path.join(format!("{}.exe", client)), &cfg.args);
return;
}
@@ -871,6 +944,14 @@ 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 {
@@ -899,7 +980,9 @@ 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,6 +12,13 @@ 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;
@@ -41,7 +48,7 @@ pub fn is_program_in_path(program: &str) -> bool {
paths.to_str().map(|paths| {
paths
.split(':')
.any(|dir| fs::metadata(format!("{dir}/{program}")).is_ok())
.any(|dir| fs::metadata(format!("{}/{}", dir, program)).is_ok())
})
})
.unwrap_or(false)
@@ -53,9 +60,9 @@ pub fn is_program_in_path(program: &str) -> bool {
.and_then(|paths| {
paths.to_str().map(|paths| {
paths.split(';').any(|dir| {
fs::metadata(format!("{dir}\\{program}.exe")).is_ok()
|| fs::metadata(format!("{dir}\\{program}.cmd")).is_ok()
|| fs::metadata(format!("{dir}\\{program}.bat")).is_ok()
fs::metadata(format!("{}\\{}.exe", dir, program)).is_ok()
|| fs::metadata(format!("{}\\{}.cmd", dir, program)).is_ok()
|| fs::metadata(format!("{}\\{}.bat", dir, program)).is_ok()
})
})
})

View File

@@ -15,7 +15,7 @@ pub async fn self_update_available(prerelease: Option<bool>) -> bool {
let latest_version = match github::latest_version(GH_OWNER, GH_REPO, prerelease).await {
Ok(v) => v,
Err(e) => {
error!("Failed to get latest version: {e}");
error!("Failed to get latest version: {}", e);
return false;
}
};
@@ -93,7 +93,7 @@ pub async fn run(update_only: bool, prerelease: Option<bool>) {
"alterware-launcher.exe"
};
if let Err(e) = http_async::download_file(
http_async::download_file(
&format!(
"{}/download/{}",
github::download_url(GH_OWNER, GH_REPO, None),
@@ -102,11 +102,7 @@ pub async fn run(update_only: bool, prerelease: Option<bool>) {
&file_path,
)
.await
{
error!("Self-update download failed: {e}");
crate::println_error!("Self-update failed ({e}), skipping update.");
return;
}
.unwrap();
if !file_path.exists() {
crate::println_error!("Failed to download launcher update.");

View File

@@ -54,6 +54,8 @@ pub struct Config {
pub cdn_url: String,
#[serde(default)]
pub offline: bool,
#[serde(default)]
pub skip_connectivity_check: bool,
}
impl Default for Config {
@@ -71,6 +73,7 @@ impl Default for Config {
prerelease: false,
cdn_url: String::default(),
offline: false,
skip_connectivity_check: false,
}
}
}