Skip to content

Commit cd8a877

Browse files
committed
More files related changes
1 parent f38ae24 commit cd8a877

File tree

4 files changed

+43
-32
lines changed

4 files changed

+43
-32
lines changed

src/main/java/fr/catcore/modremapperapi/utils/FileUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Collection;
1010
import java.util.List;
1111

12+
@Deprecated
1213
public class FileUtils {
1314
@Deprecated
1415
public static void writeTextFile(Collection<String> lines, File file) {

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/DefaultModEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package io.github.fabriccompatibiltylayers.modremappingapi.impl;
22

3-
import java.io.File;
3+
import java.nio.file.Path;
44

55
public class DefaultModEntry extends ModEntry {
6-
protected DefaultModEntry(String modName, File file, File original) {
6+
protected DefaultModEntry(String modName, Path file, Path original) {
77
super(modName, modName, file, original);
88
}
99

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/ModDiscoverer.java

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.jetbrains.annotations.NotNull;
1212
import org.spongepowered.include.com.google.common.collect.ImmutableList;
1313

14-
import java.io.File;
1514
import java.io.IOException;
1615
import java.net.URISyntaxException;
1716
import 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
}

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/ModEntry.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package io.github.fabriccompatibiltylayers.modremappingapi.impl;
22

3-
import java.io.File;
3+
import java.nio.file.Path;
44

55
public abstract class ModEntry {
66
public final String modName;
77
public final String modId;
88

9-
public final File file;
10-
public final File original;
9+
public final Path file;
10+
public final Path original;
1111

12-
protected ModEntry(String modName, String modId, File file, File original) {
12+
protected ModEntry(String modName, String modId, Path file, Path original) {
1313
this.modName = modName;
1414
this.modId = modId;
1515
this.file = file;

0 commit comments

Comments
 (0)