2023-08-29 15:53:47 -04:00
|
|
|
use crate::github;
|
2023-08-30 07:06:49 -04:00
|
|
|
use crate::global::*;
|
2023-08-29 15:53:47 -04:00
|
|
|
use crate::http;
|
|
|
|
use crate::misc;
|
|
|
|
|
|
|
|
use std::{fs, path::Path};
|
2023-09-11 07:05:18 -04:00
|
|
|
use colored::*;
|
2023-08-29 15:53:47 -04:00
|
|
|
|
|
|
|
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 {
|
2023-08-30 06:46:13 -04:00
|
|
|
misc::rev_to_int(&github::latest_tag(GH_IW4X_OWNER, GH_IW4X_REPO))
|
2023-08-29 15:53:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn update(dir: &Path) {
|
2023-08-30 07:06:49 -04:00
|
|
|
let remote = remote_revision();
|
|
|
|
let local = local_revision(dir);
|
|
|
|
|
|
|
|
if remote <= local && dir.join("iw4x.dll").exists() {
|
|
|
|
return;
|
2023-08-29 15:53:47 -04:00
|
|
|
}
|
2023-08-30 07:06:49 -04:00
|
|
|
|
2023-09-11 07:05:18 -04:00
|
|
|
println!("[{}] {}", "Downloading".bright_yellow(), dir.join("iw4x.dll").display());
|
2023-08-30 07:06:49 -04:00
|
|
|
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();
|
2023-08-29 15:53:47 -04:00
|
|
|
}
|