11package fr .catcore .modremapperapi .remapping ;
22
33import fr .catcore .modremapperapi .utils .Constants ;
4- import fr .catcore .modremapperapi .utils .FileUtils ;
54import io .github .fabriccompatibiltylayers .modremappingapi .api .v1 .MappingUtils ;
65import io .github .fabriccompatibiltylayers .modremappingapi .api .v1 .ModRemapper ;
76import io .github .fabriccompatibiltylayers .modremappingapi .api .v1 .RemapLibrary ;
1312import io .github .fabriccompatibiltylayers .modremappingapi .impl .remapper .visitor .MRAApplyVisitor ;
1413import io .github .fabriccompatibiltylayers .modremappingapi .impl .remapper .visitor .MixinPostApplyVisitor ;
1514import io .github .fabriccompatibiltylayers .modremappingapi .impl .utils .CacheUtils ;
15+ import io .github .fabriccompatibiltylayers .modremappingapi .impl .utils .FileUtils ;
1616import net .fabricmc .api .EnvType ;
1717import net .fabricmc .loader .api .FabricLoader ;
1818import net .fabricmc .mappingio .MappingVisitor ;
2525import org .jetbrains .annotations .ApiStatus ;
2626
2727import java .io .*;
28+ import java .net .URISyntaxException ;
2829import java .nio .file .Files ;
2930import java .nio .file .Path ;
3031import java .util .*;
3132import java .util .function .Supplier ;
32- import java .util .zip .ZipEntry ;
33- import java .util .zip .ZipInputStream ;
3433
3534public class RemapUtil {
3635 private static List <ModRemapper > remappers ;
@@ -43,8 +42,10 @@ public class RemapUtil {
4342
4443 private static String defaultPackage = "" ;
4544
45+ @ ApiStatus .Internal
4646 public static final List <String > MC_CLASS_NAMES = new ArrayList <>();
4747
48+ @ ApiStatus .Internal
4849 public static void init (List <io .github .fabriccompatibiltylayers .modremappingapi .api .v1 .ModRemapper > modRemappers ) {
4950 remappers = modRemappers ;
5051
@@ -85,7 +86,7 @@ public static void init(List<io.github.fabriccompatibiltylayers.modremappingapi.
8586 String className = classView .getName (MappingsUtilsImpl .getSourceNamespace ());
8687
8788 if (className != null ) {
88- MC_CLASS_NAMES .add (className );
89+ MC_CLASS_NAMES .add ("/" + className + ".class" );
8990 }
9091 }
9192
@@ -112,21 +113,22 @@ private static void downloadRemappingLibs() {
112113
113114 if (!library .url .isEmpty ()) {
114115 Constants .MAIN_LOGGER .info ("Downloading remapping library '" + library .fileName + "' from url '" + library .url + "'" );
115- io . github . fabriccompatibiltylayers . modremappingapi . impl . utils . FileUtils .downloadFile (library .url , path );
116- FileUtils .excludeFromZipFile (path . toFile () , library .toExclude );
116+ FileUtils .downloadFile (library .url , path );
117+ FileUtils .removeEntriesFromZip (path , library .toExclude );
117118 Constants .MAIN_LOGGER .info ("Remapping library ready for use." );
118119 } else if (library .path != null ) {
119120 Constants .MAIN_LOGGER .info ("Extracting remapping library '" + library .fileName + "' from mod jar." );
120- io . github . fabriccompatibiltylayers . modremappingapi . impl . utils . FileUtils .copyZipFile (library .path , path );
121+ FileUtils .copyZipFile (library .path , path );
121122 Constants .MAIN_LOGGER .info ("Remapping library ready for use." );
122123 }
123124 }
124125 }
125- } catch (IOException e ) {
126+ } catch (IOException | URISyntaxException e ) {
126127 throw new RuntimeException (e );
127128 }
128129 }
129130
131+ @ ApiStatus .Internal
130132 public static void remapMods (Map <Path , Path > pathMap ) {
131133 Constants .MAIN_LOGGER .debug ("Starting jar remapping!" );
132134 preloadClasses ();
@@ -138,32 +140,19 @@ public static void remapMods(Map<Path, Path> pathMap) {
138140 MappingsUtilsImpl .writeFullMappings ();
139141 }
140142
143+ @ ApiStatus .Internal
141144 public static List <String > makeModMappings (Path modPath ) {
142145 File path = modPath .toFile ();
143146 List <String > files = new ArrayList <>();
147+
144148 if (path .isFile ()) {
145149 try {
146- FileInputStream fileinputstream = new FileInputStream (path );
147- ZipInputStream zipinputstream = new ZipInputStream (fileinputstream );
148-
149- while (true ) {
150- ZipEntry zipentry = zipinputstream .getNextEntry ();
151- if (zipentry == null ) {
152- zipinputstream .close ();
153- fileinputstream .close ();
154- break ;
155- }
156-
157- String s1 = zipentry .getName ();
158- if (!zipentry .isDirectory ()) {
159- files .add (s1 .replace ("\\ " , "/" ));
160- }
161- }
150+ files .addAll (FileUtils .listZipContent (modPath ));
162151 } catch (IOException e ) {
163152 throw new RuntimeException (e );
164153 }
165154 } else if (path .isDirectory ()) {
166- files .addAll (generateFolderMappings (path .listFiles ()));
155+ files .addAll (FileUtils . listDirectoryContent (path .listFiles ()));
167156 }
168157
169158 List <String > classes = new ArrayList <>();
@@ -182,6 +171,7 @@ public static List<String> makeModMappings(Path modPath) {
182171 return files ;
183172 }
184173
174+ @ ApiStatus .Internal
185175 public static void generateModMappings () {
186176 try {
187177 MODS_TREE .visitEnd ();
@@ -195,6 +185,7 @@ public static void generateModMappings() {
195185 MappingsUtilsImpl .addMappingsToContext (MODS_TREE );
196186 }
197187
188+ @ ApiStatus .Internal
198189 public static void writeMcMappings () {
199190 try {
200191 MappingWriter writer = MappingWriter .create (Constants .MC_MAPPINGS_FILE .toPath (), MappingFormat .TINY_2_FILE );
@@ -204,23 +195,6 @@ public static void writeMcMappings() {
204195 }
205196 }
206197
207- private static List <String > generateFolderMappings (File [] files ) {
208- List <String > list = new ArrayList <>();
209-
210- for (File file : files ) {
211- if (file .isFile ()) list .add (file .getName ());
212- else if (file .isDirectory ()) {
213- String name = file .getName ();
214-
215- for (String fileName : generateFolderMappings (file .listFiles ())) {
216- list .add (name + "/" + fileName );
217- }
218- }
219- }
220-
221- return list ;
222- }
223-
224198 @ Deprecated
225199 public static class MappingList extends ArrayList <MappingBuilder > {
226200 public MappingList () {
0 commit comments