Search in sources :

Example 21 with PlatformManagerException

use of com.biglybt.pif.platform.PlatformManagerException in project BiglyBT by BiglySoftware.

the class PlatformManagerImpl method getRunAtLogin.

@Override
public boolean getRunAtLogin() throws PlatformManagerException {
    if (Constants.isOSX_10_8_OrHigher) {
        String item_name = SystemProperties.getApplicationName();
        try {
            StringBuffer sb = new StringBuffer();
            sb.append("tell application \"");
            sb.append("System Events");
            sb.append("\" to get the name of every login item");
            String[] items = performOSAScript(sb).split(",");
            for (String item : items) {
                if (item.trim().equalsIgnoreCase(item_name)) {
                    return (true);
                }
            }
            return (false);
        } catch (Throwable e) {
            throw new PlatformManagerException("Failed to get login items", e);
        }
    }
    File f = getLoginPList();
    if (!f.exists()) {
        return (false);
    }
    File bundle_file = getAbsoluteBundleFile();
    if (!bundle_file.exists()) {
        return (false);
    }
    try {
        convertToXML(f);
        LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
        int state = 0;
        String target = bundle_file.getAbsolutePath();
        try {
            while (true) {
                String line = lnr.readLine();
                if (line == null) {
                    break;
                }
                if (state == 0) {
                    if (containsTag(line, "AutoLaunchedApplicationDictionary")) {
                        state = 1;
                    }
                } else {
                    if (line.contains(target)) {
                        return (true);
                    }
                }
            }
            return (false);
        } finally {
            lnr.close();
        }
    } catch (Throwable e) {
        throw (new PlatformManagerException("Failed to read input file", e));
    }
}
Also used : PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException)

Aggregations

PlatformManagerException (com.biglybt.pif.platform.PlatformManagerException)21 PlatformManager (com.biglybt.platform.PlatformManager)5 LogAlert (com.biglybt.core.logging.LogAlert)4 Method (java.lang.reflect.Method)4 File (java.io.File)3 LogEvent (com.biglybt.core.logging.LogEvent)2 PlatformManagerPingCallback (com.biglybt.platform.PlatformManagerPingCallback)2 LinkLabel (com.biglybt.ui.swt.components.LinkLabel)2 URL (java.net.URL)2 URLConnection (java.net.URLConnection)2 GridData (org.eclipse.swt.layout.GridData)2 CoreException (com.biglybt.core.CoreException)1 ParameterListener (com.biglybt.core.config.ParameterListener)1 CacheFile (com.biglybt.core.diskmanager.cache.CacheFile)1 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)1 UtilitiesImpl.runnableWithException (com.biglybt.pifimpl.local.utils.UtilitiesImpl.runnableWithException)1 AEWin32Access (com.biglybt.platform.win32.access.AEWin32Access)1 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1