From 1b18e39dcfaa31b851799bf8441e4d6556c747c5 Mon Sep 17 00:00:00 2001 From: "U-BASIS\\gregd" Date: Fri, 21 Feb 2020 16:08:26 -0500 Subject: [PATCH] created central repo on first load --- .../datamodel/CentralRepoDbManager.java | 3 + .../eventlisteners/Installer.java | 120 ++++++++++++------ 2 files changed, 85 insertions(+), 38 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java index 60a644f411..320887b74d 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java @@ -255,6 +255,9 @@ public class CentralRepoDbManager { break; case SQLITE: // save the new SQLite settings + logger.info(String.format("Attempting to set up sqlite database at path: %s with filename: %s", + dbSettingsSqlite.getDbDirectory(), dbSettingsSqlite.getDbName())); + dbSettingsSqlite.saveSettings(); // Load those newly saved settings into the sqlite db manager instance // in case we are still using the same instance. diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java index d6f0df3687..22d2a88836 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java @@ -18,8 +18,12 @@ */ package org.sleuthkit.autopsy.centralrepository.eventlisteners; +import java.lang.reflect.InvocationTargetException; +import java.util.logging.Level; import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; import org.openide.modules.ModuleInstall; +import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.casemodule.Case; @@ -55,55 +59,95 @@ public class Installer extends ModuleInstall { @NbBundle.Messages({ "Installer.centralRepoUpgradeFailed.title=Central repository disabled", - "Installer.initialCreateSqlite.title=Create Sqlite Central Repository?", - "Installer.initialCreateSqlite.message=The central repository allows a user to find matching artifacts both across cases " + - "and across data sources in the same case. Having data in the central repository is useful for file discovery. Would you " + - "like to create the default Central Repository now? If you choose not to at this time, this setting can be changed in the " + - "options panel." + "Installer.initialCreateSqlite.title=Enable Central Repository?", + "Installer.initialCreateSqlite.message=The Central Repository is not enabled. Would you like to enable it? " + + "It will store information about all hashes and identifiers that you process. You can use this to ignore previously " + + "seen files and make connections between cases." }) @Override public void restored() { Case.addPropertyChangeListener(pcl); ieListener.installListeners(); - // Perform the database upgrade and inform the user if it fails - try { - String initialized = ModuleSettings.getConfigSetting("CentralRepository", "initialized"); - if (!Boolean.parseBoolean(initialized)) { - String dialogText = "

" + - NbBundle.getMessage(this.getClass(), "Installer.initialCreateSqlite.message") + - "

"; - - boolean setupSqlite = !RuntimeProperties.runningWithGUI() || - JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(), - dialogText, - NbBundle.getMessage(this.getClass(), "Installer.initialCreateSqlite.title"), - JOptionPane.YES_NO_OPTION); - - if (setupSqlite) { - CentralRepoDbManager manager = new CentralRepoDbManager(); - manager.setupDefaultSqliteSettings(); - manager.saveNewCentralRepo(); - } - - ModuleSettings.setConfigSetting("CentralRepository", "initialized", "true"); - } - else { - CentralRepoDbManager.upgradeDatabase(); - } - } catch (CentralRepoException ex) { + String initialized = ModuleSettings.getConfigSetting("CentralRepository", "initialized"); + + // if central repository hasn't been previously initialized, initialize it + if (!Boolean.parseBoolean(initialized)) { + // if running with a GUI, prompt the user if (RuntimeProperties.runningWithGUI()) { - WindowManager.getDefault().invokeWhenUIReady(() -> { - JOptionPane.showMessageDialog(null, - ex.getUserMessage(), - NbBundle.getMessage(this.getClass(), - "Installer.centralRepoUpgradeFailed.title"), - JOptionPane.ERROR_MESSAGE); - }); + try { + SwingUtilities.invokeAndWait(() -> { + try { + String dialogText = "

" + + NbBundle.getMessage(this.getClass(), "Installer.initialCreateSqlite.message") + + "

"; + + if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(), + dialogText, + NbBundle.getMessage(this.getClass(), "Installer.initialCreateSqlite.title"), + JOptionPane.YES_NO_OPTION)) { + + setupDefaultSqlite(); + } + } catch (CentralRepoException ex) { + LOGGER.log(Level.SEVERE, "There was an error while initializing the central repository database", ex); + + reportUpgradeError(ex); + } + }); + } catch (Exception ex) { + LOGGER.log(Level.SEVERE, "There was an error while running the swing utility invoke later while creating the central repository database", ex); + } + } // if no GUI, just initialize + else { + try { + setupDefaultSqlite(); + } catch (CentralRepoException ex) { + LOGGER.log(Level.SEVERE, "There was an error while initializing the central repository database", ex); + + reportUpgradeError(ex); + } + } + + ModuleSettings.setConfigSetting("CentralRepository", "initialized", "true"); + } + + // now run regular module startup code + try { + CentralRepoDbManager.upgradeDatabase(); + } catch (CentralRepoException ex) { + LOGGER.log(Level.SEVERE, "There was an error while upgrading the central repository database", ex); + if (RuntimeProperties.runningWithGUI()) { + reportUpgradeError(ex); } } } + private void setupDefaultSqlite() throws CentralRepoException { + CentralRepoDbUtil.setUseCentralRepo(true); + CentralRepoDbManager manager = new CentralRepoDbManager(); + manager.setupDefaultSqliteSettings(); + manager.createDb(); + manager.saveNewCentralRepo(); + } + + private void reportUpgradeError(CentralRepoException ex) { + try { + SwingUtilities.invokeAndWait(() -> { + JOptionPane.showMessageDialog(null, + ex.getUserMessage(), + NbBundle.getMessage(this.getClass(), + "Installer.centralRepoUpgradeFailed.title"), + JOptionPane.ERROR_MESSAGE); + }); + } catch (Exception e) { + LOGGER.warning("There was an error while running the swing utility invoke later while displaying an error " + + "for creating the central repository database: " + + e.getMessage() + System.lineSeparator() + e.getStackTrace()); + } + + } + @Override public boolean closing() { //platform about to close