obtain iw4x.dll from iw4x/iw4x-client
This commit is contained in:
parent
9dc569e646
commit
64c63bf24f
@ -1,25 +1,23 @@
|
|||||||
use crate::global::*;
|
|
||||||
|
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
|
|
||||||
pub fn latest_version() -> Version {
|
pub fn latest(owner: &str, repo: &str) -> String {
|
||||||
let github_body = crate::http::get_body_string(
|
let github_body = crate::http::get_body_string(
|
||||||
format!(
|
format!(
|
||||||
"https://api.github.com/repos/{}/{}/releases/latest",
|
"https://api.github.com/repos/{}/{}/releases/latest",
|
||||||
GH_OWNER, GH_REPO
|
owner, repo
|
||||||
)
|
)
|
||||||
.as_str(),
|
.as_str(),
|
||||||
);
|
);
|
||||||
let github_json: serde_json::Value = serde_json::from_str(&github_body).unwrap();
|
let github_json: serde_json::Value = serde_json::from_str(&github_body).unwrap();
|
||||||
let latest_version = github_json["tag_name"]
|
github_json["tag_name"]
|
||||||
.to_string()
|
.to_string()
|
||||||
.replace(['v', '"'].as_ref(), "");
|
.replace(['v', '"'].as_ref(), "")
|
||||||
Version::parse(&latest_version).unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn latest_release_url() -> String {
|
pub fn latest_version(owner: &str, repo: &str) -> Version {
|
||||||
format!(
|
Version::parse(&latest(owner, repo)).unwrap()
|
||||||
"https://github.com/{}/{}/releases/latest",
|
}
|
||||||
GH_OWNER, GH_REPO
|
|
||||||
)
|
pub fn latest_release_url(owner: &str, repo: &str) -> String {
|
||||||
|
format!("https://github.com/{}/{}/releases/latest", owner, repo)
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
pub const MASTER: &str = "https://master.alterware.dev";
|
pub const MASTER: &str = "https://master.alterware.dev";
|
||||||
pub const GH_OWNER: &str = "mxve";
|
pub const GH_OWNER: &str = "mxve";
|
||||||
pub const GH_REPO: &str = "alterware-launcher";
|
pub const GH_REPO: &str = "alterware-launcher";
|
||||||
|
pub const GH_IW4X_OWNER: &str = "iw4x";
|
||||||
|
pub const GH_IW4X_REPO: &str = "iw4x-client";
|
40
src/iw4x.rs
Normal file
40
src/iw4x.rs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
use crate::github;
|
||||||
|
use crate::http;
|
||||||
|
use crate::misc;
|
||||||
|
use crate::global::*;
|
||||||
|
|
||||||
|
use std::{fs, path::Path};
|
||||||
|
|
||||||
|
pub fn local_revision(dir: &Path) -> u16 {
|
||||||
|
if let Ok(revision) = fs::read_to_string(dir.join(".iw4xrevision")) {
|
||||||
|
misc::rev_to_int(&revision)
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remote_revision() -> u16 {
|
||||||
|
misc::rev_to_int(&github::latest(GH_IW4X_OWNER, GH_IW4X_REPO))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_available(dir: &Path) -> bool {
|
||||||
|
local_revision(dir) < remote_revision()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update(dir: &Path) {
|
||||||
|
if update_available(dir) {
|
||||||
|
println!("Updating IW4x...");
|
||||||
|
http::download_file(
|
||||||
|
&format!(
|
||||||
|
"{}/download/iw4x.dll",
|
||||||
|
github::latest_release_url(GH_IW4X_OWNER, GH_IW4X_REPO)
|
||||||
|
),
|
||||||
|
&dir.join("iw4x.dll"),
|
||||||
|
);
|
||||||
|
fs::write(
|
||||||
|
dir.join(".iw4xrevision"),
|
||||||
|
github::latest(GH_IW4X_OWNER, GH_IW4X_REPO),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
mod github;
|
mod github;
|
||||||
mod global;
|
mod global;
|
||||||
mod http;
|
mod http;
|
||||||
|
mod iw4x;
|
||||||
mod misc;
|
mod misc;
|
||||||
mod self_update;
|
mod self_update;
|
||||||
mod structs;
|
mod structs;
|
||||||
@ -177,7 +178,7 @@ fn update(game: &Game, dir: &Path) {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
for file in cdn_info {
|
for file in cdn_info {
|
||||||
if !file.name.starts_with(game.engine) {
|
if !file.name.starts_with(game.engine) || file.name == "iw4/iw4x.dll" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,6 +205,10 @@ fn update(game: &Game, dir: &Path) {
|
|||||||
http::download_file(&format!("{}/{}", MASTER, file.name), &file_path);
|
http::download_file(&format!("{}/{}", MASTER, file.name), &file_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if game.engine == "iw4" {
|
||||||
|
iw4x::update(dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn launch(file_path: &PathBuf) {
|
fn launch(file_path: &PathBuf) {
|
||||||
|
@ -11,3 +11,7 @@ pub fn stdin() -> String {
|
|||||||
std::io::stdin().read_line(&mut input).unwrap();
|
std::io::stdin().read_line(&mut input).unwrap();
|
||||||
input.trim().to_string()
|
input.trim().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn rev_to_int(rev: &str) -> u16 {
|
||||||
|
rev.strip_prefix('r').unwrap().parse::<u16>().unwrap_or(0)
|
||||||
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::github;
|
use crate::github;
|
||||||
|
use crate::global::*;
|
||||||
|
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
@ -6,7 +7,7 @@ use std::{thread, time};
|
|||||||
|
|
||||||
pub fn self_update_available() -> bool {
|
pub fn self_update_available() -> bool {
|
||||||
let current_version: Version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
let current_version: Version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
|
||||||
let latest_version = github::latest_version();
|
let latest_version = github::latest_version(GH_OWNER, GH_REPO);
|
||||||
|
|
||||||
current_version < latest_version
|
current_version < latest_version
|
||||||
}
|
}
|
||||||
@ -46,7 +47,7 @@ pub fn run(update_only: bool) {
|
|||||||
println!("Performing launcher self-update.");
|
println!("Performing launcher self-update.");
|
||||||
println!(
|
println!(
|
||||||
"If you run into any issues, please download the latest version at {}",
|
"If you run into any issues, please download the latest version at {}",
|
||||||
github::latest_release_url()
|
github::latest_release_url(GH_OWNER, GH_REPO)
|
||||||
);
|
);
|
||||||
|
|
||||||
let update_binary = PathBuf::from("alterware-launcher-update.exe");
|
let update_binary = PathBuf::from("alterware-launcher-update.exe");
|
||||||
@ -59,7 +60,7 @@ pub fn run(update_only: bool) {
|
|||||||
http::download_file(
|
http::download_file(
|
||||||
&format!(
|
&format!(
|
||||||
"{}/download/alterware-launcher.exe",
|
"{}/download/alterware-launcher.exe",
|
||||||
github::latest_release_url()
|
github::latest_release_url(GH_OWNER, GH_REPO)
|
||||||
),
|
),
|
||||||
&file_path,
|
&file_path,
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user