Skip to content

Commit e56cc05

Browse files
committed
migrate the library folder outside the mods folder to avoid it being discovered by the forge scanner
1 parent 6240cc1 commit e56cc05

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/main/java/com/falsepattern/lib/internal/impl/dependencies/DependencyLoaderImpl.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.net.URL;
4747
import java.nio.file.Files;
4848
import java.nio.file.Paths;
49+
import java.nio.file.StandardCopyOption;
4950
import java.security.MessageDigest;
5051
import java.util.ArrayList;
5152
import java.util.Map;
@@ -258,16 +259,42 @@ private void setupPaths() {
258259
}
259260
}
260261
val modsDir = Paths.get(homeDir, "mods").toFile();
262+
val oldLibDir = new File(modsDir, "falsepattern");
263+
libDir = new File(homeDir, "falsepattern");
261264
mavenJarName =
262265
String.format("%s-%s%s.jar", artifactId, preferredVersion, (suffix != null) ? ("-" + suffix) : "");
263266
jarName = groupId + "-" + mavenJarName;
264-
libDir = new File(modsDir, "falsepattern");
265267
if (!libDir.exists()) {
266268
if (!libDir.mkdirs()) {
267269
log.fatal("Failed to create directory {}", libDir);
268270
throw new RuntimeException("Failed to create directory " + libDir);
269271
}
270272
}
273+
if (oldLibDir.exists()) {
274+
log.info("Migrating old library folder. From: " + oldLibDir.getAbsolutePath() + ", To: " + libDir.getAbsolutePath());
275+
val oldFiles = oldLibDir.listFiles();
276+
if (oldFiles != null) {
277+
for (val file: oldFiles) {
278+
try {
279+
Files.move(file.toPath(), libDir.toPath().resolve(oldLibDir.toPath().relativize(file.toPath())), StandardCopyOption.REPLACE_EXISTING);
280+
} catch (IOException e) {
281+
log.warn("Failed to move file " + file.getName() + " to new dir! Deleting instead.");
282+
try {
283+
Files.deleteIfExists(file.toPath());
284+
} catch (IOException ex) {
285+
log.warn("Failed to delete file " + file.getPath() + "!");
286+
file.deleteOnExit();
287+
}
288+
}
289+
}
290+
}
291+
try {
292+
Files.deleteIfExists(oldLibDir.toPath());
293+
} catch (IOException e) {
294+
log.warn("Failed to delete old library directory!");
295+
oldLibDir.deleteOnExit();
296+
}
297+
}
271298
file = new File(libDir, jarName);
272299
}
273300

0 commit comments

Comments
 (0)