@@ -112,6 +112,20 @@ fn read_to_string_bom(path: &Path) -> anyhow::Result<String> {
112112 Ok ( String :: from_utf8 ( bytes. to_vec ( ) ) ?)
113113}
114114
115+ fn parse_version ( mod_version : & serde_yaml:: Value ) -> String {
116+ if mod_version. is_f64 ( ) {
117+ mod_version. as_f64 ( ) . unwrap ( ) . to_string ( )
118+ } else {
119+ let v = mod_version. as_str ( ) . unwrap_or ( "1.0.0" ) . to_string ( ) ;
120+
121+ if v. chars ( ) . all ( |c| c. is_ascii_digit ( ) || c == '.' ) {
122+ v
123+ } else {
124+ "1.0.0" . to_string ( )
125+ }
126+ }
127+ }
128+
115129fn get_installed_mods_sync ( mods_folder_path : String ) -> Vec < LocalMod > {
116130 let mut mods = Vec :: new ( ) ;
117131 let mod_data = get_mod_cached_new ( ) . unwrap ( ) ;
@@ -179,7 +193,7 @@ fn get_installed_mods_sync(mods_folder_path: String) -> Vec<LocalMod> {
179193 for dep in deps_yaml {
180194 deps. push ( ModDependency {
181195 name : dep[ "Name" ] . as_str ( ) . unwrap ( ) . to_string ( ) ,
182- version : dep[ "Version" ] . as_str ( ) . unwrap_or ( "0.0.0" ) . to_string ( ) ,
196+ version : parse_version ( & dep[ "Version" ] ) ,
183197 optional : false ,
184198 } ) ;
185199 }
@@ -189,14 +203,14 @@ fn get_installed_mods_sync(mods_folder_path: String) -> Vec<LocalMod> {
189203 for dep in deps_yaml {
190204 deps. push ( ModDependency {
191205 name : dep[ "Name" ] . as_str ( ) . unwrap ( ) . to_string ( ) ,
192- version : dep[ "Version" ] . as_str ( ) . unwrap_or ( "0.0.0" ) . to_string ( ) ,
206+ version : parse_version ( & dep[ "Version" ] ) ,
193207 optional : true ,
194208 } ) ;
195209 }
196210 }
197211
198212 let name = yaml[ 0 ] [ "Name" ] . as_str ( ) . context ( "" ) ?. to_string ( ) ;
199- let version = yaml[ 0 ] [ "Version" ] . as_str ( ) . context ( "" ) ? . to_string ( ) ;
213+ let version = parse_version ( & yaml[ 0 ] [ "Version" ] ) ;
200214 if !mod_data. contains_key ( & name) {
201215 println ! ( "[ WARNING ] Failed to resolve {name} in mod data, using -1 as gamebanana id" ) ;
202216 }
@@ -237,19 +251,7 @@ fn download_and_install_mod(
237251 if let Some ( deps_yaml) = yaml[ 0 ] [ "Dependencies" ] . as_sequence ( ) {
238252 for dep in deps_yaml {
239253 // FUCK YOU YAML
240- let version = if dep[ "Version" ] . is_f64 ( ) {
241- // this turns it into Number(1.1), let's parse it
242- let ver = format ! ( "{:?}" , dep[ "Version" ] ) ;
243- ver[ "Number(" . len ( ) ..ver. len ( ) - 1 ] . to_string ( )
244- } else {
245- let v = dep[ "Version" ] . as_str ( ) . unwrap_or ( "1.0.0" ) . to_string ( ) ;
246-
247- if v. chars ( ) . all ( |c| c. is_ascii_digit ( ) || c == '.' ) {
248- v
249- } else {
250- "1.0.0" . to_string ( )
251- }
252- } ;
254+ let version = parse_version ( & dep[ "Version" ] ) ;
253255
254256 deps. push ( (
255257 dep[ "Name" ]
0 commit comments