11
11
import org .jetbrains .annotations .NotNull ;
12
12
import org .spongepowered .include .com .google .common .collect .ImmutableList ;
13
13
14
- import java .io .File ;
15
14
import java .io .IOException ;
16
15
import java .net .URISyntaxException ;
17
16
import java .nio .file .*;
@@ -41,7 +40,7 @@ protected static void init(List<ModRemapper> modRemappers, boolean remapClassEdi
41
40
try {
42
41
if (!Files .exists (mcSubFolder )) Files .createDirectories (mcSubFolder );
43
42
if (!Files .exists (cacheFolder )) Files .createDirectories (cacheFolder );
44
- else io . github . fabriccompatibiltylayers . modremappingapi . impl . utils . FileUtils .emptyDir (cacheFolder );
43
+ else FileUtils .emptyDir (cacheFolder );
45
44
46
45
mods .addAll (discoverModsInFolder (mcSubFolder , cacheFolder ));
47
46
} catch (IOException | URISyntaxException e ) {
@@ -50,17 +49,24 @@ protected static void init(List<ModRemapper> modRemappers, boolean remapClassEdi
50
49
}
51
50
}
52
51
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
+ }
56
62
}
57
63
58
64
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 ));
61
67
62
68
if (!remapClassEdits ) {
63
- modPaths = excludeClassEdits (modPaths );
69
+ modPaths = excludeClassEdits (modPaths , mainTempDir );
64
70
}
65
71
66
72
for (Path path : modPaths .keySet ()) {
@@ -74,21 +80,25 @@ protected static void init(List<ModRemapper> modRemappers, boolean remapClassEdi
74
80
modPaths .values ().forEach (FabricLauncherBase .getLauncher ()::addToClassPath );
75
81
}
76
82
77
- private static Map <Path , Path > excludeClassEdits (Map <Path , Path > modPaths ) {
83
+ private static Map <Path , Path > excludeClassEdits (Map <Path , Path > modPaths , Path tempFolder ) {
78
84
Map <Path , Path > map = new HashMap <>();
79
85
Map <Path , Path > convertMap = new HashMap <>();
80
86
81
- File mainTempDir = CacheUtils .getCachePath ("temp" ).toFile ();
82
- mainTempDir .mkdirs ();
83
-
84
-
85
87
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
+ }
88
98
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 );
92
102
}
93
103
94
104
List <Path > errored = new ArrayList <>();
@@ -135,8 +145,8 @@ private static Optional<ModEntry> discoverFolderMod(Path folder, Path destinatio
135
145
return Optional .of (
136
146
new DefaultModEntry (
137
147
name ,
138
- folder . toFile () ,
139
- destination . toFile ()
148
+ folder ,
149
+ destination
140
150
)
141
151
);
142
152
}
@@ -157,8 +167,8 @@ private static Optional<ModEntry> discoverFileMod(Path file, Path destinationFol
157
167
return Optional .of (
158
168
new DefaultModEntry (
159
169
modName ,
160
- file . toFile () ,
161
- destinationFolder .resolve (fileName ). toFile ()
170
+ file ,
171
+ destinationFolder .resolve (fileName )
162
172
)
163
173
);
164
174
}
@@ -188,14 +198,14 @@ private static List<ModEntry> discoverModsInFolder(Path folder, Path destination
188
198
189
199
for (ModEntry modEntry : mods ) {
190
200
if (EXCLUDED .containsKey (modEntry .modId )) {
191
- if (Files .isDirectory (modEntry .file . toPath () )) {
201
+ if (Files .isDirectory (modEntry .file )) {
192
202
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 ));
195
205
}
196
206
}
197
207
} else {
198
- FileUtils .removeEntriesFromZip (modEntry .file . toPath () , EXCLUDED .get (modEntry .modId ));
208
+ FileUtils .removeEntriesFromZip (modEntry .file , EXCLUDED .get (modEntry .modId ));
199
209
}
200
210
}
201
211
}
0 commit comments