Search in sources :

Example 6 with CryptHandler

use of com.amaze.filemanager.database.CryptHandler in project AmazeFileManager by TeamAmaze.

the class MainFragment method findEncryptedEntry.

/**
 * Queries database to find entry for the specific path
 *
 * @param path the path to match with
 * @return the entry
 */
private static EncryptedEntry findEncryptedEntry(Context context, String path) throws Exception {
    CryptHandler handler = new CryptHandler(context);
    EncryptedEntry matchedEntry = null;
    // find closest path which matches with database entry
    for (EncryptedEntry encryptedEntry : handler.getAllEntries()) {
        if (path.contains(encryptedEntry.getPath())) {
            if (matchedEntry == null || matchedEntry.getPath().length() < encryptedEntry.getPath().length()) {
                matchedEntry = encryptedEntry;
            }
        }
    }
    return matchedEntry;
}
Also used : CryptHandler(com.amaze.filemanager.database.CryptHandler) EncryptedEntry(com.amaze.filemanager.database.models.EncryptedEntry)

Example 7 with CryptHandler

use of com.amaze.filemanager.database.CryptHandler in project AmazeFileManager by TeamAmaze.

the class MainActivityHelper method rename.

public void rename(OpenMode mode, final String oldPath, final String newPath, final Activity context, boolean rootmode) {
    final Toast toast = Toast.makeText(context, context.getString(R.string.renaming), Toast.LENGTH_SHORT);
    toast.show();
    Operations.rename(new HybridFile(mode, oldPath), new HybridFile(mode, newPath), rootmode, context, new Operations.ErrorCallBack() {

        @Override
        public void exists(HybridFile file) {
            context.runOnUiThread(() -> {
                if (toast != null)
                    toast.cancel();
                Toast.makeText(mainActivity, context.getString(R.string.fileexist), Toast.LENGTH_SHORT).show();
            });
        }

        @Override
        public void launchSAF(HybridFile file) {
        }

        @Override
        public void launchSAF(final HybridFile file, final HybridFile file1) {
            context.runOnUiThread(() -> {
                if (toast != null)
                    toast.cancel();
                mainActivity.oppathe = file.getPath();
                mainActivity.oppathe1 = file1.getPath();
                mainActivity.operation = DataUtils.RENAME;
                guideDialogForLEXA(mainActivity.oppathe1);
            });
        }

        @Override
        public void done(final HybridFile hFile, final boolean b) {
            context.runOnUiThread(() -> {
                if (b) {
                    Intent intent = new Intent(MainActivity.KEY_INTENT_LOAD_LIST);
                    intent.putExtra(MainActivity.KEY_INTENT_LOAD_LIST_FILE, hFile.getParent(context));
                    mainActivity.sendBroadcast(intent);
                    // update the database entry to reflect rename for encrypted file
                    if (oldPath.endsWith(CryptUtil.CRYPT_EXTENSION)) {
                        try {
                            CryptHandler cryptHandler = new CryptHandler(context);
                            EncryptedEntry oldEntry = cryptHandler.findEntry(oldPath);
                            EncryptedEntry newEntry = new EncryptedEntry();
                            newEntry.setId(oldEntry.getId());
                            newEntry.setPassword(oldEntry.getPassword());
                            newEntry.setPath(newPath);
                            cryptHandler.updateEntry(oldEntry, newEntry);
                        } catch (Exception e) {
                            e.printStackTrace();
                        // couldn't change the entry, leave it alone
                        }
                    }
                } else
                    Toast.makeText(context, context.getString(R.string.operationunsuccesful), Toast.LENGTH_SHORT).show();
            });
        }

        @Override
        public void invalidName(final HybridFile file) {
            context.runOnUiThread(() -> {
                if (toast != null)
                    toast.cancel();
                Toast.makeText(context, context.getString(R.string.invalid_name) + ": " + file.getName(), Toast.LENGTH_LONG).show();
            });
        }
    });
}
Also used : HybridFile(com.amaze.filemanager.filesystem.HybridFile) Toast(android.widget.Toast) CryptHandler(com.amaze.filemanager.database.CryptHandler) EncryptedEntry(com.amaze.filemanager.database.models.EncryptedEntry) Intent(android.content.Intent) Operations(com.amaze.filemanager.filesystem.Operations)

Aggregations

CryptHandler (com.amaze.filemanager.database.CryptHandler)7 EncryptedEntry (com.amaze.filemanager.database.models.EncryptedEntry)5 Intent (android.content.Intent)2 ShellNotRunningException (com.amaze.filemanager.exceptions.ShellNotRunningException)2 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)2 DocumentFile (android.support.v4.provider.DocumentFile)1 Toast (android.widget.Toast)1 HybridFile (com.amaze.filemanager.filesystem.HybridFile)1 Operations (com.amaze.filemanager.filesystem.Operations)1 CloudStorage (com.cloudrail.si.interfaces.CloudStorage)1 MalformedURLException (java.net.MalformedURLException)1 SmbException (jcifs.smb.SmbException)1