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);
}
}
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();
}
}
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;
}
}
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);
}
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();
}
}
Aggregations