mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 18:17:43 +00:00
7471 re-open case when reset windows used and case is open
This commit is contained in:
parent
309075fa57
commit
8caf0fe4cd
@ -1,3 +1,4 @@
|
|||||||
CTL_ResetWindowsAction=Reset Windows
|
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.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?
|
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?
|
||||||
|
@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.apputils;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import org.apache.commons.io.FileUtils;
|
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 String DISPLAY_NAME = Bundle.CTL_ResetWindowsAction();
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private final static Logger logger = Logger.getLogger(ResetWindowsAction.class.getName());
|
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
|
@Override
|
||||||
public boolean isEnabled() {
|
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. "
|
+ "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?",
|
+ "Are you sure you want to restart the software to reset all window locations?",
|
||||||
"ResetWindowAction.caseCloseFailure.text=Unable to close the current case, "
|
"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
|
@Override
|
||||||
public void performAction() {
|
public void performAction() {
|
||||||
@ -73,7 +78,7 @@ public final class ResetWindowsAction extends CallableSystemAction {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
FileUtils.deleteDirectory(new File(PlatformUtil.getUserConfigDirectory() + File.separator + "Windows2Local"));
|
FileUtils.deleteDirectory(new File(PlatformUtil.getUserConfigDirectory() + File.separator + WINDOWS2LOCAL));
|
||||||
} catch (IOException ex) {
|
} 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
|
//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
|
//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 {
|
try {
|
||||||
if (Case.isCaseOpen()) {
|
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();
|
Case.closeCurrentCase();
|
||||||
}
|
}
|
||||||
// The method markForRestart can not be undone once it is called.
|
// The method markForRestart can not be undone once it is called.
|
||||||
@ -92,10 +101,17 @@ public final class ResetWindowsAction extends CallableSystemAction {
|
|||||||
} catch (CaseActionException ex) {
|
} catch (CaseActionException ex) {
|
||||||
logger.log(Level.WARNING, Bundle.ResetWindowAction_caseCloseFailure_text(), ex);
|
logger.log(Level.WARNING, Bundle.ResetWindowAction_caseCloseFailure_text(), ex);
|
||||||
MessageNotifyUtil.Message.show(Bundle.ResetWindowAction_caseCloseFailure_text(), MessageNotifyUtil.MessageType.ERROR);
|
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
|
* Set this action to be enabled/disabled
|
||||||
|
@ -1932,7 +1932,7 @@ public class Case {
|
|||||||
*
|
*
|
||||||
* @return A CaseMetaData object.
|
* @return A CaseMetaData object.
|
||||||
*/
|
*/
|
||||||
CaseMetadata getMetadata() {
|
public CaseMetadata getMetadata() {
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ public final class CaseMetadata {
|
|||||||
*
|
*
|
||||||
* @return The path to the metadata file
|
* @return The path to the metadata file
|
||||||
*/
|
*/
|
||||||
Path getFilePath() {
|
public Path getFilePath() {
|
||||||
return metadataFilePath;
|
return metadataFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,12 +18,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.casemodule;
|
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.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.logging.Level;
|
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.Lookup;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
|
import org.sleuthkit.autopsy.apputils.ResetWindowsAction;
|
||||||
import org.sleuthkit.autopsy.commandlineingest.CommandLineIngestManager;
|
import org.sleuthkit.autopsy.commandlineingest.CommandLineIngestManager;
|
||||||
import org.sleuthkit.autopsy.commandlineingest.CommandLineOpenCaseManager;
|
import org.sleuthkit.autopsy.commandlineingest.CommandLineOpenCaseManager;
|
||||||
import org.sleuthkit.autopsy.commandlineingest.CommandLineOptionProcessor;
|
import org.sleuthkit.autopsy.commandlineingest.CommandLineOptionProcessor;
|
||||||
@ -65,11 +69,11 @@ public class StartupWindowProvider implements StartupWindowInterface {
|
|||||||
if (startupWindowToUse == null) {
|
if (startupWindowToUse == null) {
|
||||||
// first check whether we are running from command line
|
// first check whether we are running from command line
|
||||||
if (isRunningFromCommandLine()) {
|
if (isRunningFromCommandLine()) {
|
||||||
|
|
||||||
String defaultArg = getDefaultArgument();
|
String defaultArg = getDefaultArgument();
|
||||||
if(defaultArg != null) {
|
if (defaultArg != null) {
|
||||||
new CommandLineOpenCaseManager(defaultArg).start();
|
new CommandLineOpenCaseManager(defaultArg).start();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// Autopsy is running from command line
|
// Autopsy is running from command line
|
||||||
logger.log(Level.INFO, "Running from command line"); //NON-NLS
|
logger.log(Level.INFO, "Running from command line"); //NON-NLS
|
||||||
@ -84,35 +88,61 @@ public class StartupWindowProvider implements StartupWindowInterface {
|
|||||||
checkSolr();
|
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
|
//discover the registered windows
|
||||||
Collection<? extends StartupWindowInterface> startupWindows
|
Collection<? extends StartupWindowInterface> startupWindows
|
||||||
= Lookup.getDefault().lookupAll(StartupWindowInterface.class);
|
= Lookup.getDefault().lookupAll(StartupWindowInterface.class);
|
||||||
|
|
||||||
int windowsCount = startupWindows.size();
|
int windowsCount = startupWindows.size();
|
||||||
if (windowsCount == 1) {
|
switch (windowsCount) {
|
||||||
startupWindowToUse = startupWindows.iterator().next();
|
case 1:
|
||||||
logger.log(Level.INFO, "Will use the default startup window: " + startupWindowToUse.toString()); //NON-NLS
|
startupWindowToUse = startupWindows.iterator().next();
|
||||||
} else if (windowsCount == 2) {
|
logger.log(Level.INFO, "Will use the default startup window: {0}", startupWindowToUse.toString()); //NON-NLS
|
||||||
//pick the non default one
|
break;
|
||||||
Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
|
case 2: {
|
||||||
while (it.hasNext()) {
|
//pick the non default one
|
||||||
StartupWindowInterface window = it.next();
|
Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
|
||||||
if (!org.sleuthkit.autopsy.casemodule.StartupWindow.class.isInstance(window)) {
|
while (it.hasNext()) {
|
||||||
startupWindowToUse = window;
|
StartupWindowInterface window = it.next();
|
||||||
logger.log(Level.INFO, "Will use the custom startup window: " + startupWindowToUse.toString()); //NON-NLS
|
if (!org.sleuthkit.autopsy.casemodule.StartupWindow.class.isInstance(window)) {
|
||||||
break;
|
startupWindowToUse = window;
|
||||||
|
logger.log(Level.INFO, "Will use the custom startup window: {0}", startupWindowToUse.toString()); //NON-NLS
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
default: {
|
||||||
// select first non-Autopsy start up window
|
// select first non-Autopsy start up window
|
||||||
Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
|
Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
StartupWindowInterface window = it.next();
|
StartupWindowInterface window = it.next();
|
||||||
if (!window.getClass().getCanonicalName().startsWith("org.sleuthkit.autopsy")) {
|
if (!window.getClass().getCanonicalName().startsWith("org.sleuthkit.autopsy")) {
|
||||||
startupWindowToUse = window;
|
startupWindowToUse = window;
|
||||||
logger.log(Level.INFO, "Will use the custom startup window: " + startupWindowToUse.toString()); //NON-NLS
|
logger.log(Level.INFO, "Will use the custom startup window: {0}", startupWindowToUse.toString()); //NON-NLS
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,9 +177,9 @@ public class StartupWindowProvider implements StartupWindowInterface {
|
|||||||
* @return True if running from command line, false otherwise
|
* @return True if running from command line, false otherwise
|
||||||
*/
|
*/
|
||||||
private boolean isRunningFromCommandLine() {
|
private boolean isRunningFromCommandLine() {
|
||||||
|
|
||||||
CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class);
|
CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class);
|
||||||
if(processor != null) {
|
if (processor != null) {
|
||||||
return processor.isRunFromCommandLine();
|
return processor.isRunFromCommandLine();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -157,12 +187,12 @@ public class StartupWindowProvider implements StartupWindowInterface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default argument from the CommandLineOptionProcessor.
|
* 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);
|
CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class);
|
||||||
if(processor != null) {
|
if (processor != null) {
|
||||||
return processor.getDefaultArgument();
|
return processor.getDefaultArgument();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user