mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
named compression algorithm
This commit is contained in:
@@ -33,7 +33,7 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.ImageViewerActivity
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.NamedCompressionAlgorithm
|
||||
import com.kunzisoft.keepass.model.AttachmentState
|
||||
import com.kunzisoft.keepass.model.EntryAttachmentState
|
||||
import com.kunzisoft.keepass.model.StreamDirection
|
||||
@@ -130,7 +130,7 @@ class EntryAttachmentsItemsAdapter(context: Context)
|
||||
holder.binaryFileSize.text = Formatter.formatFileSize(context, size)
|
||||
holder.binaryFileCompression.apply {
|
||||
if (entryAttachmentState.attachment.binaryData.isCompressed) {
|
||||
text = CompressionAlgorithm.GZip.getName(context.resources)
|
||||
text = NamedCompressionAlgorithm.GZip.getName(context.resources)
|
||||
visibility = View.VISIBLE
|
||||
} else {
|
||||
text = ""
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.Entry
|
||||
import com.kunzisoft.keepass.database.element.Group
|
||||
import com.kunzisoft.keepass.database.element.MainCredential
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.NamedCompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
@@ -615,8 +615,8 @@ class DatabaseTaskProvider {
|
||||
, ACTION_DATABASE_UPDATE_COLOR_TASK)
|
||||
}
|
||||
|
||||
fun startDatabaseSaveCompression(oldCompression: CompressionAlgorithm,
|
||||
newCompression: CompressionAlgorithm,
|
||||
fun startDatabaseSaveCompression(oldCompression: NamedCompressionAlgorithm,
|
||||
newCompression: NamedCompressionAlgorithm,
|
||||
save: Boolean) {
|
||||
start(Bundle().apply {
|
||||
putSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldCompression)
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2019 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePassDX.
|
||||
*
|
||||
* KeePassDX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePassDX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element.database
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.R
|
||||
import com.kunzisoft.keepass.utils.ObjectNameResource
|
||||
import com.kunzisoft.keepass.utils.readEnum
|
||||
import com.kunzisoft.keepass.utils.writeEnum
|
||||
|
||||
|
||||
// Note: We can get away with using int's to store unsigned 32-bit ints
|
||||
// since we won't do arithmetic on these values (also unlikely to
|
||||
// reach negative ids).
|
||||
enum class NamedCompressionAlgorithm : ObjectNameResource, Parcelable {
|
||||
|
||||
None,
|
||||
GZip;
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
dest.writeEnum(this)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getName(resources: Resources): String {
|
||||
return when (this) {
|
||||
None -> resources.getString(R.string.compression_none)
|
||||
GZip -> resources.getString(R.string.compression_gzip)
|
||||
}
|
||||
}
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<NamedCompressionAlgorithm> {
|
||||
override fun createFromParcel(parcel: Parcel): NamedCompressionAlgorithm {
|
||||
return parcel.readEnum<NamedCompressionAlgorithm>() ?: None
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<NamedCompressionAlgorithm?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun CompressionAlgorithm.toNamedCompressionAlgorithm() = when(this) {
|
||||
CompressionAlgorithm.None -> NamedCompressionAlgorithm.None
|
||||
CompressionAlgorithm.GZip -> NamedCompressionAlgorithm.GZip
|
||||
}
|
||||
|
||||
|
||||
fun NamedCompressionAlgorithm.toCompressionAlgorithm() = when(this) {
|
||||
NamedCompressionAlgorithm.None -> CompressionAlgorithm.None
|
||||
NamedCompressionAlgorithm.GZip -> CompressionAlgorithm.GZip
|
||||
}
|
||||
@@ -39,7 +39,8 @@ import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.Entry
|
||||
import com.kunzisoft.keepass.database.element.Group
|
||||
import com.kunzisoft.keepass.database.element.MainCredential
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.NamedCompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.toCompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
@@ -646,11 +647,19 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateMessage(resId: Int) {
|
||||
fun updateMessage(resId: Int) {
|
||||
mProgressMessage.messageId = resId
|
||||
notifyProgressMessage()
|
||||
}
|
||||
|
||||
override fun updateMessageRetrievingDBKey() {
|
||||
updateMessage(R.string.retrieving_db_key)
|
||||
}
|
||||
|
||||
override fun updateMessageDecryptingDB() {
|
||||
updateMessage(R.string.decrypting_db)
|
||||
}
|
||||
|
||||
override fun actionOnLock() {
|
||||
if (!TimeoutHelper.temporarilyDisableLock) {
|
||||
closeDatabase(mDatabase)
|
||||
@@ -1110,8 +1119,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
&& intent.hasExtra(SAVE_DATABASE_KEY)
|
||||
) {
|
||||
|
||||
val oldElement: CompressionAlgorithm? = intent.getParcelableExtra(OLD_ELEMENT_KEY)
|
||||
val newElement: CompressionAlgorithm? = intent.getParcelableExtra(NEW_ELEMENT_KEY)
|
||||
val oldElement: NamedCompressionAlgorithm? = intent.getParcelableExtra(OLD_ELEMENT_KEY)
|
||||
val newElement: NamedCompressionAlgorithm? = intent.getParcelableExtra(NEW_ELEMENT_KEY)
|
||||
|
||||
if (oldElement == null
|
||||
|| newElement == null
|
||||
@@ -1120,8 +1129,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
||||
|
||||
return UpdateCompressionBinariesDatabaseRunnable(this,
|
||||
database,
|
||||
oldElement,
|
||||
newElement,
|
||||
oldElement.toCompressionAlgorithm(),
|
||||
newElement.toCompressionAlgorithm(),
|
||||
!database.isReadOnly && intent.getBooleanExtra(SAVE_DATABASE_KEY, false)
|
||||
) { hardwareKey, seed ->
|
||||
retrieveResponseFromChallenge(hardwareKey, seed)
|
||||
|
||||
@@ -37,7 +37,9 @@ import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.Group
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.NamedCompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.toCompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.toNamedCompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.template.TemplateEngine
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService
|
||||
import com.kunzisoft.keepass.settings.preference.*
|
||||
@@ -198,8 +200,8 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev
|
||||
// Database compression
|
||||
dbDataCompressionPref = findPreference(getString(R.string.database_data_compression_key))
|
||||
if (database.allowDataCompression) {
|
||||
dbDataCompressionPref?.summary = (database.compressionAlgorithm
|
||||
?: CompressionAlgorithm.None).getName(resources)
|
||||
dbDataCompressionPref?.summary = (database.compressionAlgorithm?.toNamedCompressionAlgorithm()
|
||||
?: NamedCompressionAlgorithm.None).getName(resources)
|
||||
} else {
|
||||
dbCompressionPrefCategory?.isVisible = false
|
||||
}
|
||||
@@ -433,13 +435,13 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev
|
||||
dbCustomColorPref?.summary = defaultColorToShow
|
||||
}
|
||||
DatabaseTaskNotificationService.ACTION_DATABASE_UPDATE_COMPRESSION_TASK -> {
|
||||
val oldCompression = data.getSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY) as CompressionAlgorithm
|
||||
val newCompression = data.getSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY) as CompressionAlgorithm
|
||||
val oldCompression = data.getSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY) as NamedCompressionAlgorithm
|
||||
val newCompression = data.getSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY) as NamedCompressionAlgorithm
|
||||
val algorithmToShow =
|
||||
if (result.isSuccess) {
|
||||
newCompression
|
||||
} else {
|
||||
mDatabase?.compressionAlgorithm = oldCompression
|
||||
mDatabase?.compressionAlgorithm = oldCompression.toCompressionAlgorithm()
|
||||
oldCompression
|
||||
}
|
||||
dbDataCompressionPref?.summary = algorithmToShow.getName(resources)
|
||||
|
||||
@@ -25,16 +25,18 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.NamedCompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.toCompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.toNamedCompressionAlgorithm
|
||||
import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter
|
||||
|
||||
class DatabaseDataCompressionPreferenceDialogFragmentCompat
|
||||
: DatabaseSavePreferenceDialogFragmentCompat(),
|
||||
ListRadioItemAdapter.RadioItemSelectedCallback<CompressionAlgorithm> {
|
||||
ListRadioItemAdapter.RadioItemSelectedCallback<NamedCompressionAlgorithm> {
|
||||
|
||||
private var mRecyclerView: RecyclerView? = null
|
||||
private var mCompressionAdapter: ListRadioItemAdapter<CompressionAlgorithm>? = null
|
||||
private var compressionSelected: CompressionAlgorithm? = null
|
||||
private var mCompressionAdapter: ListRadioItemAdapter<NamedCompressionAlgorithm>? = null
|
||||
private var compressionSelected: NamedCompressionAlgorithm? = null
|
||||
|
||||
override fun onBindDialogView(view: View) {
|
||||
super.onBindDialogView(view)
|
||||
@@ -45,7 +47,7 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat
|
||||
mRecyclerView?.layoutManager = LinearLayoutManager(context)
|
||||
|
||||
activity?.let { activity ->
|
||||
mCompressionAdapter = ListRadioItemAdapter<CompressionAlgorithm>(activity)
|
||||
mCompressionAdapter = ListRadioItemAdapter<NamedCompressionAlgorithm>(activity)
|
||||
mCompressionAdapter?.setRadioItemSelectedCallback(this)
|
||||
}
|
||||
}
|
||||
@@ -57,8 +59,8 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat
|
||||
mRecyclerView?.adapter = mCompressionAdapter
|
||||
|
||||
database?.let {
|
||||
compressionSelected = it.compressionAlgorithm
|
||||
mCompressionAdapter?.setItems(it.availableCompressionAlgorithms, compressionSelected)
|
||||
compressionSelected = it.compressionAlgorithm?.toNamedCompressionAlgorithm()
|
||||
mCompressionAdapter?.setItems(it.availableCompressionAlgorithms.map { it.toNamedCompressionAlgorithm() }, compressionSelected)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,16 +71,16 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat
|
||||
if (compressionSelected != null) {
|
||||
val newCompression = compressionSelected
|
||||
val oldCompression = database.compressionAlgorithm
|
||||
database.compressionAlgorithm = newCompression
|
||||
database.compressionAlgorithm = newCompression?.toCompressionAlgorithm()
|
||||
|
||||
if (oldCompression != null && newCompression != null)
|
||||
saveCompression(oldCompression, newCompression)
|
||||
saveCompression(oldCompression.toNamedCompressionAlgorithm(), newCompression)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onItemSelected(item: CompressionAlgorithm) {
|
||||
override fun onItemSelected(item: NamedCompressionAlgorithm) {
|
||||
this.compressionSelected = item
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.Group
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.NamedCompressionAlgorithm
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import com.kunzisoft.keepass.tasks.ActionRunnable
|
||||
import com.kunzisoft.keepass.viewmodels.DatabaseViewModel
|
||||
@@ -90,8 +90,9 @@ abstract class DatabaseSavePreferenceDialogFragmentCompat
|
||||
mDatabaseViewModel.saveColor(oldColorString, newColorString, mDatabaseAutoSaveEnable)
|
||||
}
|
||||
|
||||
protected fun saveCompression(oldCompression: CompressionAlgorithm,
|
||||
newCompression: CompressionAlgorithm) {
|
||||
protected fun saveCompression(oldCompression: NamedCompressionAlgorithm,
|
||||
newCompression: NamedCompressionAlgorithm
|
||||
) {
|
||||
mDatabaseViewModel.saveCompression(oldCompression, newCompression, mDatabaseAutoSaveEnable)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.Group
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.NamedCompressionAlgorithm
|
||||
import com.kunzisoft.keepass.tasks.ActionRunnable
|
||||
|
||||
class DatabaseViewModel: ViewModel() {
|
||||
@@ -119,8 +119,8 @@ class DatabaseViewModel: ViewModel() {
|
||||
_saveColor.value = SuperString(oldValue, newValue, save)
|
||||
}
|
||||
|
||||
fun saveCompression(oldValue: CompressionAlgorithm,
|
||||
newValue: CompressionAlgorithm,
|
||||
fun saveCompression(oldValue: NamedCompressionAlgorithm,
|
||||
newValue: NamedCompressionAlgorithm,
|
||||
save: Boolean) {
|
||||
_saveCompression.value = SuperCompression(oldValue, newValue, save)
|
||||
}
|
||||
@@ -196,8 +196,8 @@ class DatabaseViewModel: ViewModel() {
|
||||
data class SuperLong(val oldValue: Long,
|
||||
val newValue: Long,
|
||||
val save: Boolean)
|
||||
data class SuperCompression(val oldValue: CompressionAlgorithm,
|
||||
val newValue: CompressionAlgorithm,
|
||||
data class SuperCompression(val oldValue: NamedCompressionAlgorithm,
|
||||
val newValue: NamedCompressionAlgorithm,
|
||||
val save: Boolean)
|
||||
data class SuperEncryption(val oldValue: EncryptionAlgorithm,
|
||||
val newValue: EncryptionAlgorithm,
|
||||
|
||||
@@ -308,7 +308,8 @@ class Database(private val iconPackChooser: InterfaceIconPackChooser) {
|
||||
}
|
||||
|
||||
fun updateDataBinaryCompression(oldCompression: CompressionAlgorithm,
|
||||
newCompression: CompressionAlgorithm) {
|
||||
newCompression: CompressionAlgorithm
|
||||
) {
|
||||
mDatabaseKDBX?.changeBinaryCompression(oldCompression, newCompression)
|
||||
dataModifiedSinceLastLoading = true
|
||||
}
|
||||
|
||||
@@ -19,46 +19,7 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element.database
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.R
|
||||
import com.kunzisoft.keepass.utils.ObjectNameResource
|
||||
import com.kunzisoft.keepass.utils.readEnum
|
||||
import com.kunzisoft.keepass.utils.writeEnum
|
||||
|
||||
|
||||
// Note: We can get away with using int's to store unsigned 32-bit ints
|
||||
// since we won't do arithmetic on these values (also unlikely to
|
||||
// reach negative ids).
|
||||
enum class CompressionAlgorithm : ObjectNameResource, Parcelable {
|
||||
|
||||
enum class CompressionAlgorithm {
|
||||
None,
|
||||
GZip;
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
dest.writeEnum(this)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getName(resources: Resources): String {
|
||||
return when (this) {
|
||||
None -> resources.getString(R.string.compression_none)
|
||||
GZip -> resources.getString(R.string.compression_gzip)
|
||||
}
|
||||
}
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<CompressionAlgorithm> {
|
||||
override fun createFromParcel(parcel: Parcel): CompressionAlgorithm {
|
||||
return parcel.readEnum<CompressionAlgorithm>() ?: None
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<CompressionAlgorithm?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ abstract class DatabaseInput<D : DatabaseVersioned<*, *, *, *>> (protected var m
|
||||
assignMasterKey: (() -> Unit)): D
|
||||
|
||||
protected fun startKeyTimer(progressTaskUpdater: ProgressTaskUpdater?) {
|
||||
progressTaskUpdater?.updateMessage(R.string.retrieving_db_key)
|
||||
progressTaskUpdater?.updateMessageRetrievingDBKey()
|
||||
Log.d(TAG, "Start retrieving database key...")
|
||||
startTimeKey = System.currentTimeMillis()
|
||||
}
|
||||
@@ -51,7 +51,7 @@ abstract class DatabaseInput<D : DatabaseVersioned<*, *, *, *>> (protected var m
|
||||
}
|
||||
|
||||
protected fun startContentTimer(progressTaskUpdater: ProgressTaskUpdater?) {
|
||||
progressTaskUpdater?.updateMessage(R.string.decrypting_db)
|
||||
progressTaskUpdater?.updateMessageDecryptingDB()
|
||||
Log.d(TAG, "Start decrypting database content...")
|
||||
startTimeContent = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.tasks
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
|
||||
interface ProgressTaskUpdater {
|
||||
fun updateMessage(@StringRes resId: Int)
|
||||
fun updateMessageRetrievingDBKey()
|
||||
fun updateMessageDecryptingDB()
|
||||
}
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="compression_none">None</string>
|
||||
<string name="compression_gzip">Gzip</string>
|
||||
<string name="recycle_bin">Recycle bin</string>
|
||||
<string name="templates">Templates</string>
|
||||
|
||||
<string name="retrieving_db_key">Retrieving database key…</string>
|
||||
<string name="decrypting_db">Decrypting database content…</string>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user