6 Commits

Author SHA1 Message Date
140f4c335f v0.4.8 2023-09-10 12:39:44 +02:00
3e1a266c3e check first dir when matching files to download 2023-09-10 12:38:21 +02:00
92663425ef update readme 2023-09-03 19:03:46 +02:00
ffa379e6dd misc
- reduce github calls
- latest_tag returns full tag
- rev_to_int default to 0 on strip_prefix
- lint
2023-08-30 13:06:49 +02:00
a41375a791 github::latest -> latest_tag 2023-08-30 12:46:13 +02:00
ac76e9bb89 steamlocate 2.0.0-alpha.0 2023-08-30 12:45:10 +02:00
9 changed files with 86 additions and 74 deletions

44
Cargo.lock generated
View File

@ -30,7 +30,7 @@ dependencies = [
[[package]]
name = "alterware-launcher"
version = "0.4.7"
version = "0.4.8"
dependencies = [
"http_req",
"mslnk",
@ -199,23 +199,22 @@ dependencies = [
[[package]]
name = "dirs"
version = "5.0.1"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
checksum = "30baa043103c9d0c2a57cf537cc2f35623889dc0d405e6c3cccfadbc81c71309"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.4.1"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys",
"winapi",
]
[[package]]
@ -417,24 +416,12 @@ dependencies = [
"log",
]
[[package]]
name = "nom"
version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce"
[[package]]
name = "once_cell"
version = "1.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b"
[[package]]
name = "option-ext"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]]
name = "password-hash"
version = "0.4.2"
@ -767,27 +754,17 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "steamlocate"
version = "1.2.1"
version = "2.0.0-alpha.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec01c74611d14a808cb212d17c6e03f0e30736a15ed1d5736f8a53154cea3ae"
checksum = "2b1568c4a70a26c4373fe1131ffa4eff055459631b6e40c6bc118615f2d870c3"
dependencies = [
"dirs",
"keyvalues-parser",
"keyvalues-serde",
"serde",
"steamy-vdf",
"winreg",
]
[[package]]
name = "steamy-vdf"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "533127ad49314bfe71c3d3fd36b3ebac3d24f40618092e70e1cfe8362c7fac79"
dependencies = [
"nom",
]
[[package]]
name = "subtle"
version = "2.5.0"
@ -1082,11 +1059,10 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
[[package]]
name = "winreg"
version = "0.11.0"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76a1a57ff50e9b408431e8f97d5456f2807f8eb2a2cd79b06068fc87f8ecf189"
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
dependencies = [
"cfg-if",
"winapi",
]

View File

@ -1,6 +1,6 @@
[package]
name = "alterware-launcher"
version = "0.4.7"
version = "0.4.8"
edition = "2021"
build = "res/build.rs"
@ -26,7 +26,7 @@ semver = "1.0.18"
zip = "0.6.6"
[target.'cfg(windows)'.dependencies]
steamlocate = "1.2.1"
steamlocate = "2.0.0-alpha.0"
mslnk = "0.1.8"
# https://github.com/mitsuhiko/self-replace/pull/16/
windows-sys = { version = "0.48", features = [

View File

@ -1,14 +1,50 @@
# alterware-launcher
# AlterWare Launcher
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 the game directory
### [AlterWare.dev](https://alterware.dev)
##### IW4x | IW4-SP | IW5-Mod | IW6-Mod | S1-Mod
---
#### Installation
1. Download the [latest alterware-launcher.exe](https://github.com/mxve/alterware-launcher/releases/latest/download/alterware-launcher.exe)
2. Place alterware-launcher.exe in the game directory
3. Run alterware-launcher.exe, after updating the game will launch automatically
---
- Passing ```iw4-sp```, ```iw5-mod```, ```iw6-mod``` or ```s1-mod``` as the first argument will skip automatic game detection
#### Command line arguments
- Passing ```iw4-sp```, ```iw4x```, ```iw5-mod```, ```iw6-mod``` or ```s1-mod``` as the first argument will skip automatic game detection
- Passing ```update``` will stop the launcher from launching the game
- ```skip-launcher-update``` skips self-update
- ```skip-launcher-update``` skips launcher self-update
---
#### Support
Visit the [AlterWare Forum](https://forum.alterware.dev/) or [Discord](https://discord.gg/2ETE8engZM) for support.
---
#### Building from Source
- [Install Rust](https://rustup.rs/)
- Clone the repository
- Run ```cargo build --release```
- The executable will be located in ```target/release```
---
### Note for server owners:
When the launcher updates itself it needs to be restarted. It will return exit code 201 in this case.
```
@echo off
:loop
start /wait alterware-launcher.exe update
if %errorlevel% equ 201 (
goto loop
)
```

View File

@ -1,6 +1,6 @@
use semver::Version;
pub fn latest(owner: &str, repo: &str) -> String {
pub fn latest_tag(owner: &str, repo: &str) -> String {
let github_body = crate::http::get_body_string(
format!(
"https://api.github.com/repos/{}/{}/releases/latest",
@ -9,13 +9,12 @@ pub fn latest(owner: &str, repo: &str) -> String {
.as_str(),
);
let github_json: serde_json::Value = serde_json::from_str(&github_body).unwrap();
github_json["tag_name"]
.to_string()
.replace(['v', '"'].as_ref(), "")
github_json["tag_name"].to_string().replace('"', "")
}
pub fn latest_version(owner: &str, repo: &str) -> Version {
Version::parse(&latest(owner, repo)).unwrap()
let tag = latest_tag(owner, repo).replace('v', "");
Version::parse(&tag).unwrap()
}
pub fn latest_release_url(owner: &str, repo: &str) -> String {

View File

@ -1,7 +1,7 @@
use crate::github;
use crate::global::*;
use crate::http;
use crate::misc;
use crate::global::*;
use std::{fs, path::Path};
@ -14,30 +14,24 @@ pub fn local_revision(dir: &Path) -> u16 {
}
pub fn remote_revision() -> u16 {
misc::rev_to_int(&github::latest(GH_IW4X_OWNER, GH_IW4X_REPO))
}
pub fn update_available(dir: &Path) -> bool {
if !dir.join("iw4x.dll").exists() {
return true;
}
local_revision(dir) < remote_revision()
misc::rev_to_int(&github::latest_tag(GH_IW4X_OWNER, GH_IW4X_REPO))
}
pub fn update(dir: &Path) {
if update_available(dir) {
println!("Updating IW4x...");
http::download_file(
&format!(
"{}/download/iw4x.dll",
github::latest_release_url(GH_IW4X_OWNER, GH_IW4X_REPO)
),
&dir.join("iw4x.dll"),
);
fs::write(
dir.join(".iw4xrevision"),
github::latest(GH_IW4X_OWNER, GH_IW4X_REPO),
)
.unwrap();
let remote = remote_revision();
let local = local_revision(dir);
if remote <= local && dir.join("iw4x.dll").exists() {
return;
}
println!("Updating IW4x...");
http::download_file(
&format!(
"{}/download/iw4x.dll",
github::latest_release_url(GH_IW4X_OWNER, GH_IW4X_REPO)
),
&dir.join("iw4x.dll"),
);
fs::write(dir.join(".iw4xrevision"), format!("r{}", remote)).unwrap();
}

View File

@ -177,8 +177,9 @@ fn update(game: &Game, dir: &Path) {
))
.unwrap();
let engine_str = format!("{}/", game.engine);
for file in cdn_info {
if !file.name.starts_with(game.engine) || file.name == "iw4/iw4x.dll" {
if !file.name.starts_with(&engine_str) || file.name == "iw4/iw4x.dll" {
continue;
}

View File

@ -13,5 +13,8 @@ pub fn stdin() -> String {
}
pub fn rev_to_int(rev: &str) -> u16 {
rev.strip_prefix('r').unwrap().parse::<u16>().unwrap_or(0)
rev.strip_prefix('r')
.unwrap_or("0")
.parse::<u16>()
.unwrap_or(0)
}

View File

@ -16,7 +16,10 @@ pub fn self_update_available() -> bool {
pub fn run(_update_only: bool) {
if self_update_available() {
println!("A new version of the AlterWare launcher is available.");
println!("Download it at {}", github::latest_release_url(GH_OWNER, GH_REPO));
println!(
"Download it at {}",
github::latest_release_url(GH_OWNER, GH_REPO)
);
println!("Launching in 10 seconds..");
thread::sleep(time::Duration::from_secs(10));
}