Improved data file zipping
This commit is contained in:
@@ -453,11 +453,24 @@ public class SettingsMenuDialog extends SettingsDialog{
|
||||
files.addAll(schematicDirectory.list());
|
||||
String base = Core.settings.getDataDirectory().path();
|
||||
|
||||
//add directories
|
||||
for(Fi other : files.copy()){
|
||||
Fi parent = other.parent();
|
||||
while(!files.contains(parent) && !parent.equals(settings.getDataDirectory())){
|
||||
files.add(parent);
|
||||
}
|
||||
}
|
||||
|
||||
try(OutputStream fos = file.write(false, 2048); ZipOutputStream zos = new ZipOutputStream(fos)){
|
||||
for(Fi add : files){
|
||||
if(add.isDirectory()) continue;
|
||||
zos.putNextEntry(new ZipEntry(add.path().substring(base.length())));
|
||||
Streams.copy(add.read(), zos);
|
||||
String path = add.path().substring(base.length());
|
||||
if(add.isDirectory()) path += "/";
|
||||
//fix trailing / in path
|
||||
path = path.startsWith("/") ? path.substring(1) : path;
|
||||
zos.putNextEntry(new ZipEntry(path));
|
||||
if(!add.isDirectory()){
|
||||
Streams.copy(add.read(), zos);
|
||||
}
|
||||
zos.closeEntry();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user