20 Commits

Author SHA1 Message Date
572c66cc16 v0.5.3 2023-10-06 09:03:34 +02:00
cf87f7c741 misc 2023-10-06 08:34:42 +02:00
dc8b01b4c8 add changelog link 2023-10-06 08:30:29 +02:00
9e8893ce75 handle notfound; give tips to fix permission denied 2023-10-02 15:49:01 +02:00
6f92e1fb71 Create config path if it doesn't exist; don't panic 2023-10-02 15:48:22 +02:00
96c3e504f8 improve logging of http errors 2023-10-02 04:39:49 +02:00
00c14d2a02 handle shortcut creation errors 2023-10-01 00:36:12 +02:00
0378f19a75 set matrix target 2023-09-25 18:57:51 +02:00
64f4ae6429 v0.5.2 2023-09-25 18:52:35 +02:00
b2cc21aed0 Merge branch 'main' of github.com:mxve/alterware-launcher 2023-09-25 18:51:54 +02:00
dc5957ea41 build i686 target 2023-09-25 18:51:43 +02:00
54abce4d30 Merge pull request #34 from mxve/dependabot/cargo/semver-1.0.19
Bump semver from 1.0.18 to 1.0.19
2023-09-25 17:51:50 +02:00
6ae33cdcb3 self-replace 1.3.7 2023-09-25 17:51:21 +02:00
c9d30fa95a Bump semver from 1.0.18 to 1.0.19
Bumps [semver](https://github.com/dtolnay/semver) from 1.0.18 to 1.0.19.
- [Release notes](https://github.com/dtolnay/semver/releases)
- [Commits](https://github.com/dtolnay/semver/compare/1.0.18...1.0.19)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-25 15:28:54 +00:00
dc81430f6b don't ask if --bonus set 2023-09-23 01:29:04 +02:00
9c122506ce Merge pull request #31 from mxve/dependabot/cargo/http_req-0.9.3
Bump http_req from 0.9.2 to 0.9.3
2023-09-18 20:12:38 +02:00
f2ba92c31d Merge pull request #32 from mxve/dependabot/cargo/serde_json-1.0.107
Bump serde_json from 1.0.106 to 1.0.107
2023-09-18 20:12:30 +02:00
c92fb88e83 Bump serde_json from 1.0.106 to 1.0.107
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.106 to 1.0.107.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.106...v1.0.107)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-18 15:05:36 +00:00
1e0e0090f5 Bump http_req from 0.9.2 to 0.9.3
Bumps [http_req](https://github.com/jayjamesjay/http_req) from 0.9.2 to 0.9.3.
- [Release notes](https://github.com/jayjamesjay/http_req/releases)
- [Commits](https://github.com/jayjamesjay/http_req/compare/v0.9.2...v0.9.3)

---
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-09-18 15:05:29 +00:00
48f6a96a01 pwettify comfig file :3 2023-09-18 16:29:37 +02:00
8 changed files with 147 additions and 59 deletions

View File

@ -18,14 +18,21 @@ jobs:
upload-assets:
strategy:
matrix:
os:
- ubuntu-20.04
- windows-latest
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-20.04
- target: i686-unknown-linux-gnu
os: ubuntu-20.04
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: i686-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: taiki-e/upload-rust-binary-action@v1
with:
target: ${{ matrix.target }}
bin: alterware-launcher
tar: unix
zip: windows

19
Cargo.lock generated
View File

@ -30,7 +30,7 @@ dependencies = [
[[package]]
name = "alterware-launcher"
version = "0.5.1"
version = "0.5.3"
dependencies = [
"colored",
"http_req",
@ -42,7 +42,6 @@ dependencies = [
"serde_json",
"sha1_smol",
"steamlocate",
"windows-sys",
"winres",
"zip",
]
@ -313,9 +312,9 @@ dependencies = [
[[package]]
name = "http_req"
version = "0.9.2"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f680177f2ebe4aabd573d07b322d15a5e0fbc97cd739fd627b08043c89041f8"
checksum = "42ce34c74ec562d68f2c23a532c62c1332ff1d1b6147fd118bd1938e090137d0"
dependencies = [
"rustls",
"unicase",
@ -707,9 +706,9 @@ dependencies = [
[[package]]
name = "self-replace"
version = "1.3.6"
version = "1.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c56335359191626938ef6fdeb478f9f6a7c6020254d7f4641c7d810369fa0ec1"
checksum = "525db198616b2bcd0f245daf7bfd8130222f7ee6af9ff9984c19a61bf1160c55"
dependencies = [
"fastrand 1.9.0",
"tempfile",
@ -718,9 +717,9 @@ dependencies = [
[[package]]
name = "semver"
version = "1.0.18"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
checksum = "ad977052201c6de01a8ef2aa3378c4bd23217a056337d1d6da40468d267a4fb0"
[[package]]
name = "serde"
@ -744,9 +743,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.106"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cc66a619ed80bf7a0f6b17dd063a84b88f6dea1813737cf469aef1d081142c2"
checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65"
dependencies = [
"itoa",
"ryu",

View File

@ -1,6 +1,6 @@
[package]
name = "alterware-launcher"
version = "0.5.1"
version = "0.5.3"
edition = "2021"
build = "res/build.rs"
@ -15,25 +15,21 @@ panic = "abort"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
http_req = { version = "0.9.2", default-features = false, features = [
http_req = { version = "0.9.3", default-features = false, features = [
"rust-tls",
] }
sha1_smol = "1.0.0"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.106"
serde_json = "1.0.107"
rand = "0.8.5"
semver = "1.0.18"
semver = "1.0.19"
zip = "0.6.6"
colored = "2.0.4"
[target.'cfg(windows)'.dependencies]
steamlocate = "2.0.0-alpha.0"
mslnk = "0.1.8"
# https://github.com/mitsuhiko/self-replace/pull/16/
windows-sys = { version = "0.48", features = [
"Win32_Security",
] }
self-replace = "1.3.6"
self-replace = "1.3.7"
[build-dependencies]
winres = "0.1.12"

View File

@ -13,7 +13,19 @@ pub fn load(config_path: PathBuf) -> Config {
}
pub fn save(config_path: PathBuf, config: Config) {
fs::write(config_path, serde_json::to_string(&config).unwrap()).unwrap();
match fs::write(
config_path.clone(),
serde_json::to_string_pretty(&config).unwrap(),
) {
Ok(_) => (),
Err(e) => match e.kind() {
std::io::ErrorKind::NotFound => {
fs::create_dir_all(config_path.parent().unwrap()).unwrap();
save(config_path, config);
}
_ => println!("Could not save config file, got:\n{}\n", e),
},
}
}
pub fn save_value(config_path: PathBuf, key: &str, value: bool) {

View File

@ -1,20 +1,40 @@
use crate::global;
use crate::misc;
use std::{fs, io::Write, path::Path, str};
pub fn get_body(url: &str) -> Vec<u8> {
let mut res: Vec<u8> = Vec::new();
let req = http_req::request::Request::new(&url.try_into().unwrap())
match http_req::request::Request::new(&url.try_into().unwrap())
.header(
"User-Agent",
"AlterWare Launcher | github.com/mxve/alterware-launcher",
&format!(
"AlterWare Launcher | github.com/{}/{}",
global::GH_OWNER,
global::GH_REPO
),
)
.send(&mut res)
.unwrap_or_else(|error| {
panic!("\n\n{}:\n{:?}", "Error", error);
});
{
Ok(req) => {
if req.status_code() == http_req::response::StatusCode::new(302)
|| req.status_code() == http_req::response::StatusCode::new(301)
{
let location = req.headers().get("Location").unwrap().as_str();
return get_body(location);
}
if req.status_code() == http_req::response::StatusCode::new(302) {
let location = req.headers().get("Location").unwrap().as_str();
return get_body(location);
if req.status_code() != http_req::response::StatusCode::new(200) {
misc::fatal_error(&format!(
"Could not get body from {}, got {}",
url,
req.status_code()
));
}
}
Err(e) => {
misc::fatal_error(&format!("Could not get body from {}, got:\n{}", url, e));
}
}
res
@ -27,10 +47,38 @@ pub fn get_body_string(url: &str) -> String {
pub fn download_file(url: &str, file_path: &Path) {
let body = get_body(url);
let mut f = fs::File::create(file_path).unwrap_or_else(|error| {
panic!("\n\n{}:\n{:?}", "Error", error);
});
f.write_all(&body).unwrap_or_else(|error| {
panic!("\n\n{}:\n{:?}", "Error", error);
});
match fs::File::create(file_path) {
Ok(mut file) => match file.write_all(&body) {
Ok(_) => (),
Err(e) => {
misc::fatal_error(&format!(
"Could not write to file {}, got:\n{}",
file_path.to_str().unwrap(),
e
));
}
},
Err(e) => {
match e.kind() {
std::io::ErrorKind::NotFound => {
fs::create_dir_all(file_path.parent().unwrap()).unwrap();
return download_file(url, file_path);
}
std::io::ErrorKind::PermissionDenied => {
misc::fatal_error(&format!(
"Permission to {} denied.\n Please try:\n 1. Running the launcher as administrator.\n 2. Manually deleting the last downloaded file.\n 3. If your game is in the program files directory try moving it to another location.\n\n\n{}",
file_path.to_str().unwrap(),
e
));
}
_ => (),
}
misc::fatal_error(&format!(
"Could not create file {}, got:\n{}",
file_path.to_str().unwrap(),
e
));
}
}
}

View File

@ -37,26 +37,35 @@ fn get_installed_games(games: &Vec<Game>) -> Vec<(u32, PathBuf)> {
installed_games
}
#[cfg(windows)]
fn create_shortcut(path: &Path, target: &Path, icon: String, args: String) {
if let Ok(mut sl) = ShellLink::new(target) {
sl.set_arguments(Some(args));
sl.set_icon_location(Some(icon));
sl.create_lnk(path).unwrap_or_else(|error| {
println!("Error creating shortcut.\n{:#?}", error);
});
} else {
println!("Error creating shortcut.");
}
}
#[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 on the desktop) 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(
create_shortcut(
&game_dir.join(format!("launch-{}.lnk", c)),
&game_dir.join("alterware-launcher.exe"),
game_dir
.join(format!("{}.exe", c))
.to_string_lossy()
.into_owned(),
));
sl.create_lnk(&lnk).unwrap();
c.to_string(),
);
}
}
@ -71,19 +80,15 @@ fn setup_desktop_links(path: &Path, game: &Game) {
std::env::var("USERPROFILE").unwrap()
));
let target = path.join("alterware-launcher.exe");
for c in game.client.iter() {
let lnk = desktop.join(format!("{}.lnk", c));
let mut sl = ShellLink::new(target.clone()).unwrap();
sl.set_arguments(Some(c.to_string()));
sl.set_icon_location(Some(
create_shortcut(
&desktop.join(format!("{}.lnk", c)),
&path.join("alterware-launcher.exe"),
path.join(format!("{}.exe", c))
.to_string_lossy()
.into_owned(),
));
sl.create_lnk(lnk).unwrap();
c.to_string(),
);
}
}
}
@ -373,6 +378,7 @@ fn main() {
if arg_bool(&args, "--bonus") {
cfg.download_bonus_content = true;
cfg.ask_bonus_content = false;
arg_remove(&mut args, "--bonus");
}

View File

@ -1,5 +1,7 @@
use std::{fs, path::PathBuf};
use colored::Colorize;
pub fn get_file_sha1(path: &PathBuf) -> String {
let mut sha1 = sha1_smol::Sha1::new();
sha1.update(&fs::read(path).unwrap());
@ -18,3 +20,9 @@ pub fn rev_to_int(rev: &str) -> u16 {
.parse::<u16>()
.unwrap_or(0)
}
pub fn fatal_error(error: &str) {
println!("\n\n{}:\n{}", "Error".bright_red(), error);
stdin();
std::process::exit(1);
}

View File

@ -30,6 +30,7 @@ pub fn run(update_only: bool) {
use std::{fs, path::PathBuf};
use crate::http;
use crate::misc;
let working_dir = std::env::current_dir().unwrap();
let files = fs::read_dir(&working_dir).unwrap();
@ -60,10 +61,17 @@ pub fn run(update_only: bool) {
fs::remove_file(&update_binary).unwrap();
}
let launcher_name = if cfg!(target_arch = "x86") {
"alterware-launcher-x86.exe"
} else {
"alterware-launcher.exe"
};
println!("{}", launcher_name);
http::download_file(
&format!(
"{}/download/alterware-launcher.exe",
github::latest_release_url(GH_OWNER, GH_REPO)
"{}/download/{}",
github::latest_release_url(GH_OWNER, GH_REPO),
launcher_name
),
&file_path,
);
@ -75,9 +83,13 @@ pub fn run(update_only: bool) {
self_replace::self_replace("alterware-launcher-update.exe").unwrap();
fs::remove_file(&file_path).unwrap();
println!("Launcher updated. Please run it again.");
println!(
"Launcher updated. View the changelog at https://github.com/{}/{}/releases/latest",
GH_OWNER, GH_REPO,
);
println!("Please restart the launcher.");
if !update_only {
std::io::stdin().read_line(&mut String::new()).unwrap();
misc::stdin();
}
std::process::exit(201);
}