1111import org .jetbrains .annotations .NotNull ;
1212import org .spongepowered .include .com .google .common .collect .ImmutableList ;
1313
14- import java .io .File ;
1514import java .io .IOException ;
1615import java .net .URISyntaxException ;
1716import java .nio .file .*;
@@ -41,7 +40,7 @@ protected static void init(List<ModRemapper> modRemappers, boolean remapClassEdi
4140 try {
4241 if (!Files .exists (mcSubFolder )) Files .createDirectories (mcSubFolder );
4342 if (!Files .exists (cacheFolder )) Files .createDirectories (cacheFolder );
44- else io . github . fabriccompatibiltylayers . modremappingapi . impl . utils . FileUtils .emptyDir (cacheFolder );
43+ else FileUtils .emptyDir (cacheFolder );
4544
4645 mods .addAll (discoverModsInFolder (mcSubFolder , cacheFolder ));
4746 } catch (IOException | URISyntaxException e ) {
@@ -50,17 +49,24 @@ protected static void init(List<ModRemapper> modRemappers, boolean remapClassEdi
5049 }
5150 }
5251
53- File mainTempDir = CacheUtils .getCachePath ("temp" ).toFile ();
54- if (mainTempDir .exists ()) {
55- io .github .fabriccompatibiltylayers .modremappingapi .impl .utils .FileUtils .emptyDir (mainTempDir .toPath ());
52+ Path mainTempDir = CacheUtils .getCachePath ("temp" );
53+
54+ if (Files .exists (mainTempDir )) {
55+ FileUtils .emptyDir (mainTempDir );
56+ } else {
57+ try {
58+ Files .createDirectory (mainTempDir );
59+ } catch (IOException e ) {
60+ throw new RuntimeException (e );
61+ }
5662 }
5763
5864 Map <Path , Path > modPaths = mods .stream ()
59- .filter (entry -> entry .original != null )
60- .collect (Collectors .toMap (entry -> entry .original . toPath () , entry -> entry .file . toPath () ));
65+ .filter (entry -> Files . exists ( entry .original ) )
66+ .collect (Collectors .toMap (entry -> entry .original , entry -> entry .file ));
6167
6268 if (!remapClassEdits ) {
63- modPaths = excludeClassEdits (modPaths );
69+ modPaths = excludeClassEdits (modPaths , mainTempDir );
6470 }
6571
6672 for (Path path : modPaths .keySet ()) {
@@ -74,21 +80,25 @@ protected static void init(List<ModRemapper> modRemappers, boolean remapClassEdi
7480 modPaths .values ().forEach (FabricLauncherBase .getLauncher ()::addToClassPath );
7581 }
7682
77- private static Map <Path , Path > excludeClassEdits (Map <Path , Path > modPaths ) {
83+ private static Map <Path , Path > excludeClassEdits (Map <Path , Path > modPaths , Path tempFolder ) {
7884 Map <Path , Path > map = new HashMap <>();
7985 Map <Path , Path > convertMap = new HashMap <>();
8086
81- File mainTempDir = CacheUtils .getCachePath ("temp" ).toFile ();
82- mainTempDir .mkdirs ();
83-
84-
8587 for (Map .Entry <Path , Path > entry : modPaths .entrySet ()) {
86- File tempDir = new File (mainTempDir , entry .getValue ().toFile ().getParentFile ().getName ());
87- if (!tempDir .exists ()) tempDir .mkdir ();
88+ Path tempDir = tempFolder .resolve (entry .getValue ().getParent ().getFileName ().toString ());
89+
90+ if (!Files .exists (tempDir )) {
91+ try {
92+ Files .createDirectory (tempDir );
93+ } catch (IOException e ) {
94+ e .printStackTrace ();
95+ continue ;
96+ }
97+ }
8898
89- File tempFile = new File ( tempDir , entry .getValue ().toFile ().getName ());
90- map .put (tempFile . toPath () , entry .getValue ());
91- convertMap .put (entry .getKey (), tempFile . toPath () );
99+ Path tempFile = tempDir . resolve ( entry .getValue ().getFileName ().toString ());
100+ map .put (tempFile , entry .getValue ());
101+ convertMap .put (entry .getKey (), tempFile );
92102 }
93103
94104 List <Path > errored = new ArrayList <>();
@@ -135,8 +145,8 @@ private static Optional<ModEntry> discoverFolderMod(Path folder, Path destinatio
135145 return Optional .of (
136146 new DefaultModEntry (
137147 name ,
138- folder . toFile () ,
139- destination . toFile ()
148+ folder ,
149+ destination
140150 )
141151 );
142152 }
@@ -157,8 +167,8 @@ private static Optional<ModEntry> discoverFileMod(Path file, Path destinationFol
157167 return Optional .of (
158168 new DefaultModEntry (
159169 modName ,
160- file . toFile () ,
161- destinationFolder .resolve (fileName ). toFile ()
170+ file ,
171+ destinationFolder .resolve (fileName )
162172 )
163173 );
164174 }
@@ -188,14 +198,14 @@ private static List<ModEntry> discoverModsInFolder(Path folder, Path destination
188198
189199 for (ModEntry modEntry : mods ) {
190200 if (EXCLUDED .containsKey (modEntry .modId )) {
191- if (Files .isDirectory (modEntry .file . toPath () )) {
201+ if (Files .isDirectory (modEntry .file )) {
192202 for (String excluded : EXCLUDED .get (modEntry .modId )) {
193- if (Files .deleteIfExists (modEntry .file .toPath (). resolve (excluded ))) {
194- Constants .MAIN_LOGGER .debug ("File deleted: " + modEntry .file .toPath (). resolve (excluded ));
203+ if (Files .deleteIfExists (modEntry .file .resolve (excluded ))) {
204+ Constants .MAIN_LOGGER .debug ("File deleted: " + modEntry .file .resolve (excluded ));
195205 }
196206 }
197207 } else {
198- FileUtils .removeEntriesFromZip (modEntry .file . toPath () , EXCLUDED .get (modEntry .modId ));
208+ FileUtils .removeEntriesFromZip (modEntry .file , EXCLUDED .get (modEntry .modId ));
199209 }
200210 }
201211 }
0 commit comments