Search in sources :

Example 6 with ShellNotRunningException

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;
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) CloudStorage(com.cloudrail.si.interfaces.CloudStorage) DocumentFile(android.support.v4.provider.DocumentFile) CryptHandler(com.amaze.filemanager.database.CryptHandler) ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException) ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException)

Example 7 with ShellNotRunningException

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;
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) SmbException(jcifs.smb.SmbException) CloudStorage(com.cloudrail.si.interfaces.CloudStorage) MalformedURLException(java.net.MalformedURLException) ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException) DataUtils(com.amaze.filemanager.utils.DataUtils) File(java.io.File) SmbFile(jcifs.smb.SmbFile) ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException) SmbException(jcifs.smb.SmbException) MalformedURLException(java.net.MalformedURLException) SmbFile(jcifs.smb.SmbFile)

Example 8 with ShellNotRunningException

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();
}
Also used : ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException) File(java.io.File) ArrayAdapter(android.widget.ArrayAdapter) ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException)

Example 9 with ShellNotRunningException

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);
}
Also used : InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException) BufferedReader(java.io.BufferedReader) StreamNotFoundException(com.amaze.filemanager.exceptions.StreamNotFoundException) File(java.io.File)

Example 10 with ShellNotRunningException

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();
        }
    });
}
Also used : CheckBox(android.widget.CheckBox) ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException) SpannableString(android.text.SpannableString)

Aggregations

ShellNotRunningException (com.amaze.filemanager.exceptions.ShellNotRunningException)14 File (java.io.File)9 DocumentFile (android.support.v4.provider.DocumentFile)7 CloudStorage (com.cloudrail.si.interfaces.CloudStorage)6 IOException (java.io.IOException)5 SmbException (jcifs.smb.SmbException)5 SmbFile (jcifs.smb.SmbFile)5 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)4 DataUtils (com.amaze.filemanager.utils.DataUtils)4 MalformedURLException (java.net.MalformedURLException)4 StreamNotFoundException (com.amaze.filemanager.exceptions.StreamNotFoundException)2 SFtpClientTemplate (com.amaze.filemanager.filesystem.ssh.SFtpClientTemplate)2 FileNotFoundException (java.io.FileNotFoundException)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 SFTPClient (net.schmizz.sshj.sftp.SFTPClient)2 Context (android.content.Context)1 SpannableString (android.text.SpannableString)1 ArrayAdapter (android.widget.ArrayAdapter)1 CheckBox (android.widget.CheckBox)1