25
25
import org .jetbrains .annotations .ApiStatus ;
26
26
27
27
import java .io .*;
28
- import java .net .URL ;
29
28
import java .nio .file .Files ;
30
29
import java .nio .file .Path ;
31
30
import java .util .*;
@@ -49,8 +48,6 @@ public class RemapUtil {
49
48
public static void init (List <io .github .fabriccompatibiltylayers .modremappingapi .api .v1 .ModRemapper > modRemappers ) {
50
49
remappers = modRemappers ;
51
50
52
- downloadRemappingLibs ();
53
-
54
51
for (ModRemapper remapper : remappers ) {
55
52
Optional <String > pkg = remapper .getDefaultPackage ();
56
53
@@ -65,6 +62,18 @@ public static void init(List<io.github.fabriccompatibiltylayers.modremappingapi.
65
62
mappings .ifPresent (inputStreamSupplier -> MappingsUtilsImpl .loadExtraMappings (inputStreamSupplier .get ()));
66
63
}
67
64
65
+ Path sourceLibraryPath = CacheUtils .getLibraryPath (MappingsUtilsImpl .getSourceNamespace ());
66
+
67
+ if (!Files .exists (sourceLibraryPath )) {
68
+ try {
69
+ Files .createDirectories (sourceLibraryPath );
70
+ } catch (IOException e ) {
71
+ throw new RuntimeException (e );
72
+ }
73
+ }
74
+
75
+ downloadRemappingLibs ();
76
+
68
77
MINECRAFT_TREE = MappingsUtilsImpl .getMinecraftMappings ();
69
78
70
79
writeMcMappings ();
@@ -95,37 +104,20 @@ private static void downloadRemappingLibs() {
95
104
96
105
remapper .addRemapLibraries (libraries , FabricLoader .getInstance ().getEnvironmentType ());
97
106
98
- for (RemapLibrary library : libraries ) {
99
- File libPath = CacheUtils .getLibraryPath (library .fileName ).toFile ();
107
+ Map <RemapLibrary , Path > libraryPaths = CacheUtils .computeExtraLibraryPaths (libraries , MappingsUtilsImpl .getSourceNamespace ());
108
+
109
+ for (Map .Entry <RemapLibrary , Path > entry : libraryPaths .entrySet ()) {
110
+ RemapLibrary library = entry .getKey ();
111
+ Path path = entry .getValue ();
100
112
101
- if (!libPath . exists () && ! library .url .isEmpty ()) {
113
+ if (!library .url .isEmpty ()) {
102
114
Constants .MAIN_LOGGER .info ("Downloading remapping library '" + library .fileName + "' from url '" + library .url + "'" );
103
- try (BufferedInputStream inputStream = new BufferedInputStream (new URL (library .url ).openStream ())) {
104
- try (BufferedOutputStream outputStream = new BufferedOutputStream (Files .newOutputStream (libPath .toPath ()))) {
105
- byte [] buffer = new byte [2048 ];
106
-
107
- // Increments file size
108
- int length ;
109
- int downloaded = 0 ;
110
-
111
- // Looping until server finishes
112
- while ((length = inputStream .read (buffer )) != -1 ) {
113
- // Writing data
114
- outputStream .write (buffer , 0 , length );
115
- downloaded += length ;
116
- // Constants.MAIN_LOGGER.debug("Download Status: " + (downloaded * 100) / (contentLength * 1.0) + "%");
117
- }
118
-
119
- outputStream .close ();
120
- inputStream .close ();
121
- }
122
- }
123
-
124
- FileUtils .excludeFromZipFile (libPath , library .toExclude );
115
+ io .github .fabriccompatibiltylayers .modremappingapi .impl .utils .FileUtils .downloadFile (library .url , path );
116
+ FileUtils .excludeFromZipFile (path .toFile (), library .toExclude );
125
117
Constants .MAIN_LOGGER .info ("Remapping library ready for use." );
126
- } else if (! libPath . exists () && library .path != null ) {
118
+ } else if (library .path != null ) {
127
119
Constants .MAIN_LOGGER .info ("Extracting remapping library '" + library .fileName + "' from mod jar." );
128
- FileUtils .copyFile (library .path , libPath . toPath () );
120
+ io . github . fabriccompatibiltylayers . modremappingapi . impl . utils . FileUtils .copyZipFile (library .path , path );
129
121
Constants .MAIN_LOGGER .info ("Remapping library ready for use." );
130
122
}
131
123
}
@@ -346,7 +338,7 @@ private static void preloadClasses() {
346
338
"io.github.fabriccompatibiltylayers.modremappingapi.impl.ModDiscoverer" ,
347
339
"io.github.fabriccompatibiltylayers.modremappingapi.impl.ModDiscoverer$1" ,
348
340
"io.github.fabriccompatibiltylayers.modremappingapi.impl.ModEntry" ,
349
- "fr.catcore.modremapperapi.utils .RefmapJson" ,
341
+ "io.github.fabriccompatibiltylayers.modremappingapi.impl.remapper.resource .RefmapJson" ,
350
342
"fr.catcore.modremapperapi.remapping.MapEntryType" ,
351
343
"fr.catcore.modremapperapi.remapping.MappingBuilder" ,
352
344
"fr.catcore.modremapperapi.remapping.MappingBuilder$Entry" ,
0 commit comments