This commit is contained in:
Matéo Duparc 2022-06-25 21:36:22 +02:00
parent a8fb5960f2
commit a92695f8d5
Signed by untrusted user: hardcoresushi
GPG Key ID: AFE384344A45E13A
12 changed files with 40 additions and 44 deletions

@ -1 +1 @@
Subproject commit c0af6c0bc2045bb53f65fde02d192d5aca436eae Subproject commit 267fb40fe77e5ef079759bebd395c7a92ef072d2

View File

@ -429,7 +429,7 @@ class MainActivity : BaseActivity(), VolumeAdapter.Listener {
val dstPath = File(srcPath.parent, newName).canonicalFile val dstPath = File(srcPath.parent, newName).canonicalFile
val newDBName: String val newDBName: String
val success = if (volume.isHidden) { val success = if (volume.isHidden) {
if (newName.contains("/")) { if (newName.contains(PathUtils.SEPARATOR)) {
Toast.makeText(this, R.string.error_slash_in_name, Toast.LENGTH_SHORT).show() Toast.makeText(this, R.string.error_slash_in_name, Toast.LENGTH_SHORT).show()
renameVolume(volume, position) renameVolume(volume, position)
return@EditTextDialog return@EditTextDialog
@ -528,7 +528,7 @@ class MainActivity : BaseActivity(), VolumeAdapter.Listener {
openVolumeWithPassword( openVolumeWithPassword(
volume, volume,
position, position,
WidgetUtil.editTextContentEncode(dialogBinding.editPassword), WidgetUtil.encodeEditTextContent(dialogBinding.editPassword),
dialogBinding.checkboxSavePassword.isChecked, dialogBinding.checkboxSavePassword.isChecked,
) )
} }

View File

@ -104,17 +104,11 @@ class VolumeDatabase(private val context: Context): SQLiteOpenHelper(context, Co
val list: MutableList<SavedVolume> = ArrayList() val list: MutableList<SavedVolume> = ArrayList()
val cursor = readableDatabase.rawQuery("SELECT * FROM $TABLE_NAME", null) val cursor = readableDatabase.rawQuery("SELECT * FROM $TABLE_NAME", null)
while (cursor.moveToNext()){ while (cursor.moveToNext()){
val typeColumnIndex = cursor.getColumnIndex(COLUMN_TYPE)
val volumeType = if (typeColumnIndex == -1) {
EncryptedVolume.GOCRYPTFS_VOLUME_TYPE
} else {
cursor.getBlob(typeColumnIndex)[0]
}
list.add( list.add(
SavedVolume( SavedVolume(
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_NAME)), cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_NAME)),
cursor.getShort(cursor.getColumnIndexOrThrow(COLUMN_HIDDEN)) == 1.toShort(), cursor.getShort(cursor.getColumnIndexOrThrow(COLUMN_HIDDEN)) == 1.toShort(),
volumeType, cursor.getBlob(cursor.getColumnIndexOrThrow(COLUMN_TYPE))[0],
cursor.getBlob(cursor.getColumnIndexOrThrow(COLUMN_HASH)), cursor.getBlob(cursor.getColumnIndexOrThrow(COLUMN_HASH)),
cursor.getBlob(cursor.getColumnIndexOrThrow(COLUMN_IV)) cursor.getBlob(cursor.getColumnIndexOrThrow(COLUMN_IV))
) )

View File

@ -159,8 +159,8 @@ class CreateVolumeFragment: Fragment() {
} }
private fun createVolume() { private fun createVolume() {
val password = WidgetUtil.editTextContentEncode(binding.editPassword) val password = WidgetUtil.encodeEditTextContent(binding.editPassword)
val passwordConfirm = WidgetUtil.editTextContentEncode(binding.editPasswordConfirm) val passwordConfirm = WidgetUtil.encodeEditTextContent(binding.editPasswordConfirm)
if (!password.contentEquals(passwordConfirm)) { if (!password.contentEquals(passwordConfirm)) {
Toast.makeText(requireContext(), R.string.passwords_mismatch, Toast.LENGTH_SHORT).show() Toast.makeText(requireContext(), R.string.passwords_mismatch, Toast.LENGTH_SHORT).show()
Arrays.fill(password, 0) Arrays.fill(password, 0)

View File

@ -190,7 +190,7 @@ class SelectPathFragment: Fragment() {
if (isHidden) R.string.enter_volume_name else R.string.enter_volume_path, if (isHidden) R.string.enter_volume_name else R.string.enter_volume_path,
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
} else if (isHidden && currentVolumeValue.contains("/")) { } else if (isHidden && currentVolumeValue.contains(PathUtils.SEPARATOR)) {
Toast.makeText(requireContext(), R.string.error_slash_in_name, Toast.LENGTH_SHORT).show() Toast.makeText(requireContext(), R.string.error_slash_in_name, Toast.LENGTH_SHORT).show()
} else { } else {
val volumePath = getCurrentVolumePath() val volumePath = getCurrentVolumePath()

View File

@ -7,7 +7,6 @@ import android.content.ServiceConnection
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.IBinder import android.os.IBinder
import android.util.Log
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
@ -403,7 +402,13 @@ open class BaseExplorerActivity : BaseActivity(), ExplorerElementAdapter.Listene
if (!ready){ if (!ready){
CustomAlertDialogBuilder(this, themeValue) CustomAlertDialogBuilder(this, themeValue)
.setTitle(R.string.warning) .setTitle(R.string.warning)
.setMessage(getString(if (items[i].isDirectory){R.string.dir_overwrite_question} else {R.string.file_overwrite_question}, testDstPath)) .setMessage(getString(
if (items[i].isDirectory) {
R.string.dir_overwrite_question
} else {
R.string.file_overwrite_question
}, testDstPath
))
.setPositiveButton(R.string.yes) {_, _ -> .setPositiveButton(R.string.yes) {_, _ ->
items[i].dstPath = testDstPath items[i].dstPath = testDstPath
items[i].overwriteConfirmed = true items[i].overwriteConfirmed = true

View File

@ -115,7 +115,7 @@ class ExplorerActivity : BaseExplorerActivity() {
private val pickImportDirectory = registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { rootUri -> private val pickImportDirectory = registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { rootUri ->
rootUri?.let { rootUri?.let {
val tree = DocumentFile.fromTreeUri(this, it)!! //non-null after Lollipop val tree = DocumentFile.fromTreeUri(this, it)!! //non-null after Lollipop
val operation = OperationFile(PathUtils.pathJoin(tree.name!!, currentDirectoryPath), Stat.S_IFDIR) val operation = OperationFile(PathUtils.pathJoin(currentDirectoryPath, tree.name!!), Stat.S_IFDIR)
checkPathOverwrite(arrayListOf(operation), currentDirectoryPath) { checkedOperation -> checkPathOverwrite(arrayListOf(operation), currentDirectoryPath) { checkedOperation ->
checkedOperation?.let { checkedOperation?.let {
lifecycleScope.launch { lifecycleScope.launch {
@ -170,7 +170,7 @@ class ExplorerActivity : BaseExplorerActivity() {
setContentView(binding.root) setContentView(binding.root)
binding.fab.setOnClickListener { binding.fab.setOnClickListener {
if (currentItemAction != ItemsActions.NONE){ if (currentItemAction != ItemsActions.NONE){
//openDialogCreateFolder() openDialogCreateFolder()
} else { } else {
val adapter = IconTextDialogAdapter(this) val adapter = IconTextDialogAdapter(this)
adapter.items = listOf( adapter.items = listOf(

View File

@ -6,7 +6,6 @@ import android.net.Uri
import android.os.storage.StorageManager import android.os.storage.StorageManager
import android.provider.DocumentsContract import android.provider.DocumentsContract
import android.provider.OpenableColumns import android.provider.OpenableColumns
import android.util.Log
import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.ActivityResultLauncher
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import sushi.hardcore.droidfs.R import sushi.hardcore.droidfs.R
@ -18,20 +17,18 @@ import kotlin.math.max
import kotlin.math.pow import kotlin.math.pow
object PathUtils { object PathUtils {
const val SEPARATOR = '/'
fun getParentPath(path: String): String { fun getParentPath(path: String): String {
return if (path.endsWith("/")) { val strippedPath = if (path.endsWith(SEPARATOR)) {
val a = path.substring(0, max(1, path.length - 1)) path.substring(0, max(1, path.length - 1))
if (a.count { it == '/' } == 1) {
"/"
} else { } else {
a.substring(0, a.lastIndexOf("/")) path
} }
return if (strippedPath.count { it == SEPARATOR } <= 1) {
SEPARATOR.toString()
} else { } else {
if (path.count { it == '/' } <= 1) { strippedPath.substring(0, strippedPath.lastIndexOf(SEPARATOR))
"/"
} else {
path.substring(0, path.lastIndexOf("/"))
}
} }
} }
@ -39,17 +36,17 @@ object PathUtils {
val result = StringBuilder() val result = StringBuilder()
for (element in strings) { for (element in strings) {
if (element.isNotEmpty()) { if (element.isNotEmpty()) {
if (!element.startsWith(SEPARATOR) && result.last() != SEPARATOR) {
result.append(SEPARATOR)
}
result.append(element) result.append(element)
if (!element.endsWith("/")) {
result.append("/")
} }
} }
} return result.toString()
return result.substring(0, result.length - 1)
} }
fun getRelativePath(parentPath: String, childPath: String): String { fun getRelativePath(parentPath: String, childPath: String): String {
return childPath.substring(parentPath.length + if (parentPath.endsWith("/")) { return childPath.substring(parentPath.length + if (parentPath.endsWith(SEPARATOR)) {
0 0
} else { } else {
1 1
@ -75,7 +72,7 @@ object PathUtils {
if (result == null) { if (result == null) {
result = uri.path result = uri.path
result?.let { result?.let {
val cut = it.lastIndexOf('/') val cut = it.lastIndexOf(SEPARATOR)
if (cut != -1) { if (cut != -1) {
result = it.substring(cut + 1) result = it.substring(cut + 1)
} }

View File

@ -6,7 +6,7 @@ import java.nio.charset.StandardCharsets
import java.util.* import java.util.*
object WidgetUtil { object WidgetUtil {
fun editTextContentEncode(editText: EditText): ByteArray { fun encodeEditTextContent(editText: EditText): ByteArray {
val charArray = CharArray(editText.text.length) val charArray = CharArray(editText.text.length)
editText.text.getChars(0, editText.text.length, charArray, 0) editText.text.getChars(0, editText.text.length, charArray, 0)
val byteArray = StandardCharsets.UTF_8.encode( val byteArray = StandardCharsets.UTF_8.encode(