diff --git a/README.md b/README.md index 026303f..45c3a45 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,10 @@ ![GitHub tag (with filter)](https://img.shields.io/github/v/tag/mxve/alterware-launcher?filter=!v*-pre&style=flat-square&label=Latest%20release&labelColor=F3F8FF&color=E26EE5) ![GitHub (Pre-)Release Date](https://img.shields.io/github/release-date-pre/mxve/alterware-launcher?style=flat-square&label=Release%20date&labelColor=F3F8FF&color=E26EE5) ![GitHub all releases](https://img.shields.io/github/downloads/mxve/alterware-launcher/total?style=flat-square&label=Total%20downloads&labelColor=F3F8FF&color=E26EE5) ---- - > [!IMPORTANT] > **Only legitimate copies of the games are supported. If you don't own the game, please buy it.** -## Table of Contents +## 🗺️ Table of Contents diff --git a/src/github.rs b/src/github.rs index 74a67c6..2b62c64 100644 --- a/src/github.rs +++ b/src/github.rs @@ -1,6 +1,6 @@ use semver::Version; -pub async fn latest_tag(owner: &str, repo: &str) -> String { +pub async fn latest_tag(owner: &str, repo: &str) -> Result> { let github_body = crate::http_async::get_body_string( format!( "https://api.github.com/repos/{}/{}/releases/latest", @@ -8,23 +8,32 @@ pub async fn latest_tag(owner: &str, repo: &str) -> String { ) .as_str(), ) - .await - .unwrap(); + .await?; - 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)?; if let Some(tag_name) = github_json.get("tag_name") { if let Some(tag_name_str) = tag_name.as_str() { - return tag_name_str.to_string().replace('"', ""); + return Ok(tag_name_str.to_string().replace('"', "")); } } - "0.0.0".to_string() + Ok("0.0.0".to_string()) } pub async fn latest_version(owner: &str, repo: &str) -> Version { - let tag = latest_tag(owner, repo).await.replace('v', ""); - Version::parse(&tag).unwrap() + match latest_tag(owner, repo).await { + Ok(tag) => { + let cleaned_tag = tag.replace('v', ""); + Version::parse(&cleaned_tag).unwrap_or_else(|_| Version::new(0, 0, 0)) + } + Err(_) => { + crate::println_error!( + "Failed to get latest version for {owner}/{repo}, assuming we are up to date." + ); + Version::new(0, 0, 0) + } + } } pub fn latest_release_url(owner: &str, repo: &str) -> String { diff --git a/src/iw4x.rs b/src/iw4x.rs index 56681da..81c2222 100644 --- a/src/iw4x.rs +++ b/src/iw4x.rs @@ -9,7 +9,13 @@ use std::fs; use std::path::Path; pub async fn remote_revision() -> u16 { - misc::rev_to_int(&github::latest_tag(GH_IW4X_OWNER, GH_IW4X_REPO).await) + match github::latest_tag(GH_IW4X_OWNER, GH_IW4X_OWNER).await { + Ok(tag) => misc::rev_to_int(&tag), + Err(_) => { + crate::println_error!("Failed to get latest version for {GH_IW4X_OWNER}/{GH_IW4X_OWNER}, assuming we are up to date."); + 0 + } + } } pub async fn update(dir: &Path, cache: &mut structs::Cache) { diff --git a/src/main.rs b/src/main.rs index bfada5d..64f0dab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -680,7 +680,11 @@ async fn main() { let games_json = http_async::get_body_string(format!("{}/games.json", MASTER.lock().unwrap()).as_str()) .await - .unwrap(); + .unwrap_or_else(|error| { + crate::println_error!("Failed to get games.json: {:#?}", error); + misc::stdin(); + std::process::exit(1); + }); let games: Vec = serde_json::from_str(&games_json).unwrap_or_else(|error| { crate::println_error!("Error parsing games.json: {:#?}", error); misc::stdin();