Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emmanuelmess/refractor/files/1 #3150

Draft
wants to merge 46 commits into
base: release/3.7
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3ef6546
Add new file mechanism
EmmanuelMess Oct 9, 2021
85f4f50
Update SMB file handling to new system
EmmanuelMess Dec 22, 2021
a373c5e
Apply spotless and add spotless for file_operations module
EmmanuelMess Oct 11, 2021
94b9cc6
Add nullability to AmazeFile and related classes
EmmanuelMess Oct 11, 2021
f18d031
Fix tests for new SMB FileSystem
EmmanuelMess Oct 11, 2021
c0e10f5
Fix sintax in AmazeFile
EmmanuelMess Oct 11, 2021
6de2699
Remove unused AmazeFileSystem.close
EmmanuelMess Oct 14, 2021
2e782d6
Apply spotless
EmmanuelMess Oct 14, 2021
064aa2d
Add normal files to new file mechanism
EmmanuelMess Dec 25, 2021
bc451ac
Move cloud accounts to file_operations modules
EmmanuelMess Dec 25, 2021
52d4019
Add exception for impossible case in Smb file
EmmanuelMess Dec 26, 2021
6316891
Cloud to new file system
EmmanuelMess Dec 26, 2021
acff698
Apply spotless
EmmanuelMess Dec 26, 2021
c06093f
Remove URI handling from AmazeFile
EmmanuelMess Dec 26, 2021
7e577cf
Remove path separator handling from AmazeFilesystem
EmmanuelMess Dec 26, 2021
ba009a4
Rename a few files to make them more standard
EmmanuelMess Dec 26, 2021
38bd68f
Code duplication fixes in filesystem classes
EmmanuelMess Dec 26, 2021
c187668
Legibility fixes to Smb filesystem
EmmanuelMess Dec 26, 2021
c777f92
Fixed Smb files not showing under new filesystem
EmmanuelMess Dec 26, 2021
9a19a46
Fixed broken smb folders after going back
EmmanuelMess Dec 26, 2021
c00b6ac
Add ssh to new filesystem mechanism and modify instance loading
EmmanuelMess Jan 7, 2022
f01ac82
Added part of otg filesystem
EmmanuelMess Jan 9, 2022
ded7dcd
Fixed some abstract functions in AmazeFilesystem
EmmanuelMess Jan 9, 2022
f294cc9
Added part of otg filesystem
EmmanuelMess Jan 9, 2022
07db481
Add otg filesystem
EmmanuelMess Jan 22, 2022
8cc44e8
Apply spotless
EmmanuelMess Jan 22, 2022
6680915
Simplified some code with filesystems
EmmanuelMess Jan 22, 2022
a89b4f9
Convert AmazeFilesystem to kotlin
EmmanuelMess Jan 27, 2022
dcde3ad
Converted most AmazeFilesystem subclasses to kt
EmmanuelMess Jan 27, 2022
e9e2336
Converted AmazeFile to kt
EmmanuelMess Jan 27, 2022
dac1cf3
Convert Filesystems to objects
EmmanuelMess Jan 28, 2022
d2bffc2
Implementation for DocumentFileAmazeFilesystem
EmmanuelMess Jan 28, 2022
e0c65cf
Move rename operation to Filesystems
EmmanuelMess Jan 29, 2022
14b260f
Apply spotless
EmmanuelMess Jan 29, 2022
c3067ba
Added onFileFound to AmazeFile
EmmanuelMess Jan 29, 2022
f60cada
Fix some rootmode operations
EmmanuelMess Feb 6, 2022
dc81f49
Added hacks so that AmazeFilesystem subclasses actually load
EmmanuelMess Feb 19, 2022
b1f9d54
Apply spotless
EmmanuelMess Feb 19, 2022
78102ff
Fix a small test of SshFilesystemAmaze
EmmanuelMess Feb 19, 2022
6f13d97
Remove isInvalid for AmazeFile
EmmanuelMess Apr 20, 2022
73b49d5
Remove AmazeFile.deleteOnExit
EmmanuelMess Apr 20, 2022
bec6231
Remove AmazeFile.createTempFile
EmmanuelMess Apr 20, 2022
d933bb3
Move hash calculation to AmazeFile
EmmanuelMess Apr 20, 2022
6270e7a
Add human readable path
EmmanuelMess Apr 21, 2022
a103ece
Add method to calculate folder size
EmmanuelMess Apr 22, 2022
9d935ae
Add getUri for AmazeFile
EmmanuelMess Apr 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ dependencies {
implementation "com.github.topjohnwu.libsu:core:${libsuVersion}"
implementation "com.github.topjohnwu.libsu:io:${libsuVersion}"

implementation 'com.cloudrail:cloudrail-si-android:2.22.4'
implementation "com.cloudrail:cloudrail-si-android:$cloudRailVersion"

implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'//Nice charts and graphs

Expand Down Expand Up @@ -234,11 +234,12 @@ dependencies {

implementation 'org.tukaani:xz:1.8'

implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
//ReactiveX
implementation "io.reactivex.rxjava2:rxandroid:$reactiveXAndroidVersion"
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
// (see https://github.com/ReactiveX/RxJava/releases for latest 3.x.x version)
implementation group: 'io.reactivex.rxjava2', name: 'rxjava', version: '2.2.9'
implementation "io.reactivex.rxjava2:rxjava:$reactiveXVersion"

implementation project(':commons_compress_7z')
implementation project(':file_operations')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import com.amaze.filemanager.asynchronous.asynctasks.DeleteTask
import com.amaze.filemanager.asynchronous.management.ServiceWatcherUtil
import com.amaze.filemanager.asynchronous.services.CopyService
import com.amaze.filemanager.file_operations.filesystem.OpenMode
import com.amaze.filemanager.filesystem.files.FileAmazeFilesystem
import com.amaze.filemanager.filesystem.HybridFileParcelable
import com.amaze.filemanager.filesystem.RootHelper
import com.amaze.filemanager.filesystem.files.FileUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
import com.amaze.filemanager.database.models.explorer.CloudEntry;
import com.amaze.filemanager.file_operations.exceptions.CloudPluginException;
import com.amaze.filemanager.file_operations.filesystem.OpenMode;
import com.amaze.filemanager.file_operations.filesystem.filetypes.cloud.box.BoxAccount;
import com.amaze.filemanager.file_operations.filesystem.filetypes.cloud.dropbox.DropboxAccount;
import com.amaze.filemanager.file_operations.filesystem.filetypes.cloud.gdrive.GoogledriveAccount;
import com.amaze.filemanager.file_operations.filesystem.filetypes.cloud.onedrive.OnedriveAccount;
import com.amaze.filemanager.ui.activities.MainActivity;
import com.amaze.filemanager.utils.DataUtils;
import com.cloudrail.si.CloudRail;
Expand Down Expand Up @@ -130,7 +134,7 @@ public Boolean doInBackground(Void... voids) {
cloudHandler.addEntry(cloudEntryGdrive);
}

dataUtils.addAccount(cloudStorageDrive);
GoogledriveAccount.INSTANCE.add(cloudStorageDrive);
hasUpdatedDrawer = true;
} catch (CloudPluginException e) {
e.printStackTrace();
Expand Down Expand Up @@ -201,7 +205,7 @@ public Boolean doInBackground(Void... voids) {
cloudHandler.addEntry(cloudEntryDropbox);
}

dataUtils.addAccount(cloudStorageDropbox);
DropboxAccount.INSTANCE.add(cloudStorageDropbox);
hasUpdatedDrawer = true;
} catch (CloudPluginException e) {
e.printStackTrace();
Expand Down Expand Up @@ -265,7 +269,7 @@ public Boolean doInBackground(Void... voids) {
cloudHandler.addEntry(cloudEntryBox);
}

dataUtils.addAccount(cloudStorageBox);
BoxAccount.INSTANCE.add(cloudStorageBox);
hasUpdatedDrawer = true;
} catch (CloudPluginException e) {
e.printStackTrace();
Expand Down Expand Up @@ -330,7 +334,7 @@ public Boolean doInBackground(Void... voids) {
cloudHandler.addEntry(cloudEntryOnedrive);
}

dataUtils.addAccount(cloudStorageOnedrive);
OnedriveAccount.INSTANCE.add(cloudStorageOnedrive);
hasUpdatedDrawer = true;
} catch (CloudPluginException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private boolean doDeleteFile(@NonNull HybridFileParcelable file) throws Exceptio
case BOX:
case GDRIVE:
case ONEDRIVE:
CloudStorage cloudStorage = dataUtils.getAccount(file.getMode());
CloudStorage cloudStorage = dataUtils.getAccount(file.getMode()).getAccount();
try {
cloudStorage.delete(CloudUtil.stripPath(file.getMode(), file.getPath()));
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static android.os.Build.VERSION_CODES.Q;

import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Calendar;
Expand All @@ -38,6 +39,7 @@
import com.amaze.filemanager.database.UtilsHandler;
import com.amaze.filemanager.file_operations.exceptions.CloudPluginException;
import com.amaze.filemanager.file_operations.filesystem.OpenMode;
import com.amaze.filemanager.file_operations.filesystem.filetypes.AmazeFile;
import com.amaze.filemanager.filesystem.HybridFile;
import com.amaze.filemanager.filesystem.HybridFileParcelable;
import com.amaze.filemanager.filesystem.RootHelper;
Expand Down Expand Up @@ -69,8 +71,6 @@
import androidx.core.util.Pair;

import jcifs.smb.SmbAuthException;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;

public class LoadFilesListTask
extends AsyncTask<Void, Void, Pair<OpenMode, ArrayList<LayoutElementParcelable>>> {
Expand Down Expand Up @@ -141,7 +141,7 @@ public LoadFilesListTask(
hFile.setPath(hFile.getPath() + "/");
}
try {
SmbFile[] smbFile = hFile.getSmbFile(5000).listFiles();
AmazeFile[] smbFile = new AmazeFile(hFile.getPath()).listFiles(() -> context);
list = mainFragment.addToSmb(smbFile, path, showHiddenFiles);
openmode = OpenMode.SMB;
} catch (SmbAuthException e) {
Expand All @@ -150,7 +150,7 @@ public LoadFilesListTask(
}
e.printStackTrace();
return null;
} catch (SmbException | NullPointerException e) {
} catch (NullPointerException | IOException e) {
Log.w(getClass().getSimpleName(), "Failed to load smb files for path: " + path, e);
mainFragment.reauthenticateSmb();
return null;
Expand Down Expand Up @@ -225,7 +225,7 @@ public LoadFilesListTask(
case BOX:
case GDRIVE:
case ONEDRIVE:
CloudStorage cloudStorage = dataUtils.getAccount(openmode);
CloudStorage cloudStorage = dataUtils.getAccount(openmode).getAccount();
list = new ArrayList<>();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.Objects;
import java.util.concurrent.Callable;

import com.amaze.filemanager.file_operations.filesystem.filetypes.AmazeFile;
import com.amaze.filemanager.file_operations.filesystem.filetypes.ContextProvider;
import com.amaze.filemanager.filesystem.HybridFileParcelable;
import com.amaze.filemanager.filesystem.files.GenericCopyUtil;

Expand All @@ -37,18 +39,12 @@
/** Generates hashes from files (MD5 and SHA256) */
public class CalculateHashCallback implements Callable<Hash> {

private final boolean isNotADirectory;
private final InputStream inputStreamMd5;
private final InputStream inputStreamSha;
private final AmazeFile file;
private final ContextProvider contextProvider;

public CalculateHashCallback(HybridFileParcelable file, final Context context) {
if (file.isSftp()) {
throw new IllegalArgumentException("Use CalculateHashSftpCallback");
}

this.isNotADirectory = !file.isDirectory(context);
this.inputStreamMd5 = file.getInputStream(context);
this.inputStreamSha = file.getInputStream(context);
public CalculateHashCallback(AmazeFile file, final Context context) {
this.file = file;
this.contextProvider = () -> context;
}

@WorkerThread
Expand All @@ -57,67 +53,14 @@ public Hash call() throws Exception {
String md5 = null;
String sha256 = null;

if (isNotADirectory) {
md5 = getMD5Checksum();
sha256 = getSHA256Checksum();
if (!file.isDirectory(contextProvider)) {
md5 = file.getHashMD5(contextProvider);
sha256 = file.getHashSHA256(contextProvider);
}

Objects.requireNonNull(md5);
Objects.requireNonNull(sha256);

return new Hash(md5, sha256);
}

// see this How-to for a faster way to convert a byte array to a HEX string

private String getMD5Checksum() throws Exception {
byte[] b = createChecksum();
String result = "";

for (byte aB : b) {
result += Integer.toString((aB & 0xff) + 0x100, 16).substring(1);
}
return result;
}

private String getSHA256Checksum() throws NoSuchAlgorithmException, IOException {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
byte[] input = new byte[GenericCopyUtil.DEFAULT_BUFFER_SIZE];
int length;
InputStream inputStream = inputStreamMd5;
while ((length = inputStream.read(input)) != -1) {
if (length > 0) messageDigest.update(input, 0, length);
}

byte[] hash = messageDigest.digest();

StringBuilder hexString = new StringBuilder();

for (byte aHash : hash) {
// convert hash to base 16
String hex = Integer.toHexString(0xff & aHash);
if (hex.length() == 1) hexString.append('0');
hexString.append(hex);
}
inputStream.close();
return hexString.toString();
}

private byte[] createChecksum() throws Exception {
InputStream fis = inputStreamSha;

byte[] buffer = new byte[8192];
MessageDigest complete = MessageDigest.getInstance("MD5");
int numRead;

do {
numRead = fis.read(buffer);
if (numRead > 0) {
complete.update(buffer, 0, numRead);
}
} while (numRead != -1);

fis.close();
return complete.digest();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import android.widget.TextView
import android.widget.Toast
import com.amaze.filemanager.R
import com.amaze.filemanager.asynchronous.asynctasks.Task
import com.amaze.filemanager.file_operations.filesystem.filetypes.AmazeFile
import com.amaze.filemanager.file_operations.filesystem.filetypes.ContextProvider
import com.amaze.filemanager.filesystem.HybridFileParcelable
import com.amaze.filemanager.filesystem.files.FileUtils
import java.lang.ref.WeakReference
Expand All @@ -37,7 +39,7 @@ import java.util.concurrent.Callable
data class Hash(val md5: String, val sha: String)

class CalculateHashTask(
private val file: HybridFileParcelable,
private val file: AmazeFile,
context: Context,
view: View
) : Task<Hash, Callable<Hash>> {
Expand All @@ -46,11 +48,7 @@ class CalculateHashTask(
private val TAG = CalculateHashTask::class.java.simpleName
}

private val task: Callable<Hash> = if (file.isSftp) {
CalculateHashSftpCallback(file)
} else {
CalculateHashCallback(file, context)
}
private val task: Callable<Hash> = CalculateHashCallback(file, context)

private val context = WeakReference(context)
private val view = WeakReference(view)
Expand Down Expand Up @@ -82,7 +80,11 @@ class CalculateHashTask(
val mMD5LinearLayout = view.findViewById<LinearLayout>(R.id.properties_dialog_md5)
val mSHA256LinearLayout = view.findViewById<LinearLayout>(R.id.properties_dialog_sha256)

if (!file.isDirectory(context) && file.getSize() != 0L) {
val contextProvider = object : ContextProvider {
override fun getContext(): Context? = context
}

if (!file.isDirectory(contextProvider) && file.safeLength(contextProvider) != 0L) {
md5HashText.text = md5Text
sha256Text.text = shaText
mMD5LinearLayout.setOnLongClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private MoveFilesReturn processFile(
case GDRIVE:
DataUtils dataUtils = DataUtils.getInstance();

CloudStorage cloudStorage = dataUtils.getAccount(mode);
CloudStorage cloudStorage = dataUtils.getAccount(mode).getAccount();
if (baseFile.getMode() == mode) {
// source and target both in same filesystem, use API method
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import com.amaze.filemanager.database.models.explorer.CloudEntry;
import com.amaze.filemanager.file_operations.exceptions.CloudPluginException;
import com.amaze.filemanager.file_operations.filesystem.OpenMode;
import com.amaze.filemanager.file_operations.filesystem.filetypes.cloud.box.BoxAmazeFilesystem;
import com.amaze.filemanager.file_operations.filesystem.filetypes.cloud.dropbox.DropboxAmazeFilesystem;
import com.amaze.filemanager.file_operations.filesystem.filetypes.cloud.gdrive.GoogledriveAmazeFilesystem;
import com.amaze.filemanager.file_operations.filesystem.filetypes.cloud.onedrive.OnedriveAmazeFilesystem;
import com.amaze.filemanager.ui.fragments.CloudSheetFragment;

import android.content.Context;
Expand All @@ -37,10 +41,10 @@
/** Created by vishal on 18/4/17. */
public class CloudHandler {

public static final String CLOUD_PREFIX_BOX = "box:/";
public static final String CLOUD_PREFIX_DROPBOX = "dropbox:/";
public static final String CLOUD_PREFIX_GOOGLE_DRIVE = "gdrive:/";
public static final String CLOUD_PREFIX_ONE_DRIVE = "onedrive:/";
public static final String CLOUD_PREFIX_BOX = BoxAmazeFilesystem.PREFIX;
public static final String CLOUD_PREFIX_DROPBOX = DropboxAmazeFilesystem.PREFIX;
public static final String CLOUD_PREFIX_GOOGLE_DRIVE = GoogledriveAmazeFilesystem.PREFIX;
public static final String CLOUD_PREFIX_ONE_DRIVE = OnedriveAmazeFilesystem.PREFIX;

public static final String CLOUD_NAME_GOOGLE_DRIVE = "Google Drive™";
public static final String CLOUD_NAME_DROPBOX = "Dropbox";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import android.provider.MediaStore
import android.util.Log
import java.io.File

@Deprecated("Use AmazeFile.delete()")
object DeleteOperation {
private val LOG = "DeleteFileOperation"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import android.net.Uri
import android.os.Build
import android.util.Log
import androidx.documentfile.provider.DocumentFile
import androidx.preference.PreferenceManager
import com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants
import com.amaze.filemanager.file_operations.filesystem.filetypes.file.UriForSafPersistance
import java.io.File
import java.io.IOException
import java.util.*

@Deprecated("Use [com.amaze.filemanager.file_operations.filesystem.filetypes.file.ExternalSdCardOperation]")
object ExternalSdCardOperation {
val LOG = "ExternalSdCardOperation"

Expand Down Expand Up @@ -67,8 +67,7 @@ object ExternalSdCardOperation {
return null
}

val preferenceUri = PreferenceManager.getDefaultSharedPreferences(context)
.getString(PreferencesConstants.PREFERENCE_URI, null)
val preferenceUri = UriForSafPersistance.get(context)
var treeUri: Uri? = null
if (preferenceUri != null) {
treeUri = Uri.parse(preferenceUri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static final void writeUriToStorage(
case GDRIVE:
OpenMode mode = hFile.getMode();

CloudStorage cloudStorage = dataUtils.getAccount(mode);
CloudStorage cloudStorage = dataUtils.getAccount(mode).getAccount();
String path = CloudUtil.stripPath(mode, finalFilePath);
cloudStorage.upload(path, bufferedInputStream, documentFile.length(), true);
retval.add(path);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.amaze.filemanager.filesystem

import com.amaze.filemanager.file_operations.filesystem.filetypes.AmazeFile
import com.amaze.filemanager.file_operations.filesystem.filetypes.smb.SmbAmazeFilesystem
import com.amaze.filemanager.filesystem.files.FileAmazeFilesystem
import com.amaze.filemanager.filesystem.otg.OtgAmazeFilesystem
import com.amaze.filemanager.filesystem.ssh.SshAmazeFilesystem

/**
* TODO remove this by moving all Filesystem subclasses to file_operations
*/
object FilesystemLoader {
init {
AmazeFile //Loads all of the file_operations Filesystem subclasses
FileAmazeFilesystem
OtgAmazeFilesystem
SmbAmazeFilesystem
SshAmazeFilesystem.INSTANCE
}
}