Added .tar and .tar.* support, *maybe*.

This commit is contained in:
sk89q 2010-11-05 22:50:22 -07:00
parent 49739bab76
commit 5fc97f0f7d
3 changed files with 30 additions and 8 deletions

View File

@ -1098,6 +1098,9 @@ public class WorldEditListener extends PluginListener {
try { try {
chunkStore = snapshot.getChunkStore(); chunkStore = snapshot.getChunkStore();
player.print("Snapshot '" + snapshot.getName() + "' loaded; now restoring..."); player.print("Snapshot '" + snapshot.getName() + "' loaded; now restoring...");
} catch (DataException e) {
player.printError("Failed to load snapshot: " + e.getMessage());
return true;
} catch (IOException e) { } catch (IOException e) {
player.printError("Failed to load snapshot: " + e.getMessage()); player.printError("Failed to load snapshot: " + e.getMessage());
return true; return true;

View File

@ -54,13 +54,21 @@ public class Snapshot {
* @return * @return
* @throws IOException * @throws IOException
*/ */
public ChunkStore getChunkStore() throws IOException { public ChunkStore getChunkStore() throws IOException, DataException {
if (file.getName().toLowerCase().endsWith(".zip")) { if (file.getName().toLowerCase().endsWith(".zip")) {
try { try {
return new TrueZipAlphaChunkStore(file); return new TrueZipAlphaChunkStore(file);
} catch (NoClassDefFoundError e) { } catch (NoClassDefFoundError e) {
return new ZippedAlphaChunkStore(file); 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 { } else {
return new AlphaChunkStore(file); return new AlphaChunkStore(file);
} }

View File

@ -61,9 +61,7 @@ public class SnapshotRepository {
FilenameFilter filter = new FilenameFilter() { FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
File f = new File(dir, name); File f = new File(dir, name);
return (name.toLowerCase().endsWith(".zip") return isValidSnapshot(f);
&& f.isFile())
|| f.isDirectory();
} }
}; };
@ -105,17 +103,30 @@ public class SnapshotRepository {
* Check to see if a snapshot is valid. * Check to see if a snapshot is valid.
* *
* @param dir * @param dir
* @param snapshot
* @return whether it is a valid snapshot * @return whether it is a valid snapshot
*/ */
public boolean isValidSnapshotName(String 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; return false;
} }
File f = new File(dir, snapshot);
return (f.isDirectory() && (new File(f, "level.dat")).exists()) 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")
));
} }
/** /**