Compare commits
30 Commits
Author | SHA1 | Date | |
---|---|---|---|
f4fe1c6699 | |||
59f1b09337 | |||
237fa8c16f | |||
78e155408e | |||
3033dd2315 | |||
48851fa8d3 | |||
84ea4e48af | |||
b408f13cce | |||
959c3a8a61 | |||
73df20ebb6 | |||
08814a8c3e | |||
65094d4701 | |||
a20b1acdda | |||
75b1d6254b | |||
65f05a5a1c | |||
fa6bdc9f29 | |||
7595a46b44 | |||
c41a843315 | |||
a90a60ec3a | |||
209b599120 | |||
9f00b0c0e7 | |||
aaede9b6cb | |||
8a14008706 | |||
ad7e78ec47 | |||
140f4c335f | |||
3e1a266c3e | |||
92663425ef | |||
ffa379e6dd | |||
a41375a791 | |||
ac76e9bb89 |
83
Cargo.lock
generated
83
Cargo.lock
generated
@ -30,8 +30,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "alterware-launcher"
|
||||
version = "0.4.7"
|
||||
version = "0.5.1"
|
||||
dependencies = [
|
||||
"colored",
|
||||
"http_req",
|
||||
"mslnk",
|
||||
"rand",
|
||||
@ -137,6 +138,17 @@ dependencies = [
|
||||
"inout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "colored"
|
||||
version = "2.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2674ec482fbc38012cf31e6c42ba0177b431a0cb6f15fe40efa5aab1bda516f6"
|
||||
dependencies = [
|
||||
"is-terminal",
|
||||
"lazy_static",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.1.5"
|
||||
@ -199,23 +211,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]]
|
||||
@ -285,6 +296,12 @@ dependencies = [
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b"
|
||||
|
||||
[[package]]
|
||||
name = "hmac"
|
||||
version = "0.12.1"
|
||||
@ -324,6 +341,17 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is-terminal"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.6"
|
||||
@ -373,6 +401,12 @@ dependencies = [
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.147"
|
||||
@ -417,24 +451,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"
|
||||
@ -722,9 +744,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.105"
|
||||
version = "1.0.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360"
|
||||
checksum = "2cc66a619ed80bf7a0f6b17dd063a84b88f6dea1813737cf469aef1d081142c2"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
@ -767,27 +789,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 +1094,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",
|
||||
]
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "alterware-launcher"
|
||||
version = "0.4.7"
|
||||
version = "0.5.1"
|
||||
edition = "2021"
|
||||
build = "res/build.rs"
|
||||
|
||||
@ -20,13 +20,14 @@ http_req = { version = "0.9.2", default-features = false, features = [
|
||||
] }
|
||||
sha1_smol = "1.0.0"
|
||||
serde = { version = "1.0.188", features = ["derive"] }
|
||||
serde_json = "1.0.105"
|
||||
serde_json = "1.0.106"
|
||||
rand = "0.8.5"
|
||||
semver = "1.0.18"
|
||||
zip = "0.6.6"
|
||||
colored = "2.0.4"
|
||||
|
||||
[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 = [
|
||||
|
67
README.md
67
README.md
@ -1,14 +1,69 @@
|
||||
# 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
|
||||
- Passing ```update``` will stop the launcher from launching the game
|
||||
- ```skip-launcher-update``` skips self-update
|
||||
#### Command line arguments
|
||||
|
||||
- ```iw4-sp```, ```iw4x```, ```iw5-mod```, ```iw6-mod```, ```s1-mod```
|
||||
- Skip automatic detection and launch the specified game
|
||||
- This should always be the first argument if used
|
||||
- ```--update```, ```-u```
|
||||
- Only update the game, don't launch it
|
||||
- ```--skip-launcher-update```
|
||||
- Don't update the launcher
|
||||
- ```--bonus```
|
||||
- Download bonus content
|
||||
- ```--force```, ```-f```
|
||||
- Force file hash recheck
|
||||
- ```--path```, ```-p```
|
||||
- Set the game path
|
||||
- Do not include a trailing backslash in the path
|
||||
- ```--pass```
|
||||
- Pass additional arguments to the game
|
||||
- ```--version```, ```-v```
|
||||
- Print the launcher version
|
||||
|
||||
Example: ```alterware-launcher.exe iw4x --bonus -u --path "C:\Games\IW4x" --pass "-console"```
|
||||
|
||||
Some arguments can be set in alterware-launcher.json, args generally override the values of the config.
|
||||
|
||||
---
|
||||
|
||||
#### 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
|
||||
)
|
||||
```
|
30
src/config.rs
Normal file
30
src/config.rs
Normal file
@ -0,0 +1,30 @@
|
||||
use crate::structs::Config;
|
||||
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
pub fn load(config_path: PathBuf) -> Config {
|
||||
if config_path.exists() {
|
||||
let cfg = fs::read_to_string(&config_path).unwrap();
|
||||
let cfg: Config = serde_json::from_str(&cfg).unwrap_or(Config::default());
|
||||
return cfg;
|
||||
}
|
||||
save(config_path.clone(), Config::default());
|
||||
Config::default()
|
||||
}
|
||||
|
||||
pub fn save(config_path: PathBuf, config: Config) {
|
||||
fs::write(config_path, serde_json::to_string(&config).unwrap()).unwrap();
|
||||
}
|
||||
|
||||
pub fn save_value(config_path: PathBuf, key: &str, value: bool) {
|
||||
let mut config = load(config_path.clone());
|
||||
match key {
|
||||
"update_only" => config.update_only = value,
|
||||
"skip_self_update" => config.skip_self_update = value,
|
||||
"download_bonus_content" => config.download_bonus_content = value,
|
||||
"ask_bonus_content" => config.ask_bonus_content = value,
|
||||
"force_update" => config.force_update = value,
|
||||
_ => (),
|
||||
}
|
||||
save(config_path, config);
|
||||
}
|
@ -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 {
|
||||
|
33
src/iw4x.rs
33
src/iw4x.rs
@ -1,8 +1,9 @@
|
||||
use crate::github;
|
||||
use crate::global::*;
|
||||
use crate::http;
|
||||
use crate::misc;
|
||||
use crate::global::*;
|
||||
|
||||
use colored::*;
|
||||
use std::{fs, path::Path};
|
||||
|
||||
pub fn local_revision(dir: &Path) -> u16 {
|
||||
@ -14,19 +15,22 @@ 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...");
|
||||
let remote = remote_revision();
|
||||
let local = local_revision(dir);
|
||||
|
||||
if remote <= local && dir.join("iw4x.dll").exists() {
|
||||
return;
|
||||
}
|
||||
|
||||
println!(
|
||||
"[{}] {}",
|
||||
"Downloading".bright_yellow(),
|
||||
dir.join("iw4x.dll").display()
|
||||
);
|
||||
http::download_file(
|
||||
&format!(
|
||||
"{}/download/iw4x.dll",
|
||||
@ -34,10 +38,5 @@ pub fn update(dir: &Path) {
|
||||
),
|
||||
&dir.join("iw4x.dll"),
|
||||
);
|
||||
fs::write(
|
||||
dir.join(".iw4xrevision"),
|
||||
github::latest(GH_IW4X_OWNER, GH_IW4X_REPO),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
fs::write(dir.join(".iw4xrevision"), format!("r{}", remote)).unwrap();
|
||||
}
|
||||
|
253
src/main.rs
253
src/main.rs
@ -1,3 +1,4 @@
|
||||
mod config;
|
||||
mod github;
|
||||
mod global;
|
||||
mod http;
|
||||
@ -9,9 +10,10 @@ mod structs;
|
||||
use global::*;
|
||||
use structs::*;
|
||||
|
||||
use colored::*;
|
||||
#[cfg(windows)]
|
||||
use mslnk::ShellLink;
|
||||
use std::{fs, path::Path, path::PathBuf};
|
||||
use std::{borrow::Cow, collections::HashMap, fs, path::Path, path::PathBuf};
|
||||
#[cfg(windows)]
|
||||
use steamlocate::SteamDir;
|
||||
|
||||
@ -21,7 +23,7 @@ fn get_installed_games(games: &Vec<Game>) -> Vec<(u32, PathBuf)> {
|
||||
let mut steamdir = match SteamDir::locate() {
|
||||
Some(steamdir) => steamdir,
|
||||
None => {
|
||||
println!("Steam not found.");
|
||||
println!("{}", "Steam not found!".yellow());
|
||||
return installed_games;
|
||||
}
|
||||
};
|
||||
@ -38,7 +40,7 @@ fn get_installed_games(games: &Vec<Game>) -> Vec<(u32, PathBuf)> {
|
||||
#[cfg(windows)]
|
||||
fn setup_client_links(game: &Game, game_dir: &Path) {
|
||||
if game.client.len() > 1 {
|
||||
println!("Multiple clients installed, use the shortcuts (launch-<client>.lnk in the game directory or desktop shortcuts) to launch a specific client.");
|
||||
println!("Multiple clients installed, use the shortcuts (launch-<client>.lnk in the game directory or on the desktop) to launch a specific client.");
|
||||
}
|
||||
|
||||
let target = game_dir.join("alterware-launcher.exe");
|
||||
@ -90,16 +92,18 @@ fn setup_desktop_links(path: &Path, game: &Game) {
|
||||
fn auto_install(path: &Path, game: &Game) {
|
||||
setup_client_links(game, path);
|
||||
setup_desktop_links(path, game);
|
||||
update(game, path);
|
||||
update(game, path, false, false);
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn windows_launcher_install(games: &Vec<Game>) {
|
||||
println!("No game specified/found. Checking for installed Steam games..");
|
||||
println!(
|
||||
"{}",
|
||||
"No game specified/found. Checking for installed Steam games..".yellow()
|
||||
);
|
||||
let installed_games = get_installed_games(games);
|
||||
|
||||
if !installed_games.is_empty() {
|
||||
// if current directory is in the steamapps/common folder of a game, use that game
|
||||
let current_dir = std::env::current_dir().unwrap();
|
||||
for (id, path) in installed_games.iter() {
|
||||
if current_dir.starts_with(path) {
|
||||
@ -165,78 +169,224 @@ fn prompt_client_selection(games: &[Game]) -> String {
|
||||
fn manual_install(games: &[Game]) {
|
||||
let selection = prompt_client_selection(games);
|
||||
let game = games.iter().find(|&g| g.client[0] == selection).unwrap();
|
||||
update(game, &std::env::current_dir().unwrap());
|
||||
update(game, &std::env::current_dir().unwrap(), false, false);
|
||||
println!("Installation complete. Please run the launcher again or use a shortcut to launch the game.");
|
||||
std::io::stdin().read_line(&mut String::new()).unwrap();
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
fn update(game: &Game, dir: &Path) {
|
||||
let cdn_info: Vec<CdnFile> = serde_json::from_str(&http::get_body_string(
|
||||
format!("{}/files.json", MASTER).as_str(),
|
||||
))
|
||||
.unwrap();
|
||||
fn update_dir(
|
||||
cdn_info: &Vec<CdnFile>,
|
||||
remote_dir: &str,
|
||||
dir: &Path,
|
||||
hashes: &mut HashMap<String, String>,
|
||||
) {
|
||||
let remote_dir = format!("{}/", remote_dir);
|
||||
|
||||
for file in cdn_info {
|
||||
if !file.name.starts_with(game.engine) || file.name == "iw4/iw4x.dll" {
|
||||
if !file.name.starts_with(&remote_dir) || file.name == "iw4/iw4x.dll" {
|
||||
continue;
|
||||
}
|
||||
|
||||
let file_path = dir.join(&file.name.replace(&format!("{}/", game.engine), ""));
|
||||
if file_path.exists() {
|
||||
let sha1_local = misc::get_file_sha1(&file_path).to_lowercase();
|
||||
let sha1_remote = file.hash.to_lowercase();
|
||||
let file_name = &file.name.replace(remote_dir.as_str(), "");
|
||||
let file_path = dir.join(file_name);
|
||||
if file_path.exists() {
|
||||
let sha1_local = hashes
|
||||
.get(file_name)
|
||||
.map(Cow::Borrowed)
|
||||
.unwrap_or_else(|| Cow::Owned(misc::get_file_sha1(&file_path)))
|
||||
.to_string();
|
||||
|
||||
if sha1_local != sha1_remote {
|
||||
println!(
|
||||
"Updating {}...\nLocal hash: {}\nRemote hash: {}",
|
||||
file_path.display(),
|
||||
sha1_local,
|
||||
sha1_remote
|
||||
"[{}] {}",
|
||||
"Updating".bright_yellow(),
|
||||
file_path.display()
|
||||
);
|
||||
http::download_file(&format!("{}/{}", MASTER, file.name), &file_path);
|
||||
}
|
||||
} else {
|
||||
println!("Downloading {}...", file_path.display());
|
||||
println!("[{}] {}", "Checked".bright_blue(), file_path.display());
|
||||
}
|
||||
hashes.insert(file_name.to_owned(), sha1_remote.to_owned());
|
||||
} else {
|
||||
println!(
|
||||
"[{}] {}",
|
||||
"Downloading".bright_yellow(),
|
||||
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), &file_path);
|
||||
hashes.insert(file_name.to_owned(), sha1_remote.to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update(game: &Game, dir: &Path, bonus_content: bool, force: bool) {
|
||||
let cdn_info: Vec<CdnFile> = serde_json::from_str(&http::get_body_string(
|
||||
format!("{}/files.json", MASTER).as_str(),
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let mut hashes = HashMap::new();
|
||||
let hash_file = dir.join(".sha-sums");
|
||||
if hash_file.exists() && !force {
|
||||
let hash_file = fs::read_to_string(hash_file).unwrap();
|
||||
for line in hash_file.lines() {
|
||||
let mut split = line.split_whitespace();
|
||||
let hash = split.next().unwrap();
|
||||
let file = split.next().unwrap();
|
||||
hashes.insert(file.to_owned(), hash.to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
update_dir(&cdn_info, game.engine, dir, &mut hashes);
|
||||
|
||||
if game.engine == "iw4" {
|
||||
iw4x::update(dir);
|
||||
}
|
||||
|
||||
if bonus_content && !game.bonus.is_empty() {
|
||||
for bonus in game.bonus.iter() {
|
||||
update_dir(&cdn_info, bonus, dir, &mut hashes);
|
||||
}
|
||||
}
|
||||
|
||||
let mut hash_file_content = String::new();
|
||||
for (file, hash) in hashes.iter() {
|
||||
hash_file_content.push_str(&format!("{} {}\n", hash, file));
|
||||
}
|
||||
fs::write(dir.join(".sha-sums"), hash_file_content).unwrap();
|
||||
}
|
||||
|
||||
fn launch(file_path: &PathBuf) {
|
||||
println!("Launching {}...", file_path.display());
|
||||
fn launch(file_path: &PathBuf, args: &str) {
|
||||
println!("Launching {} {}", file_path.display(), args);
|
||||
std::process::Command::new(file_path)
|
||||
.args(args.trim().split(' '))
|
||||
.current_dir(file_path.parent().unwrap())
|
||||
.spawn()
|
||||
.expect("Failed to launch the game")
|
||||
.wait()
|
||||
.expect("Failed to wait for the game process to finish");
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn setup_env() {
|
||||
colored::control::set_virtual_terminal(true).unwrap_or_else(|error| {
|
||||
println!("{:#?}", error);
|
||||
colored::control::SHOULD_COLORIZE.set_override(false);
|
||||
});
|
||||
}
|
||||
|
||||
fn arg_value(args: &[String], arg: &str) -> Option<String> {
|
||||
args.iter()
|
||||
.position(|r| r == arg)
|
||||
.map(|e| args[e + 1].clone())
|
||||
}
|
||||
|
||||
fn arg_bool(args: &[String], arg: &str) -> bool {
|
||||
args.iter().any(|r| r == arg)
|
||||
}
|
||||
|
||||
fn arg_remove(args: &mut Vec<String>, arg: &str) {
|
||||
args.iter().position(|r| r == arg).map(|e| args.remove(e));
|
||||
}
|
||||
|
||||
fn arg_remove_value(args: &mut Vec<String>, arg: &str) {
|
||||
if let Some(e) = args.iter().position(|r| r == arg) {
|
||||
args.remove(e);
|
||||
args.remove(e);
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[cfg(windows)]
|
||||
setup_env();
|
||||
|
||||
let mut args: Vec<String> = std::env::args().collect();
|
||||
|
||||
let mut update_only = false;
|
||||
if args.contains(&String::from("update")) {
|
||||
update_only = true;
|
||||
args.iter()
|
||||
.position(|r| r == "update")
|
||||
.map(|e| args.remove(e));
|
||||
if arg_bool(&args, "--help") {
|
||||
println!("CLI Args:");
|
||||
println!(" <client>: Specify the client to launch");
|
||||
println!(" --help: Display this help message");
|
||||
println!(" --version: Display the launcher version");
|
||||
println!(" --path/-p <path>: Specify the game directory");
|
||||
println!(" --update/-u: Update only, don't launch the game");
|
||||
println!(" --bonus: Download bonus content");
|
||||
println!(" --force/-f: Force file hash recheck");
|
||||
println!(" --pass <args>: Pass arguments to the game");
|
||||
println!(" --skip-launcher-update: Skip launcher self-update");
|
||||
println!(
|
||||
"\nExample:\n alterware-launcher.exe iw4x --bonus --pass \"-console -nointro\""
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if !args.contains(&String::from("skip-launcher-update")) {
|
||||
self_update::run(update_only);
|
||||
if arg_bool(&args, "--version") || arg_bool(&args, "-v") {
|
||||
println!(
|
||||
"{} v{}",
|
||||
"AlterWare Launcher".bright_green(),
|
||||
env!("CARGO_PKG_VERSION")
|
||||
);
|
||||
println!("https://github.com/{}/{}", GH_OWNER, GH_REPO);
|
||||
println!(
|
||||
"\n{}{}{}{}{}{}{}",
|
||||
"For ".on_black(),
|
||||
"Alter".bright_blue().on_black().underline(),
|
||||
"Ware".white().on_black().underline(),
|
||||
".dev".on_black().underline(),
|
||||
" by ".on_black(),
|
||||
"mxve".bright_magenta().on_black().underline(),
|
||||
".de".on_black().underline()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let install_path: PathBuf;
|
||||
if let Some(path) = arg_value(&args, "--path") {
|
||||
install_path = PathBuf::from(path);
|
||||
arg_remove_value(&mut args, "--path");
|
||||
} else if let Some(path) = arg_value(&args, "-p") {
|
||||
install_path = PathBuf::from(path);
|
||||
arg_remove_value(&mut args, "-p");
|
||||
} else {
|
||||
args.iter()
|
||||
.position(|r| r == "skip-launcher-update")
|
||||
.map(|e| args.remove(e));
|
||||
install_path = std::env::current_dir().unwrap();
|
||||
}
|
||||
|
||||
let mut cfg = config::load(install_path.join("alterware-launcher.json"));
|
||||
|
||||
if !arg_bool(&args, "--skip-launcher-update") && !cfg.skip_self_update {
|
||||
self_update::run(cfg.update_only);
|
||||
} else {
|
||||
arg_remove(&mut args, "--skip-launcher-update");
|
||||
}
|
||||
|
||||
if arg_bool(&args, "--update") || arg_bool(&args, "-u") {
|
||||
cfg.update_only = true;
|
||||
arg_remove(&mut args, "--update");
|
||||
arg_remove(&mut args, "-u");
|
||||
}
|
||||
|
||||
if arg_bool(&args, "--bonus") {
|
||||
cfg.download_bonus_content = true;
|
||||
arg_remove(&mut args, "--bonus");
|
||||
}
|
||||
|
||||
if arg_bool(&args, "--force") || arg_bool(&args, "-f") {
|
||||
cfg.force_update = true;
|
||||
arg_remove(&mut args, "--force");
|
||||
arg_remove(&mut args, "-f");
|
||||
}
|
||||
|
||||
if let Some(pass) = arg_value(&args, "--pass") {
|
||||
cfg.args = pass;
|
||||
arg_remove_value(&mut args, "--pass");
|
||||
} else if cfg.args.is_empty() {
|
||||
cfg.args = String::from("");
|
||||
}
|
||||
|
||||
let games_json = http::get_body_string(format!("{}/games.json", MASTER).as_str());
|
||||
@ -248,9 +398,9 @@ fn main() {
|
||||
} else {
|
||||
'main: for g in games.iter() {
|
||||
for r in g.references.iter() {
|
||||
if std::path::Path::new(r).exists() {
|
||||
if install_path.join(r).exists() {
|
||||
if g.client.len() > 1 {
|
||||
if update_only {
|
||||
if cfg.update_only {
|
||||
game = String::from(g.client[0]);
|
||||
break 'main;
|
||||
}
|
||||
@ -277,9 +427,30 @@ fn main() {
|
||||
for g in games.iter() {
|
||||
for c in g.client.iter() {
|
||||
if c == &game {
|
||||
update(g, &std::env::current_dir().unwrap());
|
||||
if !update_only {
|
||||
launch(&PathBuf::from(format!("{}.exe", c)));
|
||||
if cfg.ask_bonus_content && !g.bonus.is_empty() {
|
||||
println!("Download bonus content? (Y/n)");
|
||||
let input = misc::stdin().to_ascii_lowercase();
|
||||
cfg.download_bonus_content = input != "n";
|
||||
config::save_value(
|
||||
install_path.join("alterware-launcher.json"),
|
||||
"download_bonus_content",
|
||||
cfg.download_bonus_content,
|
||||
);
|
||||
config::save_value(
|
||||
install_path.join("alterware-launcher.json"),
|
||||
"ask_bonus_content",
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
update(
|
||||
g,
|
||||
install_path.as_path(),
|
||||
cfg.download_bonus_content,
|
||||
cfg.force_update,
|
||||
);
|
||||
if !cfg.update_only {
|
||||
launch(&install_path.join(format!("{}.exe", c)), &cfg.args);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -292,7 +463,7 @@ fn main() {
|
||||
#[cfg(not(windows))]
|
||||
manual_install(&games);
|
||||
|
||||
println!("Game not found!");
|
||||
println!("{}", "Game not found!".bright_red());
|
||||
println!("Place the launcher in the game folder, if that doesn't work specify the client on the command line (ex. alterware-launcher.exe iw4-sp)");
|
||||
println!("Press enter to exit...");
|
||||
std::io::stdin().read_line(&mut String::new()).unwrap();
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -11,4 +11,28 @@ pub struct Game<'a> {
|
||||
pub client: Vec<&'a str>,
|
||||
pub references: Vec<&'a str>,
|
||||
pub app_id: u32,
|
||||
pub bonus: Vec<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
pub struct Config {
|
||||
pub update_only: bool,
|
||||
pub skip_self_update: bool,
|
||||
pub download_bonus_content: bool,
|
||||
pub ask_bonus_content: bool,
|
||||
pub force_update: bool,
|
||||
pub args: String,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
update_only: false,
|
||||
skip_self_update: false,
|
||||
download_bonus_content: false,
|
||||
ask_bonus_content: true,
|
||||
force_update: false,
|
||||
args: String::from(""),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user