use of com.amaze.filemanager.exceptions.ShellNotRunningException in project AmazeFileManager by TeamAmaze.
the class DeleteTask method doInBackground.
protected Boolean doInBackground(ArrayList<HybridFileParcelable>... p1) {
files = p1[0];
boolean wasDeleted = true;
if (files.size() == 0)
return true;
if (files.get(0).isOtgFile()) {
for (HybridFileParcelable file : files) {
DocumentFile documentFile = OTGUtil.getDocumentFile(file.getPath(), cd, false);
wasDeleted = documentFile.delete();
}
} else if (files.get(0).isDropBoxFile()) {
CloudStorage cloudStorageDropbox = dataUtils.getAccount(OpenMode.DROPBOX);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageDropbox.delete(CloudUtil.stripPath(OpenMode.DROPBOX, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else if (files.get(0).isBoxFile()) {
CloudStorage cloudStorageBox = dataUtils.getAccount(OpenMode.BOX);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageBox.delete(CloudUtil.stripPath(OpenMode.BOX, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else if (files.get(0).isGoogleDriveFile()) {
CloudStorage cloudStorageGdrive = dataUtils.getAccount(OpenMode.GDRIVE);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageGdrive.delete(CloudUtil.stripPath(OpenMode.GDRIVE, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else if (files.get(0).isOneDriveFile()) {
CloudStorage cloudStorageOnedrive = dataUtils.getAccount(OpenMode.ONEDRIVE);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageOnedrive.delete(CloudUtil.stripPath(OpenMode.ONEDRIVE, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else {
for (HybridFileParcelable file : files) {
try {
if (file.delete(cd, rootMode)) {
wasDeleted = true;
} else {
wasDeleted = false;
break;
}
} catch (ShellNotRunningException e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
}
// delete file from media database
if (!files.get(0).isSmb()) {
try {
for (HybridFileParcelable f : files) {
delete(cd, f.getPath());
}
} catch (Exception e) {
for (HybridFileParcelable f : files) {
FileUtils.scanFile(f.getPath(), cd);
}
}
}
// delete file entry from encrypted database
for (HybridFileParcelable file : files) {
if (file.getName().endsWith(CryptUtil.CRYPT_EXTENSION)) {
CryptHandler handler = new CryptHandler(cd);
handler.clear(file.getPath());
}
}
return wasDeleted;
}
use of com.amaze.filemanager.exceptions.ShellNotRunningException in project AmazeFileManager by TeamAmaze.
the class MoveFiles method doInBackground.
@Override
protected Boolean doInBackground(ArrayList<String>... strings) {
paths = strings[0];
if (files.size() == 0)
return true;
switch(mode) {
case SMB:
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable f : files.get(i)) {
try {
SmbFile source = new SmbFile(f.getPath());
SmbFile dest = new SmbFile(paths.get(i) + "/" + f.getName());
source.renameTo(dest);
} catch (MalformedURLException e) {
e.printStackTrace();
return false;
} catch (SmbException e) {
e.printStackTrace();
return false;
}
}
}
break;
case FILE:
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable f : files.get(i)) {
File dest = new File(paths.get(i) + "/" + f.getName());
File source = new File(f.getPath());
if (!source.renameTo(dest)) {
// check if we have root
if (mainFrag.getMainActivity().isRootExplorer()) {
try {
if (!RootUtils.rename(f.getPath(), paths.get(i) + "/" + f.getName()))
return false;
} catch (ShellNotRunningException e) {
e.printStackTrace();
return false;
}
} else
return false;
}
}
}
break;
case DROPBOX:
case BOX:
case ONEDRIVE:
case GDRIVE:
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable baseFile : files.get(i)) {
DataUtils dataUtils = DataUtils.getInstance();
CloudStorage cloudStorage = dataUtils.getAccount(mode);
String targetPath = paths.get(i) + "/" + baseFile.getName();
if (baseFile.getMode() == mode) {
// source and target both in same filesystem, use API method
try {
cloudStorage.move(CloudUtil.stripPath(mode, baseFile.getPath()), CloudUtil.stripPath(mode, targetPath));
} catch (Exception e) {
return false;
}
} else {
// not in same filesystem, execute service
return false;
}
}
}
default:
return false;
}
return true;
}
use of com.amaze.filemanager.exceptions.ShellNotRunningException in project AmazeFileManager by TeamAmaze.
the class DatabaseViewerActivity method load.
private void load(final File file) {
new Thread(() -> {
File file1 = getExternalCacheDir();
// first copying it in cache dir
if (!file.canRead() && isRootExplorer()) {
try {
RootUtils.copy(pathFile.getPath(), new File(file1.getPath(), file.getName()).getPath());
pathFile = new File(file1.getPath(), file.getName());
} catch (ShellNotRunningException e) {
e.printStackTrace();
}
delete = true;
}
try {
sqLiteDatabase = SQLiteDatabase.openDatabase(pathFile.getPath(), null, SQLiteDatabase.OPEN_READONLY);
c = sqLiteDatabase.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
arrayList = getDbTableNames(c);
arrayAdapter = new ArrayAdapter(DatabaseViewerActivity.this, android.R.layout.simple_list_item_1, arrayList);
} catch (Exception e) {
e.printStackTrace();
finish();
}
runOnUiThread(() -> {
listView.setAdapter(arrayAdapter);
});
}).start();
}
use of com.amaze.filemanager.exceptions.ShellNotRunningException in project AmazeFileManager by TeamAmaze.
the class ReadFileTask method doInBackground.
@Override
protected ReturnedValues doInBackground(Void... params) {
StringBuilder stringBuilder = new StringBuilder();
try {
InputStream inputStream = null;
switch(fileAbstraction.scheme) {
case EditableFileAbstraction.SCHEME_CONTENT:
if (fileAbstraction.uri == null)
throw new NullPointerException("Something went really wrong!");
inputStream = contentResolver.openInputStream(fileAbstraction.uri);
break;
case EditableFileAbstraction.SCHEME_FILE:
final HybridFileParcelable hybridFileParcelable = fileAbstraction.hybridFileParcelable;
if (hybridFileParcelable == null)
throw new NullPointerException("Something went really wrong!");
File file = hybridFileParcelable.getFile();
if (!file.canWrite() && isRootExplorer) {
// try loading stream associated using root
try {
cachedFile = new File(externalCacheDir, hybridFileParcelable.getName());
// creating a cache file
RootUtils.copy(hybridFileParcelable.getPath(), cachedFile.getPath());
inputStream = new FileInputStream(cachedFile);
} catch (ShellNotRunningException e) {
e.printStackTrace();
inputStream = null;
} catch (FileNotFoundException e) {
e.printStackTrace();
inputStream = null;
}
} else if (file.canRead()) {
// readable file in filesystem
try {
inputStream = new FileInputStream(hybridFileParcelable.getPath());
} catch (FileNotFoundException e) {
inputStream = null;
}
}
break;
default:
throw new IllegalArgumentException("The scheme for '" + fileAbstraction.scheme + "' cannot be processed!");
}
if (inputStream == null)
throw new StreamNotFoundException();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String buffer;
while ((buffer = bufferedReader.readLine()) != null) {
stringBuilder.append(buffer).append("\n");
}
inputStream.close();
bufferedReader.close();
} catch (StreamNotFoundException e) {
e.printStackTrace();
return new ReturnedValues(EXCEPTION_STREAM_NOT_FOUND);
} catch (IOException e) {
e.printStackTrace();
return new ReturnedValues(EXCEPTION_IO);
}
return new ReturnedValues(stringBuilder.toString(), cachedFile);
}
use of com.amaze.filemanager.exceptions.ShellNotRunningException in project AmazeFileManager by TeamAmaze.
the class GeneralDialogCreation method setPermissionsDialog.
public static void setPermissionsDialog(final View v, View but, final HybridFile file, final String f, final Context context, final MainFragment mainFrag) {
final CheckBox readown = (CheckBox) v.findViewById(R.id.creadown);
final CheckBox readgroup = (CheckBox) v.findViewById(R.id.creadgroup);
final CheckBox readother = (CheckBox) v.findViewById(R.id.creadother);
final CheckBox writeown = (CheckBox) v.findViewById(R.id.cwriteown);
final CheckBox writegroup = (CheckBox) v.findViewById(R.id.cwritegroup);
final CheckBox writeother = (CheckBox) v.findViewById(R.id.cwriteother);
final CheckBox exeown = (CheckBox) v.findViewById(R.id.cexeown);
final CheckBox exegroup = (CheckBox) v.findViewById(R.id.cexegroup);
final CheckBox exeother = (CheckBox) v.findViewById(R.id.cexeother);
String perm = f;
if (perm.length() < 6) {
v.setVisibility(View.GONE);
but.setVisibility(View.GONE);
Toast.makeText(context, R.string.not_allowed, Toast.LENGTH_SHORT).show();
return;
}
ArrayList<Boolean[]> arrayList = FileUtils.parse(perm);
Boolean[] read = arrayList.get(0);
Boolean[] write = arrayList.get(1);
final Boolean[] exe = arrayList.get(2);
readown.setChecked(read[0]);
readgroup.setChecked(read[1]);
readother.setChecked(read[2]);
writeown.setChecked(write[0]);
writegroup.setChecked(write[1]);
writeother.setChecked(write[2]);
exeown.setChecked(exe[0]);
exegroup.setChecked(exe[1]);
exeother.setChecked(exe[2]);
but.setOnClickListener(v1 -> {
int perms = RootUtils.permissionsToOctalString(readown.isChecked(), writeown.isChecked(), exeown.isChecked(), readgroup.isChecked(), writegroup.isChecked(), exegroup.isChecked(), readother.isChecked(), writeother.isChecked(), exeother.isChecked());
String options = !file.isDirectory(context) ? "-R" : "";
String command = String.format(RootUtils.CHMOD_COMMAND, options, perms, file.getPath());
try {
RootHelper.runShellCommand(command, (commandCode, exitCode, output) -> {
if (exitCode < 0) {
Toast.makeText(context, mainFrag.getString(R.string.operationunsuccesful), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, mainFrag.getResources().getString(R.string.done), Toast.LENGTH_LONG).show();
}
});
mainFrag.updateList();
} catch (ShellNotRunningException e1) {
Toast.makeText(context, mainFrag.getResources().getString(R.string.rootfailure), Toast.LENGTH_LONG).show();
e1.printStackTrace();
}
});
}
Aggregations