Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
0be3adf8d1 | |||
59f347462d | |||
78e4e18176 | |||
e0f4a5102e | |||
c80765d091 | |||
3b77755848 | |||
4c1114f3e0 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -13,7 +13,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "alterware-launcher"
|
name = "alterware-launcher"
|
||||||
version = "0.3.1"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"http_req",
|
"http_req",
|
||||||
"mslnk",
|
"mslnk",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "alterware-launcher"
|
name = "alterware-launcher"
|
||||||
version = "0.3.1"
|
version = "0.4.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
build = "res/build.rs"
|
build = "res/build.rs"
|
||||||
|
|
||||||
|
@ -7,4 +7,5 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- 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
|
||||||
|
73
src/main.rs
73
src/main.rs
@ -19,7 +19,7 @@ struct CdnFile {
|
|||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
struct Game<'a> {
|
struct Game<'a> {
|
||||||
engine: &'a str,
|
engine: &'a str,
|
||||||
client: &'a str,
|
client: Vec<&'a str>,
|
||||||
references: Vec<&'a str>,
|
references: Vec<&'a str>,
|
||||||
app_id: u32,
|
app_id: u32,
|
||||||
}
|
}
|
||||||
@ -40,7 +40,6 @@ fn get_file_sha1(path: &PathBuf) -> String {
|
|||||||
sha1.digest().to_string()
|
sha1.digest().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn get_input() -> String {
|
fn get_input() -> String {
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
std::io::stdin().read_line(&mut input).unwrap();
|
std::io::stdin().read_line(&mut input).unwrap();
|
||||||
@ -134,6 +133,29 @@ fn get_installed_games(games: &Vec<Game>) -> Vec<(u32, PathBuf)> {
|
|||||||
installed_games
|
installed_games
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn setup_client_links(game: &Game, game_dir: &PathBuf) {
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
|
||||||
|
let target = game_dir.join("alterware-launcher.exe");
|
||||||
|
|
||||||
|
for c in game.client.iter() {
|
||||||
|
let lnk = game_dir.join(format!("launch-{}.lnk", c));
|
||||||
|
|
||||||
|
let mut sl = ShellLink::new(target.clone()).unwrap();
|
||||||
|
sl.set_arguments(Some(c.to_string()));
|
||||||
|
sl.set_icon_location(Some(
|
||||||
|
game_dir
|
||||||
|
.join(format!("{}.exe", c))
|
||||||
|
.to_string_lossy()
|
||||||
|
.into_owned(),
|
||||||
|
));
|
||||||
|
sl.create_lnk(&lnk).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn windows_launcher_install(games: &Vec<Game>) {
|
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..");
|
||||||
@ -156,6 +178,7 @@ fn windows_launcher_install(games: &Vec<Game>) {
|
|||||||
let launcher_path = std::env::current_exe().unwrap();
|
let launcher_path = std::env::current_exe().unwrap();
|
||||||
fs::copy(launcher_path, path.join("alterware-launcher.exe")).unwrap();
|
fs::copy(launcher_path, path.join("alterware-launcher.exe")).unwrap();
|
||||||
println!("Launcher copied to {}", path.display());
|
println!("Launcher copied to {}", path.display());
|
||||||
|
setup_client_links(game, path);
|
||||||
|
|
||||||
println!("Create Desktop shortcut? (Y/n)");
|
println!("Create Desktop shortcut? (Y/n)");
|
||||||
let input = get_input().to_ascii_lowercase();
|
let input = get_input().to_ascii_lowercase();
|
||||||
@ -167,15 +190,19 @@ fn windows_launcher_install(games: &Vec<Game>) {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let target = path.join("alterware-launcher.exe");
|
let target = path.join("alterware-launcher.exe");
|
||||||
let lnk = desktop.join(format!("{}.lnk", game.client));
|
|
||||||
|
|
||||||
let mut sl = ShellLink::new(target).unwrap();
|
for c in game.client.iter() {
|
||||||
sl.set_icon_location(Some(
|
let lnk = desktop.join(format!("{}.lnk", c));
|
||||||
path.join(format!("{}.exe", game.client))
|
|
||||||
.to_string_lossy()
|
let mut sl = ShellLink::new(target.clone()).unwrap();
|
||||||
.into_owned(),
|
sl.set_arguments(Some(c.to_string()));
|
||||||
));
|
sl.set_icon_location(Some(
|
||||||
sl.create_lnk(lnk).unwrap();
|
path.join(format!("{}.exe", c))
|
||||||
|
.to_string_lossy()
|
||||||
|
.into_owned(),
|
||||||
|
));
|
||||||
|
sl.create_lnk(lnk).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -270,7 +297,20 @@ fn main() {
|
|||||||
'main: for g in games.iter() {
|
'main: for g in games.iter() {
|
||||||
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() {
|
||||||
game = String::from(g.client);
|
if g.client.len() > 1 {
|
||||||
|
#[cfg(windows)]
|
||||||
|
setup_client_links(g, &std::env::current_dir().unwrap());
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
println!("Multiple clients installed, set the client as the first argument to launch a specific client.");
|
||||||
|
|
||||||
|
for (i, c) in g.client.iter().enumerate() {
|
||||||
|
println!("{}: {}", i, c);
|
||||||
|
}
|
||||||
|
game = String::from(g.client[get_input().parse::<usize>().unwrap()]);
|
||||||
|
break 'main;
|
||||||
|
}
|
||||||
|
game = String::from(g.client[0]);
|
||||||
break 'main;
|
break 'main;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -278,13 +318,14 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for g in games.iter() {
|
for g in games.iter() {
|
||||||
if g.client == game {
|
for c in g.client.iter() {
|
||||||
update(g);
|
if c == &game {
|
||||||
if update_only {
|
update(g);
|
||||||
|
if !update_only {
|
||||||
|
launch(&PathBuf::from(format!("{}.exe", c)));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
launch(&PathBuf::from(format!("{}.exe", g.client)));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user