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 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,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -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))
|
||||||
)
|
)
|
||||||
|
@ -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)
|
||||||
|
@ -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()
|
||||||
|
@ -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
|
||||||
@ -588,7 +593,7 @@ open class BaseExplorerActivity : BaseActivity(), ExplorerElementAdapter.Listene
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected open fun closeVolumeOnDestroy() {
|
protected open fun closeVolumeOnDestroy() {
|
||||||
if (!encryptedVolume.isClosed()){
|
if (!encryptedVolume.isClosed()) {
|
||||||
encryptedVolume.close()
|
encryptedVolume.close()
|
||||||
}
|
}
|
||||||
RestrictedFileProvider.wipeAll(this) //additional security
|
RestrictedFileProvider.wipeAll(this) //additional security
|
||||||
@ -617,7 +622,7 @@ open class BaseExplorerActivity : BaseActivity(), ExplorerElementAdapter.Listene
|
|||||||
if (isCreating){
|
if (isCreating){
|
||||||
isCreating = false
|
isCreating = false
|
||||||
} else {
|
} else {
|
||||||
if (encryptedVolume.isClosed()){
|
if (encryptedVolume.isClosed()) {
|
||||||
finish()
|
finish()
|
||||||
} else {
|
} else {
|
||||||
isStartingActivity = false
|
isStartingActivity = false
|
||||||
|
@ -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(
|
||||||
|
@ -275,7 +275,7 @@ class ImageViewer: FileViewerActivity() {
|
|||||||
Bitmap.CompressFormat.JPEG
|
Bitmap.CompressFormat.JPEG
|
||||||
}, 100, outputStream) == true
|
}, 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()
|
Toast.makeText(this, R.string.image_saved_successfully, Toast.LENGTH_SHORT).show()
|
||||||
callback()
|
callback()
|
||||||
} else {
|
} else {
|
||||||
|
@ -81,7 +81,7 @@ abstract class EncryptedVolume: Parcelable {
|
|||||||
var offset: Long = 0
|
var offset: Long = 0
|
||||||
val ioBuffer = ByteArray(ConstValues.IO_BUFF_SIZE)
|
val ioBuffer = ByteArray(ConstValues.IO_BUFF_SIZE)
|
||||||
var length: Int
|
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)
|
os.write(ioBuffer, 0, length)
|
||||||
offset += length.toLong()
|
offset += length.toLong()
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ abstract class EncryptedVolume: Parcelable {
|
|||||||
|
|
||||||
fun exportFile(context: Context, src_path: String, output_path: Uri): Boolean {
|
fun exportFile(context: Context, src_path: String, output_path: Uri): Boolean {
|
||||||
val os = context.contentResolver.openOutputStream(output_path)
|
val os = context.contentResolver.openOutputStream(output_path)
|
||||||
if (os != null){
|
if (os != null) {
|
||||||
return exportFile(src_path, os)
|
return exportFile(src_path, os)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@ -137,7 +137,7 @@ abstract class EncryptedVolume: Parcelable {
|
|||||||
|
|
||||||
fun importFile(context: Context, src_uri: Uri, dst_path: String): Boolean {
|
fun importFile(context: Context, src_uri: Uri, dst_path: String): Boolean {
|
||||||
val inputStream = context.contentResolver.openInputStream(src_uri)
|
val inputStream = context.contentResolver.openInputStream(src_uri)
|
||||||
if (inputStream != null){
|
if (inputStream != null) {
|
||||||
return importFile(inputStream, dst_path)
|
return importFile(inputStream, dst_path)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -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 {
|
|
||||||
a.substring(0, a.lastIndexOf("/"))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (path.count { it == '/' } <= 1) {
|
path
|
||||||
"/"
|
}
|
||||||
} else {
|
return if (strippedPath.count { it == SEPARATOR } <= 1) {
|
||||||
path.substring(0, path.lastIndexOf("/"))
|
SEPARATOR.toString()
|
||||||
}
|
} else {
|
||||||
|
strippedPath.substring(0, strippedPath.lastIndexOf(SEPARATOR))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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()) {
|
||||||
result.append(element)
|
if (!element.startsWith(SEPARATOR) && result.last() != SEPARATOR) {
|
||||||
if (!element.endsWith("/")) {
|
result.append(SEPARATOR)
|
||||||
result.append("/")
|
|
||||||
}
|
}
|
||||||
|
result.append(element)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.substring(0, result.length - 1)
|
return result.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
@ -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(
|
||||||
|
@ -257,7 +257,7 @@ Java_sushi_hardcore_droidfs_filesystems_GocryptfsVolume_native_1list_1dir(JNIEnv
|
|||||||
elementList = (*env)->NewObject(env, arrayList, arrayListInit, elements.r2);
|
elementList = (*env)->NewObject(env, arrayList, arrayListInit, elements.r2);
|
||||||
|
|
||||||
unsigned int c = 0;
|
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]);
|
const char* name = &(elements.r0[c]);
|
||||||
size_t nameLen = strlen(name);
|
size_t nameLen = strlen(name);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user