@@ -158,6 +158,31 @@ impl Found {
158158 }
159159}
160160
161+ fn find_existing_dependency (
162+ dep : & Dependency ,
163+ _config : & Config ,
164+ ) -> Result < Found , String > {
165+ let mut path = env:: temp_dir ( ) ;
166+ path. push ( format ! ( "{}.geode" , dep. id) ) ;
167+
168+ if path. exists ( ) {
169+ let mod_info =
170+ try_parse_mod_info ( & path) . map_err ( |x| format ! ( "Couldn't parse mod.json: {}" , x) ) ?;
171+
172+ if !dep. version . matches ( & mod_info. version ) {
173+ info ! (
174+ "Dependency '{}' found in cache, but version '{}' does not match required '{}'" ,
175+ dep. id, mod_info. version, dep. version
176+ ) ;
177+ return Ok ( Found :: Wrong ( mod_info. version ) ) ;
178+ }
179+
180+ Ok ( Found :: Some ( path, mod_info) )
181+ } else {
182+ Ok ( Found :: None )
183+ }
184+ }
185+
161186fn find_index_dependency ( dep : & Dependency , config : & Config ) -> Result < Found , String > {
162187 info ! ( "Fetching dependency from index" ) ;
163188 let found = index:: get_mod_versions (
@@ -396,161 +421,178 @@ pub fn check_dependencies(
396421
397422 // otherwise try to find it on installed mods and then on index
398423
399- // check index
400- let found_in_index = match find_index_dependency ( dep, & config) {
424+ // dont check others if already downloaded
425+ let path_to_dep_geode;
426+ let _geode_info;
427+
428+ let found_existing = match find_existing_dependency ( dep, & config) {
401429 Ok ( f) => f,
402430 Err ( e) => {
403- warn ! ( "Failed to fetch dependency {} from index : {}" , & dep. id, e) ;
431+ warn ! ( "Failed to fetch dependency {} from cache : {}" , & dep. id, e) ;
404432 Found :: None
405433 }
406434 } ;
407- // check installed mods
408- let found_in_installed =
409- find_dependency ( dep, & config. get_current_profile ( ) . mods_dir ( ) , true , false )
410- . nice_unwrap ( "Unable to read installed mods" ) ;
411-
412- // if not found in either hjfod code
413- if !matches ! ( found_in_index, Found :: Some ( _, _) )
414- && !matches ! ( found_in_installed, Found :: Some ( _, _) )
415- {
416- if dep. importance == DependencyImportance :: Required {
417- fail ! (
418- "Dependency '{0}' not found in installed mods nor index! \
419- If this is a mod that hasn't been published yet, install it \
420- locally first, or if it's a closed-source mod that won't be \
421- on the index, mark it as external in your CMake using \
422- setup_geode_mod(... EXTERNALS {0}:{1})",
423- dep. id,
424- dep. version
425- ) ;
426- errors = true ;
427- } else {
428- info ! (
429- "Dependency '{}' not found in installed mods nor index" ,
430- dep. id
431- )
432- }
433- // bad version
434- match ( & found_in_index, & found_in_installed) {
435- ( in_index @ Found :: Wrong ( ver) , _) | ( in_index, Found :: Wrong ( ver) ) => {
436- info ! (
437- "Version '{ver}' of the mod was found in {}, but it was \
438- rejected because version '{}' is required by the dependency",
439- if matches!( in_index, Found :: Wrong ( _) ) {
440- "index"
441- } else {
442- "installed mods"
443- } ,
435+
436+ if let Found :: Some ( inst_path, inst_info) = found_existing {
437+ info ! ( "Dependency '{}' found in cache" , dep. id) ;
438+ path_to_dep_geode = inst_path;
439+ _geode_info = inst_info;
440+ }
441+ else {
442+ // check index
443+ let found_in_index = match find_index_dependency ( dep, & config) {
444+ Ok ( f) => f,
445+ Err ( e) => {
446+ warn ! ( "Failed to fetch dependency {} from index: {}" , & dep. id, e) ;
447+ Found :: None
448+ }
449+ } ;
450+ // check installed mods
451+ let found_in_installed =
452+ find_dependency ( dep, & config. get_current_profile ( ) . mods_dir ( ) , true , false )
453+ . nice_unwrap ( "Unable to read installed mods" ) ;
454+
455+ // if not found in either hjfod code
456+ if !matches ! ( found_in_index, Found :: Some ( _, _) )
457+ && !matches ! ( found_in_installed, Found :: Some ( _, _) )
458+ {
459+ if dep. importance == DependencyImportance :: Required {
460+ fail ! (
461+ "Dependency '{0}' not found in installed mods nor index! \
462+ If this is a mod that hasn't been published yet, install it \
463+ locally first, or if it's a closed-source mod that won't be \
464+ on the index, mark it as external in your CMake using \
465+ setup_geode_mod(... EXTERNALS {0}:{1})",
466+ dep. id,
444467 dep. version
445468 ) ;
469+ errors = true ;
470+ } else {
471+ info ! (
472+ "Dependency '{}' not found in installed mods nor index" ,
473+ dep. id
474+ )
446475 }
447- _ => { }
476+ // bad version
477+ match ( & found_in_index, & found_in_installed) {
478+ ( in_index @ Found :: Wrong ( ver) , _) | ( in_index, Found :: Wrong ( ver) ) => {
479+ info ! (
480+ "Version '{ver}' of the mod was found in {}, but it was \
481+ rejected because version '{}' is required by the dependency",
482+ if matches!( in_index, Found :: Wrong ( _) ) {
483+ "index"
484+ } else {
485+ "installed mods"
486+ } ,
487+ dep. version
488+ ) ;
489+ }
490+ _ => { }
491+ }
492+ // misspelled message
493+ match ( & found_in_index, & found_in_installed) {
494+ ( in_index @ Found :: Maybe ( m) , _) | ( in_index, Found :: Maybe ( m) ) => {
495+ info ! (
496+ "Another mod with a similar ID was found in {}: {m} \
497+ - maybe you misspelled?",
498+ if matches!( in_index, Found :: Maybe ( _) ) {
499+ "index"
500+ } else {
501+ "installed mods"
502+ }
503+ ) ;
504+ }
505+ _ => { }
506+ }
507+ // skip rest
508+ continue ;
448509 }
449- // misspelled message
450- match ( & found_in_index, & found_in_installed) {
451- ( in_index @ Found :: Maybe ( m) , _) | ( in_index, Found :: Maybe ( m) ) => {
510+
511+ match ( found_in_installed, found_in_index) {
512+ ( Found :: Some ( _, _) , Found :: Some ( inst_path, inst_info) ) => {
513+ info ! ( "Dependency '{}' found" , dep. id) ;
514+ path_to_dep_geode = inst_path;
515+ _geode_info = inst_info;
516+ }
517+
518+ ( Found :: Some ( inst_path, inst_info) , _) => {
519+ warn ! (
520+ "Dependency '{}' found in installed mods, but not on the \
521+ mods index - make sure that the mod is published on the \
522+ index when you publish yours, as otherwise users won't be \
523+ able to install your mod through the index!",
524+ dep. id
525+ ) ;
452526 info ! (
453- "Another mod with a similar ID was found in {}: {m} \
454- - maybe you misspelled?",
455- if matches!( in_index, Found :: Maybe ( _) ) {
456- "index"
457- } else {
458- "installed mods"
459- }
527+ "If '{0}' is a closed-source mod that won't be released on \
528+ the index, mark it as external in your CMake with \
529+ setup_geode_mod(... EXTERNALS {0}:{1})",
530+ dep. id, dep. version
460531 ) ;
532+ path_to_dep_geode = inst_path;
533+ _geode_info = inst_info;
461534 }
462- _ => { }
463- }
464- // skip rest
465- continue ;
466- }
467-
468- let path_to_dep_geode;
469- let _geode_info;
470- match ( found_in_installed, found_in_index) {
471- ( Found :: Some ( _, _) , Found :: Some ( inst_path, inst_info) ) => {
472- info ! ( "Dependency '{}' found" , dep. id) ;
473- path_to_dep_geode = inst_path;
474- _geode_info = inst_info;
475- }
476535
477- ( Found :: Some ( inst_path, inst_info) , _) => {
478- warn ! (
479- "Dependency '{}' found in installed mods, but not on the \
480- mods index - make sure that the mod is published on the \
481- index when you publish yours, as otherwise users won't be \
482- able to install your mod through the index!",
483- dep. id
484- ) ;
485- info ! (
486- "If '{0}' is a closed-source mod that won't be released on \
487- the index, mark it as external in your CMake with \
488- setup_geode_mod(... EXTERNALS {0}:{1})",
489- dep. id, dep. version
490- ) ;
491- path_to_dep_geode = inst_path;
492- _geode_info = inst_info;
493- }
536+ ( Found :: Wrong ( version) , Found :: Some ( path, indx_info) ) => {
537+ if version > indx_info. version {
538+ warn ! (
539+ "Dependency '{0}' found in installed mods, but as \
540+ version '{1}' whereas required is '{2}'. Index has valid \
541+ version '{3}', but not using it as it appears you have \
542+ a newer version installed. Either manually downgrade \
543+ the installed '{0}' to '{3}', or update your mod.json's \
544+ dependency requirements",
545+ dep. id, version, dep. version, indx_info. version
546+ ) ;
547+ continue ;
548+ }
549+ info ! (
550+ "Dependency '{}' found on the index, installing \
551+ (update '{}' => '{}')",
552+ dep. id, version, indx_info. version
553+ ) ;
554+ let geode_path = config
555+ . get_current_profile ( )
556+ . mods_dir ( )
557+ . join ( format ! ( "{}.geode" , indx_info. id) ) ;
558+ std:: fs:: copy ( path, & geode_path) . nice_unwrap ( "Failed to install .geode" ) ;
559+ path_to_dep_geode = geode_path;
560+ _geode_info = indx_info;
561+ }
494562
495- ( Found :: Wrong ( version) , Found :: Some ( path, indx_info) ) => {
496- if version > indx_info. version {
497- warn ! (
498- "Dependency '{0}' found in installed mods, but as \
499- version '{1}' whereas required is '{2}'. Index has valid \
500- version '{3}', but not using it as it appears you have \
501- a newer version installed. Either manually downgrade \
502- the installed '{0}' to '{3}', or update your mod.json's \
503- dependency requirements",
504- dep. id, version, dep. version, indx_info. version
563+ ( _, Found :: Some ( path, indx_info) ) => {
564+ info ! (
565+ "Dependency '{}' found on the index, installing (version '{}')" ,
566+ dep. id, indx_info. version
505567 ) ;
506- continue ;
568+ let geode_path = config
569+ . get_current_profile ( )
570+ . mods_dir ( )
571+ . join ( format ! ( "{}.geode" , indx_info. id) ) ;
572+ std:: fs:: copy ( path, & geode_path) . nice_unwrap ( "Failed to install .geode" ) ;
573+ path_to_dep_geode = geode_path;
574+ _geode_info = indx_info;
507575 }
508- info ! (
509- "Dependency '{}' found on the index, installing \
510- (update '{}' => '{}')",
511- dep. id, version, indx_info. version
512- ) ;
513- let geode_path = config
514- . get_current_profile ( )
515- . mods_dir ( )
516- . join ( format ! ( "{}.geode" , indx_info. id) ) ;
517- std:: fs:: copy ( path, & geode_path) . nice_unwrap ( "Failed to install .geode" ) ;
518- path_to_dep_geode = geode_path;
519- _geode_info = indx_info;
520- }
521576
522- ( _, Found :: Some ( path, indx_info) ) => {
523- info ! (
524- "Dependency '{}' found on the index, installing (version '{}')" ,
525- dep. id, indx_info. version
526- ) ;
527- let geode_path = config
528- . get_current_profile ( )
529- . mods_dir ( )
530- . join ( format ! ( "{}.geode" , indx_info. id) ) ;
531- std:: fs:: copy ( path, & geode_path) . nice_unwrap ( "Failed to install .geode" ) ;
532- path_to_dep_geode = geode_path;
533- _geode_info = indx_info;
577+ _ => unreachable ! ( ) ,
534578 }
535579
536- _ => unreachable ! ( ) ,
580+ // check already installed dependencies
581+ // let found_in_deps = find_dependency(
582+ // &dep, &dep_dir, false
583+ // ).nice_unwrap("Unable to read dependencies");
584+
585+ // !this check may be added back at some point, but for now there's not
586+ // too much performance benefit from doing this, and doing it might
587+ // cause issues if the dependency has changes
588+ // check if dependency already installed
589+ // if let Found::Some(_, info) = found_in_deps {
590+ // if info.version == geode_info.version {
591+ // continue;
592+ // }
593+ // }
537594 }
538595
539- // check already installed dependencies
540- // let found_in_deps = find_dependency(
541- // &dep, &dep_dir, false
542- // ).nice_unwrap("Unable to read dependencies");
543-
544- // !this check may be added back at some point, but for now there's not
545- // too much performance benefit from doing this, and doing it might
546- // cause issues if the dependency has changes
547- // check if dependency already installed
548- // if let Found::Some(_, info) = found_in_deps {
549- // if info.version == geode_info.version {
550- // continue;
551- // }
552- // }
553-
554596 // unzip the whole .geode package because there's only like a few
555597 // extra files there aside from the lib, headers, and resources
556598 zip:: ZipArchive :: new ( fs:: File :: open ( path_to_dep_geode) . unwrap ( ) )
0 commit comments