From 5fc97f0f7def1ab7bb2e702208cee8cd8b61c1db Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 5 Nov 2010 22:50:22 -0700 Subject: [PATCH] Added .tar and .tar.* support, *maybe*. --- src/WorldEditListener.java | 3 +++ .../sk89q/worldedit/snapshots/Snapshot.java | 10 +++++++- .../snapshots/SnapshotRepository.java | 25 +++++++++++++------ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/WorldEditListener.java b/src/WorldEditListener.java index 779b343a8..7d04b0fed 100644 --- a/src/WorldEditListener.java +++ b/src/WorldEditListener.java @@ -1098,6 +1098,9 @@ public class WorldEditListener extends PluginListener { try { chunkStore = snapshot.getChunkStore(); player.print("Snapshot '" + snapshot.getName() + "' loaded; now restoring..."); + } catch (DataException e) { + player.printError("Failed to load snapshot: " + e.getMessage()); + return true; } catch (IOException e) { player.printError("Failed to load snapshot: " + e.getMessage()); return true; diff --git a/src/com/sk89q/worldedit/snapshots/Snapshot.java b/src/com/sk89q/worldedit/snapshots/Snapshot.java index 916d0856b..1eae74883 100644 --- a/src/com/sk89q/worldedit/snapshots/Snapshot.java +++ b/src/com/sk89q/worldedit/snapshots/Snapshot.java @@ -54,13 +54,21 @@ public class Snapshot { * @return * @throws IOException */ - public ChunkStore getChunkStore() throws IOException { + public ChunkStore getChunkStore() throws IOException, DataException { if (file.getName().toLowerCase().endsWith(".zip")) { try { return new TrueZipAlphaChunkStore(file); } catch (NoClassDefFoundError e) { return new ZippedAlphaChunkStore(file); } + } else if (file.getName().toLowerCase().endsWith(".tar.bz2") + || file.getName().toLowerCase().endsWith(".tar.gz") + || file.getName().toLowerCase().endsWith(".tar")) { + try { + return new TrueZipAlphaChunkStore(file); + } catch (NoClassDefFoundError e) { + throw new DataException("TrueZIP is required for .tar support"); + } } else { return new AlphaChunkStore(file); } diff --git a/src/com/sk89q/worldedit/snapshots/SnapshotRepository.java b/src/com/sk89q/worldedit/snapshots/SnapshotRepository.java index 89f7af559..23a4d733a 100644 --- a/src/com/sk89q/worldedit/snapshots/SnapshotRepository.java +++ b/src/com/sk89q/worldedit/snapshots/SnapshotRepository.java @@ -61,9 +61,7 @@ public class SnapshotRepository { FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { File f = new File(dir, name); - return (name.toLowerCase().endsWith(".zip") - && f.isFile()) - || f.isDirectory(); + return isValidSnapshot(f); } }; @@ -105,17 +103,30 @@ public class SnapshotRepository { * Check to see if a snapshot is valid. * * @param dir - * @param snapshot * @return whether it is a valid snapshot */ public boolean isValidSnapshotName(String snapshot) { - if (!snapshot.matches("[A-Za-z0-9_\\-,.\\[\\]\\(\\) ]{1,50}")) { + return isValidSnapshot(new File(dir, snapshot)); + } + + /** + * Check to see if a snapshot is valid. + * + * @param f + * @return whether it is a valid snapshot + */ + public boolean isValidSnapshot(File f) { + if (!f.getName().matches("[A-Za-z0-9_\\-,.\\[\\]\\(\\) ]{1,50}")) { return false; } - File f = new File(dir, snapshot); return (f.isDirectory() && (new File(f, "level.dat")).exists()) - || (f.isFile() && f.getName().toLowerCase().endsWith((".zip"))); + || (f.isFile() && ( + f.getName().toLowerCase().endsWith(".zip") + || f.getName().toLowerCase().endsWith(".tar.bz2") + || f.getName().toLowerCase().endsWith(".tar.gz") + || f.getName().toLowerCase().endsWith(".tar") + )); } /**