use of com.biglybt.platform.PlatformManager in project BiglyBT by BiglySoftware.
the class UpdateInstallerImpl method addMoveAction.
@Override
public void addMoveAction(String from_file_or_resource, String to_file) throws UpdateException {
if (!from_file_or_resource.contains(File.separator)) {
from_file_or_resource = install_dir.toString() + File.separator + from_file_or_resource;
}
try {
// see if this action has a chance of succeeding
File to_f = new File(to_file);
File parent = to_f.getParentFile();
if (parent != null && !parent.exists()) {
parent.mkdirs();
}
boolean log_perm_set_fail = true;
if (parent != null) {
if (!parent.canWrite()) {
log_perm_set_fail = false;
if (!Constants.isWindowsVistaOrHigher) {
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_WARNING, "The location '" + parent.toString() + "' isn't writable, this update will probably fail." + " Check permissions and retry the update"));
}
}
try {
PlatformManager pm = PlatformManagerFactory.getPlatformManager();
if (pm.hasCapability(PlatformManagerCapabilities.CopyFilePermissions)) {
String parent_str = parent.getAbsolutePath();
PlatformManagerFactory.getPlatformManager().copyFilePermissions(parent_str, from_file_or_resource);
}
} catch (Throwable e) {
if (log_perm_set_fail) {
if (!Constants.isWindowsVistaOrHigher) {
Debug.out(e);
}
}
}
}
} catch (Throwable e) {
}
from_file_or_resource = escapeFile(from_file_or_resource);
to_file = escapeFile(to_file);
appendAction("move," + from_file_or_resource + "," + to_file);
}
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_MACOSX) {
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);
}
use of com.biglybt.platform.PlatformManager in project BiglyBT by BiglySoftware.
the class PlatformManagerUnixPlugin method initialize.
// @see com.biglybt.pif.Plugin#initialize(com.biglybt.pif.PluginInterface)
@Override
public void initialize(PluginInterface _plugin_interface) throws PluginException {
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.hasCapability(PlatformManagerCapabilities.GetVersion)) {
try {
version = platform.getVersion();
} catch (Throwable e) {
Debug.printStackTrace(e);
}
} else {
plugin_interface.getPluginProperties().setProperty("plugin.version.info", "Not required for this platform");
}
plugin_interface.getPluginProperties().setProperty("plugin.version", version);
plugin_interface.getUIManager().addUIListener(new UIManagerListener() {
boolean done = false;
@Override
public void UIDetached(UIInstance instance) {
}
@Override
public void UIAttached(UIInstance instance) {
if (!done) {
done = true;
if (Constants.compareVersions(UpdaterUtils.getUpdaterPluginVersion(), "1.8.5") >= 0) {
checkStartupScript();
}
}
}
});
}
use of com.biglybt.platform.PlatformManager in project BiglyBT by BiglySoftware.
the class DeviceManagerUI method createOverallMenu.
private void createOverallMenu(final MenuManager menu_manager, String parentID) {
MenuItem de_menu_item = menu_manager.addMenuItem(parentID, "device.search");
de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
de_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
search();
}
});
// show generic
de_menu_item = menu_manager.addMenuItem(parentID, "device.showGeneric");
de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
de_menu_item.setStyle(MenuItem.STYLE_CHECK);
de_menu_item.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
boolean is_hidden = COConfigurationManager.getBooleanParameter(CONFIG_VIEW_HIDE_REND_GENERIC, true);
menu.setData(!is_hidden);
boolean enabled = false;
if (is_hidden) {
Device[] devices = device_manager.getDevices();
for (Device d : devices) {
if (d.isHidden()) {
continue;
}
if (d instanceof DeviceMediaRenderer) {
DeviceMediaRenderer rend = (DeviceMediaRenderer) d;
if (rend.isNonSimple()) {
enabled = true;
}
}
}
} else {
enabled = true;
}
menu.setEnabled(enabled);
}
});
de_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
COConfigurationManager.setParameter(CONFIG_VIEW_HIDE_REND_GENERIC, !COConfigurationManager.getBooleanParameter(CONFIG_VIEW_HIDE_REND_GENERIC, true));
}
});
// show tagged
de_menu_item = menu_manager.addMenuItem(parentID, "device.onlyShowTagged");
de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
de_menu_item.setStyle(MenuItem.STYLE_CHECK);
de_menu_item.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
menu.setData(COConfigurationManager.getBooleanParameter(CONFIG_VIEW_SHOW_ONLY_TAGGED, false));
Device[] devices = device_manager.getDevices();
boolean has_tagged = false;
for (Device d : devices) {
if (d.isTagged()) {
has_tagged = true;
break;
}
}
menu.setEnabled(has_tagged);
}
});
de_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
COConfigurationManager.setParameter(CONFIG_VIEW_SHOW_ONLY_TAGGED, !COConfigurationManager.getBooleanParameter(CONFIG_VIEW_SHOW_ONLY_TAGGED, false));
}
});
// show hidden
de_menu_item = menu_manager.addMenuItem(parentID, "device.show");
de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
de_menu_item.addListener(show_listener);
de_menu_item.addFillListener(show_fill_listener);
// simple
de_menu_item = menu_manager.addMenuItem(parentID, "devices.sidebar.simple");
de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
de_menu_item.setStyle(MenuItem.STYLE_CHECK);
de_menu_item.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
menu.setData(COConfigurationManager.getIntParameter(CONFIG_VIEW_TYPE, SBV_SIMPLE) == SBV_SIMPLE);
}
});
de_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
COConfigurationManager.setParameter(CONFIG_VIEW_TYPE, ((Boolean) menu.getData()) ? SBV_SIMPLE : SBV_FULL);
}
});
de_menu_item = menu_manager.addMenuItem(parentID, "sep");
de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
de_menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
// on complete do
final MenuItem de_oxc_menu = menu_manager.addMenuItem(parentID, "devices.sidebar.onxcodecomplete");
de_oxc_menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
de_oxc_menu.setStyle(MenuItem.STYLE_MENU);
de_oxc_menu.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
menu.removeAllChildItems();
final List<MenuItem> oxc_items = new ArrayList<>();
final MenuItem oxc_nothing = menu_manager.addMenuItem(de_oxc_menu, "devices.sidebar.oxc.nothing");
oxc_items.add(oxc_nothing);
oxc_nothing.setStyle(MenuItem.STYLE_CHECK);
oxc_nothing.setData(oxc_action == OXC_NOTHING);
final MenuItem oxc_close_vuze = menu_manager.addMenuItem(de_oxc_menu, "devices.sidebar.oxc.closevuze");
oxc_items.add(oxc_close_vuze);
oxc_close_vuze.setStyle(MenuItem.STYLE_CHECK);
oxc_close_vuze.setData(oxc_action == OXC_QUIT_VUZE);
PlatformManager pm = PlatformManagerFactory.getPlatformManager();
int sdt = pm.getShutdownTypes();
final Map<MenuItem, String> oxc_pm_map = new HashMap<>();
for (int type : PlatformManager.SD_ALL) {
if ((sdt | type) != 0) {
String action = OXC_NOTHING;
if (type == PlatformManager.SD_SLEEP) {
action = OXC_SLEEP;
} else if (type == PlatformManager.SD_HIBERNATE) {
action = OXC_HIBERNATE;
} else if (type == PlatformManager.SD_SHUTDOWN) {
action = OXC_SHUTDOWN;
} else {
Debug.out("Unknown type: " + type);
}
MenuItem oxc_pm = menu_manager.addMenuItem(de_oxc_menu, "devices.sidebar.oxc.pm." + type);
oxc_items.add(oxc_pm);
oxc_pm.setStyle(MenuItem.STYLE_CHECK);
oxc_pm.setData(oxc_action == action);
oxc_pm_map.put(oxc_pm, action);
}
}
MenuItemListener oxc_mil = new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
if ((Boolean) menu.getData()) {
if (menu == oxc_nothing) {
setOXCState(OXC_NOTHING);
} else if (menu == oxc_close_vuze) {
setOXCState(OXC_QUIT_VUZE);
} else {
setOXCState(oxc_pm_map.get(menu));
}
}
}
};
for (MenuItem mi : oxc_items) {
mi.addListener(oxc_mil);
}
}
});
de_menu_item = menu_manager.addMenuItem(parentID, "sep2");
de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
de_menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
// options
de_menu_item = menu_manager.addMenuItem(parentID, "MainWindow.menu.view.configuration");
de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
de_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, CONFIG_SECTION_ID);
}
}
});
if (Constants.isCVSVersion()) {
de_menu_item = menu_manager.addMenuItem(parentID, "!(CVS Only)Show FTUX!");
de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
de_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
DevicesFTUX.showForDebug();
}
});
}
}
use of com.biglybt.platform.PlatformManager in project BiglyBT by BiglySoftware.
the class Utils method launch.
public static void launch(String sFileOriginal, boolean sync, boolean force_url, boolean force_anon) {
String sFileModified = sFileOriginal;
if (sFileModified == null || sFileModified.trim().length() == 0) {
return;
}
if (!force_url) {
if (!Constants.isWindows && new File(sFileModified).isDirectory()) {
PlatformManager mgr = PlatformManagerFactory.getPlatformManager();
if (mgr.hasCapability(PlatformManagerCapabilities.ShowFileInBrowser)) {
try {
PlatformManagerFactory.getPlatformManager().showFile(sFileModified);
return;
} catch (PlatformManagerException e) {
}
}
}
sFileModified = sFileModified.replaceAll("&vzemb=1", "");
String exe = getExplicitLauncher(sFileModified);
if (exe != null) {
File file = new File(sFileModified);
try {
System.out.println("Launching " + sFileModified + " with " + exe);
if (Constants.isWindows) {
try {
PlatformManagerFactory.getPlatformManager().createProcess(exe + " \"" + sFileModified + "\"", false);
return;
} catch (Throwable e) {
}
} else if (Constants.isOSX && exe.endsWith(".app")) {
ProcessBuilder pb = GeneralUtils.createProcessBuilder(file.getParentFile(), new String[] { "open", "-a", exe, file.getName() }, null);
pb.start();
return;
}
ProcessBuilder pb = GeneralUtils.createProcessBuilder(file.getParentFile(), new String[] { exe, file.getName() }, null);
pb.start();
return;
} catch (Throwable e) {
Debug.out("Launch failed", e);
}
}
}
String lc_sFile = sFileModified.toLowerCase(Locale.US);
if (lc_sFile.startsWith("tor:")) {
force_anon = true;
lc_sFile = lc_sFile.substring(4);
sFileModified = lc_sFile;
}
if (lc_sFile.startsWith("http:") || lc_sFile.startsWith("https:")) {
String net_type;
String eb_choice;
boolean use_plugins;
if (force_anon) {
net_type = AENetworkClassifier.AT_TOR;
eb_choice = "plugin";
use_plugins = true;
} else {
net_type = AENetworkClassifier.AT_PUBLIC;
try {
net_type = AENetworkClassifier.categoriseAddress(new URL(sFileModified).getHost());
} catch (Throwable e) {
}
eb_choice = COConfigurationManager.getStringParameter("browser.external.id", "system");
use_plugins = COConfigurationManager.getBooleanParameter("browser.external.non.pub", true);
if (net_type != AENetworkClassifier.AT_PUBLIC && use_plugins) {
// hack to force to that code leg
eb_choice = "plugin";
}
}
if (eb_choice.equals("system")) {
} else if (eb_choice.equals("manual")) {
String browser_exe = COConfigurationManager.getStringParameter("browser.external.prog", "");
File bf = new File(browser_exe);
if (bf.exists()) {
try {
Process proc = Runtime.getRuntime().exec(new String[] { bf.getAbsolutePath(), sFileModified });
} catch (Throwable e) {
Debug.out(e);
}
} else {
Debug.out("Can't launch '" + sFileModified + "' as manual browser '" + bf + " ' doesn't exist");
}
return;
} else {
handlePluginLaunch(eb_choice, net_type, use_plugins, sFileOriginal, sFileModified, sync, force_url, force_anon);
return;
}
} else if (lc_sFile.startsWith("chat:")) {
String plug_uri = "azplug:?id=azbuddy&arg=" + UrlUtils.encode(sFileModified);
try {
URLConnection connection = new URL(plug_uri).openConnection();
connection.connect();
String res = FileUtil.readInputStreamAsString(connection.getInputStream(), 2048);
return;
} catch (Throwable e) {
}
}
boolean launched = Program.launch(sFileModified);
if (!launched && Constants.isUnix) {
sFileModified = sFileModified.replaceAll(" ", "\\ ");
if (!Program.launch("xdg-open " + sFileModified)) {
if (!Program.launch("htmlview " + sFileModified)) {
Debug.out("Failed to launch '" + sFileModified + "'");
}
}
}
}
Aggregations