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

View File

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

View File

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

View File

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

View File

@ -138,7 +138,7 @@
<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="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="copy_failed">Copy of %s failed.</string>
<string name="copy_success_msg">The selected items have been successfully copied.</string>