From beb4af1311f63e30a1016143849a45f416dec44b Mon Sep 17 00:00:00 2001 From: Mathias Rasmussen Date: Fri, 15 Jul 2016 00:41:05 +0200 Subject: [PATCH] Remove torrent file and poster (#711) * remove torrent file and poster * Delete file instead of moving to trash --- .../controllers/torrent-list-controller.js | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/renderer/controllers/torrent-list-controller.js b/renderer/controllers/torrent-list-controller.js index f35c4cb3..e1e27ff5 100644 --- a/renderer/controllers/torrent-list-controller.js +++ b/renderer/controllers/torrent-list-controller.js @@ -114,19 +114,26 @@ module.exports = class TorrentListController { // TODO: use torrentKey, not infoHash deleteTorrent (infoHash, deleteData) { - var state = this.state - ipcRenderer.send('wt-stop-torrenting', infoHash) - if (deleteData) { - var torrentSummary = TorrentSummary.getByKey(state, infoHash) - moveItemToTrash(torrentSummary) + var index = this.state.saved.torrents.findIndex((x) => x.infoHash === infoHash) + + if (index > -1) { + var summary = this.state.saved.torrents[index] + + // remove torrent and poster file + deleteFile(TorrentSummary.getTorrentPath(summary)) + deleteFile(TorrentSummary.getPosterPath(summary)) // TODO: will the css path hack affect windows? + + // optionally delete the torrent data + if (deleteData) moveItemToTrash(summary) + + // remove torrent from saved list + this.state.saved.torrents.splice(index, 1) + State.saveThrottled(this.state) } - var index = state.saved.torrents.findIndex((x) => x.infoHash === infoHash) - if (index > -1) state.saved.torrents.splice(index, 1) - State.saveThrottled(state) - state.location.clearForward('player') // prevent user from going forward to a deleted torrent + this.state.location.clearForward('player') // prevent user from going forward to a deleted torrent sound.play('DELETE') } @@ -229,6 +236,13 @@ function findFilesRecursive (paths, cb) { }) } +function deleteFile (path) { + if (!path) return + fs.unlink(path, function (err) { + if (err) dispatch('onError', err) + }) +} + // Delete all files in a torren function moveItemToTrash (torrentSummary) { // TODO: delete directories, not just files