misc
- reduce github calls - latest_tag returns full tag - rev_to_int default to 0 on strip_prefix - lint
This commit is contained in:
parent
0ec2a44082
commit
932c41d369
@ -9,13 +9,12 @@ pub fn latest_tag(owner: &str, repo: &str) -> String {
|
||||
.as_str(),
|
||||
);
|
||||
let github_json: serde_json::Value = serde_json::from_str(&github_body).unwrap();
|
||||
github_json["tag_name"]
|
||||
.to_string()
|
||||
.replace(['v', '"'].as_ref(), "")
|
||||
github_json["tag_name"].to_string().replace('"', "")
|
||||
}
|
||||
|
||||
pub fn latest_version(owner: &str, repo: &str) -> Version {
|
||||
Version::parse(&latest_tag(owner, repo)).unwrap()
|
||||
let tag = latest_tag(owner, repo).replace('v', "");
|
||||
Version::parse(&tag).unwrap()
|
||||
}
|
||||
|
||||
pub fn latest_release_url(owner: &str, repo: &str) -> String {
|
||||
|
@ -2,4 +2,4 @@ pub const MASTER: &str = "https://master.alterware.dev";
|
||||
pub const GH_OWNER: &str = "mxve";
|
||||
pub const GH_REPO: &str = "alterware-launcher";
|
||||
pub const GH_IW4X_OWNER: &str = "iw4x";
|
||||
pub const GH_IW4X_REPO: &str = "iw4x-client";
|
||||
pub const GH_IW4X_REPO: &str = "iw4x-client";
|
||||
|
38
src/iw4x.rs
38
src/iw4x.rs
@ -1,7 +1,7 @@
|
||||
use crate::github;
|
||||
use crate::global::*;
|
||||
use crate::http;
|
||||
use crate::misc;
|
||||
use crate::global::*;
|
||||
|
||||
use std::{fs, path::Path};
|
||||
|
||||
@ -17,27 +17,21 @@ pub fn remote_revision() -> u16 {
|
||||
misc::rev_to_int(&github::latest_tag(GH_IW4X_OWNER, GH_IW4X_REPO))
|
||||
}
|
||||
|
||||
pub fn update_available(dir: &Path) -> bool {
|
||||
if !dir.join("iw4x.dll").exists() {
|
||||
return true;
|
||||
}
|
||||
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_tag(GH_IW4X_OWNER, GH_IW4X_REPO),
|
||||
)
|
||||
.unwrap();
|
||||
let remote = remote_revision();
|
||||
let local = local_revision(dir);
|
||||
|
||||
if remote <= local && dir.join("iw4x.dll").exists() {
|
||||
return;
|
||||
}
|
||||
|
||||
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"), format!("r{}", remote)).unwrap();
|
||||
}
|
||||
|
@ -13,5 +13,8 @@ pub fn stdin() -> String {
|
||||
}
|
||||
|
||||
pub fn rev_to_int(rev: &str) -> u16 {
|
||||
rev.strip_prefix('r').unwrap().parse::<u16>().unwrap_or(0)
|
||||
rev.strip_prefix('r')
|
||||
.unwrap_or("0")
|
||||
.parse::<u16>()
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
@ -16,7 +16,10 @@ pub fn self_update_available() -> bool {
|
||||
pub fn run(_update_only: bool) {
|
||||
if self_update_available() {
|
||||
println!("A new version of the AlterWare launcher is available.");
|
||||
println!("Download it at {}", github::latest_release_url(GH_OWNER, GH_REPO));
|
||||
println!(
|
||||
"Download it at {}",
|
||||
github::latest_release_url(GH_OWNER, GH_REPO)
|
||||
);
|
||||
println!("Launching in 10 seconds..");
|
||||
thread::sleep(time::Duration::from_secs(10));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user