Search in sources :

Example 1 with CloudPluginException

use of com.amaze.filemanager.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:
            try {
                SshClientUtils.execute(new SFtpClientTemplate(path) {

                    @Override
                    public Void execute(SFTPClient client) throws IOException {
                        try {
                            for (RemoteResourceInfo info : client.ls(SshClientUtils.extractRemotePathFrom(path))) {
                                HybridFileParcelable f = new HybridFileParcelable(String.format("%s/%s", path, info.getName()));
                                f.setName(info.getName());
                                f.setMode(OpenMode.SFTP);
                                f.setDirectory(info.isDirectory());
                                f.setDate(info.getAttributes().getMtime() * 1000);
                                f.setSize(f.isDirectory() ? 0 : info.getAttributes().getSize());
                                f.setPermission(Integer.toString(FilePermission.toMask(info.getAttributes().getPermissions()), 8));
                                onFileFound.onFileFound(f);
                            }
                        } catch (IOException e) {
                            Log.w("DEBUG.listFiles", "IOException", e);
                        }
                        return null;
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
            break;
        case SMB:
            try {
                SmbFile smbFile = new SmbFile(path);
                for (SmbFile smbFile1 : smbFile.listFiles()) {
                    HybridFileParcelable baseFile = new HybridFileParcelable(smbFile1.getPath());
                    baseFile.setName(smbFile1.getName());
                    baseFile.setMode(OpenMode.SMB);
                    baseFile.setDirectory(smbFile1.isDirectory());
                    baseFile.setDate(smbFile1.lastModified());
                    baseFile.setSize(baseFile.isDirectory() ? 0 : smbFile1.length());
                    onFileFound.onFileFound(baseFile);
                }
            } catch (MalformedURLException | SmbException e) {
                e.printStackTrace();
            }
            break;
        case OTG:
            OTGUtil.getDocumentFiles(path, context, 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:
            RootHelper.getFiles(path, isRoot, true, null, onFileFound);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) SFTPClient(net.schmizz.sshj.sftp.SFTPClient) RemoteResourceInfo(net.schmizz.sshj.sftp.RemoteResourceInfo) IOException(java.io.IOException) ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException) SmbException(jcifs.smb.SmbException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException) SFTPException(net.schmizz.sshj.sftp.SFTPException) SmbFile(jcifs.smb.SmbFile) SmbException(jcifs.smb.SmbException) SFtpClientTemplate(com.amaze.filemanager.filesystem.ssh.SFtpClientTemplate) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException)

Example 2 with CloudPluginException

use of com.amaze.filemanager.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.exceptions.CloudPluginException) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException) ActivityNotFoundException(android.content.ActivityNotFoundException) CloudMetaData(com.cloudrail.si.types.CloudMetaData)

Example 3 with CloudPluginException

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

the class MainActivity method onCreateLoader.

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (cloudSyncTask != null && cloudSyncTask.getStatus() == AsyncTask.Status.RUNNING) {
        cloudSyncTask.cancel(true);
    }
    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:
            return null;
    }
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException) CloudEntry(com.amaze.filemanager.database.models.CloudEntry) Uri(android.net.Uri)

Example 4 with CloudPluginException

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

the class CloudHandler method addEntry.

public void addEntry(CloudEntry cloudEntry) throws CloudPluginException {
    if (!CloudSheetFragment.isCloudProviderAvailable(context))
        throw new CloudPluginException();
    ContentValues contentValues = new ContentValues();
    // contentValues.put(COLUMN_ENCRYPTED_ID, encryptedEntry.getId());
    contentValues.put(COLUMN_CLOUD_SERVICE, cloudEntry.getServiceType().ordinal());
    try {
        contentValues.put(COLUMN_CLOUD_PERSIST, CryptUtil.encryptPassword(context, cloudEntry.getPersistData()));
    } catch (Exception e) {
        e.printStackTrace();
        // failed to encrypt, revert back to plain
        contentValues.put(COLUMN_CLOUD_PERSIST, cloudEntry.getPersistData());
    }
    SQLiteDatabase sqLiteDatabase = getWritableDatabase();
    sqLiteDatabase.insert(TABLE_CLOUD_PERSIST, null, contentValues);
}
Also used : ContentValues(android.content.ContentValues) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException)

Example 5 with CloudPluginException

use of com.amaze.filemanager.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.exceptions.CloudPluginException) Bundle(android.os.Bundle) CursorLoader(android.support.v4.content.CursorLoader) Loader(android.support.v4.content.Loader)

Aggregations

CloudPluginException (com.amaze.filemanager.exceptions.CloudPluginException)11 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 CloudEntry (com.amaze.filemanager.database.models.CloudEntry)4 SmbException (jcifs.smb.SmbException)3 SmbFile (jcifs.smb.SmbFile)3 ContentValues (android.content.ContentValues)2 Cursor (android.database.Cursor)2 CursorLoader (android.support.v4.content.CursorLoader)2 ShellNotRunningException (com.amaze.filemanager.exceptions.ShellNotRunningException)2 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)2 SFtpClientTemplate (com.amaze.filemanager.filesystem.ssh.SFtpClientTemplate)2 CloudStorage (com.cloudrail.si.interfaces.CloudStorage)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 RemoteResourceInfo (net.schmizz.sshj.sftp.RemoteResourceInfo)2 SFTPClient (net.schmizz.sshj.sftp.SFTPClient)2 SFTPException (net.schmizz.sshj.sftp.SFTPException)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1