Search in sources :

Example 1 with OperationData

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

the class UtilsHandler method addCommonBookmarks.

public void addCommonBookmarks() {
    File sd = Environment.getExternalStorageDirectory();
    String[] dirs = new String[] { new File(sd, Environment.DIRECTORY_DCIM).getAbsolutePath(), new File(sd, Environment.DIRECTORY_DOWNLOADS).getAbsolutePath(), new File(sd, Environment.DIRECTORY_MOVIES).getAbsolutePath(), new File(sd, Environment.DIRECTORY_MUSIC).getAbsolutePath(), new File(sd, Environment.DIRECTORY_PICTURES).getAbsolutePath() };
    for (String dir : dirs) {
        saveToDatabase(new OperationData(Operation.BOOKMARKS, new File(dir).getName(), dir));
    }
}
Also used : OperationData(com.amaze.filemanager.database.models.OperationData) File(java.io.File)

Example 2 with OperationData

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

the class MainActivity method deleteConnection.

@Override
public void deleteConnection(final String name, final String path) {
    int i = dataUtils.containsServer(new String[] { name, path });
    if (i != -1) {
        dataUtils.removeServer(i);
        AppConfig.getInstance().runInBackground(() -> {
            utilsHandler.removeFromDatabase(new OperationData(UtilsHandler.Operation.SMB, name, path));
        });
        // grid.removePath(name, path, DataUtils.SMB);
        drawer.refreshDrawer();
    }
}
Also used : OperationData(com.amaze.filemanager.database.models.OperationData)

Example 3 with OperationData

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

the class MainActivity method addConnection.

@Override
public void addConnection(boolean edit, @NonNull final String name, @NonNull final String path, @Nullable final String encryptedPath, @Nullable final String oldname, @Nullable final String oldPath) {
    String[] s = new String[] { name, path };
    if (!edit) {
        if ((dataUtils.containsServer(path)) == -1) {
            dataUtils.addServer(s);
            drawer.refreshDrawer();
            utilsHandler.saveToDatabase(new OperationData(UtilsHandler.Operation.SMB, name, encryptedPath));
            // grid.addPath(name, encryptedPath, DataUtils.SMB, 1);
            executeWithMainFragment(mainFragment -> {
                mainFragment.loadlist(path, false, OpenMode.UNKNOWN);
                return null;
            }, true);
        } else {
            Snackbar.make(findViewById(R.id.navigation), getString(R.string.connection_exists), Snackbar.LENGTH_SHORT).show();
        }
    } else {
        int i = dataUtils.containsServer(new String[] { oldname, oldPath });
        if (i != -1) {
            dataUtils.removeServer(i);
            AppConfig.getInstance().runInBackground(() -> {
                utilsHandler.renameSMB(oldname, oldPath, name, path);
            });
        // mainActivity.grid.removePath(oldname, oldPath, DataUtils.SMB);
        }
        dataUtils.addServer(s);
        Collections.sort(dataUtils.getServers(), new BookSorter());
        drawer.refreshDrawer();
    // mainActivity.grid.addPath(name, encryptedPath, DataUtils.SMB, 1);
    }
}
Also used : OperationData(com.amaze.filemanager.database.models.OperationData) BookSorter(com.amaze.filemanager.utils.BookSorter)

Example 4 with OperationData

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

the class TestUtils method saveSshConnectionSettings.

public static void saveSshConnectionSettings(@NonNull KeyPair hostKeyPair, @NonNull String validUsername, @Nullable String validPassword, @Nullable PrivateKey privateKey) {
    UtilsHandler utilsHandler = AppConfig.getInstance().getUtilsHandler();
    String privateKeyContents = null;
    if (privateKey != null) {
        StringWriter writer = new StringWriter();
        JcaPEMWriter jw = new JcaPEMWriter(writer);
        try {
            jw.writeObject(privateKey);
            jw.flush();
            jw.close();
        } catch (IOException shallNeverHappen) {
        }
        privateKeyContents = writer.toString();
    }
    StringBuilder fullUri = new StringBuilder().append(SSH_URI_PREFIX).append(validUsername);
    if (validPassword != null)
        fullUri.append(':').append(validPassword);
    fullUri.append("@127.0.0.1:22222");
    if (validPassword != null)
        utilsHandler.saveToDatabase(new OperationData(UtilsHandler.Operation.SFTP, SshClientUtils.encryptSshPathAsNecessary(fullUri.toString()), "Test", SecurityUtils.getFingerprint(hostKeyPair.getPublic()), null, null));
    else
        utilsHandler.saveToDatabase(new OperationData(UtilsHandler.Operation.SFTP, SshClientUtils.encryptSshPathAsNecessary(fullUri.toString()), "Test", SecurityUtils.getFingerprint(hostKeyPair.getPublic()), "id_rsa", privateKeyContents));
    shadowOf(Looper.getMainLooper()).idle();
}
Also used : OperationData(com.amaze.filemanager.database.models.OperationData) StringWriter(java.io.StringWriter) IOException(java.io.IOException) JcaPEMWriter(org.bouncycastle.openssl.jcajce.JcaPEMWriter) UtilsHandler(com.amaze.filemanager.database.UtilsHandler)

Example 5 with OperationData

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

the class UtilsHandlerTest method performEncryptUriTest.

private void performEncryptUriTest(@NonNull final String origPath) {
    String encryptedPath = SshClientUtils.encryptSshPathAsNecessary(origPath);
    utilsHandler.saveToDatabase(new OperationData(UtilsHandler.Operation.SFTP, encryptedPath, "Test", "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff", null, null));
    await().atMost(10, TimeUnit.SECONDS).until(() -> {
        List<String[]> result = utilsHandler.getSftpList();
        assertEquals(1, result.size());
        assertEquals("Test", result.get(0)[0]);
        assertEquals(origPath, result.get(0)[1]);
        assertEquals("00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff", utilsHandler.getSshHostKey(origPath));
        return true;
    });
}
Also used : OperationData(com.amaze.filemanager.database.models.OperationData)

Aggregations

OperationData (com.amaze.filemanager.database.models.OperationData)9 UtilsHandler (com.amaze.filemanager.database.UtilsHandler)2 File (java.io.File)2 Test (org.junit.Test)2 Fragment (androidx.fragment.app.Fragment)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 UtilitiesDatabase (com.amaze.filemanager.database.UtilitiesDatabase)1 AppsListFragment (com.amaze.filemanager.ui.fragments.AppsListFragment)1 CloudSheetFragment (com.amaze.filemanager.ui.fragments.CloudSheetFragment)1 CompressedExplorerFragment (com.amaze.filemanager.ui.fragments.CompressedExplorerFragment)1 FtpServerFragment (com.amaze.filemanager.ui.fragments.FtpServerFragment)1 MainFragment (com.amaze.filemanager.ui.fragments.MainFragment)1 ProcessViewerFragment (com.amaze.filemanager.ui.fragments.ProcessViewerFragment)1 SearchWorkerFragment (com.amaze.filemanager.ui.fragments.SearchWorkerFragment)1 TabFragment (com.amaze.filemanager.ui.fragments.TabFragment)1 BookSorter (com.amaze.filemanager.utils.BookSorter)1 BottomSheetDialogFragment (com.google.android.material.bottomsheet.BottomSheetDialogFragment)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 JcaPEMWriter (org.bouncycastle.openssl.jcajce.JcaPEMWriter)1