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);
}
}
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) })));
}
}
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);
}
}
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));
}
}
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")));
}
}
Aggregations