Search in sources :

Example 11 with PlatformManager

use of com.biglybt.platform.PlatformManager in project BiglyBT by BiglySoftware.

the class CoreImpl method checkSleepActions.

protected void checkSleepActions() {
    boolean ps_downloading = COConfigurationManager.getBooleanParameter("Prevent Sleep Downloading");
    boolean ps_fp_seed = COConfigurationManager.getBooleanParameter("Prevent Sleep FP Seeding");
    String tag_name = COConfigurationManager.getStringParameter("Prevent Sleep Tag");
    Tag ps_tag = null;
    tag_name = tag_name.trim();
    if (!tag_name.isEmpty()) {
        ps_tag = TagManagerFactory.getTagManager().getTagType(TagType.TT_DOWNLOAD_MANUAL).getTag(tag_name, true);
    }
    String declining_subsystems = "";
    for (PowerManagementListener l : power_listeners) {
        try {
            if (!l.requestPowerStateChange(PowerManagementListener.ST_SLEEP, null)) {
                declining_subsystems += (declining_subsystems.length() == 0 ? "" : ",") + l.getPowerName();
            }
        } catch (Throwable e) {
            Debug.out(e);
        }
    }
    PlatformManager platform = PlatformManagerFactory.getPlatformManager();
    if (declining_subsystems.length() == 0 && !(ps_downloading || ps_fp_seed || ps_tag != null)) {
        if (platform.getPreventComputerSleep()) {
            setPreventComputerSleep(platform, false, "configuration change");
        }
        return;
    }
    boolean prevent_sleep = false;
    String prevent_reason = null;
    if (declining_subsystems.length() > 0) {
        prevent_sleep = true;
        prevent_reason = "subsystems declined sleep: " + declining_subsystems;
    } else if (ps_tag != null && ps_tag.getTaggedCount() > 0) {
        prevent_sleep = true;
        prevent_reason = "tag '" + tag_name + "' has entries";
    } else {
        List<DownloadManager> managers = getGlobalManager().getDownloadManagers();
        for (DownloadManager manager : managers) {
            int state = manager.getState();
            if (state == DownloadManager.STATE_FINISHING || manager.getDownloadState().getFlag(DownloadManagerState.FLAG_METADATA_DOWNLOAD)) {
                if (ps_downloading) {
                    prevent_sleep = true;
                    prevent_reason = "active downloads";
                    break;
                }
            } else {
                if (state == DownloadManager.STATE_DOWNLOADING) {
                    PEPeerManager pm = manager.getPeerManager();
                    if (pm != null) {
                        if (pm.hasDownloadablePiece()) {
                            if (ps_downloading) {
                                prevent_sleep = true;
                                prevent_reason = "active downloads";
                                break;
                            }
                        } else {
                            // its effectively seeding, change so logic about recheck obeyed below
                            state = DownloadManager.STATE_SEEDING;
                        }
                    }
                }
                if (state == DownloadManager.STATE_SEEDING && ps_fp_seed) {
                    DiskManager disk_manager = manager.getDiskManager();
                    if (disk_manager != null && disk_manager.getCompleteRecheckStatus() != -1) {
                        if (ps_downloading) {
                            prevent_sleep = true;
                            prevent_reason = "active downloads";
                            break;
                        }
                    } else {
                        try {
                            DefaultRankCalculator calc = StartStopRulesDefaultPlugin.getRankCalculator(PluginCoreUtils.wrap(manager));
                            if (calc.getCachedIsFP()) {
                                prevent_sleep = true;
                                prevent_reason = "first-priority seeding";
                                break;
                            }
                        } catch (Throwable e) {
                        }
                    }
                }
            }
        }
    }
    if (prevent_sleep != platform.getPreventComputerSleep()) {
        if (prevent_sleep) {
            prevent_sleep_remove_trigger = false;
        } else {
            if (!prevent_sleep_remove_trigger) {
                prevent_sleep_remove_trigger = true;
                return;
            }
        }
        if (prevent_reason == null) {
            if (ps_downloading && ps_fp_seed) {
                prevent_reason = "no active downloads or first-priority seeding";
            } else if (ps_downloading) {
                prevent_reason = "no active downloads";
            } else {
                prevent_reason = "no active first-priority seeding";
            }
        }
        setPreventComputerSleep(platform, prevent_sleep, prevent_reason);
    }
}
Also used : DefaultRankCalculator(com.biglybt.plugin.startstoprules.defaultplugin.DefaultRankCalculator) PlatformManager(com.biglybt.platform.PlatformManager) PEPeerManager(com.biglybt.core.peer.PEPeerManager) Tag(com.biglybt.core.tag.Tag) DiskManager(com.biglybt.core.disk.DiskManager) PowerManagementListener(com.biglybt.pif.utils.PowerManagementListener) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 12 with PlatformManager

use of com.biglybt.platform.PlatformManager in project BiglyBT by BiglySoftware.

the class NetworkAdminImpl method pingTarget.

public NetworkAdminNode pingTarget(InetAddress interface_address, InetAddress target, final int max_millis, final NetworkAdminRouteListener listener) throws NetworkAdminException {
    PlatformManager pm = PlatformManagerFactory.getPlatformManager();
    if (!canPing()) {
        throw (new NetworkAdminException("No ping capability on platform"));
    }
    final NetworkAdminNode[] nodes = { null };
    try {
        pm.ping(interface_address, target, new PlatformManagerPingCallback() {

            private long start_time = SystemTime.getCurrentTime();

            @Override
            public boolean reportNode(int distance, InetAddress address, int millis) {
                boolean timeout = false;
                if (max_millis >= 0) {
                    long now = SystemTime.getCurrentTime();
                    if (now < start_time) {
                        start_time = now;
                    }
                    if (now - start_time >= max_millis) {
                        timeout = true;
                    }
                }
                NetworkAdminNode node = null;
                if (address != null) {
                    node = new networkNode(address, distance, millis);
                    nodes[0] = node;
                }
                boolean result;
                if (listener == null) {
                    result = false;
                } else {
                    if (node == null) {
                        result = listener.timeout(distance);
                    } else {
                        result = listener.foundNode(node, distance, millis);
                    }
                }
                return (result && !timeout);
            }
        });
    } catch (PlatformManagerException e) {
        throw (new NetworkAdminException("ping failed", e));
    }
    return (nodes[0]);
}
Also used : PlatformManagerPingCallback(com.biglybt.platform.PlatformManagerPingCallback) PlatformManager(com.biglybt.platform.PlatformManager) PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException)

Example 13 with PlatformManager

use of com.biglybt.platform.PlatformManager in project BiglyBT by BiglySoftware.

the class DiskManagerImpl method deleteDataFiles.

/**
 * Deletes all data files associated with torrent.
 * Currently, deletes all files, then tries to delete the path recursively
 * if the paths are empty.  An unexpected result may be that a empty
 * directory that the user created will be removed.
 *
 * TODO: only remove empty directories that are created for the torrent
 */
public static void deleteDataFiles(TOTorrent torrent, // enclosing dir, not for deletion
String torrent_save_dir, // file or dir for torrent
String torrent_save_file, boolean force_no_recycle) {
    if (torrent == null || torrent_save_file == null) {
        return;
    }
    try {
        if (torrent.isSimpleTorrent()) {
            File target = new File(torrent_save_dir, torrent_save_file);
            target = FMFileManagerFactory.getSingleton().getFileLink(torrent, 0, target.getCanonicalFile());
            FileUtil.deleteWithRecycle(target, force_no_recycle);
        } else {
            PlatformManager mgr = PlatformManagerFactory.getPlatformManager();
            if (Constants.isOSX && torrent_save_file.length() > 0 && COConfigurationManager.getBooleanParameter("Move Deleted Data To Recycle Bin") && (!force_no_recycle) && mgr.hasCapability(PlatformManagerCapabilities.RecoverableFileDelete)) {
                try {
                    String dir = torrent_save_dir + File.separatorChar + torrent_save_file + File.separatorChar;
                    // only delete the dir if there's only this torrent's files in it!
                    int numDataFiles = countDataFiles(torrent, torrent_save_dir, torrent_save_file);
                    if (countFiles(new File(dir), numDataFiles) == numDataFiles) {
                        mgr.performRecoverableFileDelete(dir);
                    } else {
                        deleteDataFileContents(torrent, torrent_save_dir, torrent_save_file, force_no_recycle);
                    }
                } catch (PlatformManagerException ex) {
                    deleteDataFileContents(torrent, torrent_save_dir, torrent_save_file, force_no_recycle);
                }
            } else {
                deleteDataFileContents(torrent, torrent_save_dir, torrent_save_file, force_no_recycle);
            }
        }
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
}
Also used : PlatformManager(com.biglybt.platform.PlatformManager) PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException) TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) CacheFile(com.biglybt.core.diskmanager.cache.CacheFile) File(java.io.File)

Example 14 with PlatformManager

use of com.biglybt.platform.PlatformManager in project BiglyBT by BiglySoftware.

the class AEDiagnostics method checkDumpsAndNatives.

public static void checkDumpsAndNatives() {
    try {
        PlatformManager p_man = PlatformManagerFactory.getPlatformManager();
        if (p_man.getPlatformType() == PlatformManager.PT_WINDOWS && p_man.hasCapability(PlatformManagerCapabilities.TestNativeAvailability)) {
            for (int i = 0; i < bad_dlls.length; i++) {
                String dll = bad_dlls[i][0];
                String load = bad_dlls[i][1];
                if (load.equalsIgnoreCase("n")) {
                    continue;
                }
                if (!COConfigurationManager.getBooleanParameter("platform.win32.dll_found." + dll, false)) {
                    try {
                        if (p_man.testNativeAvailability(dll + ".dll")) {
                            COConfigurationManager.setParameter("platform.win32.dll_found." + dll, true);
                            String detail = MessageText.getString("platform.win32.baddll." + dll);
                            Logger.logTextResource(new LogAlert(LogAlert.REPEATABLE, LogAlert.AT_WARNING, "platform.win32.baddll.info"), new String[] { dll + ".dll", detail });
                        }
                    } catch (Throwable e) {
                        Debug.printStackTrace(e);
                    }
                }
            }
        }
        List<File> fdirs_to_check = new ArrayList<>();
        fdirs_to_check.add(new File(SystemProperties.getApplicationPath()));
        try {
            File temp_file = File.createTempFile("AZU", "tmp");
            fdirs_to_check.add(temp_file.getParentFile());
            temp_file.delete();
        } catch (Throwable e) {
        }
        File most_recent_dump = null;
        long most_recent_time = 0;
        for (File dir : fdirs_to_check) {
            if (dir.canRead()) {
                File[] files = dir.listFiles(new FilenameFilter() {

                    @Override
                    public boolean accept(File dir, String name) {
                        return (name.startsWith("hs_err_pid") && name.endsWith(".log"));
                    }
                });
                if (files != null) {
                    long now = SystemTime.getCurrentTime();
                    long one_week_ago = now - 7 * 24 * 60 * 60 * 1000;
                    for (int i = 0; i < files.length; i++) {
                        File f = files[i];
                        long last_mod = f.lastModified();
                        if (last_mod > most_recent_time && last_mod > one_week_ago) {
                            most_recent_dump = f;
                            most_recent_time = last_mod;
                        }
                    }
                }
            }
        }
        if (most_recent_dump != null) {
            long last_done = COConfigurationManager.getLongParameter("diagnostics.dump.lasttime", 0);
            if (last_done < most_recent_time) {
                COConfigurationManager.setParameter("diagnostics.dump.lasttime", most_recent_time);
                analyseDump(most_recent_dump);
            }
        }
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    } finally {
        dump_check_done_sem.releaseForever();
    }
}
Also used : PlatformManager(com.biglybt.platform.PlatformManager) LogAlert(com.biglybt.core.logging.LogAlert)

Example 15 with PlatformManager

use of com.biglybt.platform.PlatformManager in project BiglyBT by BiglySoftware.

the class PlatformManagerUpdateChecker method initialize.

@Override
public void initialize(PluginInterface _plugin_interface) {
    plugin_interface = _plugin_interface;
    plugin_interface.getPluginProperties().setProperty("plugin.name", "Platform-Specific Support");
    // default version if plugin not present
    String version = "1.0";
    PlatformManager platform = PlatformManagerFactory.getPlatformManager();
    if (platform.getPlatformType() == PlatformManager.PT_WINDOWS) {
        if (platform.hasCapability(PlatformManagerCapabilities.GetVersion)) {
            try {
                version = platform.getVersion();
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
        plugin_interface.getUpdateManager().registerUpdatableComponent(this, false);
    } else {
        plugin_interface.getPluginProperties().setProperty("plugin.version.info", "Not required for this platform");
    }
    plugin_interface.getPluginProperties().setProperty("plugin.version", version);
}
Also used : PlatformManager(com.biglybt.platform.PlatformManager)

Aggregations

PlatformManager (com.biglybt.platform.PlatformManager)18 PlatformManagerException (com.biglybt.pif.platform.PlatformManagerException)5 File (java.io.File)4 LogAlert (com.biglybt.core.logging.LogAlert)3 LinkLabel (com.biglybt.ui.swt.components.LinkLabel)3 ArrayList (java.util.ArrayList)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Tag (com.biglybt.core.tag.Tag)2 PlatformManagerPingCallback (com.biglybt.platform.PlatformManagerPingCallback)2 ParameterListener (com.biglybt.core.config.ParameterListener)1 UnassociatedDevice (com.biglybt.core.devices.DeviceManager.UnassociatedDevice)1 DiskManager (com.biglybt.core.disk.DiskManager)1 CacheFile (com.biglybt.core.diskmanager.cache.CacheFile)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 PEPeerManager (com.biglybt.core.peer.PEPeerManager)1 TagManager (com.biglybt.core.tag.TagManager)1 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)1 UPnPDevice (com.biglybt.net.upnp.UPnPDevice)1 UPnPRootDevice (com.biglybt.net.upnp.UPnPRootDevice)1