dms[i].moveDataFiles(target);
}
catch (Throwable e) {
Logger.log(new LogAlert(dms[i], LogAlert.REPEATABLE,
"Download data move operation failed", e));
}
}
}
}
}
});
itemFileMoveData.setEnabled(fileMove);
final MenuItem itemFileMoveTorrent = new MenuItem(menuFiles, SWT.PUSH);
Messages.setLanguageText(itemFileMoveTorrent, "MyTorrentsView.menu.movetorrent");
itemFileMoveTorrent.addListener(SWT.Selection, new DMTask(dms) {
public void run(DownloadManager[] dms) {
if (dms != null && dms.length > 0) {
DirectoryDialog dd = new DirectoryDialog(composite.getShell());
String filter_path = TorrentOpener.getFilterPathTorrent();
// If we don't have a decent path, default to the path of the first
// torrent.
if (filter_path == null || filter_path.trim().length() == 0) {
filter_path = new File(dms[0].getTorrentFileName()).getParent();
}
dd.setFilterPath(filter_path);
dd.setText(MessageText.getString("MyTorrentsView.menu.movedata.dialog"));
String path = dd.open();
if (path != null) {
File target = new File(path);
TorrentOpener.setFilterPathTorrent(target.toString());
for (int i = 0; i < dms.length; i++) {
try {
dms[i].moveTorrentFile(target);
}
catch (Throwable e) {
Logger.log(new LogAlert(dms[i], LogAlert.REPEATABLE,
"Download torrent move operation failed", e));
}
}
}
}
}
});
itemFileMoveTorrent.setEnabled(fileMove);
final MenuItem itemCheckFilesExist = new MenuItem(menuFiles, SWT.PUSH);
Messages.setLanguageText(itemCheckFilesExist, "MyTorrentsView.menu.checkfilesexist");
itemCheckFilesExist.addListener(SWT.Selection, new DMTask(dms) {
public void run(DownloadManager dm) {
dm.filesExist( true );
}
});
final MenuItem itemFileRescan = new MenuItem(menuFiles, SWT.CHECK);
Messages.setLanguageText(itemFileRescan, "MyTorrentsView.menu.rescanfile");
itemFileRescan.addListener(SWT.Selection, new DMTask(dms) {
public void run(DownloadManager dm) {
dm.getDownloadState().setFlag(DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES,
itemFileRescan.getSelection());
}
});
itemFileRescan.setSelection(allScanSelected);
itemFileRescan.setEnabled(fileRescan);
// clear allocation
MenuItem itemFileClearAlloc = new MenuItem(menuFiles, SWT.PUSH);
Messages.setLanguageText(itemFileClearAlloc, "MyTorrentsView.menu.clear_alloc_data");
itemFileClearAlloc.addListener(SWT.Selection, new DMTask(dms) {
public void run(DownloadManager dm) {
dm.setDataAlreadyAllocated( false );
}
});
itemFileClearAlloc.setEnabled(allStopped);
// clear resume
MenuItem itemFileClearResume = new MenuItem(menuFiles, SWT.PUSH);
Messages.setLanguageText(itemFileClearResume, "MyTorrentsView.menu.clear_resume_data");
itemFileClearResume.addListener(SWT.Selection, new DMTask(dms) {
public void run(DownloadManager dm) {
dm.getDownloadState().clearResumeData();
}
});
itemFileClearResume.setEnabled(allStopped);
// Advanced - > Rename
final MenuItem itemRename = new MenuItem(menuAdvanced, SWT.DROP_DOWN);
Messages.setLanguageText(itemRename, "MyTorrentsView.menu.rename");
itemRename.setEnabled(hasSelection);
itemRename.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
for (DownloadManager dm : dms) {
AdvRenameWindow window = new AdvRenameWindow();
window.open(dm);
}
}
});
// === advanced > export ===
// =========================
if (userMode > 0) {
final MenuItem itemExport = new MenuItem(menuAdvanced, SWT.CASCADE);
Messages.setLanguageText(itemExport, "MyTorrentsView.menu.exportmenu"); //$NON-NLS-1$
Utils.setMenuItemImage(itemExport, "export");
itemExport.setEnabled(hasSelection);
final Menu menuExport = new Menu(composite.getShell(), SWT.DROP_DOWN);
itemExport.setMenu(menuExport);
// Advanced > Export > Export XML
final MenuItem itemExportXML = new MenuItem(menuExport, SWT.PUSH);
Messages.setLanguageText(itemExportXML, "MyTorrentsView.menu.export");
itemExportXML.addListener(SWT.Selection, new DMTask(dms) {
public void run(DownloadManager[] dms) {
DownloadManager dm = dms[0]; // First only.
if (dm != null) new ExportTorrentWizard(itemExportXML.getDisplay(), dm);
}
});
// Advanced > Export > Export Torrent
final MenuItem itemExportTorrent = new MenuItem(menuExport, SWT.PUSH);
Messages.setLanguageText(itemExportTorrent, "MyTorrentsView.menu.exporttorrent");
itemExportTorrent.addListener(SWT.Selection, new DMTask(dms) {
public void run(DownloadManager[] dms) {
// FileDialog for single download
// DirectoryDialog for multiple.
File[] destinations = new File[dms.length];
if (dms.length == 1) {
FileDialog fd = new FileDialog(composite.getShell(), SWT.SAVE);
fd.setFileName(dms[0].getTorrentFileName());
String path = fd.open();
if (path == null) {return;}
destinations[0] = new File(path);
}
else {
DirectoryDialog dd = new DirectoryDialog(composite.getShell(), SWT.SAVE);
String path = dd.open();
if (path == null) {return;}
for (int i=0; i<dms.length; i++) {
destinations[i] = new File(path, new File(dms[i].getTorrentFileName()).getName());
}
}
int i=0;
try {
for (; i<dms.length; i++) {
File target = destinations[i];
if (target.exists()) {
MessageBox mb = new MessageBox(composite.getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
mb.setText(MessageText.getString("exportTorrentWizard.process.outputfileexists.title"));
mb.setMessage(MessageText.getString("exportTorrentWizard.process.outputfileexists.message") + "\n" + destinations[i].getName());
int result = mb.open();
if (result == SWT.NO) {return;}
if (!target.delete()) {
throw (new Exception("Failed to delete file"));
}
} // end deal with clashing torrent
// first copy the torrent - DON'T use "writeTorrent" as this amends the
// "filename" field in the torrent
TorrentUtils.copyToFile(dms[i].getDownloadState().getTorrent(), target);
// now remove the non-standard entries
TOTorrent dest = TOTorrentFactory.deserialiseFromBEncodedFile(target);
dest.removeAdditionalProperties();
dest.serialiseToBEncodedFile(target);
} // end for
} // end try
catch (Throwable e) {
Logger.log(new LogAlert(dms[i], LogAlert.UNREPEATABLE, "Torrent export failed", e));
}
} // end run()
}); // end DMTask
// Advanced > Export > WebSeed URL