Search in sources :

Example 21 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class SpeedLimitHandler method setNetLimitPauseAllActive.

private void setNetLimitPauseAllActive(boolean active) {
    GlobalManager gm = core.getGlobalManager();
    if (active) {
        if (!net_limit_pause_all_active) {
            logger.logAlertRepeatable(LoggerChannel.LT_INFORMATION, "Pausing all downloads as network limit exceeded");
        }
        gm.pauseDownloads();
        net_limit_pause_all_active = true;
    } else {
        if (!rule_pause_all_active) {
            if (COConfigurationManager.getBooleanParameter("speed.limit.handler.schedule.pa_capable", false)) {
                if (net_limit_pause_all_active) {
                    logger.logAlertRepeatable(LoggerChannel.LT_INFORMATION, "Resuming all downloads as network limit no longer exceeded");
                }
                gm.resumeDownloads(true);
            }
        }
        net_limit_pause_all_active = false;
    }
    COConfigurationManager.setParameter("speed.limit.handler.schedule.nl_pa_active", active);
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager)

Example 22 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class SpeedLimitHandler method setRulePauseAllActive.

private void setRulePauseAllActive(boolean active) {
    GlobalManager gm = core.getGlobalManager();
    if (active) {
        if (!rule_pause_all_active) {
            logger.logAlertRepeatable(LoggerChannel.LT_INFORMATION, "Pausing all downloads due to pause_all rule");
        }
        gm.pauseDownloads();
        rule_pause_all_active = true;
    } else {
        if (!net_limit_pause_all_active) {
            if (COConfigurationManager.getBooleanParameter("speed.limit.handler.schedule.pa_capable", false)) {
                if (rule_pause_all_active) {
                    logger.logAlertRepeatable(LoggerChannel.LT_INFORMATION, "Resuming all downloads as pause_all rule no longer applies");
                }
                gm.resumeDownloads(true);
            }
        }
        rule_pause_all_active = false;
    }
    COConfigurationManager.setParameter("speed.limit.handler.schedule.pa_active", active);
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager)

Example 23 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class TorrentUtil method calculateToolbarStates.

// XXX Don't think *View's need this call anymore.  ToolBarView does it fo them
public static Map<String, Long> calculateToolbarStates(ISelectedContent[] currentContent, String viewID_unused) {
    // System.out.println("calculateToolbarStates(" + currentContent.length + ", " + viewID_unused + " via " + Debug.getCompressedStackTrace());
    /*
		String[] TBKEYS = new String[] {
			"download",
			"play",
			"stream",
			"run",
			"top",
			"up",
			"down",
			"bottom",
			"start",
			"stop",
			"remove"
		};
		*/
    Map<String, Long> mapNewToolbarStates = new HashMap<>();
    String[] itemsNeedingSelection = {};
    String[] itemsNeedingRealDMSelection = { "remove", "top", "bottom", "transcode", "startstop" };
    String[] itemsRequiring1DMwithHash = { "details", "comment", "up", "down" };
    String[] itemsRequiring1DMSelection = {};
    int numSelection = currentContent.length;
    boolean hasSelection = numSelection > 0;
    boolean has1Selection = numSelection == 1;
    for (int i = 0; i < itemsNeedingSelection.length; i++) {
        String itemID = itemsNeedingSelection[i];
        mapNewToolbarStates.put(itemID, hasSelection ? UIToolBarItem.STATE_ENABLED : 0);
    }
    TableView tv = SelectedContentManager.getCurrentlySelectedTableView();
    // not sure why we assume that the existance of any table view
    boolean hasRealDM = tv != null;
    if (!hasRealDM && numSelection > 0) {
        hasRealDM = true;
        for (int i = 0; i < currentContent.length; i++) {
            ISelectedContent content = currentContent[i];
            DownloadManager dm = content.getDownloadManager();
            if (dm == null) {
                hasRealDM = false;
                break;
            }
        }
    }
    if (!hasRealDM) {
        MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
        if (mdi != null) {
            MdiEntrySWT entry = mdi.getCurrentEntrySWT();
            if (entry != null) {
                if (entry.getDatasource() instanceof DownloadManager) {
                    hasRealDM = true;
                } else if ((entry instanceof UIPluginView) && (((UIPluginView) entry).getDataSource() instanceof DownloadManager)) {
                    hasRealDM = true;
                }
            }
        }
    }
    boolean canStart = false;
    boolean canStop = false;
    boolean canRemoveFileInfo = false;
    boolean canRunFileInfo = false;
    boolean canCheckExist = false;
    boolean hasDM = false;
    boolean canRecheck = false;
    if (currentContent.length > 0 && hasRealDM) {
        // well, in fact, we can have hasRealDM set to true here (because tv isn't null) and actually not have a real dm.
        // fancy that - protect against null DownloadManagers...
        boolean canMoveUp = false;
        boolean canMoveDown = false;
        boolean canDownload = false;
        canCheckExist = true;
        GlobalManager gm = null;
        for (int i = 0; i < currentContent.length; i++) {
            ISelectedContent content = currentContent[i];
            DownloadManager dm = content.getDownloadManager();
            if (dm == null) {
                if (!canDownload && content.getDownloadInfo() != null) {
                    canDownload = true;
                }
                continue;
            }
            if (gm == null) {
                gm = dm.getGlobalManager();
            }
            int state = dm.getState();
            canCheckExist &= (state == DownloadManager.STATE_ERROR || state == DownloadManager.STATE_STOPPED || state == DownloadManager.STATE_QUEUED);
            int fileIndex = content.getFileIndex();
            if (fileIndex == -1) {
                if (!canMoveUp && gm.isMoveableUp(dm)) {
                    canMoveUp = true;
                }
                if (!canMoveDown && gm.isMoveableDown(dm)) {
                    canMoveDown = true;
                }
                hasDM = true;
                if (!canStart && ManagerUtils.isStartable(dm)) {
                    canStart = true;
                }
                if (!canStop && ManagerUtils.isStopable(dm)) {
                    canStop = true;
                }
            } else {
                DiskManagerFileInfoSet fileInfos = dm.getDiskManagerFileInfoSet();
                if (fileIndex < fileInfos.nbFiles()) {
                    DiskManagerFileInfo fileInfo = fileInfos.getFiles()[fileIndex];
                    if (!canStart && (fileInfo.isSkipped())) {
                        canStart = true;
                    }
                    if (!canStop && !fileInfo.isSkipped()) {
                        canStop = true;
                    }
                    if (!canRemoveFileInfo && !fileInfo.isSkipped()) {
                        int storageType = fileInfo.getStorageType();
                        if (storageType == DiskManagerFileInfo.ST_LINEAR || storageType == DiskManagerFileInfo.ST_COMPACT) {
                            canRemoveFileInfo = true;
                        }
                    }
                    if (!canRunFileInfo && fileInfo.getAccessMode() == DiskManagerFileInfo.READ && fileInfo.getDownloaded() == fileInfo.getLength() && fileInfo.getFile(true).exists()) {
                        canRunFileInfo = true;
                    }
                }
            }
            canRecheck = canRecheck || dm.canForceRecheck();
        }
        boolean canRemove = hasDM || canRemoveFileInfo;
        mapNewToolbarStates.put("remove", canRemove ? UIToolBarItem.STATE_ENABLED : 0);
        mapNewToolbarStates.put("download", canDownload ? UIToolBarItem.STATE_ENABLED : 0);
        if (currentContent.length == 1) {
            mapNewToolbarStates.put("up", canMoveUp ? UIToolBarItem.STATE_ENABLED : 0);
            mapNewToolbarStates.put("down", canMoveDown ? UIToolBarItem.STATE_ENABLED : 0);
        }
    }
    boolean canRun = has1Selection && ((hasDM && !canRunFileInfo) || (!hasDM && canRunFileInfo));
    if (canRun) {
        ISelectedContent content = currentContent[0];
        DownloadManager dm = content.getDownloadManager();
        if (dm == null) {
            canRun = false;
        } else {
            TOTorrent torrent = dm.getTorrent();
            if (torrent == null) {
                canRun = false;
            } else if (!dm.getAssumedComplete() && torrent.isSimpleTorrent()) {
                canRun = false;
            /*
									} else if (PlatformTorrentUtils.useEMP(torrent)
											&& PlatformTorrentUtils.embeddedPlayerAvail()
											&& PlayUtils.canProgressiveOrIsComplete(torrent)) {
										// play button enabled and not UMP.. don't need launch

										canRun = false;

									}
									*/
            }
        }
    }
    mapNewToolbarStates.put("run", canRun ? UIToolBarItem.STATE_ENABLED : 0);
    mapNewToolbarStates.put("start", canStart ? UIToolBarItem.STATE_ENABLED : 0);
    mapNewToolbarStates.put("stop", canStop ? UIToolBarItem.STATE_ENABLED : 0);
    mapNewToolbarStates.put("startstop", canStart || canStop ? UIToolBarItem.STATE_ENABLED : 0);
    for (int i = 0; i < itemsNeedingRealDMSelection.length; i++) {
        String itemID = itemsNeedingRealDMSelection[i];
        if (!mapNewToolbarStates.containsKey(itemID)) {
            mapNewToolbarStates.put(itemID, hasSelection && hasDM && hasRealDM ? UIToolBarItem.STATE_ENABLED : 0);
        }
    }
    for (int i = 0; i < itemsRequiring1DMSelection.length; i++) {
        String itemID = itemsRequiring1DMSelection[i];
        if (!mapNewToolbarStates.containsKey(itemID)) {
            mapNewToolbarStates.put(itemID, has1Selection && hasDM ? UIToolBarItem.STATE_ENABLED : 0);
        }
    }
    for (int i = 0; i < itemsRequiring1DMwithHash.length; i++) {
        String itemID = itemsRequiring1DMwithHash[i];
        if (!mapNewToolbarStates.containsKey(itemID)) {
            mapNewToolbarStates.put(itemID, hasDM ? UIToolBarItem.STATE_ENABLED : 0);
        }
    }
    mapNewToolbarStates.put("download", has1Selection && (!(currentContent[0] instanceof ISelectedVuzeFileContent)) && currentContent[0].getDownloadManager() == null && (currentContent[0].getHash() != null || currentContent[0].getDownloadInfo() != null) ? UIToolBarItem.STATE_ENABLED : 0);
    if (tv != null) {
        TableColumn tc = tv.getTableColumn(RankItem.COLUMN_ID);
        if (tc != null && !tc.isVisible()) {
            mapNewToolbarStates.put("up", 0L);
            mapNewToolbarStates.put("down", 0L);
        }
    }
    mapNewToolbarStates.put(TU_ITEM_RECHECK, canRecheck ? UIToolBarItem.STATE_ENABLED : 0);
    mapNewToolbarStates.put(TU_ITEM_CHECK_FILES, canCheckExist ? UIToolBarItem.STATE_ENABLED : 0);
    return mapNewToolbarStates;
}
Also used : ISelectedVuzeFileContent(com.biglybt.ui.selectedcontent.ISelectedVuzeFileContent) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) DiskManagerFileInfoSet(com.biglybt.core.disk.DiskManagerFileInfoSet) MdiEntrySWT(com.biglybt.ui.swt.mdi.MdiEntrySWT) DownloadManager(com.biglybt.core.download.DownloadManager) TableColumn(com.biglybt.pif.ui.tables.TableColumn) GlobalManager(com.biglybt.core.global.GlobalManager) TOTorrent(com.biglybt.core.torrent.TOTorrent) UIPluginView(com.biglybt.pif.ui.UIPluginView) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT) TableView(com.biglybt.ui.common.table.TableView)

Example 24 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class Initializer method handleCoreStarted.

void handleCoreStarted(Core core) {
    boolean main_window_will_report_complete = false;
    try {
        GlobalManager gm = core.getGlobalManager();
        InitialisationFunctions.lateInitialisation(core);
        if (gm == null) {
            return;
        }
        // Ensure colors initialized
        Colors.getInstance();
        Initializer.this.reportPercent(curPercent + 1);
        new UserAlerts(gm);
        reportCurrentTaskByKey("splash.initializeGui");
        Initializer.this.reportPercent(curPercent + 1);
        main_window_will_report_complete = true;
        if (STARTUP_UIFIRST) {
            windowInitStub.init(core);
        } else {
            MainWindowFactory.create(core, Display.getDefault(), Initializer.this);
        }
        reportCurrentTaskByKey("splash.openViews");
        SWTUpdateChecker.initialize();
        // setup the update monitor
        UpdateMonitor.getSingleton(core);
        // Tell listeners that all is initialized :
        Alerts.initComplete();
    } finally {
        if (!main_window_will_report_complete) {
            init_task.release();
        }
    }
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager)

Example 25 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class Initializer method cleanupOldStuff.

private void cleanupOldStuff() {
    File v3Shares = new File(SystemProperties.getUserPath(), "v3shares");
    if (v3Shares.isDirectory()) {
        FileUtil.recursiveDeleteNoCheck(v3Shares);
    }
    File dirFriends = new File(SystemProperties.getUserPath(), "friends");
    if (dirFriends.isDirectory()) {
        FileUtil.recursiveDeleteNoCheck(dirFriends);
    }
    File dirMedia = new File(SystemProperties.getUserPath(), "media");
    if (dirMedia.isDirectory()) {
        FileUtil.recursiveDeleteNoCheck(dirMedia);
    }
    deleteConfig("v3.Friends.dat");
    deleteConfig("unsentdata.config");
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(final Core core) {
            new AEThread2("cleanupOldStuff", true) {

                @Override
                public void run() {
                    GlobalManager gm = core.getGlobalManager();
                    List dms = gm.getDownloadManagers();
                    for (Object o : dms) {
                        DownloadManager dm = (DownloadManager) o;
                        if (dm != null) {
                            String val = PlatformTorrentUtils.getContentMapString(dm.getTorrent(), "Ad ID");
                            if (val != null) {
                                try {
                                    gm.removeDownloadManager(dm, true, true);
                                } catch (Exception e) {
                                }
                            }
                        }
                    }
                }
            }.start();
        }
    });
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager) List(java.util.List) File(java.io.File) DownloadManager(com.biglybt.core.download.DownloadManager) PluginException(com.biglybt.pif.PluginException) IOException(java.io.IOException)

Aggregations

GlobalManager (com.biglybt.core.global.GlobalManager)48 DownloadManager (com.biglybt.core.download.DownloadManager)33 Core (com.biglybt.core.Core)10 TOTorrent (com.biglybt.core.torrent.TOTorrent)10 List (java.util.List)7 CoreRunningListener (com.biglybt.core.CoreRunningListener)6 File (java.io.File)6 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)5 UIFunctions (com.biglybt.ui.UIFunctions)5 GlobalManagerStats (com.biglybt.core.global.GlobalManagerStats)4 PEPeerManager (com.biglybt.core.peer.PEPeerManager)4 HashWrapper (com.biglybt.core.util.HashWrapper)4 PluginInterface (com.biglybt.pif.PluginInterface)4 Menu (org.eclipse.swt.widgets.Menu)4 DiskManagerFileInfoSet (com.biglybt.core.disk.DiskManagerFileInfoSet)3 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)3 PEPeer (com.biglybt.core.peer.PEPeer)3 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)3 PluginException (com.biglybt.pif.PluginException)3 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)3