Search in sources :

Example 31 with LogAlert

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));
                }
            }
        }
    }
}
Also used : File(java.io.File) LogAlert(com.biglybt.core.logging.LogAlert)

Example 32 with LogAlert

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));
    }
}
Also used : TOTorrent(com.biglybt.core.torrent.TOTorrent) File(java.io.File) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) IOException(java.io.IOException) LogAlert(com.biglybt.core.logging.LogAlert)

Example 33 with LogAlert

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();
    }
}
Also used : SystemTray(java.awt.SystemTray) ActionEvent(java.awt.event.ActionEvent) MenuItem(java.awt.MenuItem) Image(java.awt.Image) URL(java.net.URL) LogAlert(com.biglybt.core.logging.LogAlert) ActionListener(java.awt.event.ActionListener) TrayIcon(java.awt.TrayIcon) File(java.io.File) PopupMenu(java.awt.PopupMenu)

Example 34 with LogAlert

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;
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) LogAlert(com.biglybt.core.logging.LogAlert) UIFunctions(com.biglybt.ui.UIFunctions) UpdateInstaller(com.biglybt.pif.update.UpdateInstaller) UpdateManager(com.biglybt.pif.update.UpdateManager) File(java.io.File)

Example 35 with LogAlert

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();
        }
    });
}
Also used : TOTorrent(com.biglybt.core.torrent.TOTorrent) CoreRunningListener(com.biglybt.core.CoreRunningListener) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) LogAlert(com.biglybt.core.logging.LogAlert) Core(com.biglybt.core.Core) Display(org.eclipse.swt.widgets.Display)

Aggregations

LogAlert (com.biglybt.core.logging.LogAlert)72 File (java.io.File)21 LogEvent (com.biglybt.core.logging.LogEvent)20 URL (java.net.URL)7 Core (com.biglybt.core.Core)5 ParameterListener (com.biglybt.core.config.ParameterListener)5 DownloadManager (com.biglybt.core.download.DownloadManager)5 TOTorrent (com.biglybt.core.torrent.TOTorrent)5 UIFunctions (com.biglybt.ui.UIFunctions)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)4 PlatformManagerException (com.biglybt.pif.platform.PlatformManagerException)4 Method (java.lang.reflect.Method)4 CoreRunningListener (com.biglybt.core.CoreRunningListener)3 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)3 URLClassLoader (java.net.URLClassLoader)3 CoreException (com.biglybt.core.CoreException)2 CacheFile (com.biglybt.core.diskmanager.cache.CacheFile)2 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)2