Search in sources :

Example 1 with BackupManager

use of com.biglybt.core.backup.BackupManager in project BiglyBT by BiglySoftware.

the class ConfigSectionBackupRestoreSWT method restoreBackup.

private void restoreBackup() {
    if (Utils.runIfNotSWTThread(this::restoreBackup)) {
        return;
    }
    String def_dir = COConfigurationManager.getStringParameter(SCFG_BACKUP_FOLDER_DEFAULT);
    DirectoryDialog dialog = new DirectoryDialog(shell, SWT.APPLICATION_MODAL);
    if (!def_dir.isEmpty()) {
        dialog.setFilterPath(def_dir);
    }
    dialog.setMessage(MessageText.getString("br.restore.folder.info"));
    dialog.setText(MessageText.getString("br.restore.folder.title"));
    final String path = dialog.open();
    if (path != null) {
        MessageBoxShell mb = new MessageBoxShell(SWT.ICON_WARNING | SWT.OK | SWT.CANCEL, MessageText.getString("br.restore.warning.title"), MessageText.getString("br.restore.warning.info"));
        mb.setDefaultButtonUsingStyle(SWT.CANCEL);
        mb.setParent(shell);
        mb.open(returnVal -> {
            if (returnVal != SWT.OK) {
                return;
            }
            final TextViewerWindow viewer = new TextViewerWindow(MessageText.getString("br.backup.progress"), null, "", true, true);
            viewer.setEditable(false);
            viewer.setOKEnabled(false);
            BackupManager backup_manager = BackupManagerFactory.getManager(CoreFactory.getSingleton());
            backup_manager.restore(new File(path), new BackupManager.BackupListener() {

                @Override
                public boolean reportProgress(String str) {
                    return (append(str, false));
                }

                @Override
                public void reportComplete() {
                    append("Restore Complete!", true);
                    Utils.execSWTThread(() -> {
                        MessageBoxShell mb1 = new MessageBoxShell(SWT.ICON_INFORMATION | SWT.OK, MessageText.getString("ConfigView.section.security.restart.title"), MessageText.getString("ConfigView.section.security.restart.msg"));
                        mb1.setParent(shell);
                        mb1.open(returnVal1 -> {
                            UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
                            if (uiFunctions != null) {
                                uiFunctions.dispose(true);
                            }
                        });
                    });
                }

                @Override
                public void reportError(Throwable error) {
                    append("Restore Failed: " + Debug.getNestedExceptionMessage(error), true);
                }

                private boolean append(final String str, final boolean complete) {
                    if (viewer.isDisposed() || str == null) {
                        return (false);
                    }
                    Utils.execSWTThread(() -> {
                        if (!viewer.isDisposed()) {
                            if (str.endsWith("...")) {
                                viewer.append(str);
                            } else {
                                viewer.append(str + "\r\n");
                            }
                            if (complete) {
                                viewer.setOKEnabled(true);
                            }
                        }
                    });
                    return (true);
                }
            });
            viewer.goModal();
        });
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ParameterImpl(com.biglybt.pifimpl.local.ui.config.ParameterImpl) Date(java.util.Date) COConfigurationManager(com.biglybt.core.config.COConfigurationManager) TextViewerWindow(com.biglybt.ui.swt.TextViewerWindow) UIFunctionsManagerSWT(com.biglybt.ui.swt.UIFunctionsManagerSWT) MessageText(com.biglybt.core.internat.MessageText) ConfigSectionBackupRestore(com.biglybt.ui.config.ConfigSectionBackupRestore) File(java.io.File) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) BackupRestore(com.biglybt.core.config.ConfigKeys.BackupRestore) Debug(com.biglybt.core.util.Debug) Utils(com.biglybt.ui.swt.Utils) BackupManagerFactory(com.biglybt.core.backup.BackupManagerFactory) BackupManager(com.biglybt.core.backup.BackupManager) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) CoreFactory(com.biglybt.core.CoreFactory) BaseSwtParameter(com.biglybt.ui.swt.config.BaseSwtParameter) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) InfoParameter(com.biglybt.pif.ui.config.InfoParameter) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) TextViewerWindow(com.biglybt.ui.swt.TextViewerWindow) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) BackupManager(com.biglybt.core.backup.BackupManager) File(java.io.File) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 2 with BackupManager

use of com.biglybt.core.backup.BackupManager in project BiglyBT by BiglySoftware.

the class ConfigSectionBackupRestore method runBackup.

private void runBackup(BackupManager backup_manager, String path, final Runnable stats_updater) {
    final TextViewerWindow viewer = new TextViewerWindow(MessageText.getString("br.backup.progress"), null, "", true, true);
    viewer.setEditable(false);
    viewer.setOKEnabled(false);
    BackupManager.BackupListener listener = new BackupManager.BackupListener() {

        @Override
        public boolean reportProgress(String str) {
            return (append(str, false));
        }

        @Override
        public void reportComplete() {
            append("Backup Complete!", true);
        }

        @Override
        public void reportError(Throwable error) {
            append("Backup Failed: " + Debug.getNestedExceptionMessage(error), true);
        }

        private boolean append(final String str, final boolean complete) {
            if (viewer.isDisposed()) {
                return (false);
            }
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    if (str.endsWith("...")) {
                        viewer.append(str);
                    } else {
                        viewer.append(str + "\r\n");
                    }
                    if (complete) {
                        viewer.setOKEnabled(true);
                        stats_updater.run();
                    }
                }
            });
            return (true);
        }
    };
    if (path == null) {
        backup_manager.runAutoBackup(listener);
    } else {
        backup_manager.backup(new File(path), listener);
    }
    viewer.goModal();
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) TextViewerWindow(com.biglybt.ui.swt.TextViewerWindow) BackupManager(com.biglybt.core.backup.BackupManager) File(java.io.File)

Example 3 with BackupManager

use of com.biglybt.core.backup.BackupManager in project BiglyBT by BiglySoftware.

the class ConfigSectionBackupRestore method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    ImageLoader imageLoader = ImageLoader.getInstance();
    Image imgOpenFolder = imageLoader.getImage("openFolderButton");
    GridData gridData;
    GridLayout layout;
    final Composite cBR = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    cBR.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 1;
    cBR.setLayout(layout);
    Label info_label = new Label(cBR, SWT.WRAP);
    Messages.setLanguageText(info_label, "ConfigView.section.br.overview");
    gridData = Utils.getWrappableLabelGridData(1, GridData.HORIZONTAL_ALIGN_FILL);
    info_label.setLayoutData(gridData);
    // wiki link
    final Label linkLabel = new Label(cBR, SWT.NULL);
    linkLabel.setText(MessageText.getString("ConfigView.label.please.visit.here"));
    linkLabel.setData(Constants.URL_WIKI + "w/Backup_And_Restore");
    linkLabel.setCursor(linkLabel.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    linkLabel.setForeground(Colors.blue);
    gridData = Utils.getWrappableLabelGridData(1, 0);
    linkLabel.setLayoutData(gridData);
    linkLabel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent arg0) {
            Utils.launch((String) ((Label) arg0.widget).getData());
        }

        @Override
        public void mouseDown(MouseEvent arg0) {
            Utils.launch((String) ((Label) arg0.widget).getData());
        }
    });
    ClipboardCopy.addCopyToClipMenu(linkLabel);
    final BackupManager backup_manager = BackupManagerFactory.getManager(CoreFactory.getSingleton());
    // backup
    Group gBackup = new Group(cBR, SWT.NULL);
    Messages.setLanguageText(gBackup, "br.backup");
    layout = new GridLayout(2, false);
    gBackup.setLayout(layout);
    gBackup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // info
    Label last_backup_label = new Label(gBackup, SWT.NULL);
    Messages.setLanguageText(last_backup_label, "br.backup.last.time");
    final Label last_backup_time = new Label(gBackup, SWT.NULL);
    Label last_backup_error_label = new Label(gBackup, SWT.NULL);
    Messages.setLanguageText(last_backup_error_label, "br.backup.last.error");
    final Label last_backup_error = new Label(gBackup, SWT.NULL);
    final Runnable stats_updater = new Runnable() {

        @Override
        public void run() {
            long backup_time = backup_manager.getLastBackupTime();
            last_backup_time.setText(backup_time == 0 ? "" : String.valueOf(new Date(backup_time)));
            last_backup_error.setText(backup_manager.getLastBackupError());
        }
    };
    stats_updater.run();
    // manual button
    Label backup_manual_label = new Label(gBackup, SWT.NULL);
    Messages.setLanguageText(backup_manual_label, "br.backup.manual.info");
    Button backup_button = new Button(gBackup, SWT.PUSH);
    Messages.setLanguageText(backup_button, "br.backup");
    backup_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default");
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
            if (def_dir != null) {
                dialog.setFilterPath(def_dir);
            }
            dialog.setMessage(MessageText.getString("br.backup.folder.info"));
            dialog.setText(MessageText.getString("br.backup.folder.title"));
            String path = dialog.open();
            if (path != null) {
                COConfigurationManager.setParameter("br.backup.folder.default", path);
                runBackup(backup_manager, path, stats_updater);
            }
        }
    });
    final BooleanParameter auto_backup_enable = new BooleanParameter(gBackup, "br.backup.auto.enable", "br.backup.auto.enable");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    auto_backup_enable.setLayoutData(gridData);
    Composite gDefaultDir = new Composite(gBackup, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 3;
    layout.marginHeight = 2;
    gDefaultDir.setLayout(layout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    gDefaultDir.setLayoutData(gridData);
    Label lblDefaultDir = new Label(gDefaultDir, SWT.NONE);
    Messages.setLanguageText(lblDefaultDir, "ConfigView.section.file.defaultdir.ask");
    lblDefaultDir.setLayoutData(new GridData());
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    final StringParameter pathParameter = new StringParameter(gDefaultDir, "br.backup.auto.dir", "");
    pathParameter.setLayoutData(gridData);
    if (pathParameter.getValue().length() == 0) {
        String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default");
        pathParameter.setValue(def_dir);
    }
    Button browse = new Button(gDefaultDir, SWT.PUSH);
    browse.setImage(imgOpenFolder);
    imgOpenFolder.setBackground(browse.getBackground());
    browse.setToolTipText(MessageText.getString("ConfigView.button.browse"));
    browse.addListener(SWT.Selection, new Listener() {

        /* (non-Javadoc)
			 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
			 */
        @Override
        public void handleEvent(Event event) {
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
            dialog.setFilterPath(pathParameter.getValue());
            dialog.setMessage(MessageText.getString("br.backup.auto.dir.select"));
            dialog.setText(MessageText.getString("ConfigView.section.file.defaultdir.ask"));
            String path = dialog.open();
            if (path != null) {
                pathParameter.setValue(path);
                COConfigurationManager.setParameter("br.backup.folder.default", path);
            }
        }
    });
    Composite gPeriod = new Composite(gDefaultDir, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 6;
    layout.marginLeft = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.marginTop = 0;
    layout.marginBottom = 0;
    gPeriod.setLayout(layout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    gPeriod.setLayoutData(gridData);
    Label lbl_backup_days = new Label(gPeriod, SWT.NULL);
    Messages.setLanguageText(lbl_backup_days, "br.backup.auto.everydays");
    IntParameter backup_everydays = new IntParameter(gPeriod, "br.backup.auto.everydays", 0, Integer.MAX_VALUE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    backup_everydays.setLayoutData(gridData);
    Label lbl_backup_hours = new Label(gPeriod, SWT.NULL);
    Messages.setLanguageText(lbl_backup_hours, "br.backup.auto.everyhours");
    IntParameter backup_everyhours = new IntParameter(gPeriod, "br.backup.auto.everyhours", 1, Integer.MAX_VALUE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    backup_everyhours.setLayoutData(gridData);
    // for whatever reason if you set enable synchronously it gets reset :(
    Utils.execSWTThreadLater(1, new Runnable() {

        public void run() {
            backup_everyhours.setEnabled(backup_everydays.getValue() == 0);
        }
    });
    backup_everydays.addChangeListener(new ParameterChangeAdapter() {

        @Override
        public void parameterChanged(Parameter p, boolean caused_internally) {
            backup_everyhours.setEnabled(backup_everydays.getValue() == 0);
        }
    });
    Label lbl_backup_retain = new Label(gDefaultDir, SWT.NULL);
    Messages.setLanguageText(lbl_backup_retain, "br.backup.auto.retain");
    IntParameter backup_retain = new IntParameter(gDefaultDir, "br.backup.auto.retain", 1, Integer.MAX_VALUE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    backup_retain.setLayoutData(gridData);
    BooleanParameter chkNotify = new BooleanParameter(gDefaultDir, "br.backup.notify", "br.backup.notify");
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    chkNotify.setLayoutData(gridData);
    Label backup_auto_label = new Label(gDefaultDir, SWT.NULL);
    Messages.setLanguageText(backup_auto_label, "br.backup.auto.now");
    Button backup_auto_button = new Button(gDefaultDir, SWT.PUSH);
    Messages.setLanguageText(backup_auto_button, "br.test");
    backup_auto_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            runBackup(backup_manager, null, stats_updater);
        }
    });
    auto_backup_enable.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(gDefaultDir));
    // restore
    Group gRestore = new Group(cBR, SWT.NULL);
    Messages.setLanguageText(gRestore, "br.restore");
    layout = new GridLayout(2, false);
    gRestore.setLayout(layout);
    gRestore.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Label restore_label = new Label(gRestore, SWT.NULL);
    Messages.setLanguageText(restore_label, "br.restore.info");
    Button restore_button = new Button(gRestore, SWT.PUSH);
    Messages.setLanguageText(restore_button, "br.restore");
    restore_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default");
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
            if (def_dir != null) {
                dialog.setFilterPath(def_dir);
            }
            dialog.setMessage(MessageText.getString("br.restore.folder.info"));
            dialog.setText(MessageText.getString("br.restore.folder.title"));
            final String path = dialog.open();
            if (path != null) {
                MessageBoxShell mb = new MessageBoxShell(SWT.ICON_WARNING | SWT.OK | SWT.CANCEL, MessageText.getString("br.restore.warning.title"), MessageText.getString("br.restore.warning.info"));
                mb.setDefaultButtonUsingStyle(SWT.CANCEL);
                mb.setParent(parent.getShell());
                mb.open(new UserPrompterResultListener() {

                    @Override
                    public void prompterClosed(int returnVal) {
                        if (returnVal != SWT.OK) {
                            return;
                        }
                        final TextViewerWindow viewer = new TextViewerWindow(MessageText.getString("br.backup.progress"), null, "", true, true);
                        viewer.setEditable(false);
                        viewer.setOKEnabled(false);
                        backup_manager.restore(new File(path), new BackupManager.BackupListener() {

                            @Override
                            public boolean reportProgress(String str) {
                                return (append(str, false));
                            }

                            @Override
                            public void reportComplete() {
                                append("Restore Complete!", true);
                                Utils.execSWTThread(new AERunnable() {

                                    @Override
                                    public void runSupport() {
                                        MessageBoxShell mb = new MessageBoxShell(SWT.ICON_INFORMATION | SWT.OK, MessageText.getString("ConfigView.section.security.restart.title"), MessageText.getString("ConfigView.section.security.restart.msg"));
                                        mb.setParent(parent.getShell());
                                        mb.open(new UserPrompterResultListener() {

                                            @Override
                                            public void prompterClosed(int returnVal) {
                                                UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
                                                if (uiFunctions != null) {
                                                    uiFunctions.dispose(true, false);
                                                }
                                            }
                                        });
                                    }
                                });
                            }

                            @Override
                            public void reportError(Throwable error) {
                                append("Restore Failed: " + Debug.getNestedExceptionMessage(error), true);
                            }

                            private boolean append(final String str, final boolean complete) {
                                if (viewer.isDisposed()) {
                                    return (false);
                                }
                                Utils.execSWTThread(new AERunnable() {

                                    @Override
                                    public void runSupport() {
                                        if (str.endsWith("...")) {
                                            viewer.append(str);
                                        } else {
                                            viewer.append(str + "\r\n");
                                        }
                                        if (complete) {
                                            viewer.setOKEnabled(true);
                                        }
                                    }
                                });
                                return (true);
                            }
                        });
                        viewer.goModal();
                    }
                });
            }
        }
    });
    return (cBR);
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) ParameterChangeListener(com.biglybt.ui.swt.config.ParameterChangeListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) TextViewerWindow(com.biglybt.ui.swt.TextViewerWindow) StringParameter(com.biglybt.ui.swt.config.StringParameter) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ParameterChangeAdapter(com.biglybt.ui.swt.config.ParameterChangeAdapter) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) BackupManager(com.biglybt.core.backup.BackupManager) BooleanParameter(com.biglybt.ui.swt.config.BooleanParameter) Date(java.util.Date) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) AERunnable(com.biglybt.core.util.AERunnable) GridData(org.eclipse.swt.layout.GridData) MouseEvent(org.eclipse.swt.events.MouseEvent) BooleanParameter(com.biglybt.ui.swt.config.BooleanParameter) StringParameter(com.biglybt.ui.swt.config.StringParameter) IntParameter(com.biglybt.ui.swt.config.IntParameter) Parameter(com.biglybt.ui.swt.config.Parameter) ChangeSelectionActionPerformer(com.biglybt.ui.swt.config.ChangeSelectionActionPerformer) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) File(java.io.File) IntParameter(com.biglybt.ui.swt.config.IntParameter)

Example 4 with BackupManager

use of com.biglybt.core.backup.BackupManager in project BiglyBT by BiglySoftware.

the class ConfigSectionBackupRestore method build.

@Override
public void build() {
    Core core = CoreFactory.getSingleton();
    BackupManager backup_manager = BackupManagerFactory.getManager(core);
    List<Parameter> listBackupParams = new ArrayList<>();
    add("overview", new LabelParameterImpl("ConfigView.section.br.overview"));
    // wiki link
    add(SECTION_ID + ".link", new HyperlinkParameterImpl("ConfigView.label.please.visit.here", Wiki.BACKUP_AND_RESTORE));
    // backup
    long backup_time = backup_manager.getLastBackupTime();
    InfoParameterImpl paramInfoLastTime = new InfoParameterImpl(null, "br.backup.last.time", backup_time == 0 ? "" : String.valueOf(new Date(backup_time)));
    add(PP_BACKUP_LAST_TIME, paramInfoLastTime, listBackupParams);
    InfoParameterImpl paramInfoLastErr = new InfoParameterImpl(null, "br.backup.last.error", backup_manager.getLastBackupError());
    add(PP_BACKUP_LAST_ERR, paramInfoLastErr, listBackupParams);
    if (cbManualBackup != null) {
        ActionParameterImpl paramBackupButton = new ActionParameterImpl("br.backup.manual.info", "br.backup");
        paramBackupButton.setStyle(ActionParameter.STYLE_BUTTON);
        paramBackupButton.addListener(param -> cbManualBackup.run(mapPluginParams));
        add("btnManualBackup", paramBackupButton, listBackupParams);
    }
    BooleanParameterImpl paramEnableBackup = new BooleanParameterImpl(BCFG_BACKUP_AUTO_ENABLE, "br.backup.auto.enable");
    add(paramEnableBackup, listBackupParams);
    // 
    DirectoryParameterImpl paramPath = new DirectoryParameterImpl(SCFG_BACKUP_AUTO_DIR, "ConfigView.section.file.defaultdir.ask");
    add(paramPath, listBackupParams);
    paramPath.setDialogTitleKey("ConfigView.section.file.defaultdir.ask");
    paramPath.setDialogMessageKey("br.backup.auto.dir.select");
    if (paramPath.getValue().length() == 0) {
        String def_dir = COConfigurationManager.getStringParameter(SCFG_BACKUP_FOLDER_DEFAULT);
        paramPath.setValue(def_dir);
    }
    paramPath.addListener(p -> {
        String path = ((DirectoryParameter) p).getValue();
        COConfigurationManager.setParameter(SCFG_BACKUP_FOLDER_DEFAULT, path);
    });
    // 
    BooleanParameterImpl paramDoPlugins = new BooleanParameterImpl(BCFG_BACKUP_PLUGINS, "br.backup.do.plugins");
    add(paramDoPlugins, listBackupParams);
    IntParameterImpl paramBackupDays = new IntParameterImpl(ICFG_BACKUP_AUTO_EVERYDAYS, ICFG_BACKUP_AUTO_EVERYDAYS, 0, Integer.MAX_VALUE);
    add(paramBackupDays, listBackupParams);
    IntParameterImpl paramBackupHours = new IntParameterImpl(ICFG_BACKUP_AUTO_EVERYHOURS, ICFG_BACKUP_AUTO_EVERYHOURS, 0, Integer.MAX_VALUE);
    add(paramBackupHours, listBackupParams);
    IntParameterImpl paramAutoRetain = new IntParameterImpl(ICFG_BACKUP_AUTO_RETAIN, ICFG_BACKUP_AUTO_RETAIN, 1, Integer.MAX_VALUE);
    add(paramAutoRetain, listBackupParams);
    BooleanParameterImpl paramNotify = new BooleanParameterImpl(BCFG_BACKUP_NOTIFY, "br.backup.notify");
    paramNotify.setAllowedUiTypes(UIInstance.UIT_SWT);
    add(paramNotify, listBackupParams);
    ActionParameterImpl paramBackupNow = new ActionParameterImpl("br.backup.auto.now", "br.test");
    add("backupNow", paramBackupNow, listBackupParams);
    paramBackupNow.addListener(param -> {
        if (cbBackupNow == null) {
            backup_manager.runAutoBackup(null);
        } else {
            cbBackupNow.run(mapPluginParams);
        }
    });
    ParameterListener enableListener = (n) -> {
        boolean enable = paramEnableBackup.getValue();
        boolean hoursEnable = enable && paramBackupDays.getValue() == 0;
        paramPath.setEnabled(enable);
        paramBackupDays.setEnabled(enable);
        paramBackupHours.setEnabled(hoursEnable);
        paramAutoRetain.setEnabled(enable);
        paramNotify.setEnabled(enable);
        paramBackupNow.setEnabled(enable);
    };
    paramEnableBackup.addListener(enableListener);
    paramBackupDays.addListener(enableListener);
    enableListener.parameterChanged(null);
    add(new ParameterGroupImpl("br.backup", listBackupParams));
    if (cbRestore != null) {
        List<Parameter> listRestoreParams = new ArrayList<>();
        ActionParameterImpl paramButtonRestore = new ActionParameterImpl("br.restore.info", "br.restore");
        add(SECTION_ID + ".restore", paramButtonRestore, listRestoreParams);
        paramButtonRestore.addListener(param -> cbRestore.run(mapPluginParams));
        add(new BooleanParameterImpl(BCFG_RESTORE_AUTOPAUSE, BCFG_RESTORE_AUTOPAUSE), listRestoreParams);
        add(new ParameterGroupImpl("br.restore", listRestoreParams));
    }
}
Also used : Date(java.util.Date) COConfigurationManager(com.biglybt.core.config.COConfigurationManager) com.biglybt.pifimpl.local.ui.config(com.biglybt.pifimpl.local.ui.config) ArrayList(java.util.ArrayList) com.biglybt.pif.ui.config(com.biglybt.pif.ui.config) BackupRestore(com.biglybt.core.config.ConfigKeys.BackupRestore) List(java.util.List) BackupManagerFactory(com.biglybt.core.backup.BackupManagerFactory) BackupManager(com.biglybt.core.backup.BackupManager) UIInstance(com.biglybt.pif.ui.UIInstance) CoreFactory(com.biglybt.core.CoreFactory) Wiki(com.biglybt.core.util.Wiki) Core(com.biglybt.core.Core) ArrayList(java.util.ArrayList) BackupManager(com.biglybt.core.backup.BackupManager) Date(java.util.Date) Core(com.biglybt.core.Core)

Example 5 with BackupManager

use of com.biglybt.core.backup.BackupManager in project BiglyBT by BiglySoftware.

the class ConfigSectionBackupRestoreSWT method runBackup.

private static void runBackup(BackupManager backup_manager, String path, final Runnable stats_updater) {
    // switch to non-modal after user request
    boolean modal = false;
    if (Utils.runIfNotSWTThread(() -> runBackup(backup_manager, path, stats_updater))) {
        return;
    }
    final TextViewerWindow viewer = new TextViewerWindow(MessageText.getString("br.backup.progress"), null, "", modal, modal);
    viewer.setEditable(false);
    viewer.setOKEnabled(false);
    BackupManager.BackupListener listener = new BackupManager.BackupListener() {

        @Override
        public boolean reportProgress(String str) {
            return (append(str, false));
        }

        @Override
        public void reportComplete() {
            append("Backup Complete!", true);
        }

        @Override
        public void reportError(Throwable error) {
            append("Backup Failed: " + Debug.getNestedExceptionMessage(error), true);
        }

        private boolean append(final String str, final boolean complete) {
            if (viewer.isDisposed() || str == null) {
                return (false);
            }
            Utils.execSWTThread(() -> {
                if (str.endsWith("...")) {
                    viewer.append(str);
                } else {
                    viewer.append(str + "\r\n");
                }
                if (complete) {
                    viewer.setOKEnabled(true);
                    stats_updater.run();
                }
            });
            return (true);
        }
    };
    if (path == null) {
        backup_manager.runAutoBackup(listener);
    } else {
        backup_manager.backup(new File(path), listener);
    }
    if (modal) {
        viewer.goModal();
    }
}
Also used : TextViewerWindow(com.biglybt.ui.swt.TextViewerWindow) BackupManager(com.biglybt.core.backup.BackupManager) File(java.io.File)

Aggregations

BackupManager (com.biglybt.core.backup.BackupManager)5 TextViewerWindow (com.biglybt.ui.swt.TextViewerWindow)4 File (java.io.File)4 Date (java.util.Date)3 CoreFactory (com.biglybt.core.CoreFactory)2 BackupManagerFactory (com.biglybt.core.backup.BackupManagerFactory)2 COConfigurationManager (com.biglybt.core.config.COConfigurationManager)2 BackupRestore (com.biglybt.core.config.ConfigKeys.BackupRestore)2 AERunnable (com.biglybt.core.util.AERunnable)2 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)2 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)2 Core (com.biglybt.core.Core)1 MessageText (com.biglybt.core.internat.MessageText)1 Debug (com.biglybt.core.util.Debug)1 Wiki (com.biglybt.core.util.Wiki)1 UIInstance (com.biglybt.pif.ui.UIInstance)1 com.biglybt.pif.ui.config (com.biglybt.pif.ui.config)1 InfoParameter (com.biglybt.pif.ui.config.InfoParameter)1 com.biglybt.pifimpl.local.ui.config (com.biglybt.pifimpl.local.ui.config)1 ParameterImpl (com.biglybt.pifimpl.local.ui.config.ParameterImpl)1