9 Commits

Author SHA1 Message Date
7ca7615222 v0.4.2 2023-08-17 20:26:25 +02:00
2195f42abc fix: unix.. again 2023-08-17 20:26:08 +02:00
f7635d4089 return 101 when restart is required after self-update 2023-08-17 18:32:32 +02:00
9598ec3dfe v0.4.1 2023-08-16 13:01:32 +02:00
37266207e7 create release as draft 2023-08-16 13:01:25 +02:00
e041df80c5 don't copy if current & target path are the same 2023-08-16 13:00:15 +02:00
b157bcb2c2 remove cache busting 2023-08-16 12:57:27 +02:00
beae0adce5 Merge pull request #21 from mxve/build/symbols
build: add symbols
2023-08-15 19:05:22 +02:00
Edo
f9ec044a15 build: add symbols 2023-08-15 19:03:38 +02:00
5 changed files with 39 additions and 40 deletions

View File

@ -11,8 +11,9 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: taiki-e/create-gh-release-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: true
token: ${{ secrets.GITHUB_TOKEN }}
upload-assets:
strategy:

2
Cargo.lock generated
View File

@ -13,7 +13,7 @@ dependencies = [
[[package]]
name = "alterware-launcher"
version = "0.4.0"
version = "0.4.2"
dependencies = [
"http_req",
"mslnk",

View File

@ -1,11 +1,15 @@
[package]
name = "alterware-launcher"
version = "0.4.0"
version = "0.4.2"
edition = "2021"
build = "res/build.rs"
[profile.release]
opt-level = "s"
# Symbols are a nice thing
debug = true
panic = "abort"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -35,4 +39,4 @@ winres = "0.1.12"
[package.metadata.winres]
OriginalFilename = "alterware-launcher.exe"
FileDescription = "AlterWare Launcher"
ProductName = "AlterWare Launcher"
ProductName = "AlterWare Launcher"

View File

@ -9,3 +9,6 @@
- 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
### Note for server owners:
When the launcher updates itself it needs to be restarted. It will return exit code 101 in this case.

View File

@ -2,7 +2,6 @@ mod http;
#[cfg(windows)]
use mslnk::ShellLink;
use semver::Version;
use std::time::{SystemTime, UNIX_EPOCH};
use std::{fs, path::PathBuf};
#[cfg(not(windows))]
use std::{thread, time};
@ -27,13 +26,6 @@ struct Game<'a> {
const MASTER: &str = "https://master.alterware.dev";
const REPO: &str = "mxve/alterware-launcher";
fn get_cache_buster() -> u64 {
match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(n) => n.as_secs(),
Err(_) => 1,
}
}
fn get_file_sha1(path: &PathBuf) -> String {
let mut sha1 = sha1_smol::Sha1::new();
sha1.update(&fs::read(path).unwrap());
@ -61,7 +53,7 @@ fn self_update_available() -> bool {
}
#[cfg(not(windows))]
fn self_update() {
fn self_update(_update_only: bool) {
if self_update_available() {
println!("A new version of the AlterWare launcher is available.");
println!("Download it at https://github.com/{}/releases/latest", REPO);
@ -71,7 +63,7 @@ fn self_update() {
}
#[cfg(windows)]
fn self_update() {
fn self_update(update_only: bool) {
let working_dir = std::env::current_dir().unwrap();
let files = fs::read_dir(&working_dir).unwrap();
@ -114,8 +106,10 @@ fn self_update() {
self_replace::self_replace("alterware-launcher-update.exe").unwrap();
fs::remove_file(&file_path).unwrap();
println!("Launcher updated. Please run it again.");
std::io::stdin().read_line(&mut String::new()).unwrap();
std::process::exit(0);
if !update_only {
std::io::stdin().read_line(&mut String::new()).unwrap();
}
std::process::exit(101);
}
}
@ -176,8 +170,12 @@ fn windows_launcher_install(games: &Vec<Game>) {
let game = games.iter().find(|&g| g.app_id == input).unwrap();
let launcher_path = std::env::current_exe().unwrap();
fs::copy(launcher_path, path.join("alterware-launcher.exe")).unwrap();
println!("Launcher copied to {}", path.display());
let target_path = path.join("alterware-launcher.exe");
if launcher_path != target_path {
fs::copy(launcher_path, target_path).unwrap();
println!("Launcher copied to {}", path.display());
}
setup_client_links(game, path);
println!("Create Desktop shortcut? (Y/n)");
@ -218,7 +216,7 @@ fn windows_launcher_install(games: &Vec<Game>) {
fn update(game: &Game) {
let cdn_info: Vec<CdnFile> = serde_json::from_str(&http::get_body_string(
format!("{}/files.json?{}", MASTER, get_cache_buster()).as_str(),
format!("{}/files.json", MASTER).as_str(),
))
.unwrap();
@ -238,10 +236,7 @@ fn update(game: &Game) {
sha1_local,
sha1_remote
);
http::download_file(
&format!("{}/{}?{}", MASTER, file.name, get_cache_buster()),
&file_path,
);
http::download_file(&format!("{}/{}", MASTER, file.name), &file_path);
}
} else {
println!("Downloading {}...", file_path.display());
@ -250,10 +245,7 @@ fn update(game: &Game) {
fs::create_dir_all(parent).unwrap();
}
}
http::download_file(
&format!("{}/{}?{}", MASTER, file.name, get_cache_buster()),
&file_path,
);
http::download_file(&format!("{}/{}", MASTER, file.name), &file_path);
}
}
}
@ -270,18 +262,6 @@ fn launch(file_path: &PathBuf) {
fn main() {
let mut args: Vec<String> = std::env::args().collect();
if !args.contains(&String::from("skip-launcher-update")) {
self_update();
} else {
args.iter()
.position(|r| r == "skip-launcher-update")
.map(|e| args.remove(e));
}
let games_json =
http::get_body_string(format!("{}/games.json?{}", MASTER, get_cache_buster()).as_str());
let games: Vec<Game> = serde_json::from_str(&games_json).unwrap();
let mut update_only = false;
if args.contains(&String::from("update")) {
update_only = true;
@ -290,6 +270,17 @@ fn main() {
.map(|e| args.remove(e));
}
if !args.contains(&String::from("skip-launcher-update")) {
self_update(update_only);
} else {
args.iter()
.position(|r| r == "skip-launcher-update")
.map(|e| args.remove(e));
}
let games_json = http::get_body_string(format!("{}/games.json", MASTER).as_str());
let games: Vec<Game> = serde_json::from_str(&games_json).unwrap();
let mut game: String = String::new();
if args.len() > 1 {
game = String::from(&args[1]);