Search in sources :

Example 21 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.

the class LoadFilesListTask method listApks.

private ArrayList<LayoutElementParcelable> listApks() {
    ArrayList<LayoutElementParcelable> songs = new ArrayList<>();
    final String[] projection = { MediaStore.Files.FileColumns.DATA };
    Cursor cursor = c.getContentResolver().query(MediaStore.Files.getContentUri("external"), projection, null, null, null);
    if (cursor.getCount() > 0 && cursor.moveToFirst()) {
        do {
            String path = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA));
            if (path != null && path.endsWith(".apk")) {
                HybridFileParcelable strings = RootHelper.generateBaseFile(new File(path), showHiddenFiles);
                if (strings != null) {
                    LayoutElementParcelable parcelable = createListParcelables(strings);
                    if (parcelable != null)
                        songs.add(parcelable);
                }
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
    return songs;
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) ArrayList(java.util.ArrayList) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) Cursor(android.database.Cursor) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File) SmbFile(jcifs.smb.SmbFile)

Example 22 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.

the class MoveFiles method onPostExecute.

@Override
public void onPostExecute(Boolean movedCorrectly) {
    if (movedCorrectly) {
        if (mainFrag != null && mainFrag.getCurrentPath().equals(paths.get(0))) {
            // mainFrag.updateList();
            Intent intent = new Intent(MainActivity.KEY_INTENT_LOAD_LIST);
            intent.putExtra(MainActivity.KEY_INTENT_LOAD_LIST_FILE, paths.get(0));
            context.sendBroadcast(intent);
        }
        for (int i = 0; i < paths.size(); i++) {
            for (HybridFileParcelable f : files.get(i)) {
                FileUtils.scanFile(f.getPath(), context);
                FileUtils.scanFile(paths.get(i) + "/" + f.getName(), context);
            }
        }
        // updating encrypted db entry if any encrypted file was moved
        AppConfig.runInBackground(() -> {
            for (int i = 0; i < paths.size(); i++) {
                for (HybridFileParcelable file : files.get(i)) {
                    if (file.getName().endsWith(CryptUtil.CRYPT_EXTENSION)) {
                        try {
                            CryptHandler cryptHandler = new CryptHandler(context);
                            EncryptedEntry oldEntry = cryptHandler.findEntry(file.getPath());
                            EncryptedEntry newEntry = new EncryptedEntry();
                            newEntry.setId(oldEntry.getId());
                            newEntry.setPassword(oldEntry.getPassword());
                            newEntry.setPath(paths.get(i) + "/" + file.getName());
                            cryptHandler.updateEntry(oldEntry, newEntry);
                        } catch (Exception e) {
                            e.printStackTrace();
                        // couldn't change the entry, leave it alone
                        }
                    }
                }
            }
        });
    } else {
        for (int i = 0; i < paths.size(); i++) {
            Intent intent = new Intent(context, CopyService.class);
            intent.putExtra(CopyService.TAG_COPY_SOURCES, files.get(i));
            intent.putExtra(CopyService.TAG_COPY_TARGET, paths.get(i));
            intent.putExtra(CopyService.TAG_COPY_MOVE, true);
            intent.putExtra(CopyService.TAG_COPY_OPEN_MODE, mode.ordinal());
            ServiceWatcherUtil.runService(context, intent);
        }
    }
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) CryptHandler(com.amaze.filemanager.database.CryptHandler) EncryptedEntry(com.amaze.filemanager.database.models.EncryptedEntry) Intent(android.content.Intent) ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException) SmbException(jcifs.smb.SmbException) MalformedURLException(java.net.MalformedURLException)

Example 23 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.

the class PrepareCopyTask method checkConflicts.

private ArrayList<HybridFileParcelable> checkConflicts(final ArrayList<HybridFileParcelable> filesToCopy, HybridFile destination) {
    final ArrayList<HybridFileParcelable> conflictingFiles = new ArrayList<>();
    destination.forEachChildrenFile(context, rootMode, new OnFileFound() {

        @Override
        public void onFileFound(HybridFileParcelable file) {
            for (HybridFileParcelable j : filesToCopy) {
                if (file.getName().equals((j).getName())) {
                    conflictingFiles.add(j);
                }
            }
        }
    });
    return conflictingFiles;
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) ArrayList(java.util.ArrayList) OnFileFound(com.amaze.filemanager.utils.OnFileFound)

Example 24 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable 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 25 with HybridFileParcelable

use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.

the class CopyService method checkFiles.

// check if copy is successful
// avoid using the method as there is no way to know when we would be returning from command callbacks
// rather confirm from the command result itself, inside it's callback
boolean checkFiles(HybridFile hFile1, HybridFile hFile2) throws ShellNotRunningException {
    if (RootHelper.isDirectory(hFile1.getPath(), isRootExplorer, 5)) {
        if (RootHelper.fileExists(hFile2.getPath()))
            return false;
        ArrayList<HybridFileParcelable> baseFiles = RootHelper.getFilesList(hFile1.getPath(), true, true, null);
        if (baseFiles.size() > 0) {
            boolean b = true;
            for (HybridFileParcelable baseFile : baseFiles) {
                if (!checkFiles(new HybridFile(baseFile.getMode(), baseFile.getPath()), new HybridFile(hFile2.getMode(), hFile2.getPath() + "/" + (baseFile.getName()))))
                    b = false;
            }
            return b;
        }
        return RootHelper.fileExists(hFile2.getPath());
    } else {
        ArrayList<HybridFileParcelable> baseFiles = RootHelper.getFilesList(hFile1.getParent(), true, true, null);
        int i = -1;
        int index = -1;
        for (HybridFileParcelable b : baseFiles) {
            i++;
            if (b.getPath().equals(hFile1.getPath())) {
                index = i;
                break;
            }
        }
        ArrayList<HybridFileParcelable> baseFiles1 = RootHelper.getFilesList(hFile1.getParent(), true, true, null);
        int i1 = -1;
        int index1 = -1;
        for (HybridFileParcelable b : baseFiles1) {
            i1++;
            if (b.getPath().equals(hFile1.getPath())) {
                index1 = i1;
                break;
            }
        }
        return baseFiles.get(index).getSize() == baseFiles1.get(index1).getSize();
    }
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) HybridFile(com.amaze.filemanager.filesystem.HybridFile)

Aggregations

HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)35 File (java.io.File)19 ArrayList (java.util.ArrayList)16 HybridFile (com.amaze.filemanager.filesystem.HybridFile)15 LayoutElementParcelable (com.amaze.filemanager.adapters.data.LayoutElementParcelable)11 SmbFile (jcifs.smb.SmbFile)11 Intent (android.content.Intent)8 Cursor (android.database.Cursor)7 ShellNotRunningException (com.amaze.filemanager.exceptions.ShellNotRunningException)7 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)6 SharedPreferences (android.content.SharedPreferences)5 DataUtils (com.amaze.filemanager.utils.DataUtils)5 Context (android.content.Context)4 AppsListFragment (com.amaze.filemanager.fragments.AppsListFragment)4 MainFragment (com.amaze.filemanager.fragments.MainFragment)4 OnFileFound (com.amaze.filemanager.utils.OnFileFound)4 Uri (android.net.Uri)3 AsyncTask (android.os.AsyncTask)3 Build (android.os.Build)3 TextUtils (android.text.TextUtils)3