Search in sources :

Example 16 with PlatformManagerException

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

the class PlatformManagerImpl method showFile.

/**
 * {@inheritDoc}
 */
@Override
public void showFile(String file_name) throws PlatformManagerException {
    try {
        File file = new File(file_name);
        access.createProcess("explorer.exe " + (file.isDirectory() ? "/e," : "/e,/select,") + "\"" + file_name + "\"", false);
    /*
        	Runtime.getRuntime().exec(
        			new String[] { "explorer.exe",
        					file.isDirectory() ? "/e," : "/e,/select,",
        							"\"" + file_name + "\"" });
        							*/
    } catch (Throwable e) {
        throw new PlatformManagerException("Failed to show file " + file_name, e);
    }
}
Also used : PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException)

Example 17 with PlatformManagerException

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

the class PlatformManagerImpl method setExplicitVMOptions.

@Override
public void setExplicitVMOptions(String[] options) throws PlatformManagerException {
    checkCapability(PlatformManagerCapabilities.AccessExplicitVMOptions);
    File local_options = checkAndGetLocalVMOptionFile();
    try {
        if (local_options.exists()) {
            File backup = new File(local_options.getParentFile(), local_options.getName() + ".bak");
            if (backup.exists()) {
                backup.delete();
            }
            if (!local_options.renameTo(backup)) {
                throw (new Exception("Failed to move " + local_options + " to " + backup));
            }
            boolean ok = false;
            try {
                PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(local_options), "UTF-8"));
                try {
                    for (String option : options) {
                        pw.println(option);
                    }
                    ok = true;
                } finally {
                    pw.close();
                }
            } finally {
                if (!ok) {
                    local_options.delete();
                    backup.renameTo(local_options);
                }
            }
        }
    } catch (Throwable e) {
        throw (new PlatformManagerException(MessageText.getString("platform.jvmopt.accesserror", new String[] { Debug.getNestedExceptionMessage(e) })));
    }
}
Also used : PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException) PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException)

Example 18 with PlatformManagerException

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

the class PlatformManagerImpl method registerAdditionalFileType.

@Override
public void registerAdditionalFileType(// e.g. "BitTorrent"
String name, // e.g. "BitTorrent File"
String description, // e.g. ".torrent"
String type, // e.g. "application/x-bittorrent"
String content_type) throws PlatformManagerException {
    try {
        if (OSXAccess.canSetDefaultApp()) {
            if (type != null) {
                String osxType = type.startsWith(".") ? type.substring(1) : type;
                OSXAccess.setDefaultAppForExt(BUNDLE_ID, osxType);
            }
            if (content_type != null) {
                OSXAccess.setDefaultAppForMime(BUNDLE_ID, content_type);
            }
        }
    } catch (Throwable t) {
        throw new PlatformManagerException("registerAdditionalFileType failed on platform manager", t);
    }
}
Also used : PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException)

Example 19 with PlatformManagerException

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

the class PlatformManagerImpl method setRunAtLogin.

@Override
public void setRunAtLogin(boolean run) throws PlatformManagerException {
    if (getRunAtLogin() == run) {
        return;
    }
    File bundle_file = getAbsoluteBundleFile();
    if (!bundle_file.exists()) {
        throw (new PlatformManagerException("Failed to write set run-at-login, bundle not found"));
    }
    String abs_target = bundle_file.getAbsolutePath();
    if (Constants.isOSX_10_8_OrHigher) {
        if (run) {
            try {
                StringBuffer sb = new StringBuffer();
                sb.append("tell application \"");
                sb.append("System Events");
                sb.append("\" to make login item at end with properties {path:\"");
                sb.append(abs_target);
                sb.append("\", hidden:false}");
                System.out.println(performOSAScript(sb));
                return;
            } catch (Throwable e) {
                throw new PlatformManagerException("Failed to add login item", e);
            }
        } else {
            try {
                StringBuffer sb = new StringBuffer();
                sb.append("tell application \"");
                sb.append("System Events");
                sb.append("\" to delete login item \"");
                sb.append(SystemProperties.getApplicationName());
                sb.append("\"");
                System.out.println(performOSAScript(sb));
                return;
            } catch (Throwable e) {
                throw new PlatformManagerException("Failed to delete login item", e);
            }
        }
    }
    File f = getLoginPList();
    if (f.exists()) {
        convertToXML(f);
    } else {
        try {
            PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(f), "UTF-8"));
            try {
                pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                pw.println("<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
                pw.println("<plist version=\"1.0\">");
                pw.println("<dict>");
                pw.println("</dict>");
                pw.println("</plist>");
            } finally {
                pw.close();
            }
        } catch (Throwable e) {
            throw (new PlatformManagerException("Failed to write output file", e));
        }
    }
    try {
        List<String> lines = new ArrayList<>();
        LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
        int dict_line = -1;
        int auto_launch_line = -1;
        int target_index = -1;
        try {
            while (true) {
                String line = lnr.readLine();
                if (line == null) {
                    break;
                }
                lines.add(line);
                if (dict_line == -1 && containsTag(line, "<dict>")) {
                    dict_line = lines.size();
                }
                if (auto_launch_line == -1 && containsTag(line, "AutoLaunchedApplicationDictionary")) {
                    auto_launch_line = lines.size();
                }
                if (line.contains(abs_target)) {
                    target_index = lines.size();
                }
            }
            if (dict_line == -1) {
                throw (new PlatformManagerException("Malformed plist - no 'dict' entry"));
            }
            if (auto_launch_line == -1) {
                lines.add(dict_line, "\t<key>AutoLaunchedApplicationDictionary</key>");
                auto_launch_line = dict_line + 1;
                lines.add(auto_launch_line, "\t<array>");
                lines.add(auto_launch_line + 1, "\t</array>");
            }
        } finally {
            lnr.close();
        }
        if (run) {
            if (target_index != -1 || auto_launch_line == -1) {
                return;
            }
            target_index = auto_launch_line + 1;
            lines.add(target_index++, "\t\t<dict>");
            lines.add(target_index++, "\t\t\t<key>Path</key>");
            lines.add(target_index++, "\t\t\t<string>" + abs_target + "</string>");
            lines.add(target_index++, "\t\t</dict>");
        } else {
            if (target_index == -1) {
                return;
            }
            while (!containsTag(lines.get(target_index), "</dict>")) {
                lines.remove(target_index);
            }
            lines.remove(target_index);
            target_index--;
            while (!containsTag(lines.get(target_index), "<dict>")) {
                lines.remove(target_index);
                target_index--;
            }
            lines.remove(target_index);
        }
        File backup = new File(f.getParentFile(), f.getName() + ".bak");
        if (backup.exists()) {
            backup.delete();
        }
        if (!f.renameTo(backup)) {
            throw (new PlatformManagerException("Failed to backup " + f));
        }
        boolean ok = false;
        try {
            PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(f), "UTF-8"));
            try {
                for (String line : lines) {
                    pw.println(line);
                }
            } finally {
                pw.close();
                if (pw.checkError()) {
                    throw (new PlatformManagerException("Failed to write output file"));
                }
                ok = true;
            }
        } finally {
            if (!ok) {
                backup.renameTo(f);
            }
        }
    } catch (PlatformManagerException e) {
        throw (e);
    } catch (Throwable e) {
        throw (new PlatformManagerException("Failed to write output file", e));
    }
}
Also used : PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException)

Example 20 with PlatformManagerException

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

the class PlatformManagerImpl method checkAndGetLocalVMOptionFile.

private File checkAndGetLocalVMOptionFile() throws PlatformManagerException {
    String vendor = System.getProperty("java.vendor", "<unknown>");
    if (!vendor.toLowerCase().startsWith("sun ") && !vendor.toLowerCase().startsWith("oracle ")) {
        throw (new PlatformManagerException(MessageText.getString("platform.jvmopt.sunonly", new String[] { vendor })));
    }
    File[] option_files = getJVMOptionFiles();
    if (option_files.length != 2) {
        throw (new PlatformManagerException(MessageText.getString("platform.jvmopt.configerror")));
    }
    File shared_options = option_files[0];
    if (shared_options.exists()) {
        try {
            String s_options = FileUtil.readFileAsString(shared_options, -1);
            if (s_options.contains(getJVMOptionRedirect())) {
                File local_options = option_files[1];
                return (local_options);
            } else {
                throw (new PlatformManagerException(MessageText.getString("platform.jvmopt.nolink")));
            }
        } catch (Throwable e) {
            throw (new PlatformManagerException(MessageText.getString("platform.jvmopt.accesserror", new String[] { Debug.getNestedExceptionMessage(e) })));
        }
    } else {
        throw (new PlatformManagerException(MessageText.getString("platform.jvmopt.nolinkfile")));
    }
}
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