Implement basic caching: Try to download, use cache on failure
This commit is contained in:
parent
059a093db2
commit
9beed53d0b
|
@ -81,7 +81,13 @@ public class Resclone implements ClientModInitializer, RescloneApi {
|
||||||
fileName += Integer.toHexString(s.source.hashCode());
|
fileName += Integer.toHexString(s.source.hashCode());
|
||||||
PackMetaLoaded p = new PackMetaLoaded(getConfigPath().resolve("cache").resolve(fileName), s.name);
|
PackMetaLoaded p = new PackMetaLoaded(getConfigPath().resolve("cache").resolve(fileName), s.name);
|
||||||
//If file is not present: download and process pack
|
//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
|
//Download
|
||||||
fetcherInstances.get(s.fetcher).get(s.source, p.zipPath);
|
fetcherInstances.get(s.fetcher).get(s.source, p.zipPath);
|
||||||
//Process
|
//Process
|
||||||
|
@ -89,7 +95,6 @@ public class Resclone implements ClientModInitializer, RescloneApi {
|
||||||
props.put("create", "false");
|
props.put("create", "false");
|
||||||
URI zipfile = URI.create("jar:" + p.zipPath.toUri().toString());
|
URI zipfile = URI.create("jar:" + p.zipPath.toUri().toString());
|
||||||
try (FileSystem zipfs = FileSystems.newFileSystem(zipfile, props)) {
|
try (FileSystem zipfs = FileSystems.newFileSystem(zipfile, props)) {
|
||||||
//ZipFile file = new ZipFile(meta.zipPath.toFile());
|
|
||||||
for (PackProcessor processor : processors) {
|
for (PackProcessor processor : processors) {
|
||||||
processor.process(zipfs);
|
processor.process(zipfs);
|
||||||
}
|
}
|
||||||
|
@ -98,8 +103,18 @@ public class Resclone implements ClientModInitializer, RescloneApi {
|
||||||
e.printStackTrace();
|
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);
|
metas.add(p);
|
||||||
} catch (RescloneException e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue