5656import me .itzg .helpers .json .ObjectMappers ;
5757import org .apache .commons .compress .archivers .zip .ZipArchiveEntry ;
5858import org .apache .commons .compress .archivers .zip .ZipFile ;
59+ import org .jetbrains .annotations .NotNull ;
5960import org .jetbrains .annotations .Nullable ;
6061import reactor .core .publisher .Flux ;
6162import reactor .core .publisher .Mono ;
@@ -800,17 +801,21 @@ private Mono<ResolveResult> downloadOrResolveFile(InstallContext context, CurseF
800801
801802 // Will try to locate an existing file by alternate names that browser might create,
802803 // but only for non-world files of the modpack
803- final Path locatedFile = !isWorld ? locateFileIn (cfFile .getFileName (),
804- outputDir ,
805- downloadsRepo
806- ) : null ;
804+ final Path locatedFile = !isWorld ?
805+ locateFileIn (cfFile .getFileName (), outputDir )
806+ : null ;
807807
808808 if (locatedFile != null ) {
809809 log .info ("Mod file {} already exists" , locatedFile );
810810 return FileHashVerifier .verify (locatedFile , cfFile .getHashes ())
811811 .map (ResolveResult ::new );
812812 }
813813 else {
814+ final Path fileInRepo = locateModInRepo (cfFile .getFileName ());
815+ if (fileInRepo != null ) {
816+ return copyFromDownloadsRepo (outputFile , fileInRepo );
817+ }
818+
814819 return context .cfApi .download (cfFile , outputFile , modFileDownloadStatusHandler (this .outputDir , log ))
815820 .flatMap (path -> FileHashVerifier .verify (path , cfFile .getHashes ()))
816821 .map (ResolveResult ::new )
@@ -837,22 +842,20 @@ private Mono<ResolveResult> handleFileNeedingManualDownload(CurseForgeMod modInf
837842 return Mono .just (new ResolveResult (outputFile ).setDownloadNeeded (true ));
838843 }
839844 else {
840- return Mono .just (resolved )
841- .publishOn (Schedulers .boundedElastic ())
842- .flatMap (path -> {
843- try {
844- log .info ("Mod file {} obtained from downloads repo" ,
845- this .outputDir .relativize (outputFile )
846- );
847- //noinspection BlockingMethodInNonBlockingContext because IntelliJ is confused
848- return Mono .just (Files .copy (resolved , outputFile ));
849- } catch (IOException e ) {
850- return Mono .error (new GenericException ("Failed to copy file from downloads repo" , e ));
851- }
845+ return copyFromDownloadsRepo (outputFile , resolved );
846+ }
847+ }
852848
849+ private @ NotNull Mono <ResolveResult > copyFromDownloadsRepo (Path outputFile , Path resolved ) {
850+ return
851+ Mono .fromCallable (() -> {
852+ log .info ("Mod file {} obtained from downloads repo" ,
853+ this .outputDir .relativize (outputFile )
854+ );
855+ return Files .copy (resolved , outputFile );
853856 })
857+ .subscribeOn (Schedulers .boundedElastic ())
854858 .map (ResolveResult ::new );
855- }
856859 }
857860
858861 private PathWithInfo extractWorldZip (CurseForgeMod modInfo , Path zipPath , Path worldsDir ) {
0 commit comments