Skip to content

Commit

Permalink
fix: use exact expected path when finding Northar core mods
Browse files Browse the repository at this point in the history
  • Loading branch information
AnActualEmerald committed Mar 16, 2024
1 parent e4afaec commit dcf3c71
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ impl Config {
self.current_profile = current_profile.into();
}

pub fn current_profile_dir(&self) -> Option<PathBuf> {
self.game_dir().map(|d| d.join(&self.current_profile))
}

pub fn is_ignored(&self, val: &str) -> bool {
self.ignore.contains(val)
}
Expand Down
46 changes: 28 additions & 18 deletions src/core/commands/northstar.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::path::Path;
use std::fs;
use std::path::{Path, PathBuf};
use std::time::Duration;

use crate::config::DIRS;
Expand All @@ -12,7 +13,7 @@ use crate::{get_answer, modfile};
use anyhow::{anyhow, Result};
use indicatif::{ProgressBar, ProgressStyle};
use owo_colors::OwoColorize;
use thermite::model::{InstalledMod, Mod};
use thermite::model::{Mod, ModJSON};
use thermite::prelude::*;
use tracing::{debug, warn};

Expand Down Expand Up @@ -111,13 +112,7 @@ pub fn update_ns() -> Result<bool> {
dir.clone()
} else {
// the fact that this works is kinda funny but also makes my life massively easier
let Ok(p) = ns_client
.path
.join("..")
.join("..")
.join("..")
.canonicalize()
else {
let Ok(p) = ns_client.join("..").join("..").join("..").canonicalize() else {
warn!("Northstar installation seems to be invalid, aborting update");
println!(
"Can't update this Northstar installation. Try running {} first",
Expand All @@ -135,25 +130,40 @@ pub fn update_ns() -> Result<bool> {
}
}

pub fn update_check() -> Result<Option<(InstalledMod, Mod)>> {
pub fn update_check() -> Result<Option<(PathBuf, Mod)>> {
let ns_client_path = CONFIG
.current_profile_dir()
.ok_or_else(|| anyhow!("Unable to get current profile directory from config"))?
.join("mods")
.join("Northstar.Client");
let index = get_package_index()?;
let mods = find_mods(CONFIG.install_dir()?)?;
let Some(ns_client) = mods.get_item(&ModName::new("northstar", "Northstar.Client", None))
else {

if !ns_client_path.try_exists()? {
debug!(
"Didn't find 'Northstar.Client' in '{}'",
CONFIG.install_dir()?.display()
"Didn't find 'Northstar.Client' at '{}'",
ns_client_path.display()
);
return Err(anyhow!("Unable to find Northstar.Client mod"));
};
}

let mod_json_path = ns_client_path.join("mod.json");
let mod_json: ModJSON = serde_json::from_slice(&fs::read(mod_json_path)?)?;

// else {
// debug!(
// "Didn't find 'Northstar.Client' in '{}'",
// search_dir.display()
// );
// return Err(anyhow!("Unable to find Northstar.Client mod"));
// };

let remote_ns = index
.get_item(&ModName::new("northstar", "Northstar", None))
.ok_or_else(|| anyhow!("Unable to find Northstar in Thunderstore index"))?;

if ns_client.mod_json.version == remote_ns.latest {
if mod_json.version == remote_ns.latest {
Ok(None)
} else {
Ok(Some((ns_client.clone(), remote_ns.clone())))
Ok(Some((ns_client_path, remote_ns.clone())))
}
}
3 changes: 2 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use thermite::{
use tracing::debug;

lazy_static! {
static ref RE: Regex = Regex::new(r"^(\S\w+)[\.-](\w+)(?:[@-](\d+\.\d+\.\d+))?$").unwrap();
static ref RE: Regex =
Regex::new(r"^(\S\w+)[\.-](\w+)(?:[@-](\d+\.\d+\.\d+))?$").expect("ModName regex");
}

pub fn validate_modname(input: &str) -> Result<ModName, String> {
Expand Down

0 comments on commit dcf3c71

Please sign in to comment.