Added detection of McRegion-format worlds for snapshot detection.

This commit is contained in:
sk89q 2011-03-09 23:51:40 -08:00
parent 96e75a4cae
commit 1d68fdd11c
6 changed files with 34 additions and 1 deletions

View File

@ -75,4 +75,11 @@ public abstract class ChunkStore {
public void close() throws IOException {
}
/**
* Returns whether the chunk store is of this type.
*
* @return
*/
public abstract boolean isValid();
}

View File

@ -62,4 +62,9 @@ public class FileLegacyChunkStore extends LegacyChunkStore {
throw new MissingChunkException();
}
}
@Override
public boolean isValid() {
return true; // Yeah, oh well
}
}

View File

@ -54,4 +54,9 @@ public class FileMcRegionChunkStore extends McRegionChunkStore {
}
}
@Override
public boolean isValid() {
return new File(path, "region").isDirectory();
}
}

View File

@ -164,4 +164,9 @@ public class TrueZipLegacyChunkStore extends LegacyChunkStore {
public void close() throws IOException {
zip.close();
}
@Override
public boolean isValid() {
return true; // Yeah, oh well
}
}

View File

@ -161,4 +161,9 @@ public class ZippedAlphaChunkStore extends LegacyChunkStore {
public void close() throws IOException {
zip.close();
}
@Override
public boolean isValid() {
return true; // Yeah, oh well
}
}

View File

@ -73,7 +73,13 @@ public class Snapshot {
throw new DataException("TrueZIP is required for .tar support");
}
} else {
return new FileLegacyChunkStore(file);
ChunkStore chunkStore = new FileMcRegionChunkStore(file);
if (!chunkStore.isValid()) {
return new FileLegacyChunkStore(file);
}
return chunkStore;
}
}