Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CaseOpenAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2016 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.casemodule;
20 
21 import java.awt.Cursor;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.io.File;
25 import javax.swing.JFileChooser;
26 import javax.swing.JOptionPane;
27 import javax.swing.SwingUtilities;
28 import javax.swing.filechooser.FileFilter;
29 import javax.swing.filechooser.FileNameExtensionFilter;
30 import org.openide.util.NbBundle;
31 import org.openide.util.lookup.ServiceProvider;
32 import org.openide.windows.WindowManager;
35 import org.openide.DialogDescriptor;
36 import org.openide.DialogDisplayer;
37 import org.openide.NotifyDescriptor;
39 import java.util.logging.Level;
41 
45 @ServiceProvider(service = CaseOpenAction.class)
46 public final class CaseOpenAction implements ActionListener {
47 
48  private static final Logger logger = Logger.getLogger(CaseOpenAction.class.getName());
49  private static final String PROP_BASECASE = "LBL_BaseCase_PATH"; //NON-NLS
50  private final JFileChooser fileChooser = new JFileChooser();
51  private final FileFilter caseMetadataFileFilter;
52 
56  public CaseOpenAction() {
57  caseMetadataFileFilter = new FileNameExtensionFilter(NbBundle.getMessage(CaseOpenAction.class, "CaseOpenAction.autFilter.title", Version.getName(), Case.CASE_DOT_EXTENSION), Case.CASE_EXTENSION);
58  fileChooser.setDragEnabled(false);
59  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
60  fileChooser.setMultiSelectionEnabled(false);
61  fileChooser.setFileFilter(caseMetadataFileFilter);
62  if (null != ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE)) {
63  fileChooser.setCurrentDirectory(new File(ModuleSettings.getConfigSetting("Case", PROP_BASECASE))); //NON-NLS
64  }
65  }
66 
73  @Override
74  public void actionPerformed(ActionEvent e) {
75  /*
76  * If ingest is running, do a dialog to warn the user and confirm the
77  * intent to close the current case and leave the ingest process
78  * incomplete.
79  */
81  NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(
82  NbBundle.getMessage(this.getClass(), "CloseCaseWhileIngesting.Warning"),
83  NbBundle.getMessage(this.getClass(), "CloseCaseWhileIngesting.Warning.title"),
84  NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
85  descriptor.setValue(NotifyDescriptor.NO_OPTION);
86  Object res = DialogDisplayer.getDefault().notify(descriptor);
87  if (res != null && res == DialogDescriptor.YES_OPTION) {
88  Case currentCase = null;
89  try {
90  currentCase = Case.getCurrentCase();
91  currentCase.closeCase();
92  } catch (IllegalStateException ignored) {
93  /*
94  * No current case.
95  */
96  } catch (CaseActionException ex) {
97  logger.log(Level.SEVERE, String.format("Error closing case at %s while ingest was running", (null != currentCase ? currentCase.getCaseDirectory() : "?")), ex); //NON-NLS
98  }
99  } else {
100  return;
101  }
102  }
103 
108  int retval = fileChooser.showOpenDialog(WindowManager.getDefault().getMainWindow());
109  if (retval == JFileChooser.APPROVE_OPTION) {
110  /*
111  * Close the startup window, if it is open.
112  */
114 
115  /*
116  * Try to open the case associated with the case metadata file the
117  * user selected.
118  */
119  final String path = fileChooser.getSelectedFile().getPath();
120  String dirPath = fileChooser.getSelectedFile().getParent();
121  ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE, dirPath.substring(0, dirPath.lastIndexOf(File.separator)));
122  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
123  new Thread(() -> {
124  try {
125  Case.open(path);
126  } catch (CaseActionException ex) {
127  logger.log(Level.SEVERE, String.format("Error opening case with metadata file path %s", path), ex); //NON-NLS
128  SwingUtilities.invokeLater(() -> {
129  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
130  JOptionPane.showMessageDialog(
131  WindowManager.getDefault().getMainWindow(),
132  ex.getMessage(), // Should be user-friendly
133  NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"), //NON-NLS
134  JOptionPane.ERROR_MESSAGE);
135  if (!Case.isCaseOpen()) {
137  }
138  });
139  }
140  }).start();
141  }
142  }
143 }
static synchronized IngestManager getInstance()
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static String getConfigSetting(String moduleName, String settingName)
static void open(String caseMetadataFilePath)
Definition: Case.java:595
synchronized static Logger getLogger(String name)
Definition: Logger.java:166

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.