diff --git a/Core/src/org/sleuthkit/autopsy/apputils/Bundle.properties-MERGED b/Core/src/org/sleuthkit/autopsy/apputils/Bundle.properties-MERGED index dbac8b0fc1..dd9fc3b03e 100644 --- a/Core/src/org/sleuthkit/autopsy/apputils/Bundle.properties-MERGED +++ b/Core/src/org/sleuthkit/autopsy/apputils/Bundle.properties-MERGED @@ -1,3 +1,4 @@ CTL_ResetWindowsAction=Reset Windows ResetWindowAction.caseCloseFailure.text=Unable to close the current case, the software will restart and the windows locations will reset the next time the software is closed. +ResetWindowAction.caseSaveMetadata.text=Unable to save current case path, the software will restart and the windows locations will reset but the current case will not be opened upon restart. ResetWindowAction.confirm.text=In order to perform the resetting of window locations the software will close and restart. If a case is currently open it will be closed. If ingest or a search is currently running it will be terminated. Are you sure you want to restart the software to reset all window locations? diff --git a/Core/src/org/sleuthkit/autopsy/apputils/ResetWindowsAction.java b/Core/src/org/sleuthkit/autopsy/apputils/ResetWindowsAction.java index 7a44030bb6..faab218a59 100644 --- a/Core/src/org/sleuthkit/autopsy/apputils/ResetWindowsAction.java +++ b/Core/src/org/sleuthkit/autopsy/apputils/ResetWindowsAction.java @@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.apputils; import java.io.File; import java.io.IOException; +import java.nio.charset.Charset; import java.util.logging.Level; import javax.swing.SwingUtilities; import org.apache.commons.io.FileUtils; @@ -51,6 +52,8 @@ public final class ResetWindowsAction extends CallableSystemAction { private static final String DISPLAY_NAME = Bundle.CTL_ResetWindowsAction(); private static final long serialVersionUID = 1L; private final static Logger logger = Logger.getLogger(ResetWindowsAction.class.getName()); + private final static String WINDOWS2LOCAL = "Windows2Local"; + private final static String CASE_TO_REOPEN_FILE = "caseToOpen.txt"; @Override public boolean isEnabled() { @@ -61,7 +64,9 @@ public final class ResetWindowsAction extends CallableSystemAction { + "If a case is currently open it will be closed. If ingest or a search is currently running it will be terminated. " + "Are you sure you want to restart the software to reset all window locations?", "ResetWindowAction.caseCloseFailure.text=Unable to close the current case, " - + "the software will restart and the windows locations will reset the next time the software is closed."}) + + "the software will restart and the windows locations will reset the next time the software is closed.", + "ResetWindowAction.caseSaveMetadata.text=Unable to save current case path, " + + "the software will restart and the windows locations will reset but the current case will not be opened upon restart."}) @Override public void performAction() { @@ -73,7 +78,7 @@ public final class ResetWindowsAction extends CallableSystemAction { @Override public void run() { try { - FileUtils.deleteDirectory(new File(PlatformUtil.getUserConfigDirectory() + File.separator + "Windows2Local")); + FileUtils.deleteDirectory(new File(PlatformUtil.getUserConfigDirectory() + File.separator + WINDOWS2LOCAL)); } catch (IOException ex) { //While we would like the user to be aware of this in the unlikely event that the directory can not be deleted //Because our deletion is being attempted in a shutdown hook I don't know that we can pop up UI elements during the shutdown proces @@ -83,6 +88,10 @@ public final class ResetWindowsAction extends CallableSystemAction { }); try { if (Case.isCaseOpen()) { + String caseMetadataFilePath = Case.getCurrentCase().getMetadata().getFilePath().toString(); + File caseToOpenFile = new File(ResetWindowsAction.getCaseToReopenFilePath()); + Charset encoding = null; + FileUtils.writeStringToFile(caseToOpenFile, caseMetadataFilePath, encoding); Case.closeCurrentCase(); } // The method markForRestart can not be undone once it is called. @@ -92,10 +101,17 @@ public final class ResetWindowsAction extends CallableSystemAction { } catch (CaseActionException ex) { logger.log(Level.WARNING, Bundle.ResetWindowAction_caseCloseFailure_text(), ex); MessageNotifyUtil.Message.show(Bundle.ResetWindowAction_caseCloseFailure_text(), MessageNotifyUtil.MessageType.ERROR); + } catch (IOException ex) { + logger.log(Level.WARNING, Bundle.ResetWindowAction_caseSaveMetadata_text(), ex); + MessageNotifyUtil.Message.show(Bundle.ResetWindowAction_caseSaveMetadata_text(), MessageNotifyUtil.MessageType.ERROR); } } }); } + + public static String getCaseToReopenFilePath(){ + return PlatformUtil.getUserConfigDirectory() + File.separator + CASE_TO_REOPEN_FILE; + } /** * Set this action to be enabled/disabled diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index c0497c083c..15b18d2c4d 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -1932,7 +1932,7 @@ public class Case { * * @return A CaseMetaData object. */ - CaseMetadata getMetadata() { + public CaseMetadata getMetadata() { return metadata; } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/CaseMetadata.java b/Core/src/org/sleuthkit/autopsy/casemodule/CaseMetadata.java index 5f7ffe9ea7..96f9899dae 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/CaseMetadata.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/CaseMetadata.java @@ -218,7 +218,7 @@ public final class CaseMetadata { * * @return The path to the metadata file */ - Path getFilePath() { + public Path getFilePath() { return metadataFilePath; } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/StartupWindowProvider.java b/Core/src/org/sleuthkit/autopsy/casemodule/StartupWindowProvider.java index 9b62bdb0e0..d3cc39f6ad 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/StartupWindowProvider.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/StartupWindowProvider.java @@ -18,12 +18,16 @@ */ package org.sleuthkit.autopsy.casemodule; +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; import java.util.Collection; import java.util.Iterator; import java.util.logging.Level; -import org.netbeans.spi.sendopts.OptionProcessor; +import org.apache.commons.io.FileUtils; import org.openide.util.Lookup; import org.openide.util.NbBundle; +import org.sleuthkit.autopsy.apputils.ResetWindowsAction; import org.sleuthkit.autopsy.commandlineingest.CommandLineIngestManager; import org.sleuthkit.autopsy.commandlineingest.CommandLineOpenCaseManager; import org.sleuthkit.autopsy.commandlineingest.CommandLineOptionProcessor; @@ -65,11 +69,11 @@ public class StartupWindowProvider implements StartupWindowInterface { if (startupWindowToUse == null) { // first check whether we are running from command line if (isRunningFromCommandLine()) { - + String defaultArg = getDefaultArgument(); - if(defaultArg != null) { - new CommandLineOpenCaseManager(defaultArg).start(); - return; + if (defaultArg != null) { + new CommandLineOpenCaseManager(defaultArg).start(); + return; } else { // Autopsy is running from command line logger.log(Level.INFO, "Running from command line"); //NON-NLS @@ -84,35 +88,61 @@ public class StartupWindowProvider implements StartupWindowInterface { checkSolr(); } + File openPreviousCaseFile = new File(ResetWindowsAction.getCaseToReopenFilePath()); + String caseFilePath = ""; + if (openPreviousCaseFile.exists()) { + try { + Charset encoding = null; + caseFilePath = FileUtils.readFileToString(openPreviousCaseFile, encoding); + if (new File(caseFilePath).exists()) { + Case.openAsCurrentCase(caseFilePath); + FileUtils.forceDelete(openPreviousCaseFile); + //the case is now open we do not want to display the start up windows + return; + } else { + logger.log(Level.WARNING, "Unable to open previously open case because metadata file not found at: {0}", caseFilePath); + } + } catch (IOException ex) { + logger.log(Level.WARNING, "Unable to open file containing path " + ResetWindowsAction.getCaseToReopenFilePath() + " to previously open case, will not open previous case.", ex); + } catch (CaseActionException ex) { + logger.log(Level.WARNING, "Unable to open previously open case with metadata file: " + caseFilePath, ex); + } + } //discover the registered windows Collection startupWindows = Lookup.getDefault().lookupAll(StartupWindowInterface.class); int windowsCount = startupWindows.size(); - if (windowsCount == 1) { - startupWindowToUse = startupWindows.iterator().next(); - logger.log(Level.INFO, "Will use the default startup window: " + startupWindowToUse.toString()); //NON-NLS - } else if (windowsCount == 2) { - //pick the non default one - Iterator it = startupWindows.iterator(); - while (it.hasNext()) { - StartupWindowInterface window = it.next(); - if (!org.sleuthkit.autopsy.casemodule.StartupWindow.class.isInstance(window)) { - startupWindowToUse = window; - logger.log(Level.INFO, "Will use the custom startup window: " + startupWindowToUse.toString()); //NON-NLS - break; + switch (windowsCount) { + case 1: + startupWindowToUse = startupWindows.iterator().next(); + logger.log(Level.INFO, "Will use the default startup window: {0}", startupWindowToUse.toString()); //NON-NLS + break; + case 2: { + //pick the non default one + Iterator it = startupWindows.iterator(); + while (it.hasNext()) { + StartupWindowInterface window = it.next(); + if (!org.sleuthkit.autopsy.casemodule.StartupWindow.class.isInstance(window)) { + startupWindowToUse = window; + logger.log(Level.INFO, "Will use the custom startup window: {0}", startupWindowToUse.toString()); //NON-NLS + break; + } } + break; } - } else { - // select first non-Autopsy start up window - Iterator it = startupWindows.iterator(); - while (it.hasNext()) { - StartupWindowInterface window = it.next(); - if (!window.getClass().getCanonicalName().startsWith("org.sleuthkit.autopsy")) { - startupWindowToUse = window; - logger.log(Level.INFO, "Will use the custom startup window: " + startupWindowToUse.toString()); //NON-NLS - break; + default: { + // select first non-Autopsy start up window + Iterator it = startupWindows.iterator(); + while (it.hasNext()) { + StartupWindowInterface window = it.next(); + if (!window.getClass().getCanonicalName().startsWith("org.sleuthkit.autopsy")) { + startupWindowToUse = window; + logger.log(Level.INFO, "Will use the custom startup window: {0}", startupWindowToUse.toString()); //NON-NLS + break; + } } + break; } } @@ -147,9 +177,9 @@ public class StartupWindowProvider implements StartupWindowInterface { * @return True if running from command line, false otherwise */ private boolean isRunningFromCommandLine() { - + CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class); - if(processor != null) { + if (processor != null) { return processor.isRunFromCommandLine(); } return false; @@ -157,12 +187,12 @@ public class StartupWindowProvider implements StartupWindowInterface { /** * Get the default argument from the CommandLineOptionProcessor. - * - * @return If set, the default argument otherwise null. + * + * @return If set, the default argument otherwise null. */ - private String getDefaultArgument() { + private String getDefaultArgument() { CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class); - if(processor != null) { + if (processor != null) { return processor.getDefaultArgument(); } return null;