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
|
||||
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?
|
||||
|
@ -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,11 +101,18 @@ 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
|
||||
*
|
||||
|
@ -1932,7 +1932,7 @@ public class Case {
|
||||
*
|
||||
* @return A CaseMetaData object.
|
||||
*/
|
||||
CaseMetadata getMetadata() {
|
||||
public CaseMetadata getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ public final class CaseMetadata {
|
||||
*
|
||||
* @return The path to the metadata file
|
||||
*/
|
||||
Path getFilePath() {
|
||||
public Path getFilePath() {
|
||||
return metadataFilePath;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
@ -67,9 +71,9 @@ public class StartupWindowProvider implements StartupWindowInterface {
|
||||
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<? extends StartupWindowInterface> 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<? extends StartupWindowInterface> 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<? extends StartupWindowInterface> 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<? extends StartupWindowInterface> 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<? extends StartupWindowInterface> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,7 +179,7 @@ public class StartupWindowProvider implements StartupWindowInterface {
|
||||
private boolean isRunningFromCommandLine() {
|
||||
|
||||
CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class);
|
||||
if(processor != null) {
|
||||
if (processor != null) {
|
||||
return processor.isRunFromCommandLine();
|
||||
}
|
||||
return false;
|
||||
@ -162,7 +192,7 @@ public class StartupWindowProvider implements StartupWindowInterface {
|
||||
*/
|
||||
private String getDefaultArgument() {
|
||||
CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class);
|
||||
if(processor != null) {
|
||||
if (processor != null) {
|
||||
return processor.getDefaultArgument();
|
||||
}
|
||||
return null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user