Search in sources :

Example 6 with FileSystem

use of com.frostwire.platform.FileSystem in project frostwire by frostwire.

the class BaseHttpDownload method moveAndComplete.

protected void moveAndComplete(File src, File dst) {
    FileSystem fs = Platforms.fileSystem();
    if (fs.copy(src, dst)) {
        if (!fs.delete(src)) {
            LOG.warn("Error deleting source file while moving: " + src);
        }
        state = TransferState.SCANNING;
        fs.scan(dst);
        complete(TransferState.COMPLETE);
    } else {
        complete(TransferState.ERROR_MOVING_INCOMPLETE);
    }
}
Also used : FileSystem(com.frostwire.platform.FileSystem)

Example 7 with FileSystem

use of com.frostwire.platform.FileSystem in project frostwire by frostwire.

the class BTEngine method setupSaveDir.

private File setupSaveDir(File saveDir) {
    File result = null;
    if (saveDir == null) {
        if (ctx.dataDir != null) {
            result = ctx.dataDir;
        } else {
            LOG.warn("Unable to setup save dir path, review your logic, both saveDir and ctx.dataDir are null.");
        }
    } else {
        result = saveDir;
    }
    FileSystem fs = Platforms.get().fileSystem();
    if (result != null && !fs.isDirectory(result) && !fs.mkdirs(result)) {
        result = null;
        LOG.warn("Failed to create save dir to download");
    }
    if (result != null && !fs.canWrite(result)) {
        result = null;
        LOG.warn("Failed to setup save dir with write access");
    }
    return result;
}
Also used : FileSystem(com.frostwire.platform.FileSystem) File(java.io.File)

Example 8 with FileSystem

use of com.frostwire.platform.FileSystem in project frostwire by frostwire.

the class BTEngine method saveTorrent.

private void saveTorrent(TorrentInfo ti) {
    File torrentFile;
    try {
        String name = getEscapedFilename(ti);
        torrentFile = torrentFile(name);
        byte[] arr = ti.toEntry().bencode();
        FileSystem fs = Platforms.get().fileSystem();
        fs.write(torrentFile, arr);
        fs.scan(torrentFile);
    } catch (Throwable e) {
        LOG.warn("Error saving torrent info to file", e);
    }
}
Also used : FileSystem(com.frostwire.platform.FileSystem) File(java.io.File)

Example 9 with FileSystem

use of com.frostwire.platform.FileSystem in project frostwire by frostwire.

the class Librarian method deleteFiles.

/**
 * Deletes files.
 * If the fileType is audio it'll use MusicUtils.deleteTracks and
 * tell apollo to clean everything there, playslists, recents, etc.
 *
 * @param context
 * @param fileType
 * @param fds
 */
public void deleteFiles(final Context context, byte fileType, Collection<FileDescriptor> fds) {
    List<Integer> ids = new ArrayList<>(fds.size());
    final int audioMediaType = MediaType.getAudioMediaType().getId();
    if (fileType == audioMediaType) {
        ArrayList<Long> trackIdsToDelete = new ArrayList<>();
        for (FileDescriptor fd : fds) {
            // just in case, as we had similar checks in other code
            if (fd.fileType == audioMediaType) {
                trackIdsToDelete.add((long) fd.id);
                ids.add(fd.id);
            }
        }
        // wish I could do just trackIdsToDelete.toArray(new long[0]) ...
        long[] songsArray = new long[trackIdsToDelete.size()];
        int i = 0;
        for (Long l : trackIdsToDelete) {
            songsArray[i++] = l;
        }
        try {
            MusicUtils.deleteTracks(context, songsArray, false);
        } catch (Throwable t) {
            t.printStackTrace();
        }
    } else {
        for (FileDescriptor fd : fds) {
            ids.add(fd.id);
        }
    }
    try {
        if (context != null) {
            ContentResolver cr = context.getContentResolver();
            TableFetcher fetcher = TableFetchers.getFetcher(fileType);
            cr.delete(fetcher.getContentUri(), MediaColumns._ID + " IN " + buildSet(ids), null);
        } else {
            Log.e(TAG, "Failed to delete files from media store, no context available");
        }
    } catch (Throwable e) {
        Log.e(TAG, "Failed to delete files from media store", e);
    }
    if (fileType == Constants.FILE_TYPE_TORRENTS) {
        FileSystem fs = Platforms.fileSystem();
        for (FileDescriptor fd : fds) {
            try {
                fs.delete(new File(fd.filePath));
            } catch (Throwable ignored) {
            }
        }
    }
    UIUtils.broadcastAction(context, Constants.ACTION_FILE_ADDED_OR_REMOVED, new UIUtils.IntentByteExtra(Constants.EXTRA_REFRESH_FILE_TYPE, fileType));
}
Also used : ArrayList(java.util.ArrayList) FileDescriptor(com.frostwire.android.core.FileDescriptor) ContentResolver(android.content.ContentResolver) FileSystem(com.frostwire.platform.FileSystem) TableFetcher(com.frostwire.android.core.providers.TableFetcher) UIUtils(com.frostwire.android.gui.util.UIUtils) File(java.io.File)

Aggregations

FileSystem (com.frostwire.platform.FileSystem)9 File (java.io.File)6 UIUtils (com.frostwire.android.gui.util.UIUtils)2 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1 DocumentFile (android.support.v4.provider.DocumentFile)1 FileDescriptor (com.frostwire.android.core.FileDescriptor)1 TableFetcher (com.frostwire.android.core.providers.TableFetcher)1 Box (com.frostwire.mp4.Box)1 IsoFile (com.frostwire.mp4.IsoFile)1 Mp4Demuxer (com.frostwire.mp4.Mp4Demuxer)1 Mp4Info (com.frostwire.mp4.Mp4Info)1 DefaultFileSystem (com.frostwire.platform.DefaultFileSystem)1 Platforms (com.frostwire.platform.Platforms)1 YouTubeCrawledSearchResult (com.frostwire.search.youtube.YouTubeCrawledSearchResult)1 YouTubeExtractor (com.frostwire.search.youtube.YouTubeExtractor)1 HttpClientFactory (com.frostwire.util.HttpClientFactory)1 Logger (com.frostwire.util.Logger)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1