1
- use std:: path:: Path ;
1
+ use std:: fs;
2
+ use std:: path:: { Path , PathBuf } ;
2
3
use std:: time:: Duration ;
3
4
4
5
use crate :: config:: DIRS ;
@@ -12,7 +13,7 @@ use crate::{get_answer, modfile};
12
13
use anyhow:: { anyhow, Result } ;
13
14
use indicatif:: { ProgressBar , ProgressStyle } ;
14
15
use owo_colors:: OwoColorize ;
15
- use thermite:: model:: { InstalledMod , Mod } ;
16
+ use thermite:: model:: { Mod , ModJSON } ;
16
17
use thermite:: prelude:: * ;
17
18
use tracing:: { debug, warn} ;
18
19
@@ -111,13 +112,7 @@ pub fn update_ns() -> Result<bool> {
111
112
dir. clone ( )
112
113
} else {
113
114
// 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 {
121
116
warn ! ( "Northstar installation seems to be invalid, aborting update" ) ;
122
117
println ! (
123
118
"Can't update this Northstar installation. Try running {} first" ,
@@ -135,25 +130,40 @@ pub fn update_ns() -> Result<bool> {
135
130
}
136
131
}
137
132
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" ) ;
139
139
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 ( ) ? {
143
142
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( )
146
145
) ;
147
146
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
+ // };
149
159
150
160
let remote_ns = index
151
161
. get_item ( & ModName :: new ( "northstar" , "Northstar" , None ) )
152
162
. ok_or_else ( || anyhow ! ( "Unable to find Northstar in Thunderstore index" ) ) ?;
153
163
154
- if ns_client . mod_json . version == remote_ns. latest {
164
+ if mod_json. version == remote_ns. latest {
155
165
Ok ( None )
156
166
} else {
157
- Ok ( Some ( ( ns_client . clone ( ) , remote_ns. clone ( ) ) ) )
167
+ Ok ( Some ( ( ns_client_path , remote_ns. clone ( ) ) ) )
158
168
}
159
169
}
0 commit comments