Make this configurable

This commit is contained in:
Minecon724 2025-04-23 19:47:09 +02:00
commit 6a6fdd5471
Signed by: Minecon724
GPG key ID: A02E6E67AB961189
2 changed files with 9 additions and 6 deletions

View file

@ -62,7 +62,8 @@ class BackupWorker @AssistedInject constructor(
PathTools.compressDocumentFileDirectory(
contentResolver = applicationContext.contentResolver,
source = world.getOrThrow().documentFile!!,
target = it
target = it,
inflate = true
)
}
}

View file

@ -13,12 +13,13 @@ class PathTools {
fun compressDocumentFileDirectory(
contentResolver: ContentResolver,
source: DocumentFile,
target: OutputStream
target: OutputStream,
inflate: Boolean = false
) {
target.use {
ZstdCompressorOutputStream(it).use {
TarArchiveOutputStream(it).use { outputStream ->
compressInner(contentResolver, source, outputStream)
compressInner(contentResolver, source, outputStream, "", inflate)
outputStream.finish()
}
}
@ -29,14 +30,15 @@ class PathTools {
contentResolver: ContentResolver,
source: DocumentFile,
archiveOutputStream: TarArchiveOutputStream,
prefix: String = ""
prefix: String = "",
inflate: Boolean = false,
) {
source.listFiles().forEach {
if (!it.isDirectory) {
val entry = TarArchiveEntry(prefix + it.name)
entry.setModTime(it.lastModified())
val inflate = it.name!!.endsWith(".mca")
val inflate = inflate and it.name!!.endsWith(".mca")
if (inflate) {
contentResolver.openInputStream(it.uri)!!.use { inputStream ->
@ -66,7 +68,7 @@ class PathTools {
archiveOutputStream.putArchiveEntry(entry)
archiveOutputStream.closeArchiveEntry() // Close directory entry immediately (no content)
compressInner(contentResolver, it, archiveOutputStream, prefix + it.name + "/")
compressInner(contentResolver, it, archiveOutputStream, prefix + it.name + "/", inflate)
}
}
}