add the root folder of zipped files in the zip file too

This commit is contained in:
tibbi 2017-09-02 20:16:11 +02:00
parent 5a0f6adff8
commit e3def060d8

View file

@ -241,18 +241,24 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
try { try {
sourcePaths.forEach { sourcePaths.forEach {
val base = File(it).toURI() var name: String
var mainFile = File(it) var mainFile = File(it)
queue.push(mainFile) val base = mainFile.parentFile.toURI()
res = zout res = zout
queue.push(mainFile)
if (mainFile.isDirectory) {
name = "${mainFile.name.trimEnd('/')}/"
zout.putNextEntry(ZipEntry(name))
}
while (!queue.isEmpty()) { while (!queue.isEmpty()) {
mainFile = queue.pop() mainFile = queue.pop()
if (mainFile.isDirectory) { if (mainFile.isDirectory) {
for (file in mainFile.listFiles()) { for (file in mainFile.listFiles()) {
var name = base.relativize(file.toURI()).path name = base.relativize(file.toURI()).path
if (file.isDirectory) { if (file.isDirectory) {
queue.push(file) queue.push(file)
name = if (name.endsWith("/")) name else "$name/" name = "${name.trimEnd('/')}/"
zout.putNextEntry(ZipEntry(name)) zout.putNextEntry(ZipEntry(name))
} else { } else {
zout.putNextEntry(ZipEntry(name)) zout.putNextEntry(ZipEntry(name))
@ -261,7 +267,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
} }
} }
} else { } else {
val name = if (base.path == it) it.getFilenameFromPath() else base.relativize(mainFile.toURI()).path name = if (base.path == it) it.getFilenameFromPath() else base.relativize(mainFile.toURI()).path
zout.putNextEntry(ZipEntry(name)) zout.putNextEntry(ZipEntry(name))
FileInputStream(mainFile).copyTo(zout) FileInputStream(mainFile).copyTo(zout)
zout.closeEntry() zout.closeEntry()