Remove torrent file and poster (#711)
* remove torrent file and poster * Delete file instead of moving to trash
This commit is contained in:
@@ -114,19 +114,26 @@ module.exports = class TorrentListController {
|
|||||||
|
|
||||||
// TODO: use torrentKey, not infoHash
|
// TODO: use torrentKey, not infoHash
|
||||||
deleteTorrent (infoHash, deleteData) {
|
deleteTorrent (infoHash, deleteData) {
|
||||||
var state = this.state
|
|
||||||
|
|
||||||
ipcRenderer.send('wt-stop-torrenting', infoHash)
|
ipcRenderer.send('wt-stop-torrenting', infoHash)
|
||||||
|
|
||||||
if (deleteData) {
|
var index = this.state.saved.torrents.findIndex((x) => x.infoHash === infoHash)
|
||||||
var torrentSummary = TorrentSummary.getByKey(state, infoHash)
|
|
||||||
moveItemToTrash(torrentSummary)
|
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)
|
this.state.location.clearForward('player') // prevent user from going forward to a deleted torrent
|
||||||
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
|
|
||||||
sound.play('DELETE')
|
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
|
// Delete all files in a torren
|
||||||
function moveItemToTrash (torrentSummary) {
|
function moveItemToTrash (torrentSummary) {
|
||||||
// TODO: delete directories, not just files
|
// TODO: delete directories, not just files
|
||||||
|
|||||||
Reference in New Issue
Block a user