From e56cc058db6c6aca683e03265b468da4e22d15b1 Mon Sep 17 00:00:00 2001 From: FalsePattern <30945458+FalsePattern@users.noreply.github.com> Date: Fri, 30 Sep 2022 14:25:27 +0200 Subject: [PATCH] migrate the library folder outside the mods folder to avoid it being discovered by the forge scanner --- .../dependencies/DependencyLoaderImpl.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/falsepattern/lib/internal/impl/dependencies/DependencyLoaderImpl.java b/src/main/java/com/falsepattern/lib/internal/impl/dependencies/DependencyLoaderImpl.java index 51a2bef..f6529f0 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/dependencies/DependencyLoaderImpl.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/dependencies/DependencyLoaderImpl.java @@ -46,6 +46,7 @@ import java.io.InputStream; import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.security.MessageDigest; import java.util.ArrayList; import java.util.Map; @@ -258,16 +259,42 @@ public class DependencyLoaderImpl { } } val modsDir = Paths.get(homeDir, "mods").toFile(); + val oldLibDir = new File(modsDir, "falsepattern"); + libDir = new File(homeDir, "falsepattern"); mavenJarName = String.format("%s-%s%s.jar", artifactId, preferredVersion, (suffix != null) ? ("-" + suffix) : ""); jarName = groupId + "-" + mavenJarName; - libDir = new File(modsDir, "falsepattern"); if (!libDir.exists()) { if (!libDir.mkdirs()) { log.fatal("Failed to create directory {}", libDir); throw new RuntimeException("Failed to create directory " + libDir); } } + if (oldLibDir.exists()) { + log.info("Migrating old library folder. From: " + oldLibDir.getAbsolutePath() + ", To: " + libDir.getAbsolutePath()); + val oldFiles = oldLibDir.listFiles(); + if (oldFiles != null) { + for (val file: oldFiles) { + try { + Files.move(file.toPath(), libDir.toPath().resolve(oldLibDir.toPath().relativize(file.toPath())), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + log.warn("Failed to move file " + file.getName() + " to new dir! Deleting instead."); + try { + Files.deleteIfExists(file.toPath()); + } catch (IOException ex) { + log.warn("Failed to delete file " + file.getPath() + "!"); + file.deleteOnExit(); + } + } + } + } + try { + Files.deleteIfExists(oldLibDir.toPath()); + } catch (IOException e) { + log.warn("Failed to delete old library directory!"); + oldLibDir.deleteOnExit(); + } + } file = new File(libDir, jarName); }