mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-29 21:33:07 -08:00
Try to fix decompression
This commit is contained in:
1 parent
f3fdca368b
commit
e7159c9d36
6 files changed
+19
-8
No files matched your search
@@ -42,6 +42,7 @@ import com.kunzisoft.keepass.activities.dialogs.FileTooBigDialogFragment.Compani
|
||||
import com.kunzisoft.keepass.activities.helpers.SelectFileHelper
|
||||
import com.kunzisoft.keepass.activities.lock.LockingActivity
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
@@ -442,7 +443,8 @@ class EntryEditActivity : LockingActivity(),
|
||||
}
|
||||
|
||||
private fun buildNewAttachment(attachmentToUploadUri: Uri, fileName: String) {
|
||||
mDatabase?.buildNewBinary(applicationContext.filesDir)?.let { binaryAttachment ->
|
||||
val compression: Boolean = mDatabase?.compressionAlgorithm == CompressionAlgorithm.GZip
|
||||
mDatabase?.buildNewBinary(applicationContext.filesDir, false, compression)?.let { binaryAttachment ->
|
||||
val entryAttachment = Attachment(fileName, binaryAttachment)
|
||||
// Ask to replace the current attachment
|
||||
if ((mDatabase?.allowMultipleAttachments != true && entryEditContentsView?.containsAttachment() == true) ||
|
||||
|
||||
@@ -30,11 +30,13 @@ open class SaveDatabaseRunnable(protected var context: Context,
|
||||
: ActionRunnable() {
|
||||
|
||||
var mAfterSaveDatabase: ((Result) -> Unit)? = null
|
||||
protected var mAllowRemoveUnlinkedAttachments = true
|
||||
|
||||
override fun onStartRun() {}
|
||||
|
||||
override fun onActionRun() {
|
||||
database.removeUnlinkedAttachment()
|
||||
if (mAllowRemoveUnlinkedAttachments)
|
||||
database.removeUnlinkedAttachment()
|
||||
if (saveDatabase && result.isSuccess) {
|
||||
try {
|
||||
database.saveData(context.contentResolver)
|
||||
|
||||
+5
@@ -31,6 +31,11 @@ class UpdateCompressionBinariesDatabaseRunnable (
|
||||
saveDatabase: Boolean)
|
||||
: SaveDatabaseRunnable(context, database, saveDatabase) {
|
||||
|
||||
init {
|
||||
// To prevent attachment corruption during compression
|
||||
mAllowRemoveUnlinkedAttachments = false
|
||||
}
|
||||
|
||||
override fun onStartRun() {
|
||||
// Set new compression
|
||||
if (database.allowDataCompression) {
|
||||
|
||||
@@ -439,9 +439,11 @@ class Database {
|
||||
return false
|
||||
}
|
||||
|
||||
fun buildNewBinary(cacheDirectory: File): BinaryAttachment? {
|
||||
fun buildNewBinary(cacheDirectory: File,
|
||||
enableProtection: Boolean = false,
|
||||
compressed: Boolean? = null): BinaryAttachment? {
|
||||
return mDatabaseKDB?.buildNewBinary(cacheDirectory)
|
||||
?: mDatabaseKDBX?.buildNewBinary(cacheDirectory)
|
||||
?: mDatabaseKDBX?.buildNewBinary(cacheDirectory, enableProtection, compressed)
|
||||
}
|
||||
|
||||
fun removeAttachmentIfNotUsed(attachment: Attachment) {
|
||||
|
||||
@@ -203,7 +203,7 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Unable to change compression for $key")
|
||||
Log.e(TAG, "Unable to change compression for $key", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -541,8 +541,8 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
|
||||
}
|
||||
|
||||
fun buildNewBinary(cacheDirectory: File,
|
||||
protection: Boolean = false,
|
||||
compression: Boolean? = null,
|
||||
protection: Boolean,
|
||||
compression: Boolean?,
|
||||
cacheId: String? = null): BinaryAttachment {
|
||||
// Unused cache key if needed
|
||||
val binaryId = cacheId ?: binaryPool.findUnusedKey().toString()
|
||||
|
||||
@@ -253,7 +253,7 @@ class DatabaseInputKDBX(cacheDirectory: File,
|
||||
val byteLength = size - 1
|
||||
// Read in a file
|
||||
val protectedFlag = dataInputStream.readBytes(1)[0].toInt() != 0
|
||||
val protectedBinary = mDatabase.buildNewBinary(cacheDirectory, protectedFlag)
|
||||
val protectedBinary = mDatabase.buildNewBinary(cacheDirectory, protectedFlag, false)
|
||||
protectedBinary.getOutputDataStream().use { outputStream ->
|
||||
dataInputStream.readBytes(byteLength, DatabaseKDBX.BUFFER_SIZE_BYTES) { buffer ->
|
||||
outputStream.write(buffer)
|
||||
|
||||
Reference in new issue
Block a user