Search in sources :

Example 1 with PlatformManagerException

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

the class ConfigSectionStartShutdown method buildOptions.

private void buildOptions(final Composite parent, final PlatformManager platform, final Composite area, boolean rebuild) throws PlatformManagerException {
    if (rebuild) {
        Control[] kids = area.getChildren();
        for (Control k : kids) {
            k.dispose();
        }
    }
    String[] options = platform.getExplicitVMOptions();
    {
        // max mem
        long max_mem = AEJavaManagement.getJVMLongOption(options, "-Xmx");
        final int MIN_MAX_JVM = 32 * 1024 * 1024;
        GridData gridData = new GridData();
        Label label = new Label(area, SWT.NULL);
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "jvm.max.mem", new String[] { encodeDisplayLong(MIN_MAX_JVM) });
        gridData = new GridData();
        gridData.widthHint = 125;
        final StringParameter max_vm = new StringParameter(area, "jvm.max.mem", "", false);
        max_vm.setLayoutData(gridData);
        max_vm.setValue(max_mem == -1 ? "" : encodeDisplayLong(max_mem));
        max_vm.addChangeListener(new ParameterChangeAdapter() {

            private String last_value;

            @Override
            public void parameterChanged(Parameter p, boolean caused_internally) {
                if (max_vm.isDisposed()) {
                    max_vm.removeChangeListener(this);
                    return;
                }
                String val = max_vm.getValue();
                if (last_value != null && last_value.equals(val)) {
                    return;
                }
                last_value = val;
                try {
                    long max_mem = decodeDisplayLong(val);
                    if (max_mem < MIN_MAX_JVM) {
                        throw (new Exception("Min=" + encodeDisplayLong(MIN_MAX_JVM)));
                    }
                    String[] options = platform.getExplicitVMOptions();
                    options = AEJavaManagement.setJVMLongOption(options, "-Xmx", max_mem);
                    long min_mem = AEJavaManagement.getJVMLongOption(options, "-Xms");
                    if (min_mem == -1 || min_mem > max_mem) {
                        options = AEJavaManagement.setJVMLongOption(options, "-Xms", max_mem);
                    }
                    platform.setExplicitVMOptions(options);
                    buildOptions(parent, platform, area, true);
                } catch (Throwable e) {
                    String param_name = MessageText.getString("jvm.max.mem");
                    int pos = param_name.indexOf('[');
                    if (pos != -1) {
                        param_name = param_name.substring(0, pos).trim();
                    }
                    MessageBoxShell mb = new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.invalid.value.title"), MessageText.getString("ConfigView.section.invalid.value", new String[] { val, param_name, Debug.getNestedExceptionMessage(e) }));
                    mb.setParent(parent.getShell());
                    mb.open(null);
                }
            }
        });
        label = new Label(area, SWT.NULL);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(label, gridData);
        Long max_heap_mb = AEJavaManagement.getMaxHeapMB();
        if (max_heap_mb > 0) {
            Messages.setLanguageText(label, "jvm.max.mem.current", new String[] { DisplayFormatters.formatByteCountToKiBEtc(max_heap_mb * 1024 * 1024, true) });
        }
    }
    {
        // min mem
        final int MIN_MIN_JVM = 8 * 1024 * 1024;
        long min_mem = AEJavaManagement.getJVMLongOption(options, "-Xms");
        GridData gridData = new GridData();
        Label label = new Label(area, SWT.NULL);
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "jvm.min.mem", new String[] { encodeDisplayLong(MIN_MIN_JVM) });
        gridData = new GridData();
        gridData.widthHint = 125;
        final StringParameter min_vm = new StringParameter(area, "jvm.min.mem", "", false);
        min_vm.setLayoutData(gridData);
        min_vm.setValue(min_mem == -1 ? "" : encodeDisplayLong(min_mem));
        min_vm.addChangeListener(new ParameterChangeAdapter() {

            private String last_value;

            @Override
            public void parameterChanged(Parameter p, boolean caused_internally) {
                if (min_vm.isDisposed()) {
                    min_vm.removeChangeListener(this);
                    return;
                }
                String val = min_vm.getValue();
                if (last_value != null && last_value.equals(val)) {
                    return;
                }
                last_value = val;
                try {
                    long min_mem = decodeDisplayLong(val);
                    if (min_mem < MIN_MIN_JVM) {
                        throw (new Exception("Min=" + encodeDisplayLong(MIN_MIN_JVM)));
                    }
                    String[] options = platform.getExplicitVMOptions();
                    options = AEJavaManagement.setJVMLongOption(options, "-Xms", min_mem);
                    long max_mem = AEJavaManagement.getJVMLongOption(options, "-Xmx");
                    if (max_mem == -1 || max_mem < min_mem) {
                        options = AEJavaManagement.setJVMLongOption(options, "-Xmx", min_mem);
                    }
                    platform.setExplicitVMOptions(options);
                    buildOptions(parent, platform, area, true);
                } catch (Throwable e) {
                    String param_name = MessageText.getString("jvm.min.mem");
                    int pos = param_name.indexOf('[');
                    if (pos != -1) {
                        param_name = param_name.substring(0, pos).trim();
                    }
                    MessageBoxShell mb = new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.invalid.value.title"), MessageText.getString("ConfigView.section.invalid.value", new String[] { val, param_name, Debug.getNestedExceptionMessage(e) }));
                    mb.setParent(parent.getShell());
                    mb.open(null);
                }
            }
        });
        label = new Label(area, SWT.NULL);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(label, gridData);
    }
    {
        // max DIRECT mem
        final int MIN_DIRECT_JVM = 32 * 1024 * 1024;
        final String OPTION_KEY = "-XX:MaxDirectMemorySize=";
        long max_direct = AEJavaManagement.getJVMLongOption(options, OPTION_KEY);
        GridData gridData = new GridData();
        Label label = new Label(area, SWT.NULL);
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "jvm.max.direct.mem", new String[] { encodeDisplayLong(MIN_DIRECT_JVM) });
        gridData = new GridData();
        gridData.widthHint = 125;
        final StringParameter max_direct_vm = new StringParameter(area, "jvm.max.direct.mem", "", false);
        max_direct_vm.setLayoutData(gridData);
        max_direct_vm.setValue(max_direct == -1 ? "" : encodeDisplayLong(max_direct));
        max_direct_vm.addChangeListener(new ParameterChangeAdapter() {

            private String last_value;

            @Override
            public void parameterChanged(Parameter p, boolean caused_internally) {
                if (max_direct_vm.isDisposed()) {
                    max_direct_vm.removeChangeListener(this);
                    return;
                }
                String val = max_direct_vm.getValue();
                if (last_value != null && last_value.equals(val)) {
                    return;
                }
                last_value = val;
                try {
                    long max_direct = decodeDisplayLong(val);
                    if (max_direct < MIN_DIRECT_JVM) {
                        throw (new Exception("Min=" + encodeDisplayLong(MIN_DIRECT_JVM)));
                    }
                    String[] options = platform.getExplicitVMOptions();
                    options = AEJavaManagement.setJVMLongOption(options, OPTION_KEY, max_direct);
                    platform.setExplicitVMOptions(options);
                    buildOptions(parent, platform, area, true);
                } catch (Throwable e) {
                    String param_name = MessageText.getString("jvm.max.direct.mem");
                    int pos = param_name.indexOf('[');
                    if (pos != -1) {
                        param_name = param_name.substring(0, pos).trim();
                    }
                    MessageBoxShell mb = new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.invalid.value.title"), MessageText.getString("ConfigView.section.invalid.value", new String[] { val, param_name, Debug.getNestedExceptionMessage(e) }));
                    mb.setParent(parent.getShell());
                    mb.open(null);
                }
            }
        });
        label = new Label(area, SWT.NULL);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        Utils.setLayoutData(label, gridData);
        Messages.setLanguageText(label, "jvm.max.direct.mem.info");
    }
    // all options
    Label label = new Label(area, SWT.NULL);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    Utils.setLayoutData(label, gridData);
    Messages.setLanguageText(label, "jvm.options.summary");
    for (String option : options) {
        label = new Label(area, SWT.NULL);
        label.setText(option);
        gridData = new GridData();
        gridData.horizontalSpan = 3;
        gridData.horizontalIndent = 20;
        Utils.setLayoutData(label, gridData);
    }
    if (rebuild) {
        parent.layout(true, true);
    }
}
Also used : LinkLabel(com.biglybt.ui.swt.components.LinkLabel) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException) GridData(org.eclipse.swt.layout.GridData)

Example 2 with PlatformManagerException

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

the class ConfigSectionInterface method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    GridData gridData;
    GridLayout layout;
    Label label;
    Composite cDisplay = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(cDisplay, gridData);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    cDisplay.setLayout(layout);
    final PlatformManager platform = PlatformManagerFactory.getPlatformManager();
    // ***** auto open group
    Group gAutoOpen = new Group(cDisplay, SWT.NULL);
    Messages.setLanguageText(gAutoOpen, "ConfigView.label.autoopen");
    layout = new GridLayout(3, false);
    gAutoOpen.setLayout(layout);
    Utils.setLayoutData(gAutoOpen, new GridData(GridData.FILL_HORIZONTAL));
    label = new Label(gAutoOpen, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.label.autoopen.detailstab");
    new BooleanParameter(gAutoOpen, "Open Details", "ConfigView.label.autoopen.dl");
    new BooleanParameter(gAutoOpen, "Open Seeding Details", "ConfigView.label.autoopen.cd");
    label = new Label(gAutoOpen, SWT.NULL);
    Messages.setLanguageText(label, "ConfigView.label.autoopen.downloadbars");
    new BooleanParameter(gAutoOpen, "Open Bar Incomplete", "ConfigView.label.autoopen.dl");
    new BooleanParameter(gAutoOpen, "Open Bar Complete", "ConfigView.label.autoopen.cd");
    if (!Constants.isOSX) {
        new BooleanParameter(cDisplay, "Show Status In Window Title", "ConfigView.label.info.in.window.title");
    }
    new BooleanParameter(cDisplay, "Remember transfer bar location", "ConfigView.label.transferbar.remember_location");
    Composite gBarTrans = new Composite(cDisplay, SWT.NULL);
    layout = new GridLayout(4, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    gBarTrans.setLayout(layout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalIndent = 25;
    Utils.setLayoutData(gBarTrans, gridData);
    label = new Label(gBarTrans, SWT.NULL);
    Messages.setLanguageText(label, "label.bar.trans");
    new IntParameter(gBarTrans, "Bar Transparency", 0, 100);
    label = new Label(gBarTrans, SWT.NULL);
    Messages.setLanguageText(label, "label.show.icon.area");
    new BooleanParameter(gBarTrans, "Transfer Bar Show Icon Area");
    {
        // sys tray
        Group gSysTray = new Group(cDisplay, SWT.NULL);
        Messages.setLanguageText(gSysTray, "ConfigView.label.systray");
        layout = new GridLayout();
        layout.numColumns = 2;
        gSysTray.setLayout(layout);
        Utils.setLayoutData(gSysTray, new GridData(GridData.FILL_HORIZONTAL));
        BooleanParameter est = new BooleanParameter(gSysTray, "Enable System Tray", "ConfigView.section.interface.enabletray");
        est.addChangeListener(new ParameterChangeAdapter() {

            @Override
            public void booleanParameterChanging(Parameter p, boolean toValue) {
                if (toValue) {
                    SystemTraySWT.getTray();
                } else {
                    SystemTraySWT.getTray().dispose();
                }
            }
        });
        BooleanParameter stdo = new BooleanParameter(gSysTray, "System Tray Disabled Override", "ConfigView.label.closetotrayoverride");
        BooleanParameter ctt = new BooleanParameter(gSysTray, "Close To Tray", "ConfigView.label.closetotray");
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        ctt.setLayoutData(gridData);
        BooleanParameter mtt = new BooleanParameter(gSysTray, "Minimize To Tray", "ConfigView.label.minimizetotray");
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        mtt.setLayoutData(gridData);
        BooleanParameter esttt = new BooleanParameter(gSysTray, "ui.systray.tooltip.enable", "ConfigView.label.enableSystrayToolTip");
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        esttt.setLayoutData(gridData);
        BooleanParameter estttd = new BooleanParameter(gSysTray, "ui.systray.tooltip.next.eta.enable", "ConfigView.label.enableSystrayToolTipNextETA");
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        gridData.horizontalIndent = 25;
        estttd.setLayoutData(gridData);
        est.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(stdo.getControls(), true));
        IAdditionalActionPerformer st_enabler = new GenericActionPerformer(new Control[] {}) {

            @Override
            public void performAction() {
                boolean st_enabled = est.isSelected();
                boolean override = stdo.isSelected();
                boolean dl_stats = esttt.isSelected();
                ctt.setEnabled(st_enabled || override);
                mtt.setEnabled(st_enabled || override);
                esttt.setEnabled(st_enabled);
                estttd.setEnabled(st_enabled && dl_stats);
            }
        };
        est.setAdditionalActionPerformer(st_enabler);
        stdo.setAdditionalActionPerformer(st_enabler);
        esttt.setAdditionalActionPerformer(st_enabler);
    }
    /**
     * Default download / upload limits available in the UI.
     */
    Group limit_group = new Group(cDisplay, SWT.NULL);
    Messages.setLanguageText(limit_group, "ConfigView.label.set_ui_transfer_speeds");
    layout = new GridLayout();
    layout.numColumns = 2;
    limit_group.setLayout(layout);
    Utils.setLayoutData(limit_group, new GridData(GridData.FILL_HORIZONTAL));
    Label limit_group_label = new Label(limit_group, SWT.WRAP);
    Utils.setLayoutData(limit_group_label, Utils.getWrappableLabelGridData(2, GridData.GRAB_HORIZONTAL));
    Messages.setLanguageText(limit_group_label, "ConfigView.label.set_ui_transfer_speeds.description");
    String[] limit_types = new String[] { "download", "upload" };
    final String limit_type_prefix = "config.ui.speed.partitions.manual.";
    for (int i = 0; i < limit_types.length; i++) {
        final BooleanParameter bp = new BooleanParameter(limit_group, limit_type_prefix + limit_types[i] + ".enabled", false, "ConfigView.label.set_ui_transfer_speeds.description." + limit_types[i]);
        final StringParameter sp = new StringParameter(limit_group, limit_type_prefix + limit_types[i] + ".values", "");
        IAdditionalActionPerformer iaap = new GenericActionPerformer(new Control[] {}) {

            @Override
            public void performAction() {
                sp.getControl().setEnabled(bp.isSelected());
            }
        };
        gridData = new GridData();
        gridData.widthHint = 150;
        sp.setLayoutData(gridData);
        iaap.performAction();
        bp.setAdditionalActionPerformer(iaap);
    }
    // send version
    new BooleanParameter(cDisplay, "Send Version Info", "ConfigView.label.allowSendVersion");
    Composite cArea = new Composite(cDisplay, SWT.NULL);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    cArea.setLayout(layout);
    Utils.setLayoutData(cArea, new GridData(GridData.FILL_HORIZONTAL));
    new LinkLabel(cArea, "ConfigView.label.version.info.link", Constants.URL_WIKI + "w/Version.azureusplatform.com");
    if (!Constants.isOSX) {
        BooleanParameter confirm = new BooleanParameter(cArea, "confirmationOnExit", "ConfigView.section.style.confirmationOnExit");
        gridData = new GridData();
        gridData.horizontalSpan = 2;
        confirm.setLayoutData(gridData);
    }
    cArea = new Composite(cDisplay, SWT.NULL);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    cArea.setLayout(layout);
    Utils.setLayoutData(cArea, new GridData(GridData.FILL_HORIZONTAL));
    // clear remembered decisions
    final Label clear_label = new Label(cArea, SWT.NULL);
    Messages.setLanguageText(clear_label, "ConfigView.section.interface.cleardecisions");
    final Button clear_decisions = new Button(cArea, SWT.PUSH);
    Messages.setLanguageText(clear_decisions, "ConfigView.section.interface.cleardecisionsbutton");
    clear_decisions.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            RememberedDecisionsManager.clearAll();
        }
    });
    final Label clear_tracker_label = new Label(cArea, SWT.NULL);
    Messages.setLanguageText(clear_tracker_label, "ConfigView.section.interface.cleartrackers");
    final Button clear_tracker_button = new Button(cArea, SWT.PUSH);
    Messages.setLanguageText(clear_tracker_button, "ConfigView.section.interface.cleartrackersbutton");
    clear_tracker_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TrackersUtil.getInstance().clearAllTrackers(true);
        }
    });
    final Label clear_save_path_label = new Label(cArea, SWT.NULL);
    Messages.setLanguageText(clear_save_path_label, "ConfigView.section.interface.clearsavepaths");
    final Button clear_save_path_button = new Button(cArea, SWT.PUSH);
    Messages.setLanguageText(clear_save_path_button, "ConfigView.section.interface.clearsavepathsbutton");
    clear_save_path_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            COConfigurationManager.setParameter("saveTo_list", new ArrayList());
        }
    });
    decisions_parameter_listener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            if (clear_decisions.isDisposed()) {
                // tidy up from previous incarnations
                COConfigurationManager.removeParameterListener("MessageBoxWindow.decisions", this);
            } else {
                boolean enabled = COConfigurationManager.getMapParameter("MessageBoxWindow.decisions", new HashMap()).size() > 0;
                clear_label.setEnabled(enabled);
                clear_decisions.setEnabled(enabled);
            }
        }
    };
    decisions_parameter_listener.parameterChanged(null);
    COConfigurationManager.addParameterListener("MessageBoxWindow.decisions", decisions_parameter_listener);
    if (platform.hasCapability(PlatformManagerCapabilities.RegisterFileAssociations)) {
        Composite cResetAssoc = new Composite(cArea, SWT.NULL);
        layout = new GridLayout();
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 2;
        cResetAssoc.setLayout(layout);
        Utils.setLayoutData(cResetAssoc, new GridData());
        label = new Label(cResetAssoc, SWT.NULL);
        Messages.setLanguageText(label, "ConfigView.section.interface.resetassoc");
        Button reset = new Button(cResetAssoc, SWT.PUSH);
        Messages.setLanguageText(reset, // $NON-NLS-1$
        "ConfigView.section.interface.resetassocbutton");
        reset.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                try {
                    platform.registerApplication();
                } catch (PlatformManagerException e) {
                    Logger.log(new LogAlert(LogAlert.UNREPEATABLE, "Failed to register application", e));
                }
            }
        });
        new BooleanParameter(cArea, "config.interface.checkassoc", "ConfigView.section.interface.checkassoc");
    }
    return cDisplay;
}
Also used : PlatformManager(com.biglybt.platform.PlatformManager) ParameterListener(com.biglybt.core.config.ParameterListener) HashMap(java.util.HashMap) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) ArrayList(java.util.ArrayList) GridLayout(org.eclipse.swt.layout.GridLayout) LogAlert(com.biglybt.core.logging.LogAlert) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) GridData(org.eclipse.swt.layout.GridData) ParameterListener(com.biglybt.core.config.ParameterListener) PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException)

Example 3 with PlatformManagerException

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

the class NetworkAdminImpl method getRoute.

public NetworkAdminNode[] getRoute(InetAddress interface_address, InetAddress target, final int max_millis, final NetworkAdminRouteListener listener) throws NetworkAdminException {
    PlatformManager pm = PlatformManagerFactory.getPlatformManager();
    if (!canTraceRoute()) {
        throw (new NetworkAdminException("No trace-route capability on platform"));
    }
    final List nodes = new ArrayList();
    try {
        pm.traceRoute(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.add(node);
                }
                boolean result;
                if (listener == null) {
                    result = true;
                } else {
                    if (node == null) {
                        result = listener.timeout(distance);
                    } else {
                        result = listener.foundNode(node, distance, millis);
                    }
                }
                return (result && !timeout);
            }
        });
    } catch (PlatformManagerException e) {
        throw (new NetworkAdminException("trace-route failed", e));
    }
    return ((NetworkAdminNode[]) nodes.toArray(new NetworkAdminNode[nodes.size()]));
}
Also used : PlatformManagerPingCallback(com.biglybt.platform.PlatformManagerPingCallback) PlatformManager(com.biglybt.platform.PlatformManager) PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException)

Example 4 with PlatformManagerException

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

the class PlatformManagerFactory method getPlatformManager.

public static PlatformManager getPlatformManager() {
    try {
        boolean force_dummy = System.getProperty(SystemProperties.SYSPROP_PLATFORM_MANAGER_DISABLE, "false").equals("true");
        class_mon.enter();
        if (platform_manager == null && !force_dummy) {
            try {
                String cla = System.getProperty("az.factory.platformmanager.impl", "");
                boolean explicit_class = cla.length() > 0;
                if (!explicit_class) {
                    int platformType = getPlatformType();
                    switch(platformType) {
                        case PlatformManager.PT_WINDOWS:
                            cla = "com.biglybt.platform.win32.PlatformManagerImpl";
                            break;
                        case PlatformManager.PT_MACOSX:
                            cla = "com.biglybt.platform.macosx.PlatformManagerImpl";
                            break;
                        case PlatformManager.PT_UNIX:
                            cla = "com.biglybt.platform.unix.PlatformManagerImpl";
                            break;
                        default:
                            cla = "com.biglybt.platform.dummy.PlatformManagerImpl";
                            break;
                    }
                }
                Class<?> platform_manager_class = Class.forName(cla);
                try {
                    Method methGetSingleton = platform_manager_class.getMethod("getSingleton");
                    platform_manager = (PlatformManager) methGetSingleton.invoke(null);
                } catch (NoSuchMethodException e) {
                } catch (SecurityException e) {
                } catch (IllegalAccessException e) {
                } catch (IllegalArgumentException e) {
                } catch (InvocationTargetException e) {
                }
                if (explicit_class) {
                    if (platform_manager == null) {
                        platform_manager = (PlatformManager) Class.forName(cla).newInstance();
                    }
                }
            } catch (Throwable e) {
                if (!(e instanceof PlatformManagerException)) {
                    Debug.printStackTrace(e);
                }
            }
        }
        if (platform_manager == null) {
            platform_manager = com.biglybt.platform.dummy.PlatformManagerImpl.getSingleton();
        }
        return (platform_manager);
    } finally {
        class_mon.exit();
    }
}
Also used : Method(java.lang.reflect.Method) PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with PlatformManagerException

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

the class PlatformManagerImpl method performRecoverableFileDelete.

/**
 * {@inheritDoc}
 */
@Override
public void performRecoverableFileDelete(String path) throws PlatformManagerException {
    File file = new File(path);
    if (!file.exists()) {
        if (Logger.isEnabled())
            Logger.log(new LogEvent(LOGID, LogEvent.LT_WARNING, "Cannot find " + file.getName()));
        return;
    }
    try {
        Class<?> claFileManager = getFileManagerClass();
        if (claFileManager != null) {
            Method methMoveToTrash = claFileManager.getMethod("moveToTrash", new Class[] { File.class });
            if (methMoveToTrash != null) {
                Object result = methMoveToTrash.invoke(null, new Object[] { file });
                if (result instanceof Boolean) {
                    if (((Boolean) result).booleanValue()) {
                        return;
                    }
                }
            }
        }
    } catch (Throwable e) {
    }
    boolean useOSA = !NativeInvocationBridge.sharedInstance().isEnabled() || !NativeInvocationBridge.sharedInstance().performRecoverableFileDelete(file);
    if (useOSA) {
        try {
            StringBuffer sb = new StringBuffer();
            sb.append("tell application \"");
            sb.append("Finder");
            sb.append("\" to move (posix file \"");
            sb.append(path);
            sb.append("\" as alias) to the trash");
            performOSAScript(sb);
        } catch (Throwable e) {
            throw new PlatformManagerException("Failed to move file", e);
        }
    }
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) Method(java.lang.reflect.Method) 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