forked from hardcoresushi/DroidFS
Cleaning
This commit is contained in:
parent
a8fb5960f2
commit
a92695f8d5
@ -1 +1 @@
|
||||
Subproject commit c0af6c0bc2045bb53f65fde02d192d5aca436eae
|
||||
Subproject commit 267fb40fe77e5ef079759bebd395c7a92ef072d2
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
@ -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))
|
||||
)
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
@ -588,7 +593,7 @@ open class BaseExplorerActivity : BaseActivity(), ExplorerElementAdapter.Listene
|
||||
}
|
||||
|
||||
protected open fun closeVolumeOnDestroy() {
|
||||
if (!encryptedVolume.isClosed()){
|
||||
if (!encryptedVolume.isClosed()) {
|
||||
encryptedVolume.close()
|
||||
}
|
||||
RestrictedFileProvider.wipeAll(this) //additional security
|
||||
@ -617,7 +622,7 @@ open class BaseExplorerActivity : BaseActivity(), ExplorerElementAdapter.Listene
|
||||
if (isCreating){
|
||||
isCreating = false
|
||||
} else {
|
||||
if (encryptedVolume.isClosed()){
|
||||
if (encryptedVolume.isClosed()) {
|
||||
finish()
|
||||
} else {
|
||||
isStartingActivity = false
|
||||
|
@ -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(
|
||||
|
@ -275,7 +275,7 @@ class ImageViewer: FileViewerActivity() {
|
||||
Bitmap.CompressFormat.JPEG
|
||||
}, 100, outputStream) == true
|
||||
){
|
||||
if (encryptedVolume.importFile(ByteArrayInputStream(outputStream.toByteArray()), filePath)){
|
||||
if (encryptedVolume.importFile(ByteArrayInputStream(outputStream.toByteArray()), filePath)) {
|
||||
Toast.makeText(this, R.string.image_saved_successfully, Toast.LENGTH_SHORT).show()
|
||||
callback()
|
||||
} else {
|
||||
|
@ -81,7 +81,7 @@ abstract class EncryptedVolume: Parcelable {
|
||||
var offset: Long = 0
|
||||
val ioBuffer = ByteArray(ConstValues.IO_BUFF_SIZE)
|
||||
var length: Int
|
||||
while (read(fileHandle, ioBuffer, offset).also { length = it } > 0){
|
||||
while (read(fileHandle, ioBuffer, offset).also { length = it } > 0) {
|
||||
os.write(ioBuffer, 0, length)
|
||||
offset += length.toLong()
|
||||
}
|
||||
@ -105,7 +105,7 @@ abstract class EncryptedVolume: Parcelable {
|
||||
|
||||
fun exportFile(context: Context, src_path: String, output_path: Uri): Boolean {
|
||||
val os = context.contentResolver.openOutputStream(output_path)
|
||||
if (os != null){
|
||||
if (os != null) {
|
||||
return exportFile(src_path, os)
|
||||
}
|
||||
return false
|
||||
@ -137,7 +137,7 @@ abstract class EncryptedVolume: Parcelable {
|
||||
|
||||
fun importFile(context: Context, src_uri: Uri, dst_path: String): Boolean {
|
||||
val inputStream = context.contentResolver.openInputStream(src_uri)
|
||||
if (inputStream != null){
|
||||
if (inputStream != null) {
|
||||
return importFile(inputStream, dst_path)
|
||||
}
|
||||
return false
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -257,7 +257,7 @@ Java_sushi_hardcore_droidfs_filesystems_GocryptfsVolume_native_1list_1dir(JNIEnv
|
||||
elementList = (*env)->NewObject(env, arrayList, arrayListInit, elements.r2);
|
||||
|
||||
unsigned int c = 0;
|
||||
for (unsigned int i=0; i<elements.r2; ++i){
|
||||
for (unsigned int i=0; i<elements.r2; ++i) {
|
||||
const char* name = &(elements.r0[c]);
|
||||
size_t nameLen = strlen(name);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user