Search in sources :

Example 1 with CloudPluginException

use of com.amaze.filemanager.file_operations.exceptions.CloudPluginException in project AmazeFileManager by TeamAmaze.

the class CloudUtil method getCloudFiles.

public static void getCloudFiles(String path, CloudStorage cloudStorage, OpenMode openMode, OnFileFound fileFoundCallback) throws CloudPluginException {
    String strippedPath = stripPath(openMode, path);
    try {
        for (CloudMetaData cloudMetaData : cloudStorage.getChildren(strippedPath)) {
            HybridFileParcelable baseFile = new HybridFileParcelable(path + "/" + cloudMetaData.getName(), "", (cloudMetaData.getModifiedAt() == null) ? 0l : cloudMetaData.getModifiedAt(), cloudMetaData.getSize(), cloudMetaData.getFolder());
            baseFile.setName(cloudMetaData.getName());
            baseFile.setMode(openMode);
            fileFoundCallback.onFileFound(baseFile);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new CloudPluginException();
    }
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) CloudPluginException(com.amaze.filemanager.file_operations.exceptions.CloudPluginException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ActivityNotFoundException(android.content.ActivityNotFoundException) CloudPluginException(com.amaze.filemanager.file_operations.exceptions.CloudPluginException) CloudMetaData(com.cloudrail.si.types.CloudMetaData)

Example 2 with CloudPluginException

use of com.amaze.filemanager.file_operations.exceptions.CloudPluginException in project AmazeFileManager by TeamAmaze.

the class HybridFile method forEachChildrenFile.

/**
 * Helper method to list children of this file
 */
public void forEachChildrenFile(Context context, boolean isRoot, OnFileFound onFileFound) {
    switch(mode) {
        case SFTP:
            SshClientUtils.<Boolean>execute(new SFtpClientTemplate<Boolean>(path) {

                @Override
                public Boolean execute(SFTPClient client) {
                    try {
                        for (RemoteResourceInfo info : client.ls(SshClientUtils.extractRemotePathFrom(path))) {
                            boolean isDirectory = false;
                            try {
                                isDirectory = SshClientUtils.isDirectory(client, info);
                            } catch (IOException ifBrokenSymlink) {
                                Log.w(TAG, "IOException checking isDirectory(): " + info.getPath());
                                continue;
                            }
                            HybridFileParcelable f = new HybridFileParcelable(path, isDirectory, info);
                            onFileFound.onFileFound(f);
                        }
                    } catch (IOException e) {
                        Log.w("DEBUG.listFiles", "IOException", e);
                        AppConfig.toast(context, context.getString(R.string.cannot_read_directory, parseAndFormatUriForDisplay(path), e.getMessage()));
                    }
                    return true;
                }
            });
            break;
        case SMB:
            try {
                SmbFile smbFile = getSmbFile();
                if (smbFile != null) {
                    for (SmbFile smbFile1 : smbFile.listFiles()) {
                        HybridFileParcelable baseFile;
                        try {
                            SmbFile sf = new SmbFile(smbFile1.getURL(), smbFile.getContext());
                            baseFile = new HybridFileParcelable(sf);
                        } catch (MalformedURLException shouldNeverHappen) {
                            shouldNeverHappen.printStackTrace();
                            baseFile = new HybridFileParcelable(smbFile1);
                        }
                        onFileFound.onFileFound(baseFile);
                    }
                }
            } catch (SmbException e) {
                e.printStackTrace();
            }
            break;
        case OTG:
            OTGUtil.getDocumentFiles(path, context, onFileFound);
            break;
        case DOCUMENT_FILE:
            OTGUtil.getDocumentFiles(SafRootHolder.getUriRoot(), path, context, OpenMode.DOCUMENT_FILE, onFileFound);
            break;
        case DROPBOX:
        case BOX:
        case GDRIVE:
        case ONEDRIVE:
            try {
                CloudUtil.getCloudFiles(path, dataUtils.getAccount(mode), mode, onFileFound);
            } catch (CloudPluginException e) {
                e.printStackTrace();
            }
            break;
        default:
            ListFilesCommand.INSTANCE.listFiles(path, isRoot, true, openMode -> null, hybridFileParcelable -> {
                onFileFound.onFileFound(hybridFileParcelable);
                return null;
            });
    }
}
Also used : SmbException(jcifs.smb.SmbException) CloudPluginException(com.amaze.filemanager.file_operations.exceptions.CloudPluginException) MalformedURLException(java.net.MalformedURLException) SFTPClient(net.schmizz.sshj.sftp.SFTPClient) RemoteResourceInfo(net.schmizz.sshj.sftp.RemoteResourceInfo) IOException(java.io.IOException) SmbFile(jcifs.smb.SmbFile)

Example 3 with CloudPluginException

use of com.amaze.filemanager.file_operations.exceptions.CloudPluginException in project AmazeFileManager by TeamAmaze.

the class MainActivity method onCreateLoader.

@NonNull
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Uri uri = Uri.withAppendedPath(Uri.parse("content://" + CloudContract.PROVIDER_AUTHORITY), "/keys.db/secret_keys");
    String[] projection = new String[] { CloudContract.COLUMN_ID, CloudContract.COLUMN_CLIENT_ID, CloudContract.COLUMN_CLIENT_SECRET_KEY };
    switch(id) {
        case REQUEST_CODE_CLOUD_LIST_KEY:
            Uri uriAppendedPath = uri;
            switch(OpenMode.getOpenMode(args.getInt(ARGS_KEY_LOADER, 2))) {
                case GDRIVE:
                    uriAppendedPath = ContentUris.withAppendedId(uri, 2);
                    break;
                case DROPBOX:
                    uriAppendedPath = ContentUris.withAppendedId(uri, 3);
                    break;
                case BOX:
                    uriAppendedPath = ContentUris.withAppendedId(uri, 4);
                    break;
                case ONEDRIVE:
                    uriAppendedPath = ContentUris.withAppendedId(uri, 5);
                    break;
            }
            return new CursorLoader(this, uriAppendedPath, projection, null, null, null);
        case REQUEST_CODE_CLOUD_LIST_KEYS:
            try {
                List<CloudEntry> cloudEntries = cloudHandler.getAllEntries();
                // we want keys for services saved in database, and the cloudrail app key which
                // is at index 1
                String[] ids = new String[cloudEntries.size() + 1];
                ids[0] = 1 + "";
                for (int i = 1; i <= cloudEntries.size(); i++) {
                    // we need to get only those cloud details which user wants
                    switch(cloudEntries.get(i - 1).getServiceType()) {
                        case GDRIVE:
                            ids[i] = 2 + "";
                            break;
                        case DROPBOX:
                            ids[i] = 3 + "";
                            break;
                        case BOX:
                            ids[i] = 4 + "";
                            break;
                        case ONEDRIVE:
                            ids[i] = 5 + "";
                            break;
                    }
                }
                return new CursorLoader(this, uri, projection, CloudContract.COLUMN_ID, ids, null);
            } catch (CloudPluginException e) {
                e.printStackTrace();
                Toast.makeText(this, getResources().getString(R.string.cloud_error_plugin), Toast.LENGTH_LONG).show();
            }
        default:
            Uri undefinedUriAppendedPath = ContentUris.withAppendedId(uri, 7);
            return new CursorLoader(this, undefinedUriAppendedPath, projection, null, null, null);
    }
}
Also used : CursorLoader(androidx.loader.content.CursorLoader) CloudPluginException(com.amaze.filemanager.file_operations.exceptions.CloudPluginException) CloudEntry(com.amaze.filemanager.database.models.explorer.CloudEntry) Uri(android.net.Uri) NonNull(androidx.annotation.NonNull)

Example 4 with CloudPluginException

use of com.amaze.filemanager.file_operations.exceptions.CloudPluginException in project AmazeFileManager by TeamAmaze.

the class MainActivity method addConnection.

@Override
public void addConnection(OpenMode service) {
    try {
        if (cloudHandler.findEntry(service) != null) {
            // cloud entry already exists
            Toast.makeText(this, getResources().getString(R.string.connection_exists), Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(MainActivity.this, getResources().getString(R.string.please_wait), Toast.LENGTH_LONG).show();
            Bundle args = new Bundle();
            args.putInt(ARGS_KEY_LOADER, service.ordinal());
            // check if we already had done some work on the loader
            Loader loader = getSupportLoaderManager().getLoader(REQUEST_CODE_CLOUD_LIST_KEY);
            if (loader != null && loader.isStarted()) {
                // making sure that loader is not started
                getSupportLoaderManager().destroyLoader(REQUEST_CODE_CLOUD_LIST_KEY);
            }
            getSupportLoaderManager().initLoader(REQUEST_CODE_CLOUD_LIST_KEY, args, this);
        }
    } catch (CloudPluginException e) {
        e.printStackTrace();
        Toast.makeText(this, getResources().getString(R.string.cloud_error_plugin), Toast.LENGTH_LONG).show();
    }
}
Also used : CloudPluginException(com.amaze.filemanager.file_operations.exceptions.CloudPluginException) Bundle(android.os.Bundle) CursorLoader(androidx.loader.content.CursorLoader) Loader(androidx.loader.content.Loader)

Example 5 with CloudPluginException

use of com.amaze.filemanager.file_operations.exceptions.CloudPluginException in project AmazeFileManager by TeamAmaze.

the class HybridFile method listFiles.

/**
 * Helper method to list children of this file
 *
 * @deprecated use forEachChildrenFile()
 */
public ArrayList<HybridFileParcelable> listFiles(Context context, boolean isRoot) {
    ArrayList<HybridFileParcelable> arrayList = new ArrayList<>();
    switch(mode) {
        case SFTP:
            arrayList = SshClientUtils.execute(new SFtpClientTemplate<ArrayList<HybridFileParcelable>>(path) {

                @Override
                public ArrayList<HybridFileParcelable> execute(SFTPClient client) {
                    ArrayList<HybridFileParcelable> retval = new ArrayList<>();
                    try {
                        for (RemoteResourceInfo info : client.ls(SshClientUtils.extractRemotePathFrom(path))) {
                            boolean isDirectory = false;
                            try {
                                isDirectory = SshClientUtils.isDirectory(client, info);
                            } catch (IOException ifBrokenSymlink) {
                                Log.w(TAG, "IOException checking isDirectory(): " + info.getPath());
                                continue;
                            }
                            HybridFileParcelable f = new HybridFileParcelable(path, isDirectory, info);
                            retval.add(f);
                        }
                    } catch (IOException e) {
                        Log.w("DEBUG.listFiles", "IOException", e);
                    }
                    return retval;
                }
            });
            break;
        case SMB:
            try {
                SmbFile smbFile = getSmbFile();
                if (smbFile != null) {
                    for (SmbFile smbFile1 : smbFile.listFiles()) {
                        HybridFileParcelable baseFile = new HybridFileParcelable(smbFile1);
                        arrayList.add(baseFile);
                    }
                }
            } catch (SmbException e) {
                arrayList.clear();
                e.printStackTrace();
            }
            break;
        case OTG:
            arrayList = OTGUtil.getDocumentFilesList(path, context);
            break;
        case DOCUMENT_FILE:
            final ArrayList<HybridFileParcelable> hybridFileParcelables = new ArrayList<>();
            OTGUtil.getDocumentFiles(SafRootHolder.getUriRoot(), path, context, OpenMode.DOCUMENT_FILE, file -> hybridFileParcelables.add(file));
            arrayList = hybridFileParcelables;
            break;
        case DROPBOX:
        case BOX:
        case GDRIVE:
        case ONEDRIVE:
            try {
                arrayList = CloudUtil.listFiles(path, dataUtils.getAccount(mode), mode);
            } catch (CloudPluginException e) {
                e.printStackTrace();
                arrayList = new ArrayList<>();
            }
            break;
        default:
            arrayList = RootHelper.getFilesList(path, isRoot, true);
    }
    return arrayList;
}
Also used : SmbException(jcifs.smb.SmbException) SFtpClientTemplate(com.amaze.filemanager.filesystem.ssh.SFtpClientTemplate) CloudPluginException(com.amaze.filemanager.file_operations.exceptions.CloudPluginException) ArrayList(java.util.ArrayList) SFTPClient(net.schmizz.sshj.sftp.SFTPClient) RemoteResourceInfo(net.schmizz.sshj.sftp.RemoteResourceInfo) IOException(java.io.IOException) SmbFile(jcifs.smb.SmbFile)

Aggregations

CloudPluginException (com.amaze.filemanager.file_operations.exceptions.CloudPluginException)8 IOException (java.io.IOException)3 SmbException (jcifs.smb.SmbException)3 SmbFile (jcifs.smb.SmbFile)3 Context (android.content.Context)2 NonNull (androidx.annotation.NonNull)2 CursorLoader (androidx.loader.content.CursorLoader)2 CloudEntry (com.amaze.filemanager.database.models.explorer.CloudEntry)2 CloudStorage (com.cloudrail.si.interfaces.CloudStorage)2 ArrayList (java.util.ArrayList)2 RemoteResourceInfo (net.schmizz.sshj.sftp.RemoteResourceInfo)2 SFTPClient (net.schmizz.sshj.sftp.SFTPClient)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 Nullable (androidx.annotation.Nullable)1 Pair (androidx.core.util.Pair)1 Loader (androidx.loader.content.Loader)1 LayoutElementParcelable (com.amaze.filemanager.adapters.data.LayoutElementParcelable)1 OpenMode (com.amaze.filemanager.file_operations.filesystem.OpenMode)1