Remove torrent file and poster (#711)

* remove torrent file and poster

* Delete file instead of moving to trash
This commit is contained in:
Mathias Rasmussen
2016-07-15 00:41:05 +02:00
committed by DC
parent f0aeab0207
commit beb4af1311

View File

@@ -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