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);
}
}
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;
}
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);
}
}
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));
}
Aggregations