diff --git a/src/main/java/io/gitlab/jfronny/resclone/Resclone.java b/src/main/java/io/gitlab/jfronny/resclone/Resclone.java index f2cd57b..4efdaff 100644 --- a/src/main/java/io/gitlab/jfronny/resclone/Resclone.java +++ b/src/main/java/io/gitlab/jfronny/resclone/Resclone.java @@ -81,7 +81,13 @@ public class Resclone implements ClientModInitializer, RescloneApi { fileName += Integer.toHexString(s.source.hashCode()); PackMetaLoaded p = new PackMetaLoaded(getConfigPath().resolve("cache").resolve(fileName), s.name); //If file is not present: download and process pack - if (!Files.isRegularFile(p.zipPath)) { + Path p1 = p.zipPath; + if (Files.exists(p.zipPath)) { + p1 = p.zipPath.getParent().resolve(p.zipPath.getFileName() + ".bak"); + Files.deleteIfExists(p1); + Files.move(p.zipPath, p1); + } + try { //Download fetcherInstances.get(s.fetcher).get(s.source, p.zipPath); //Process @@ -89,7 +95,6 @@ public class Resclone implements ClientModInitializer, RescloneApi { props.put("create", "false"); URI zipfile = URI.create("jar:" + p.zipPath.toUri().toString()); try (FileSystem zipfs = FileSystems.newFileSystem(zipfile, props)) { - //ZipFile file = new ZipFile(meta.zipPath.toFile()); for (PackProcessor processor : processors) { processor.process(zipfs); } @@ -98,8 +103,18 @@ public class Resclone implements ClientModInitializer, RescloneApi { e.printStackTrace(); } } + catch (Throwable e) { + if (!p1.equals(p.zipPath)) { + System.err.println("Failed to download, using cache"); + Files.deleteIfExists(p.zipPath); + Files.move(p1, p.zipPath); + } else + throw new RescloneException("Failed to download initial"); + } + if (!p1.equals(p.zipPath)) + Files.deleteIfExists(p1); metas.add(p); - } catch (RescloneException e) { + } catch (Throwable e) { e.printStackTrace(); } }