From ea75fcd45b3943163806299e763fd5b0013e3608 Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Mon, 16 Oct 2023 21:14:36 -0400 Subject: [PATCH] move around code to prevent showing issue --- .../CentralRepositoryNotificationDialog.java | 5 +- .../eventlisteners/Installer.java | 71 ------------ .../eventlisteners/OnUIShowing.java | 107 ++++++++++++++++++ 3 files changed, 110 insertions(+), 73 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/OnUIShowing.java diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java index 883d979c90..aa2e908674 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java @@ -34,8 +34,9 @@ public class CentralRepositoryNotificationDialog { * application is running with a GUI. */ static boolean shouldDisplay() { - return Version.getBuildType() == Version.Type.RELEASE - && RuntimeProperties.runningWithGUI(); + return //Version.getBuildType() == Version.Type.RELEASE + //&& + RuntimeProperties.runningWithGUI(); } /** diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java index f15dec3029..f5b486e78d 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java @@ -90,7 +90,6 @@ public class Installer extends ModuleInstall { public void restored() { // must happen first to move any legacy settings that exist. upgradeSettingsPath(); - setupDefaultCentralRepository(); } @@ -151,76 +150,6 @@ public class Installer extends ModuleInstall { } } - /** - * Checks if the central repository has been set up and configured. If not, - * does the set up unconditionally. If the application is running with a - * GUI, a notification will be displayed to the user if the mode is RELEASE - * (in other words, developers are exempt from seeing the notification). - */ - private void setupDefaultCentralRepository() { - Map centralRepoSettings = ModuleSettings.getConfigSettings(CentralRepoSettings.getInstance().getModuleSettingsKey()); - String initializedStr = centralRepoSettings.get("initialized"); - - // check to see if the repo has been initialized asking to setup cr - boolean initialized = Boolean.parseBoolean(initializedStr); - - // if it hasn't received that flag, check for a previous install where cr is already setup - if (!initialized) { - boolean prevRepo = Boolean.parseBoolean(centralRepoSettings.get("db.useCentralRepo")); - // if it has been previously set up and is in use, mark as previously initialized and save the settings - if (prevRepo) { - initialized = true; - ModuleSettings.setConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "initialized", "true"); - } - } - - if(initialized) { - return; // Nothing to do - } - - if (CentralRepositoryNotificationDialog.shouldDisplay()) { - CentralRepositoryNotificationDialog.display(); - } - - try { - CentralRepoDbManager manager = new CentralRepoDbManager(); - if (UserPreferences.getIsMultiUserModeEnabled()) { - // Set up using existing multi-user settings. - manager.setupPostgresDb(CentralRepoDbChoice.POSTGRESQL_MULTIUSER); - } else { - manager.setupDefaultSqliteDb(); - } - } catch (CentralRepoException ex) { - logger.log(Level.SEVERE, "There was an error while initializing the central repository database", ex); - - doMessageBoxIfRunningInGUI(ex); - } - - ModuleSettings.setConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "initialized", "true"); - } - - /** - * Display a central repository exception in a message box if running with a - * GUI. - * - * @param ex The exception. - */ - @NbBundle.Messages({"Installer.centralRepoUpgradeFailed.title=Central repository disabled"}) - private void doMessageBoxIfRunningInGUI(CentralRepoException ex) { - if (RuntimeProperties.runningWithGUI()) { - try { - SwingUtilities.invokeAndWait(() -> { - JOptionPane.showMessageDialog(null, - ex.getUserMessage(), - NbBundle.getMessage(this.getClass(), "Installer.centralRepoUpgradeFailed.title"), - JOptionPane.ERROR_MESSAGE); - }); - } catch (InterruptedException | InvocationTargetException e) { - logger.log(Level.WARNING, e.getMessage(), e); - } - } - } - @Override public void uninstalled() { /* diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/OnUIShowing.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/OnUIShowing.java new file mode 100644 index 0000000000..5db0906748 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/OnUIShowing.java @@ -0,0 +1,107 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package org.sleuthkit.autopsy.centralrepository.eventlisteners; + +import java.lang.reflect.InvocationTargetException; +import java.util.Map; +import java.util.logging.Level; +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; +import org.openide.util.NbBundle; +import org.openide.windows.OnShowing; +import org.sleuthkit.autopsy.centralrepository.CentralRepoSettings; +import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbChoice; +import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbManager; +import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoException; +import org.sleuthkit.autopsy.core.RuntimeProperties; +import org.sleuthkit.autopsy.core.UserPreferences; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.coreutils.ModuleSettings; + +/** + * + * @author gregd + */ +@OnShowing +public class OnUIShowing implements Runnable { + private static final Logger logger = Logger.getLogger(OnUIShowing.class.getName()); + + @Override + public void run() { + setupDefaultCentralRepository(); + } + + /** + * Checks if the central repository has been set up and configured. If not, + * does the set up unconditionally. If the application is running with a + * GUI, a notification will be displayed to the user if the mode is RELEASE + * (in other words, developers are exempt from seeing the notification). + */ + private void setupDefaultCentralRepository() { + Map centralRepoSettings = ModuleSettings.getConfigSettings(CentralRepoSettings.getInstance().getModuleSettingsKey()); + String initializedStr = centralRepoSettings.get("initialized"); + + // check to see if the repo has been initialized asking to setup cr + boolean initialized = Boolean.parseBoolean(initializedStr); + + // if it hasn't received that flag, check for a previous install where cr is already setup + if (!initialized) { + boolean prevRepo = Boolean.parseBoolean(centralRepoSettings.get("db.useCentralRepo")); + // if it has been previously set up and is in use, mark as previously initialized and save the settings + if (prevRepo) { + initialized = true; + ModuleSettings.setConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "initialized", "true"); + } + } + + if(initialized) { + return; // Nothing to do + } + + if (CentralRepositoryNotificationDialog.shouldDisplay()) { + CentralRepositoryNotificationDialog.display(); + } + + try { + CentralRepoDbManager manager = new CentralRepoDbManager(); + if (UserPreferences.getIsMultiUserModeEnabled()) { + // Set up using existing multi-user settings. + manager.setupPostgresDb(CentralRepoDbChoice.POSTGRESQL_MULTIUSER); + } else { + manager.setupDefaultSqliteDb(); + } + } catch (CentralRepoException ex) { + logger.log(Level.SEVERE, "There was an error while initializing the central repository database", ex); + + doMessageBoxIfRunningInGUI(ex); + } + + ModuleSettings.setConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "initialized", "true"); + } + + /** + * Display a central repository exception in a message box if running with a + * GUI. + * + * @param ex The exception. + */ + @NbBundle.Messages({"Installer.centralRepoUpgradeFailed.title=Central repository disabled"}) + private void doMessageBoxIfRunningInGUI(CentralRepoException ex) { + if (RuntimeProperties.runningWithGUI()) { + try { + SwingUtilities.invokeAndWait(() -> { + JOptionPane.showMessageDialog(null, + ex.getUserMessage(), + NbBundle.getMessage(this.getClass(), "Installer.centralRepoUpgradeFailed.title"), + JOptionPane.ERROR_MESSAGE); + }); + } catch (InterruptedException | InvocationTargetException e) { + logger.log(Level.WARNING, e.getMessage(), e); + } + } + } + + +}