17 Commits

Author SHA1 Message Date
b3168b0a58 don't panic if cleaning up left over files fails 2023-11-06 02:08:29 +01:00
b1cffb44ad v0.6.1 2023-11-06 01:56:49 +01:00
5414213a19 fix existing file hashes always being calculated 2023-11-06 01:56:26 +01:00
6ce845e761 v0.6.0 2023-11-05 17:20:59 +01:00
ecff4846ed improve setup_env on Windows
(real)
935a72e05be1a213a12238f522c8b35f872ecf63
2023-11-04 11:48:04 +01:00
1578924579 lint 2023-11-04 11:35:19 +01:00
33fc7d0f6a import std::env 2023-11-04 07:48:40 +01:00
461eb05ac5 maint(win): improve setup_env on Windows 2023-11-04 07:27:58 +01:00
cb210b16e1 Merge pull request #40 from mxve/async
Async
2023-11-02 16:05:10 +01:00
41ff4acd65 update iw4x first
so we don't have to pass the progressbar to iw4x just to not have it break by a little println
2023-11-02 11:44:08 +01:00
24672aa500 only show filename in pb 2023-11-02 11:31:50 +01:00
05def16ba6 use String::default() for empty strings
as suggested by diamante quality control ™️
2023-11-02 11:27:43 +01:00
d28fed938c Merge branch 'main' of github.com:mxve/alterware-launcher 2023-11-02 10:40:45 +01:00
82a1e4ba53 Merge pull request #38 from mxve/dependabot/cargo/serde-1.0.190
Bump serde from 1.0.189 to 1.0.190
2023-10-30 22:00:19 +01:00
de7a661465 Merge pull request #39 from mxve/dependabot/cargo/http_req-0.10.1
Bump http_req from 0.10.0 to 0.10.1
2023-10-30 22:00:07 +01:00
7e8e0fbc97 Bump http_req from 0.10.0 to 0.10.1
Bumps [http_req](https://github.com/jayjamesjay/http_req) from 0.10.0 to 0.10.1.
- [Release notes](https://github.com/jayjamesjay/http_req/releases)
- [Commits](https://github.com/jayjamesjay/http_req/compare/v0.10.0...v0.10.1)

---
updated-dependencies:
- dependency-name: http_req
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-30 15:31:10 +00:00
b09b92ee7f Bump serde from 1.0.189 to 1.0.190
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.189 to 1.0.190.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.189...v1.0.190)

---
updated-dependencies:
- dependency-name: serde
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-30 15:30:54 +00:00
7 changed files with 55 additions and 32 deletions

14
Cargo.lock generated
View File

@ -28,7 +28,7 @@ dependencies = [
[[package]] [[package]]
name = "alterware-launcher" name = "alterware-launcher"
version = "0.5.4" version = "0.6.1"
dependencies = [ dependencies = [
"colored", "colored",
"futures-util", "futures-util",
@ -438,9 +438,9 @@ dependencies = [
[[package]] [[package]]
name = "http_req" name = "http_req"
version = "0.10.0" version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "158d4edacc70c9bdb0464314063b8d9d60fa776442dc13b00a13581b88b0a0a0" checksum = "a536d8715c89f5647abd1563c490b75a76221de4b57833a1f243cf5c5fe7860c"
dependencies = [ dependencies = [
"rustls", "rustls",
"rustls-pemfile", "rustls-pemfile",
@ -1135,18 +1135,18 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.189" version = "1.0.190"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.189" version = "1.0.190"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "alterware-launcher" name = "alterware-launcher"
version = "0.5.4" version = "0.6.1"
edition = "2021" edition = "2021"
build = "res/build.rs" build = "res/build.rs"
@ -15,11 +15,11 @@ panic = "abort"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
http_req = { version = "0.10.0", default-features = false, features = [ http_req = { version = "0.10.1", default-features = false, features = [
"rust-tls", "rust-tls",
] } ] }
sha1_smol = "1.0.0" sha1_smol = "1.0.0"
serde = { version = "1.0.189", features = ["derive"] } serde = { version = "1.0.190", features = ["derive"] }
serde_json = "1.0.107" serde_json = "1.0.107"
rand = "0.8.5" rand = "0.8.5"
semver = "1.0.20" semver = "1.0.20"

View File

@ -31,7 +31,7 @@ pub async fn download_file(
misc::cute_path(path), misc::cute_path(path),
misc::human_readable_bytes(total_size) misc::human_readable_bytes(total_size)
)); ));
pb.set_message(misc::cute_path(path)); pb.set_message(path.file_name().unwrap().to_str().unwrap().to_string());
let mut file = let mut file =
File::create(path).or(Err(format!("Failed to create file '{}'", path.display())))?; File::create(path).or(Err(format!("Failed to create file '{}'", path.display())))?;
@ -47,6 +47,6 @@ pub async fn download_file(
pb.set_position(new); pb.set_position(new);
} }
pb.set_message(""); pb.set_message(String::default());
Ok(()) Ok(())
} }

View File

@ -23,13 +23,21 @@ pub fn update(dir: &Path) {
let local = local_revision(dir); let local = local_revision(dir);
if remote <= local && dir.join("iw4x.dll").exists() { if remote <= local && dir.join("iw4x.dll").exists() {
println!(
"[{}] No files to download for IW4x",
"Info".bright_magenta(),
);
return; return;
} }
println!(
"[{}] Downloading outdated or missing files for IW4x",
"Info".bright_magenta()
);
println!( println!(
"[{}] {}", "[{}] {}",
"Downloading".bright_yellow(), "Downloading".bright_yellow(),
dir.join("iw4x.dll").display() misc::cute_path(&dir.join("iw4x.dll"))
); );
http::download_file( http::download_file(
&format!( &format!(

View File

@ -12,11 +12,10 @@ use global::*;
use structs::*; use structs::*;
use colored::*; use colored::*;
use indicatif::ProgressBar;
#[cfg(windows)] #[cfg(windows)]
use mslnk::ShellLink; use mslnk::ShellLink;
use std::{borrow::Cow, collections::HashMap, env, fs, path::Path, path::PathBuf};
use indicatif::ProgressBar;
use std::{borrow::Cow, collections::HashMap, fs, path::Path, path::PathBuf};
#[cfg(windows)] #[cfg(windows)]
use steamlocate::SteamDir; use steamlocate::SteamDir;
@ -78,10 +77,7 @@ fn setup_desktop_links(path: &Path, game: &Game) {
let input = misc::stdin().to_ascii_lowercase(); let input = misc::stdin().to_ascii_lowercase();
if input == "y" || input.is_empty() { if input == "y" || input.is_empty() {
let desktop = PathBuf::from(&format!( let desktop = PathBuf::from(&format!("{}\\Desktop", env::var("USERPROFILE").unwrap()));
"{}\\Desktop",
std::env::var("USERPROFILE").unwrap()
));
for c in game.client.iter() { for c in game.client.iter() {
create_shortcut( create_shortcut(
@ -112,7 +108,7 @@ async 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() {
let current_dir = std::env::current_dir().unwrap(); let current_dir = env::current_dir().unwrap();
for (id, path) in installed_games.iter() { for (id, path) in installed_games.iter() {
if current_dir.starts_with(path) { if current_dir.starts_with(path) {
println!("Found game in current directory."); println!("Found game in current directory.");
@ -142,7 +138,7 @@ async fn windows_launcher_install(games: &Vec<Game<'_>>) {
if *id == input { if *id == input {
let game = games.iter().find(|&g| g.app_id == input).unwrap(); let game = games.iter().find(|&g| g.app_id == input).unwrap();
let launcher_path = std::env::current_exe().unwrap(); let launcher_path = env::current_exe().unwrap();
let target_path = path.join("alterware-launcher.exe"); let target_path = path.join("alterware-launcher.exe");
if launcher_path != target_path { if launcher_path != target_path {
@ -177,7 +173,7 @@ fn prompt_client_selection(games: &[Game]) -> String {
async fn manual_install(games: &[Game<'_>]) { async fn manual_install(games: &[Game<'_>]) {
let selection = prompt_client_selection(games); let selection = prompt_client_selection(games);
let game = games.iter().find(|&g| g.client[0] == selection).unwrap(); let game = games.iter().find(|&g| g.client[0] == selection).unwrap();
update(game, &std::env::current_dir().unwrap(), false, false).await; update(game, &env::current_dir().unwrap(), false, false).await;
println!("Installation complete. Please run the launcher again or use a shortcut to launch the game."); 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::io::stdin().read_line(&mut String::new()).unwrap();
std::process::exit(0); std::process::exit(0);
@ -231,6 +227,7 @@ async fn update_dir(
"Checked".bright_blue(), "Checked".bright_blue(),
misc::cute_path(&file_path) misc::cute_path(&file_path)
)); ));
hashes.insert(file_name.to_owned(), file.hash.to_lowercase());
} }
} else { } else {
files_to_download.push(file.clone()); files_to_download.push(file.clone());
@ -294,13 +291,13 @@ async fn update(game: &Game<'_>, dir: &Path, bonus_content: bool, force: bool) {
} }
} }
let pb = ProgressBar::new(0);
update_dir(&cdn_info, game.engine, dir, &mut hashes, &pb).await;
if game.engine == "iw4" { if game.engine == "iw4" {
iw4x::update(dir); iw4x::update(dir);
} }
let pb = ProgressBar::new(0);
update_dir(&cdn_info, game.engine, dir, &mut hashes, &pb).await;
if bonus_content && !game.bonus.is_empty() { if bonus_content && !game.bonus.is_empty() {
for bonus in game.bonus.iter() { for bonus in game.bonus.iter() {
update_dir(&cdn_info, bonus, dir, &mut hashes, &pb).await; update_dir(&cdn_info, bonus, dir, &mut hashes, &pb).await;
@ -334,6 +331,22 @@ fn setup_env() {
println!("{:#?}", error); println!("{:#?}", error);
colored::control::SHOULD_COLORIZE.set_override(false); colored::control::SHOULD_COLORIZE.set_override(false);
}); });
if let Ok(system_root) = env::var("SystemRoot") {
if let Ok(current_dir) = env::current_dir() {
if current_dir.starts_with(system_root) {
if let Ok(current_exe) = env::current_exe() {
if let Some(parent) = current_exe.parent() {
if let Err(error) = env::set_current_dir(parent) {
eprintln!("{:#?}", error);
} else {
println!("Running from the system directory. Changed working directory to the executable location.");
}
}
}
}
}
}
} }
fn arg_value(args: &[String], arg: &str) -> Option<String> { fn arg_value(args: &[String], arg: &str) -> Option<String> {
@ -362,7 +375,7 @@ async fn main() {
#[cfg(windows)] #[cfg(windows)]
setup_env(); setup_env();
let mut args: Vec<String> = std::env::args().collect(); let mut args: Vec<String> = env::args().collect();
if arg_bool(&args, "--help") { if arg_bool(&args, "--help") {
println!("CLI Args:"); println!("CLI Args:");
@ -409,7 +422,7 @@ async fn main() {
install_path = PathBuf::from(path); install_path = PathBuf::from(path);
arg_remove_value(&mut args, "-p"); arg_remove_value(&mut args, "-p");
} else { } else {
install_path = std::env::current_dir().unwrap(); install_path = env::current_dir().unwrap();
} }
let mut cfg = config::load(install_path.join("alterware-launcher.json")); let mut cfg = config::load(install_path.join("alterware-launcher.json"));
@ -442,7 +455,7 @@ async fn main() {
cfg.args = pass; cfg.args = pass;
arg_remove_value(&mut args, "--pass"); arg_remove_value(&mut args, "--pass");
} else if cfg.args.is_empty() { } else if cfg.args.is_empty() {
cfg.args = String::from(""); cfg.args = String::default();
} }
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());
@ -462,7 +475,7 @@ async fn main() {
} }
#[cfg(windows)] #[cfg(windows)]
setup_client_links(g, &std::env::current_dir().unwrap()); setup_client_links(g, &env::current_dir().unwrap());
#[cfg(not(windows))] #[cfg(not(windows))]
println!("Multiple clients installed, set the client as the first argument to launch a specific client."); println!("Multiple clients installed, set the client as the first argument to launch a specific client.");

View File

@ -43,7 +43,9 @@ pub fn run(update_only: bool) {
&& (file_name.contains(".__relocated__.exe") && (file_name.contains(".__relocated__.exe")
|| file_name.contains(".__selfdelete__.exe")) || file_name.contains(".__selfdelete__.exe"))
{ {
fs::remove_file(file.path()).unwrap(); fs::remove_file(file.path()).unwrap_or_else(|_| {
println!("Failed to remove old launcher file.");
});
} }
} }

View File

@ -32,7 +32,7 @@ impl Default for Config {
download_bonus_content: false, download_bonus_content: false,
ask_bonus_content: true, ask_bonus_content: true,
force_update: false, force_update: false,
args: String::from(""), args: String::default(),
} }
} }
} }