Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
18651a68ca | |||
79559fe46a | |||
8fd66d16af | |||
4d3c6b9dab | |||
7ca7615222 | |||
2195f42abc | |||
f7635d4089 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -13,7 +13,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "alterware-launcher"
|
name = "alterware-launcher"
|
||||||
version = "0.4.1"
|
version = "0.4.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"http_req",
|
"http_req",
|
||||||
"mslnk",
|
"mslnk",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "alterware-launcher"
|
name = "alterware-launcher"
|
||||||
version = "0.4.1"
|
version = "0.4.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
build = "res/build.rs"
|
build = "res/build.rs"
|
||||||
|
|
||||||
|
@ -9,3 +9,6 @@
|
|||||||
- Passing ```iw4-sp```, ```iw5-mod```, ```iw6-mod``` or ```s1-mod``` as the first argument will skip automatic game detection
|
- 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
|
- Passing ```update``` will stop the launcher from launching the game
|
||||||
- ```skip-launcher-update``` skips self-update
|
- ```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.
|
57
src/main.rs
57
src/main.rs
@ -53,7 +53,7 @@ fn self_update_available() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
fn self_update() {
|
fn self_update(_update_only: bool) {
|
||||||
if self_update_available() {
|
if self_update_available() {
|
||||||
println!("A new version of the AlterWare launcher is available.");
|
println!("A new version of the AlterWare launcher is available.");
|
||||||
println!("Download it at https://github.com/{}/releases/latest", REPO);
|
println!("Download it at https://github.com/{}/releases/latest", REPO);
|
||||||
@ -63,7 +63,7 @@ fn self_update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn self_update() {
|
fn self_update(update_only: bool) {
|
||||||
let working_dir = std::env::current_dir().unwrap();
|
let working_dir = std::env::current_dir().unwrap();
|
||||||
let files = fs::read_dir(&working_dir).unwrap();
|
let files = fs::read_dir(&working_dir).unwrap();
|
||||||
|
|
||||||
@ -106,8 +106,10 @@ fn self_update() {
|
|||||||
self_replace::self_replace("alterware-launcher-update.exe").unwrap();
|
self_replace::self_replace("alterware-launcher-update.exe").unwrap();
|
||||||
fs::remove_file(&file_path).unwrap();
|
fs::remove_file(&file_path).unwrap();
|
||||||
println!("Launcher updated. Please run it again.");
|
println!("Launcher updated. Please run it again.");
|
||||||
std::io::stdin().read_line(&mut String::new()).unwrap();
|
if !update_only {
|
||||||
std::process::exit(0);
|
std::io::stdin().read_line(&mut String::new()).unwrap();
|
||||||
|
}
|
||||||
|
std::process::exit(101);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,6 +156,21 @@ fn windows_launcher_install(games: &Vec<Game>) {
|
|||||||
let installed_games = get_installed_games(games);
|
let installed_games = get_installed_games(games);
|
||||||
|
|
||||||
if !installed_games.is_empty() {
|
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) {
|
||||||
|
println!("Found game in current directory.");
|
||||||
|
println!("Installing AlterWare client for {}.", id);
|
||||||
|
let game = games.iter().find(|&g| g.app_id == *id).unwrap();
|
||||||
|
setup_client_links(game, path);
|
||||||
|
update(&game, path);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
println!("Installed games:");
|
println!("Installed games:");
|
||||||
|
|
||||||
for (id, path) in installed_games.iter() {
|
for (id, path) in installed_games.iter() {
|
||||||
@ -201,6 +218,9 @@ fn windows_launcher_install(games: &Vec<Game>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update(game, path);
|
||||||
|
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();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,7 +232,7 @@ fn windows_launcher_install(games: &Vec<Game>) {
|
|||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(game: &Game) {
|
fn update(game: &Game, dir: &PathBuf) {
|
||||||
let cdn_info: Vec<CdnFile> = serde_json::from_str(&http::get_body_string(
|
let cdn_info: Vec<CdnFile> = serde_json::from_str(&http::get_body_string(
|
||||||
format!("{}/files.json", MASTER).as_str(),
|
format!("{}/files.json", MASTER).as_str(),
|
||||||
))
|
))
|
||||||
@ -223,7 +243,7 @@ fn update(game: &Game) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let file_path = PathBuf::from(&file.name.replace(&format!("{}/", game.engine), ""));
|
let file_path = dir.join(&file.name.replace(&format!("{}/", game.engine), ""));
|
||||||
if file_path.exists() {
|
if file_path.exists() {
|
||||||
let sha1_local = get_file_sha1(&file_path).to_lowercase();
|
let sha1_local = get_file_sha1(&file_path).to_lowercase();
|
||||||
let sha1_remote = file.hash.to_lowercase();
|
let sha1_remote = file.hash.to_lowercase();
|
||||||
@ -260,8 +280,16 @@ fn launch(file_path: &PathBuf) {
|
|||||||
fn main() {
|
fn main() {
|
||||||
let mut args: Vec<String> = std::env::args().collect();
|
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 !args.contains(&String::from("skip-launcher-update")) {
|
if !args.contains(&String::from("skip-launcher-update")) {
|
||||||
self_update();
|
self_update(update_only);
|
||||||
} else {
|
} else {
|
||||||
args.iter()
|
args.iter()
|
||||||
.position(|r| r == "skip-launcher-update")
|
.position(|r| r == "skip-launcher-update")
|
||||||
@ -271,14 +299,6 @@ fn main() {
|
|||||||
let games_json = http::get_body_string(format!("{}/games.json", MASTER).as_str());
|
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 games: Vec<Game> = serde_json::from_str(&games_json).unwrap();
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut game: String = String::new();
|
let mut game: String = String::new();
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
game = String::from(&args[1]);
|
game = String::from(&args[1]);
|
||||||
@ -287,6 +307,11 @@ fn main() {
|
|||||||
for r in g.references.iter() {
|
for r in g.references.iter() {
|
||||||
if std::path::Path::new(r).exists() {
|
if std::path::Path::new(r).exists() {
|
||||||
if g.client.len() > 1 {
|
if g.client.len() > 1 {
|
||||||
|
if update_only {
|
||||||
|
game = String::from(g.client[0]);
|
||||||
|
break 'main;
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
setup_client_links(g, &std::env::current_dir().unwrap());
|
setup_client_links(g, &std::env::current_dir().unwrap());
|
||||||
|
|
||||||
@ -309,7 +334,7 @@ fn main() {
|
|||||||
for g in games.iter() {
|
for g in games.iter() {
|
||||||
for c in g.client.iter() {
|
for c in g.client.iter() {
|
||||||
if c == &game {
|
if c == &game {
|
||||||
update(g);
|
update(g, &std::env::current_dir().unwrap());
|
||||||
if !update_only {
|
if !update_only {
|
||||||
launch(&PathBuf::from(format!("{}.exe", c)));
|
launch(&PathBuf::from(format!("{}.exe", c)));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user