Search in sources :

Example 6 with Core

use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.

the class UI method coreCreated.

@Override
public void coreCreated(Core core) {
    super.coreCreated(core);
    if (core.isStarted()) {
        startUI();
        return;
    }
    core.addLifecycleListener(new CoreLifecycleAdapter() {

        @Override
        public void started(Core core) {
            startUI();
        }
    });
}
Also used : CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) Core(com.biglybt.core.Core)

Example 7 with Core

use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.

the class DeviceManagerImpl method initWithCore.

void initWithCore(final Core _core) {
    synchronized (this) {
        if (core != null) {
            return;
        }
        core = _core;
    }
    try {
        od_manual_ta = PluginInitializer.getDefaultInterface().getTorrentManager().getPluginAttribute("device.manager.od.ta.manual");
        rss_publisher = new DeviceManagerRSSFeed(this);
        // need to pick up auto-search early on
        COConfigurationManager.addAndFireParameterListeners(new String[] { AUTO_SEARCH_CONFIG_KEY, AUTO_HIDE_OLD_CONFIG_KEY }, new ParameterListener() {

            @Override
            public void parameterChanged(String name) {
                auto_search = COConfigurationManager.getBooleanParameter(AUTO_SEARCH_CONFIG_KEY, true);
                auto_hide_old_days = COConfigurationManager.getIntParameter(AUTO_HIDE_OLD_CONFIG_KEY, AUTO_HIDE_OLD_DAYS_DEFAULT);
            }
        });
        // init tivo before upnp as upnp init completion starts up tivo
        tivo_manager = new DeviceTivoManager(this);
        upnp_manager = new DeviceManagerUPnPImpl(this);
        loadConfig();
        new DeviceiTunesManager(this);
        drive_manager = new DeviceDriveManager(this);
        transcode_manager = new TranscodeManagerImpl(this);
        transcode_manager.initialise();
        core.addLifecycleListener(new CoreLifecycleAdapter() {

            @Override
            public void stopping(Core core) {
                synchronized (DeviceManagerImpl.this) {
                    if (config_dirty || config_unclean) {
                        saveConfig();
                    }
                    closing = true;
                    transcode_manager.close();
                    DeviceImpl[] devices = getDevices();
                    for (DeviceImpl device : devices) {
                        device.close();
                    }
                }
            }
        });
        upnp_manager.initialise();
        SimpleTimer.addPeriodicEvent("DeviceManager:update", DEVICE_UPDATE_PERIOD, new TimerEventPerformer() {

            private int tick_count = 0;

            @Override
            public void perform(TimerEvent event) {
                List<DeviceImpl> copy;
                tick_count++;
                transcode_manager.updateStatus(tick_count);
                synchronized (DeviceManagerImpl.this) {
                    if (device_list.size() == 0) {
                        return;
                    }
                    copy = new ArrayList<>(device_list);
                }
                for (DeviceImpl device : copy) {
                    device.updateStatus(tick_count);
                }
                if (auto_hide_old_days > 0 && tick_count % DEVICE_AUTO_HIDE_CHECK_TICKS == 0) {
                    long now = SystemTime.getCurrentTime();
                    int num_hidden = 0;
                    for (DeviceImpl device : copy) {
                        if (device.isLivenessDetectable() && !device.isTagged()) {
                            int type = device.getType();
                            if (type == Device.DT_CONTENT_DIRECTORY) {
                            } else if (type == Device.DT_MEDIA_RENDERER) {
                                DeviceMediaRenderer rend = (DeviceMediaRenderer) device;
                                if (rend.getRendererSpecies() != DeviceMediaRenderer.RS_OTHER) {
                                    continue;
                                }
                            } else {
                                continue;
                            }
                            long age = now - device.getLastSeen();
                            if (age > auto_hide_old_days * 24 * 60 * 60 * 1000L) {
                                if (!device.isHidden()) {
                                    log("Auto-hiding '" + device.getName() + "'");
                                    device.setHidden(true);
                                    device.setAutoHidden(true);
                                    num_hidden++;
                                }
                            } else {
                                if (device.isHidden() && device.isAutoHidden()) {
                                    log("Auto-showing '" + device.getName() + "'");
                                    device.setAutoHidden(false);
                                    device.setHidden(false);
                                }
                            }
                        }
                    }
                    if (num_hidden > 0) {
                        Logger.log(new LogAlert(true, LogAlert.AT_INFORMATION, MessageText.getString("device.autohide.alert", new String[] { String.valueOf(num_hidden), String.valueOf(auto_hide_old_days) })));
                    }
                }
            }
        });
        initialized = true;
        listeners.dispatch(LT_INITIALIZED, null);
        core.addPowerManagementListener(this);
    } finally {
        init_sem.releaseForever();
    }
}
Also used : CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) LogAlert(com.biglybt.core.logging.LogAlert) ParameterListener(com.biglybt.core.config.ParameterListener) Core(com.biglybt.core.Core)

Example 8 with Core

use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.

the class GlobalManagerImpl method statsRequest.

@Override
public void statsRequest(Map request, Map reply) {
    Core core = CoreFactory.getSingleton();
    Map glob = new HashMap();
    reply.put("gm", glob);
    try {
        glob.put("u_rate", new Long(stats.getDataAndProtocolSendRate()));
        glob.put("d_rate", new Long(stats.getDataAndProtocolReceiveRate()));
        glob.put("d_lim", new Long(TransferSpeedValidator.getGlobalDownloadRateLimitBytesPerSecond()));
        boolean auto_up = TransferSpeedValidator.isAutoSpeedActive(this) && TransferSpeedValidator.isAutoUploadAvailable(core);
        glob.put("auto_up", new Long(auto_up ? COConfigurationManager.getLongParameter(SpeedManagerImpl.CONFIG_VERSION) : 0));
        long up_lim = NetworkManager.getMaxUploadRateBPSNormal();
        boolean seeding_only = NetworkManager.isSeedingOnlyUploadRate();
        glob.put("so", new Long(seeding_only ? 1 : 0));
        if (seeding_only) {
            up_lim = NetworkManager.getMaxUploadRateBPSSeedingOnly();
        }
        glob.put("u_lim", new Long(up_lim));
        SpeedManager sm = core.getSpeedManager();
        if (sm != null) {
            glob.put("u_cap", new Long(sm.getEstimatedUploadCapacityBytesPerSec().getBytesPerSec()));
            glob.put("d_cap", new Long(sm.getEstimatedDownloadCapacityBytesPerSec().getBytesPerSec()));
        }
        List<DownloadManager> dms = getDownloadManagers();
        int comp = 0;
        int incomp = 0;
        long comp_up = 0;
        long incomp_up = 0;
        long incomp_down = 0;
        for (DownloadManager dm : dms) {
            int state = dm.getState();
            if (state == DownloadManager.STATE_SEEDING || state == DownloadManager.STATE_DOWNLOADING) {
                DownloadManagerStats stats = dm.getStats();
                if (dm.isDownloadComplete(false)) {
                    comp++;
                    comp_up += stats.getProtocolSendRate() + stats.getDataSendRate();
                } else {
                    incomp++;
                    incomp_up += stats.getProtocolSendRate() + stats.getDataSendRate();
                    incomp_down += stats.getProtocolReceiveRate() + stats.getDataReceiveRate();
                }
            }
        }
        glob.put("dm_i", new Long(incomp));
        glob.put("dm_c", new Long(comp));
        glob.put("dm_i_u", new Long(incomp_up));
        glob.put("dm_i_d", new Long(incomp_down));
        glob.put("dm_c_u", new Long(comp_up));
        glob.put("nat", new Long(nat_status));
        boolean request_limiting = COConfigurationManager.getBooleanParameter("Use Request Limiting");
        glob.put("req_lim", new Long(request_limiting ? 1 : 0));
        if (request_limiting) {
            glob.put("req_focus", new Long(COConfigurationManager.getBooleanParameter("Use Request Limiting Priorities") ? 1 : 0));
        }
        boolean bias_up = COConfigurationManager.getBooleanParameter("Bias Upload Enable");
        glob.put("bias_up", new Long(bias_up ? 1 : 0));
        if (bias_up) {
            glob.put("bias_slack", new Long(COConfigurationManager.getLongParameter("Bias Upload Slack KBs")));
            glob.put("bias_ulim", new Long(COConfigurationManager.getBooleanParameter("Bias Upload Handle No Limit") ? 1 : 0));
        }
    } catch (Throwable e) {
    }
}
Also used : SpeedManager(com.biglybt.core.speedmanager.SpeedManager) Core(com.biglybt.core.Core)

Example 9 with Core

use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.

the class TorrentFolderWatcher method importAddedFiles.

void importAddedFiles() {
    Core core = CoreFactory.getSingleton();
    try {
        this_mon.enter();
        if (!running) {
            return;
        }
        GlobalManager global_manager = _global_manager;
        if (global_manager == null || !core.isStarted()) {
            return;
        }
        com.biglybt.pif.download.DownloadManager plugin_dm = core.getPluginManager().getDefaultPluginInterface().getDownloadManager();
        boolean save_torrents_default = COConfigurationManager.getBooleanParameter("Save Torrent Files");
        String torrent_save_path = COConfigurationManager.getStringParameter("General_sDefaultTorrent_Directory");
        int start_state = COConfigurationManager.getBooleanParameter("Start Watched Torrents Stopped") ? DownloadManager.STATE_STOPPED : DownloadManager.STATE_QUEUED;
        int num_folders = COConfigurationManager.getIntParameter("Watch Torrent Folder Path Count", 1);
        List<File> folders = new ArrayList<>();
        List<String> tags = new ArrayList<>();
        for (int i = 0; i < num_folders; i++) {
            String folder_path = COConfigurationManager.getStringParameter("Watch Torrent Folder Path" + (i == 0 ? "" : (" " + i)));
            File folder = null;
            if (folder_path != null && folder_path.length() > 0) {
                folder = new File(folder_path);
                if (!folder.isDirectory()) {
                    if (!folder.exists()) {
                        FileUtil.mkdirs(folder);
                    }
                    if (!folder.isDirectory()) {
                        if (Logger.isEnabled())
                            Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "[Watch Torrent Folder Path] " + "does not exist or " + "is not a dir"));
                        folder = null;
                    }
                }
            }
            if (folder != null) {
                folders.add(folder);
                String tag = COConfigurationManager.getStringParameter("Watch Torrent Folder Tag" + (i == 0 ? "" : (" " + i)), null);
                if (tag != null && tag.trim().length() == 0) {
                    tag = null;
                }
                tags.add(tag);
            }
        }
        if (folders.isEmpty()) {
            if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "[Watch Torrent Folder Path] not configured"));
            return;
        }
        String data_save_path = COConfigurationManager.getStringParameter("Default save path");
        File f = null;
        if (data_save_path != null && data_save_path.length() > 0) {
            f = new File(data_save_path);
            // Path is not an existing directory.
            if (!f.isDirectory()) {
                if (!f.exists()) {
                    FileUtil.mkdirs(f);
                }
                // If path is still not a directory, abort.
                if (!f.isDirectory()) {
                    if (Logger.isEnabled()) {
                        Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "[Default save path] does not exist or is not a dir"));
                    }
                    Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_ERROR, "[Default save path] does not exist or is not a dir"));
                    return;
                }
            }
        }
        // If we get here, and this is true, then data_save_path isn't valid.
        if (f == null) {
            if (Logger.isEnabled()) {
                Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "[Default save path] needs to be set for auto-.torrent-import to work"));
            }
            Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_ERROR, "[Default save path] needs to be set for auto-.torrent-import to work"));
        }
        for (int i = 0; i < to_delete.size(); i++) {
            TOTorrent torrent = (TOTorrent) to_delete.get(i);
            try {
                TorrentUtils.delete(torrent);
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
        to_delete.clear();
        for (int folder_index = 0; folder_index < folders.size(); folder_index++) {
            File folder = folders.get(folder_index);
            final String tag_name = tags.get(folder_index);
            // if we are saving torrents to the same location as we import them from
            // then we can't assume that its safe to delete the torrent after import!
            boolean save_torrents = save_torrents_default;
            if (torrent_save_path.length() == 0 || new File(torrent_save_path).getAbsolutePath().equals(folder.getAbsolutePath()) || !new File(torrent_save_path).isDirectory()) {
                save_torrents = false;
            }
            String[] currentFileList = folder.list(filename_filter);
            if (currentFileList == null) {
                Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "There was a problem trying to get a listing of torrents from " + folder));
            } else {
                for (int i = 0; i < currentFileList.length; i++) {
                    if (!running) {
                        return;
                    }
                    File file = new File(folder, currentFileList[i]);
                    if (file.getName().toLowerCase(Locale.US).endsWith(".magnet")) {
                        handleMagnet(file);
                    } else {
                        try {
                            TOTorrent torrent = TorrentUtils.readFromFile(file, false);
                            if (global_manager.getDownloadManager(torrent) != null) {
                                if (Logger.isEnabled())
                                    Logger.log(new LogEvent(LOGID, file.getAbsolutePath() + " is already being downloaded"));
                            // we can't touch the torrent file as it is (probably)
                            // being used for the download
                            } else if (plugin_dm.lookupDownloadStub(torrent.getHash()) != null) {
                                if (Logger.isEnabled())
                                    Logger.log(new LogEvent(LOGID, file.getAbsolutePath() + " is an archived download"));
                                if (!save_torrents) {
                                    File imported = new File(folder, file.getName() + ".imported");
                                    TorrentUtils.move(file, imported);
                                } else {
                                    to_delete.add(torrent);
                                }
                            } else {
                                final DownloadManagerInitialisationAdapter dmia = new DownloadManagerInitialisationAdapter() {

                                    @Override
                                    public int getActions() {
                                        return (ACT_ASSIGNS_TAGS);
                                    }

                                    @Override
                                    public void initialised(DownloadManager dm, boolean for_seeding) {
                                        if (tag_name != null) {
                                            TagManager tm = TagManagerFactory.getTagManager();
                                            TagType tt = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL);
                                            Tag tag = tt.getTag(tag_name, true);
                                            try {
                                                if (tag == null) {
                                                    tag = tt.createTag(tag_name, true);
                                                }
                                                tag.addTaggable(dm);
                                            } catch (Throwable e) {
                                                Debug.out(e);
                                            }
                                        }
                                    }
                                };
                                byte[] hash = null;
                                try {
                                    hash = torrent.getHash();
                                } catch (Exception e) {
                                }
                                if (!save_torrents) {
                                    File imported = new File(folder, file.getName() + ".imported");
                                    TorrentUtils.move(file, imported);
                                    global_manager.addDownloadManager(imported.getAbsolutePath(), hash, data_save_path, start_state, true, false, dmia);
                                } else {
                                    global_manager.addDownloadManager(file.getAbsolutePath(), hash, data_save_path, start_state, true, false, dmia);
                                    // add torrent for deletion, since there will be a
                                    // saved copy elsewhere
                                    to_delete.add(torrent);
                                }
                                if (Logger.isEnabled())
                                    Logger.log(new LogEvent(LOGID, "Auto-imported " + file.getAbsolutePath()));
                            }
                        } catch (Throwable e) {
                            Debug.out("Failed to auto-import torrent file '" + file.getAbsolutePath() + "' - " + Debug.getNestedExceptionMessage(e));
                            Debug.printStackTrace(e);
                        }
                    }
                }
            }
        }
    } finally {
        this_mon.exit();
    }
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) ArrayList(java.util.ArrayList) DownloadManagerInitialisationAdapter(com.biglybt.core.download.DownloadManagerInitialisationAdapter) DownloadManager(com.biglybt.core.download.DownloadManager) LogAlert(com.biglybt.core.logging.LogAlert) TagType(com.biglybt.core.tag.TagType) TagManager(com.biglybt.core.tag.TagManager) GlobalManager(com.biglybt.core.global.GlobalManager) TOTorrent(com.biglybt.core.torrent.TOTorrent) Tag(com.biglybt.core.tag.Tag) File(java.io.File) Core(com.biglybt.core.Core)

Example 10 with Core

use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.

the class TagManagerImpl method init.

private void init() {
    if (!enabled) {
        return;
    }
    Core core = CoreFactory.getSingleton();
    final TagPropertyTrackerHandler auto_tracker = new TagPropertyTrackerHandler(core, this);
    untagged_handler = new TagPropertyUntaggedHandler(core, this);
    new TagPropertyTrackerTemplateHandler(core, this);
    constraint_handler = new TagPropertyConstraintHandler(core, this);
    core.addLifecycleListener(new CoreLifecycleAdapter() {

        @Override
        public void started(Core core) {
            core.getPluginManager().getDefaultPluginInterface().getDownloadManager().getGlobalDownloadEventNotifier().addCompletionListener(TagManagerImpl.this);
        }

        @Override
        public void componentCreated(Core core, CoreComponent component) {
            if (component instanceof GlobalManager) {
                GlobalManager global_manager = (GlobalManager) component;
                global_manager.addDownloadManagerInitialisationAdapter(new DownloadManagerInitialisationAdapter() {

                    @Override
                    public int getActions() {
                        return (ACT_ASSIGNS_TAGS);
                    }

                    @Override
                    public void initialised(DownloadManager manager, boolean for_seeding) {
                        com.biglybt.core.disk.DiskManagerFileInfo[] files = manager.getDiskManagerFileInfoSet().getFiles();
                        for (com.biglybt.core.disk.DiskManagerFileInfo file : files) {
                            if (file.getTorrentFile().getPathComponents().length == 1) {
                                String name = file.getTorrentFile().getRelativePath().toLowerCase(Locale.US);
                                if (name.equals("index.html") || name.equals("index.htm")) {
                                    TagType tt = TagManagerFactory.getTagManager().getTagType(TagType.TT_DOWNLOAD_MANUAL);
                                    String tag_name = "Websites";
                                    Tag tag = tt.getTag(tag_name, true);
                                    try {
                                        if (tag == null) {
                                            tag = tt.createTag(tag_name, true);
                                        }
                                        if (!tag.hasTaggable(manager)) {
                                            tag.addTaggable(manager);
                                            tag.setDescription(MessageText.getString("tag.website.desc"));
                                        }
                                    } catch (Throwable e) {
                                        Debug.out(e);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                });
                global_manager.addDownloadManagerInitialisationAdapter(new DownloadManagerInitialisationAdapter() {

                    @Override
                    public int getActions() {
                        return (ACT_PROCESSES_TAGS);
                    }

                    @Override
                    public void initialised(DownloadManager manager, boolean for_seeding) {
                        if (for_seeding) {
                            return;
                        }
                        // perform any auto-tagging - note that auto-tags aren't applied to the download
                        // yet
                        List<Tag> auto_tags = auto_tracker.getTagsForDownload(manager);
                        Set<Tag> tags = new HashSet<>(getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, manager));
                        tags.addAll(auto_tags);
                        if (tags.size() == 0) {
                            // pick up untagged tags here as they haven't been added yet :(
                            tags.addAll(untagged_handler.getUntaggedTags());
                        }
                        if (tags.size() > 0) {
                            List<Tag> sl_tags = new ArrayList<>();
                            for (Tag tag : tags) {
                                TagFeatureFileLocation fl = (TagFeatureFileLocation) tag;
                                if (fl.supportsTagInitialSaveFolder()) {
                                    File save_loc = fl.getTagInitialSaveFolder();
                                    if (save_loc != null) {
                                        sl_tags.add(tag);
                                    }
                                }
                            }
                            if (sl_tags.size() > 0) {
                                if (sl_tags.size() > 1) {
                                    Collections.sort(sl_tags, new Comparator<Tag>() {

                                        @Override
                                        public int compare(Tag o1, Tag o2) {
                                            return (o1.getTagID() - o2.getTagID());
                                        }
                                    });
                                }
                                TagFeatureFileLocation tag = (TagFeatureFileLocation) sl_tags.get(0);
                                long options = tag.getTagInitialSaveOptions();
                                boolean set_data = (options & TagFeatureFileLocation.FL_DATA) != 0;
                                boolean set_torrent = (options & TagFeatureFileLocation.FL_TORRENT) != 0;
                                File new_loc = tag.getTagInitialSaveFolder();
                                if (set_data) {
                                    File old_loc = manager.getSaveLocation();
                                    if (!new_loc.equals(old_loc)) {
                                        manager.setTorrentSaveDir(new_loc.getAbsolutePath());
                                    }
                                }
                                if (set_torrent) {
                                    File old_torrent_file = new File(manager.getTorrentFileName());
                                    if (old_torrent_file.exists()) {
                                        try {
                                            manager.setTorrentFile(new_loc, old_torrent_file.getName());
                                        } catch (Throwable e) {
                                            Debug.out(e);
                                        }
                                    }
                                }
                            }
                        }
                    }
                });
            }
        }

        @Override
        public void stopped(Core core) {
            destroy();
        }
    });
    SimpleTimer.addPeriodicEvent("TM:Sync", 30 * 1000, new TimerEventPerformer() {

        @Override
        public void perform(TimerEvent event) {
            for (TagType tt : tag_types) {
                ((TagTypeBase) tt).sync();
            }
        }
    });
}
Also used : CoreLifecycleAdapter(com.biglybt.core.CoreLifecycleAdapter) DownloadManager(com.biglybt.core.download.DownloadManager) GlobalManager(com.biglybt.core.global.GlobalManager) CoreComponent(com.biglybt.core.CoreComponent) Core(com.biglybt.core.Core) DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) DownloadManagerInitialisationAdapter(com.biglybt.core.download.DownloadManagerInitialisationAdapter) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File)

Aggregations

Core (com.biglybt.core.Core)71 CoreRunningListener (com.biglybt.core.CoreRunningListener)37 DownloadManager (com.biglybt.core.download.DownloadManager)17 CoreLifecycleAdapter (com.biglybt.core.CoreLifecycleAdapter)12 GlobalManager (com.biglybt.core.global.GlobalManager)10 File (java.io.File)9 GridLayout (org.eclipse.swt.layout.GridLayout)8 UIFunctions (com.biglybt.ui.UIFunctions)6 Composite (org.eclipse.swt.widgets.Composite)6 ParameterListener (com.biglybt.core.config.ParameterListener)5 LogAlert (com.biglybt.core.logging.LogAlert)5 TOTorrent (com.biglybt.core.torrent.TOTorrent)5 AERunnable (com.biglybt.core.util.AERunnable)5 GridData (org.eclipse.swt.layout.GridData)5 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)4 PluginInterface (com.biglybt.pif.PluginInterface)4 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)4 ArrayList (java.util.ArrayList)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 MessageText (com.biglybt.core.internat.MessageText)3