Skip to content

Commit

Permalink
fix lack of a buffer when backing up world before restoration, and au…
Browse files Browse the repository at this point in the history
…tocleanup
  • Loading branch information
HeatherComputer committed Sep 22, 2024
1 parent 8ea5d21 commit 23daacc
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static void main(String args[]) throws IllegalBackupException {
}

type = CLIIOHelpers.getBackupType(type);
if (type.equals("snapshot (command-made only)")) type = "snapshots";
if ("snapshot (command-made only)".equals(type)) type = "snapshots";

/*/
if (backupLocation.startsWith(Pattern.quote(File.separator)) || backupLocation.indexOf(":") == 1) {
Expand All @@ -146,7 +146,7 @@ public static void main(String args[]) throws IllegalBackupException {
Arrays.asList(new String[]{"Export backup as zip", "Restore single file", "Restore entire world"})
);

if (restore.equals("Export backup as zip")) {
if ("Export backup as zip".equals(restore)) {
exportMode = true;
}

Expand Down Expand Up @@ -263,7 +263,7 @@ private static int getBackupDate(File backupDir, boolean exportMode) throws IOEx
throw new IOException(String.format("Selected backup directory %s is empty, or is a file!", backupDir.getAbsolutePath()));
}
ArrayList<String> fileNameList = new ArrayList<String>(Arrays.asList(fileNameArray)); //i need to do this. i hate this.
fileNameList.removeIf((name) -> (
fileNameList.removeIf(name -> (
name.endsWith("json") ||
name.contains("incomplete") ||
name.contains("DS_Store")
Expand Down Expand Up @@ -779,7 +779,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) thro
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException {
if (file.getFileName().toString().equals("level.dat")) levelDatPathWrapper.add(file);
if ("level.dat".equals(file.getFileName().toString())) levelDatPathWrapper.add(file);
return FileVisitResult.CONTINUE;
}
});
Expand Down Expand Up @@ -856,6 +856,7 @@ private static String backupExistingWorld(File worldDir, boolean export) {
FileOutputStream outputStream = new FileOutputStream(out);
ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
zipOutputStream.setLevel(4);
byte[] bytes = new byte[1024];
Files.walkFileTree(worldDir.toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) {
Expand All @@ -866,8 +867,15 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) {
return FileVisitResult.CONTINUE;
}
zipOutputStream.putNextEntry(new ZipEntry(targetFile.toString()));
byte[] bytes = Files.readAllBytes(file);
zipOutputStream.write(bytes, 0, bytes.length);
FileInputStream is = new FileInputStream(file.toFile());
while (true) {
int i = is.read(bytes);
if (i < 0) break;
zipOutputStream.write(bytes, 0, i);
}
is.close();
//byte[] bytes = Files.readAllBytes(file);
//zipOutputStream.write(bytes, 0, bytes.length);
zipOutputStream.closeEntry();

} catch (IOException e) {
Expand Down

0 comments on commit 23daacc

Please sign in to comment.