Allow selecting individual files to torrent

Saves bandwidth and disk space when a torrent contains extra files you don't need

Fixes #360
This commit is contained in:
DC
2016-05-11 05:42:06 -07:00
parent 0095687bf5
commit 6518a1535c
4 changed files with 113 additions and 19 deletions

View File

@@ -153,6 +153,11 @@ function cleanUpConfig () {
delete ts.posterURL
ts.posterFileName = infoHash + extension
}
// Migration: add per-file selections
if (!ts.selections) {
ts.selections = ts.files.map((x) => true)
}
})
}
@@ -231,6 +236,9 @@ function dispatch (action, ...args) {
if (action === 'toggleSelectTorrent') {
toggleSelectTorrent(args[0] /* infoHash */)
}
if (action === 'toggleTorrentFile') {
toggleTorrentFile(args[0] /* infoHash */, args[1] /* index */)
}
if (action === 'openTorrentContextMenu') {
openTorrentContextMenu(args[0] /* infoHash */)
}
@@ -709,7 +717,7 @@ function startTorrentingSummary (torrentSummary) {
}
console.log('start torrenting %s %s', s.torrentKey, torrentID)
ipcRenderer.send('wt-start-torrenting', s.torrentKey, torrentID, path, s.fileModtimes)
ipcRenderer.send('wt-start-torrenting', s.torrentKey, torrentID, path, s.fileModtimes, s.selections)
}
//
@@ -818,6 +826,9 @@ function torrentMetadata (torrentKey, torrentInfo) {
torrentSummary.path = torrentInfo.path
torrentSummary.files = torrentInfo.files
torrentSummary.magnetURI = torrentInfo.magnetURI
if (!torrentSummary.selections) {
torrentSummary.selections = torrentSummary.files.map((x) => true)
}
update()
// Save the .torrent file, if it hasn't been saved already
@@ -1058,6 +1069,14 @@ function toggleSelectTorrent (infoHash) {
update()
}
function toggleTorrentFile (infoHash, index) {
var torrentSummary = getTorrentSummary(infoHash)
torrentSummary.selections[index] = !torrentSummary.selections[index]
// Let the WebTorrent process know to start or stop fetching that file
ipcRenderer.send('wt-select-files', infoHash, torrentSummary.selections)
}
function openTorrentContextMenu (infoHash) {
var torrentSummary = getTorrentSummary(infoHash)
var menu = new electron.remote.Menu()