mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Restore unknown compression
This commit is contained in:
@@ -28,7 +28,7 @@ import java.util.zip.GZIPOutputStream
|
||||
|
||||
class BinaryAttachment : Parcelable {
|
||||
|
||||
var isCompressed: Boolean = false
|
||||
var isCompressed: Boolean? = null
|
||||
private set
|
||||
var isProtected: Boolean = false
|
||||
private set
|
||||
@@ -44,19 +44,20 @@ class BinaryAttachment : Parcelable {
|
||||
* Empty protected binary
|
||||
*/
|
||||
constructor() {
|
||||
this.isCompressed = false
|
||||
this.isCompressed = null
|
||||
this.isProtected = false
|
||||
this.dataFile = null
|
||||
}
|
||||
|
||||
constructor(dataFile: File, enableProtection: Boolean = false, compressed: Boolean = false) {
|
||||
constructor(dataFile: File, enableProtection: Boolean = false, compressed: Boolean? = null) {
|
||||
this.isCompressed = compressed
|
||||
this.isProtected = enableProtection
|
||||
this.dataFile = dataFile
|
||||
}
|
||||
|
||||
private constructor(parcel: Parcel) {
|
||||
isCompressed = parcel.readByte().toInt() != 0
|
||||
val compressedByte = parcel.readByte().toInt()
|
||||
isCompressed = if (compressedByte == 2) null else compressedByte != 0
|
||||
isProtected = parcel.readByte().toInt() != 0
|
||||
parcel.readString()?.let {
|
||||
dataFile = File(it)
|
||||
@@ -83,7 +84,7 @@ class BinaryAttachment : Parcelable {
|
||||
fun compress(bufferSize: Int = DEFAULT_BUFFER_SIZE) {
|
||||
dataFile?.let { concreteDataFile ->
|
||||
// To compress, create a new binary with file
|
||||
if (!isCompressed) {
|
||||
if (isCompressed != true) {
|
||||
val fileBinaryCompress = File(concreteDataFile.parent, concreteDataFile.name + "_temp")
|
||||
GZIPOutputStream(FileOutputStream(fileBinaryCompress)).use { outputStream ->
|
||||
getInputDataStream().use { inputStream ->
|
||||
@@ -99,6 +100,8 @@ class BinaryAttachment : Parcelable {
|
||||
isCompressed = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
isCompressed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,7 +109,7 @@ class BinaryAttachment : Parcelable {
|
||||
@Throws(IOException::class)
|
||||
fun decompress(bufferSize: Int = DEFAULT_BUFFER_SIZE) {
|
||||
dataFile?.let { concreteDataFile ->
|
||||
if (isCompressed) {
|
||||
if (isCompressed != false) {
|
||||
val fileBinaryDecompress = File(concreteDataFile.parent, concreteDataFile.name + "_temp")
|
||||
FileOutputStream(fileBinaryDecompress).use { outputStream ->
|
||||
GZIPInputStream(getInputDataStream()).use { inputStream ->
|
||||
@@ -122,6 +125,8 @@ class BinaryAttachment : Parcelable {
|
||||
isCompressed = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
isCompressed = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,7 +157,7 @@ class BinaryAttachment : Parcelable {
|
||||
override fun hashCode(): Int {
|
||||
|
||||
var result = 0
|
||||
result = 31 * result + if (isCompressed) 1 else 0
|
||||
result = 31 * result + if (isCompressed == null) 2 else if (isCompressed!!) 1 else 0
|
||||
result = 31 * result + if (isProtected) 1 else 0
|
||||
result = 31 * result + dataFile!!.hashCode()
|
||||
return result
|
||||
@@ -167,7 +172,7 @@ class BinaryAttachment : Parcelable {
|
||||
}
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
dest.writeByte((if (isCompressed) 1 else 0).toByte())
|
||||
dest.writeByte((if (isCompressed == null) 2 else if (isCompressed!!) 1 else 0).toByte())
|
||||
dest.writeByte((if (isProtected) 1 else 0).toByte())
|
||||
dest.writeString(dataFile?.absolutePath)
|
||||
}
|
||||
|
||||
@@ -540,7 +540,7 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
|
||||
|
||||
fun buildNewBinary(cacheDirectory: File,
|
||||
protection: Boolean,
|
||||
compression: Boolean,
|
||||
compression: Boolean?,
|
||||
binaryPoolId: Int? = null): BinaryAttachment {
|
||||
// New file with current time
|
||||
val fileInCache = File(cacheDirectory, System.currentTimeMillis().toString())
|
||||
|
||||
@@ -253,7 +253,8 @@ 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, false)
|
||||
// Unknown compression at this level
|
||||
val protectedBinary = mDatabase.buildNewBinary(cacheDirectory, protectedFlag, null)
|
||||
protectedBinary.getOutputDataStream().use { outputStream ->
|
||||
dataInputStream.readBytes(byteLength, DatabaseKDBX.BUFFER_SIZE_BYTES) { buffer ->
|
||||
outputStream.write(buffer)
|
||||
|
||||
@@ -440,7 +440,7 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX,
|
||||
|
||||
// Force decompression in this specific case
|
||||
val binaryInputStream = if (mDatabaseKDBX.compressionAlgorithm == CompressionAlgorithm.None
|
||||
&& binary.isCompressed) {
|
||||
&& binary.isCompressed == true) {
|
||||
GZIPInputStream(binary.getInputDataStream())
|
||||
} else {
|
||||
binary.getInputDataStream()
|
||||
|
||||
Reference in New Issue
Block a user