This commit is contained in:
Matéo Duparc 2022-06-25 21:36:22 +02:00
parent a8fb5960f2
commit a92695f8d5
Signed by: 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 newDBName: String
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()
renameVolume(volume, position)
return@EditTextDialog
@ -528,7 +528,7 @@ class MainActivity : BaseActivity(), VolumeAdapter.Listener {
openVolumeWithPassword(
volume,
position,
WidgetUtil.editTextContentEncode(dialogBinding.editPassword),
WidgetUtil.encodeEditTextContent(dialogBinding.editPassword),
dialogBinding.checkboxSavePassword.isChecked,
)
}

View File

@ -104,17 +104,11 @@ class VolumeDatabase(private val context: Context): SQLiteOpenHelper(context, Co
val list: MutableList<SavedVolume> = ArrayList()
val cursor = readableDatabase.rawQuery("SELECT * FROM $TABLE_NAME", null)
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(
SavedVolume(
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_NAME)),
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_IV))
)

View File

@ -159,8 +159,8 @@ class CreateVolumeFragment: Fragment() {
}
private fun createVolume() {
val password = WidgetUtil.editTextContentEncode(binding.editPassword)
val passwordConfirm = WidgetUtil.editTextContentEncode(binding.editPasswordConfirm)
val password = WidgetUtil.encodeEditTextContent(binding.editPassword)
val passwordConfirm = WidgetUtil.encodeEditTextContent(binding.editPasswordConfirm)
if (!password.contentEquals(passwordConfirm)) {
Toast.makeText(requireContext(), R.string.passwords_mismatch, Toast.LENGTH_SHORT).show()
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,
Toast.LENGTH_SHORT
).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()
} else {
val volumePath = getCurrentVolumePath()

View File

@ -7,7 +7,6 @@ import android.content.ServiceConnection
import android.net.Uri
import android.os.Bundle
import android.os.IBinder
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
@ -403,7 +402,13 @@ open class BaseExplorerActivity : BaseActivity(), ExplorerElementAdapter.Listene
if (!ready){
CustomAlertDialogBuilder(this, themeValue)
.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) {_, _ ->
items[i].dstPath = testDstPath
items[i].overwriteConfirmed = true

View File

@ -115,7 +115,7 @@ class ExplorerActivity : BaseExplorerActivity() {
private val pickImportDirectory = registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { rootUri ->
rootUri?.let {
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 ->
checkedOperation?.let {
lifecycleScope.launch {
@ -170,7 +170,7 @@ class ExplorerActivity : BaseExplorerActivity() {
setContentView(binding.root)
binding.fab.setOnClickListener {
if (currentItemAction != ItemsActions.NONE){
//openDialogCreateFolder()
openDialogCreateFolder()
} else {
val adapter = IconTextDialogAdapter(this)
adapter.items = listOf(

View File

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

View File

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