Bug fixes & Allow export to SD cards

This commit is contained in:
Hardcore Sushi 2020-08-29 20:48:12 +02:00
parent 9d0a6e170e
commit 06efdb61c3
5 changed files with 65 additions and 41 deletions

View File

@ -37,6 +37,7 @@ class OpenActivity : BaseActivity() {
private lateinit var fingerprintPasswordHashSaver: FingerprintPasswordHashSaver private lateinit var fingerprintPasswordHashSaver: FingerprintPasswordHashSaver
private lateinit var rootCipherDir: String private lateinit var rootCipherDir: String
private var sessionID = -1 private var sessionID = -1
private var isStartingActivity = false
private var isFinishingIntentionally = false private var isFinishingIntentionally = false
private var usf_fingerprint = false private var usf_fingerprint = false
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -83,6 +84,7 @@ class OpenActivity : BaseActivity() {
fun pickDirectory(view: View?) { fun pickDirectory(view: View?) {
val i = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) val i = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
isStartingActivity = true
startActivityForResult(i, PICK_DIRECTORY_REQUEST_CODE) startActivityForResult(i, PICK_DIRECTORY_REQUEST_CODE)
} }
@ -237,7 +239,11 @@ class OpenActivity : BaseActivity() {
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
if (intent.action == "pick"){ if (intent.action == "pick"){
finish() if (isStartingActivity){
isStartingActivity = false
} else {
finish()
}
} }
if (::fingerprintPasswordHashSaver.isInitialized && fingerprintPasswordHashSaver.isListening){ if (::fingerprintPasswordHashSaver.isInitialized && fingerprintPasswordHashSaver.isListening){
fingerprintPasswordHashSaver.stopListening() fingerprintPasswordHashSaver.stopListening()

View File

@ -144,10 +144,9 @@ open class BaseExplorerActivity : BaseActivity() {
.show() .show()
} }
} }
} else {
invalidateOptionsMenu()
} }
} }
invalidateOptionsMenu()
} }
protected open fun onExplorerItemLongClick(position: Int) { protected open fun onExplorerItemLongClick(position: Int) {
@ -425,8 +424,12 @@ open class BaseExplorerActivity : BaseActivity() {
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
if (!isChangingConfigurations && !isStartingActivity){ if (!isChangingConfigurations){
finish() if (isStartingActivity){
isStartingActivity = false
} else {
finish()
}
} }
} }

View File

@ -11,6 +11,7 @@ import android.view.WindowManager
import android.widget.EditText import android.widget.EditText
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.documentfile.provider.DocumentFile
import sushi.hardcore.droidfs.CameraActivity import sushi.hardcore.droidfs.CameraActivity
import sushi.hardcore.droidfs.OpenActivity import sushi.hardcore.droidfs.OpenActivity
import sushi.hardcore.droidfs.R import sushi.hardcore.droidfs.R
@ -225,35 +226,38 @@ class ExplorerActivity : BaseExplorerActivity() {
if (resultCode == Activity.RESULT_OK && data != null) { if (resultCode == Activity.RESULT_OK && data != null) {
object : LoadingTask(this, R.string.loading_msg_export){ object : LoadingTask(this, R.string.loading_msg_export){
override fun doTask(activity: AppCompatActivity) { override fun doTask(activity: AppCompatActivity) {
val uri = data.data data.data?.let {uri ->
val outputDir = PathUtils.getFullPathFromTreeUri(uri, activity) contentResolver.takePersistableUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
var failedItem: String? = null DocumentFile.fromTreeUri(activity, uri)?.let { treeDocumentFile ->
for (i in explorerAdapter.selectedItems) { var failedItem: String? = null
val element = explorerAdapter.getItem(i) for (i in explorerAdapter.selectedItems) {
val fullPath = PathUtils.path_join(currentDirectoryPath, element.name) val element = explorerAdapter.getItem(i)
failedItem = if (element.isDirectory) { val fullPath = PathUtils.path_join(currentDirectoryPath, element.name)
recursiveExportDirectory(fullPath, outputDir) failedItem = if (element.isDirectory) {
} else { recursiveExportDirectory(fullPath, treeDocumentFile)
if (gocryptfsVolume.exportFile(fullPath, PathUtils.path_join(outputDir, element.name))) null else fullPath } else {
} if (exportFileInto(fullPath, treeDocumentFile)) null else fullPath
if (failedItem != null) { }
stopTask { if (failedItem != null) {
ColoredAlertDialogBuilder(activity) stopTask {
.setTitle(R.string.error) ColoredAlertDialogBuilder(activity)
.setMessage(getString(R.string.export_failed, failedItem)) .setTitle(R.string.error)
.setPositiveButton(R.string.ok, null) .setMessage(getString(R.string.export_failed, failedItem))
.show() .setPositiveButton(R.string.ok, null)
.show()
}
break
}
}
if (failedItem == null) {
stopTask {
ColoredAlertDialogBuilder(activity)
.setTitle(R.string.success_export)
.setMessage(R.string.success_export_msg)
.setPositiveButton(R.string.ok, null)
.show()
}
} }
break
}
}
if (failedItem == null) {
stopTask {
ColoredAlertDialogBuilder(activity)
.setTitle(R.string.success_export)
.setMessage(R.string.success_export_msg)
.setPositiveButton(R.string.ok, null)
.show()
} }
} }
} }
@ -631,7 +635,7 @@ class ExplorerActivity : BaseExplorerActivity() {
} }
private fun recursiveImportDirectoryFromOtherVolume(remote_gocryptfsVolume: GocryptfsVolume, remote_directory_path: String, outputPath: String): String? { private fun recursiveImportDirectoryFromOtherVolume(remote_gocryptfsVolume: GocryptfsVolume, remote_directory_path: String, outputPath: String): String? {
val mappedElements = gocryptfsVolume.recursiveMapFiles(remote_directory_path) val mappedElements = remote_gocryptfsVolume.recursiveMapFiles(remote_directory_path)
val dstDirectoryPath = checkPathOverwrite(PathUtils.path_join(outputPath, File(remote_directory_path).name), true) val dstDirectoryPath = checkPathOverwrite(PathUtils.path_join(outputPath, File(remote_directory_path).name), true)
if (dstDirectoryPath == null){ if (dstDirectoryPath == null){
return "" return ""
@ -663,23 +667,34 @@ class ExplorerActivity : BaseExplorerActivity() {
return null return null
} }
private fun recursiveExportDirectory(plain_directory_path: String, output_dir: String?): String? { private fun exportFileInto(srcPath: String, treeDocumentFile: DocumentFile): Boolean {
if (File(PathUtils.path_join(output_dir, plain_directory_path)).mkdir()) { val outputStream = treeDocumentFile.createFile("*/*", File(srcPath).name)?.uri?.let {
contentResolver.openOutputStream(it)
}
return if (outputStream != null){
gocryptfsVolume.exportFile(srcPath, outputStream)
} else {
false
}
}
private fun recursiveExportDirectory(plain_directory_path: String, treeDocumentFile: DocumentFile): String? {
treeDocumentFile.createDirectory(plain_directory_path)?.let {childTree ->
val explorerElements = gocryptfsVolume.listDir(plain_directory_path) val explorerElements = gocryptfsVolume.listDir(plain_directory_path)
for (e in explorerElements) { for (e in explorerElements) {
val fullPath = PathUtils.path_join(plain_directory_path, e.name) val fullPath = PathUtils.path_join(plain_directory_path, e.name)
if (e.isDirectory) { if (e.isDirectory) {
val failedItem = recursiveExportDirectory(fullPath, output_dir) val failedItem = recursiveExportDirectory(fullPath, childTree)
failedItem?.let { return it } failedItem?.let { return it }
} else { } else {
if (!gocryptfsVolume.exportFile(fullPath, PathUtils.path_join(output_dir, fullPath))) { if (!exportFileInto(fullPath, childTree)){
return fullPath return fullPath
} }
} }
} }
return null return null
} }
return output_dir return treeDocumentFile.name
} }
private fun recursiveRemoveDirectory(plain_directory_path: String): String? { private fun recursiveRemoveDirectory(plain_directory_path: String): String? {

View File

@ -32,7 +32,7 @@
app:showAsAction="ifRoom" app:showAsAction="ifRoom"
android:visible="false" android:visible="false"
android:icon="@drawable/icon_decrypt" android:icon="@drawable/icon_decrypt"
android:title="@string/decrypt"/> android:title="@string/decrypt_files"/>
<item <item
android:id="@+id/share" android:id="@+id/share"

View File

@ -138,7 +138,7 @@
<string name="github">GitHub</string> <string name="github">GitHub</string>
<string name="github_summary">Want to read the documentation, request feature, report bug, read the source code… Check the DroidFS\'s repository !</string> <string name="github_summary">Want to read the documentation, request feature, report bug, read the source code… Check the DroidFS\'s repository !</string>
<string name="share">Share</string> <string name="share">Share</string>
<string name="decrypt">Decrypt</string> <string name="decrypt_files">Export/Decrypt</string>
<string name="loading_msg_copy">Copying selected items…</string> <string name="loading_msg_copy">Copying selected items…</string>
<string name="copy_failed">Copy of %s failed.</string> <string name="copy_failed">Copy of %s failed.</string>
<string name="copy_success_msg">The selected items have been successfully copied.</string> <string name="copy_success_msg">The selected items have been successfully copied.</string>