Skip to content

Commit feb63d5

Browse files
fix: use exact expected path when finding Northar core mods
1 parent e4afaec commit feb63d5

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ impl Config {
9595
self.current_profile = current_profile.into();
9696
}
9797

98+
pub fn current_profile_dir(&self) -> Option<PathBuf> {
99+
self.game_dir().map(|d| d.join(&self.current_profile))
100+
}
101+
98102
pub fn is_ignored(&self, val: &str) -> bool {
99103
self.ignore.contains(val)
100104
}

src/core/commands/northstar.rs

+28-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::path::Path;
1+
use std::fs;
2+
use std::path::{Path, PathBuf};
23
use std::time::Duration;
34

45
use crate::config::DIRS;
@@ -12,7 +13,7 @@ use crate::{get_answer, modfile};
1213
use anyhow::{anyhow, Result};
1314
use indicatif::{ProgressBar, ProgressStyle};
1415
use owo_colors::OwoColorize;
15-
use thermite::model::{InstalledMod, Mod};
16+
use thermite::model::{Mod, ModJSON};
1617
use thermite::prelude::*;
1718
use tracing::{debug, warn};
1819

@@ -111,13 +112,7 @@ pub fn update_ns() -> Result<bool> {
111112
dir.clone()
112113
} else {
113114
// the fact that this works is kinda funny but also makes my life massively easier
114-
let Ok(p) = ns_client
115-
.path
116-
.join("..")
117-
.join("..")
118-
.join("..")
119-
.canonicalize()
120-
else {
115+
let Ok(p) = ns_client.join("..").join("..").join("..").canonicalize() else {
121116
warn!("Northstar installation seems to be invalid, aborting update");
122117
println!(
123118
"Can't update this Northstar installation. Try running {} first",
@@ -135,25 +130,40 @@ pub fn update_ns() -> Result<bool> {
135130
}
136131
}
137132

138-
pub fn update_check() -> Result<Option<(InstalledMod, Mod)>> {
133+
pub fn update_check() -> Result<Option<(PathBuf, Mod)>> {
134+
let ns_client_path = CONFIG
135+
.current_profile_dir()
136+
.ok_or_else(|| anyhow!("Unable to get current profile directory from config"))?
137+
.join("mods")
138+
.join("Northstar.Client");
139139
let index = get_package_index()?;
140-
let mods = find_mods(CONFIG.install_dir()?)?;
141-
let Some(ns_client) = mods.get_item(&ModName::new("northstar", "Northstar.Client", None))
142-
else {
140+
141+
if !ns_client_path.try_exists()? {
143142
debug!(
144-
"Didn't find 'Northstar.Client' in '{}'",
145-
CONFIG.install_dir()?.display()
143+
"Didn't find 'Northstar.Client' at '{}'",
144+
ns_client_path.display()
146145
);
147146
return Err(anyhow!("Unable to find Northstar.Client mod"));
148-
};
147+
}
148+
149+
let mod_json_path = ns_client_path.join("mod.json");
150+
let mod_json: ModJSON = serde_json::from_slice(&fs::read(mod_json_path)?)?;
151+
152+
// else {
153+
// debug!(
154+
// "Didn't find 'Northstar.Client' in '{}'",
155+
// search_dir.display()
156+
// );
157+
// return Err(anyhow!("Unable to find Northstar.Client mod"));
158+
// };
149159

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

154-
if ns_client.mod_json.version == remote_ns.latest {
164+
if mod_json.version == remote_ns.latest {
155165
Ok(None)
156166
} else {
157-
Ok(Some((ns_client.clone(), remote_ns.clone())))
167+
Ok(Some((ns_client_path, remote_ns.clone())))
158168
}
159169
}

src/utils.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ use thermite::{
2121
use tracing::debug;
2222

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

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

0 commit comments

Comments
 (0)