use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class TorrentUtil method exportDownloads.
protected static void exportDownloads(Shell shell, DownloadManager[] dms) {
if (dms != null && dms.length > 0) {
DirectoryDialog dd = new DirectoryDialog(shell);
String filter_path = TorrentOpener.getFilterPathExport();
// 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.exportdownload.dialog"));
String path = dd.open();
if (path != null) {
TorrentOpener.setFilterPathExport(path);
File target = new File(path);
for (int i = 0; i < dms.length; i++) {
try {
dms[i].exportDownload(target);
} catch (Throwable e) {
Logger.log(new LogAlert(dms[i], LogAlert.REPEATABLE, "Download export operation failed", e));
}
}
}
}
}
use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class TorrentUtil method exportTorrent.
protected static void exportTorrent(DownloadManager[] dms, Shell parentShell) {
// FileDialog for single download
// DirectoryDialog for multiple.
File[] destinations = new File[dms.length];
if (dms.length == 1) {
FileDialog fd = new FileDialog(parentShell, 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(parentShell, 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(parentShell, 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));
}
}
use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class UserAlerts method doStuff.
private void doStuff(Object relatedObject, String item_name, boolean do_popup, String popup_def_text, boolean popup_is_error, boolean do_native_tray, String native_text, boolean do_speech, final String speech_text, boolean do_sound, String sound_file) {
final String default_sound = "com/biglybt/ui/icons/downloadFinished.wav";
try {
this_mon.enter();
if (do_popup) {
String popup_text = MessageText.getString(popup_def_text, new String[] { item_name });
forceNotify(popup_is_error ? UIFunctions.STATUSICON_ERROR : UIFunctions.STATUSICON_NONE, null, popup_text, null, new Object[] { relatedObject }, -1);
}
if (do_speech) {
new AEThread2("SaySound") {
@Override
public void run() {
try {
Runtime.getRuntime().exec(new String[] { "say", COConfigurationManager.getStringParameter(speech_text) });
// Speech Synthesis services
Thread.sleep(2500);
} catch (Throwable e) {
}
}
}.start();
}
if (do_sound) {
String file = COConfigurationManager.getStringParameter(sound_file);
file = file.trim();
if (file.startsWith("<")) {
file = "";
}
if (audio_clip == null || !file.equals(audio_resource)) {
audio_clip = null;
if (file.length() != 0) {
File f = new File(file);
try {
if (f.exists()) {
URL file_url = f.toURI().toURL();
audio_clip = Applet.newAudioClip(file_url);
}
} catch (Throwable e) {
Debug.printStackTrace(e);
} finally {
if (audio_clip == null) {
Logger.log(new LogAlert(relatedObject, LogAlert.UNREPEATABLE, LogAlert.AT_ERROR, "Failed to load audio file '" + file + "'"));
}
}
}
if (audio_clip == null) {
audio_clip = Applet.newAudioClip(UserAlerts.class.getClassLoader().getResource(default_sound));
}
audio_resource = file;
}
if (audio_clip != null) {
new AEThread2("DownloadSound") {
@Override
public void run() {
try {
audio_clip.play();
Thread.sleep(2500);
} catch (Throwable e) {
}
}
}.start();
}
}
if (do_native_tray) {
if (native_tray_icon == null) {
if (SystemTray.isSupported()) {
SystemTray st = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/com/biglybt/ui/icons/a32info.png"));
native_tray_icon = new TrayIcon(image, "");
native_tray_icon.setImageAutoSize(true);
native_tray_icon.setToolTip(MessageText.getString("label.product.alerts"));
try {
PopupMenu menu = new PopupMenu();
native_tray_icon.setPopupMenu(menu);
MenuItem mi = new MenuItem(MessageText.getString("sharing.progress.hide"));
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
try {
this_mon.enter();
try {
SystemTray st = SystemTray.getSystemTray();
st.remove(native_tray_icon);
native_tray_icon = null;
} catch (Throwable e) {
}
} finally {
this_mon.exit();
}
}
});
menu.add(mi);
} catch (Throwable e) {
Debug.out(e);
}
st.add(native_tray_icon);
}
}
if (native_tray_icon != null) {
native_tray_icon.displayMessage(MessageText.getString(native_text), item_name, popup_is_error ? MessageType.ERROR : MessageType.INFO);
/* Unfortunately removing the icon also removes any messages associated with it
* that may be in the notification area (on Windows 10 for example)
final int mine = ++native_message_count;
SimpleTimer.addEvent(
"iconhider",
SystemTime.getOffsetTime( 30*1000 ),
new TimerEventPerformer(){
@Override
public void perform(TimerEvent event){
try{
this_mon.enter();
if ( native_message_count == mine ){
try{
SystemTray st = SystemTray.getSystemTray();
st.remove( native_tray_icon );
native_tray_icon = null;
}catch( Throwable e ){
}
}
}finally{
this_mon.exit();
}
}
});
*/
}
}
} catch (Throwable e) {
Debug.printStackTrace(e);
} finally {
this_mon.exit();
}
}
use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class UI method processArgs.
@Override
public String[] processArgs(CommandLine commands, String[] args) {
boolean showMainWindow = args.length == 0 || COConfigurationManager.getBooleanParameter("Activate Window On External Download");
boolean open = true;
if (commands.hasOption("closedown") || commands.hasOption("shutdown")) {
try {
UpdateManager um = core.getPluginManager().getDefaultPluginInterface().getUpdateManager();
UpdateInstaller[] installers = um.getInstallers();
for (UpdateInstaller installer : installers) {
installer.destroy();
}
} catch (Throwable e) {
}
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.dispose(false, false);
}
return null;
}
if (commands.hasOption("restart")) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.dispose(true, false);
}
return null;
}
if (commands.hasOption("share")) {
showMainWindow = true;
open = false;
}
if (commands.hasOption("open")) {
showMainWindow = true;
}
String[] rest = commands.getArgs();
for (int i = 0; i < rest.length; i++) {
String filename = rest[i];
File file = new File(filename);
boolean isURI;
if (!file.exists() && !isURI(filename)) {
String magnet_uri = UrlUtils.normaliseMagnetURI(filename);
isURI = magnet_uri != null;
if (isURI) {
filename = magnet_uri;
}
} else {
isURI = isURI(filename);
}
if (isURI) {
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "StartServer: args[" + i + "] handling as a URI: " + filename));
} else {
try {
if (!file.exists()) {
throw (new Exception("File '" + file + "' not found"));
}
filename = file.getCanonicalPath();
Logger.log(new LogEvent(LOGID, "StartServer: file = " + filename));
} catch (Throwable e) {
Logger.log(new LogAlert(LogAlert.REPEATABLE, LogAlert.AT_ERROR, "Failed to access torrent file '" + filename + "'. Ensure sufficient temporary " + "file space available (check browser cache usage)."));
}
}
boolean queued = false;
try {
this_mon.enter();
if (queueTorrents) {
queued_torrents.add(new Object[] { filename, Boolean.valueOf(open) });
queued = true;
}
} finally {
this_mon.exit();
}
if (!queued) {
handleFile(filename, open);
}
}
if (showMainWindow) {
showMainWindow();
}
return args;
}
use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class TorrentOpener method openTorrentsForTracking.
protected static void openTorrentsForTracking(final String path, final String[] fileNames) {
CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {
@Override
public void coreRunning(final Core core) {
final Display display = Utils.getDisplay();
if (display == null || display.isDisposed() || core == null)
return;
new AEThread2("TorrentOpener") {
@Override
public void run() {
for (int i = 0; i < fileNames.length; i++) {
try {
TOTorrent t = TorrentUtils.readFromFile(new File(path, fileNames[i]), true);
core.getTrackerHost().hostTorrent(t, true, true);
} catch (Throwable e) {
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, "Torrent open fails for '" + path + File.separator + fileNames[i] + "'", e));
}
}
}
}.start();
}
});
}
Aggregations