|
46 | 46 | import java.net.URL; |
47 | 47 | import java.nio.file.Files; |
48 | 48 | import java.nio.file.Paths; |
| 49 | +import java.nio.file.StandardCopyOption; |
49 | 50 | import java.security.MessageDigest; |
50 | 51 | import java.util.ArrayList; |
51 | 52 | import java.util.Map; |
@@ -258,16 +259,42 @@ private void setupPaths() { |
258 | 259 | } |
259 | 260 | } |
260 | 261 | val modsDir = Paths.get(homeDir, "mods").toFile(); |
| 262 | + val oldLibDir = new File(modsDir, "falsepattern"); |
| 263 | + libDir = new File(homeDir, "falsepattern"); |
261 | 264 | mavenJarName = |
262 | 265 | String.format("%s-%s%s.jar", artifactId, preferredVersion, (suffix != null) ? ("-" + suffix) : ""); |
263 | 266 | jarName = groupId + "-" + mavenJarName; |
264 | | - libDir = new File(modsDir, "falsepattern"); |
265 | 267 | if (!libDir.exists()) { |
266 | 268 | if (!libDir.mkdirs()) { |
267 | 269 | log.fatal("Failed to create directory {}", libDir); |
268 | 270 | throw new RuntimeException("Failed to create directory " + libDir); |
269 | 271 | } |
270 | 272 | } |
| 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 | + } |
271 | 298 | file = new File(libDir, jarName); |
272 | 299 | } |
273 | 300 |
|
|
0 commit comments