diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java index ab2fbfa4c3..60a644f411 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java @@ -18,16 +18,11 @@ import org.sleuthkit.autopsy.coordinationservice.CoordinationService; import org.sleuthkit.autopsy.coreutils.Logger; -public class CentralRepoDbManager { - private static final String CENTRAL_REPO_DB_NAME = "central_repository"; - private static final String CENTRAL_REPO_SQLITE_EXT = ".db"; - +public class CentralRepoDbManager { private static final Logger logger = Logger.getLogger(CentralRepoDbManager.class.getName()); + + private static final String CENTRAL_REPO_DB_NAME = "central_repository"; - public static String getDefaultSqliteDbName() { - return CENTRAL_REPO_DB_NAME + CENTRAL_REPO_SQLITE_EXT; - } - /** * Upgrade the current Central Reposity schema to the newest version. If the * upgrade fails, the Central Repository will be disabled and the current @@ -36,10 +31,9 @@ public class CentralRepoDbManager { @NbBundle.Messages(value = {"EamDbUtil.centralRepoDisabled.message= The Central Repository has been disabled.", "EamDbUtil.centralRepoUpgradeFailed.message=Failed to upgrade Central Repository.", "EamDbUtil.centralRepoConnectionFailed.message=Unable to connect to Central Repository.", "EamDbUtil.exclusiveLockAquisitionFailure.message=Unable to acquire exclusive lock for Central Repository."}) public static void upgradeDatabase() throws CentralRepoException { if (!CentralRepository.isEnabled()) { - // TODO -// EamDbSettingsDialog dialog = new EamDbSettingsDialog(); -// dialog.promptUserForSetup(); + return; } + CentralRepository db = null; CoordinationService.Lock lock = null; //get connection @@ -129,6 +123,11 @@ public class CentralRepoDbManager { return dbSettingsSqlite; } + public void setupDefaultSqliteSettings() { + selectedPlatform = CentralRepoPlatforms.SQLITE; + dbSettingsSqlite.setupDefaultSettings(); + } + /** * Returns if changes to the central repository configuration were * successfully applied @@ -313,7 +312,7 @@ public class CentralRepoDbManager { break; case SQLITE: File databasePath = new File(tfDatabasePath); - dbSettingsSqlite.setDbName(getDefaultSqliteDbName()); + dbSettingsSqlite.setDbName(SqliteCentralRepoSettings.DEFAULT_DBNAME); dbSettingsSqlite.setDbDirectory(databasePath.getPath()); break; default: diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteCentralRepoSettings.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteCentralRepoSettings.java index 3b2a424c4a..b0ffee2ed2 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteCentralRepoSettings.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteCentralRepoSettings.java @@ -42,8 +42,8 @@ import static org.sleuthkit.autopsy.centralrepository.datamodel.RdbmsCentralRepo */ public final class SqliteCentralRepoSettings { + public final static String DEFAULT_DBNAME = "central_repository.db"; // NON-NLS private final static Logger LOGGER = Logger.getLogger(SqliteCentralRepoSettings.class.getName()); - private final static String DEFAULT_DBNAME = "central_repository.db"; // NON-NLS private final static String DEFAULT_DBDIRECTORY = PlatformUtil.getUserDirectory() + File.separator + "central_repository"; // NON-NLS private final static String JDBC_DRIVER = "org.sqlite.JDBC"; // NON-NLS private final static String JDBC_BASE_URI = "jdbc:sqlite:"; // NON-NLS @@ -89,6 +89,14 @@ public final class SqliteCentralRepoSettings { this.bulkThreshold = RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD; } } + + /** + * sets database directory and name to defaults + */ + public void setupDefaultSettings() { + dbName = DEFAULT_DBNAME; + dbDirectory = DEFAULT_DBDIRECTORY; + } public void saveSettings() { createDbDirectory(); diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java index 73ab88d87c..d6f0df3687 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java @@ -28,6 +28,7 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoException; import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbUtil; import org.sleuthkit.autopsy.core.RuntimeProperties; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.coreutils.ModuleSettings; /** * Install event listeners during module initialization @@ -52,7 +53,14 @@ public class Installer extends ModuleInstall { super(); } - @NbBundle.Messages({"Installer.centralRepoUpgradeFailed.title=Central repository disabled"}) + @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." + }) @Override public void restored() { Case.addPropertyChangeListener(pcl); @@ -60,7 +68,29 @@ public class Installer extends ModuleInstall { // Perform the database upgrade and inform the user if it fails try { - CentralRepoDbManager.upgradeDatabase(); + 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) { if (RuntimeProperties.runningWithGUI()) { WindowManager.getDefault().invokeWhenUIReady(() -> { diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java index 6614d90094..c45d05bb68 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/EamDbSettingsDialog.java @@ -44,6 +44,7 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoException; import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoPlatforms; import org.sleuthkit.autopsy.centralrepository.datamodel.DatabaseTestResult; +import org.sleuthkit.autopsy.centralrepository.datamodel.SqliteCentralRepoSettings; /** * Configuration dialog for Central Repository database settings. @@ -84,7 +85,7 @@ public class EamDbSettingsDialog extends JDialog { if (pathname.isDirectory()) { return true; } - return pathname.getName().equalsIgnoreCase(CentralRepoDbManager.getDefaultSqliteDbName()); + return pathname.getName().equalsIgnoreCase(SqliteCentralRepoSettings.DEFAULT_DBNAME); } @Override @@ -500,7 +501,7 @@ public class EamDbSettingsDialog extends JDialog { }//GEN-LAST:event_cbDatabaseTypeActionPerformed private void updateFullDbPath() { - dataBaseFileTextArea.setText(tfDatabasePath.getText() + File.separator + manager.getDefaultSqliteDbName()); + dataBaseFileTextArea.setText(tfDatabasePath.getText() + File.separator + SqliteCentralRepoSettings.DEFAULT_DBNAME); dataBaseFileTextArea.setCaretPosition(dataBaseFileTextArea.getText().length()); }