Autopsy  4.1
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;
40 import org.openide.util.HelpCtx;
41 import org.openide.util.actions.CallableSystemAction;
43 
47 @ServiceProvider(service = CaseOpenAction.class)
48 public final class CaseOpenAction extends CallableSystemAction implements ActionListener {
49 
50  private static final Logger logger = Logger.getLogger(CaseOpenAction.class.getName());
51  private static final String PROP_BASECASE = "LBL_BaseCase_PATH"; //NON-NLS
52  private static final long serialVersionUID = 1L;
53  private final JFileChooser fileChooser = new JFileChooser();
54  private final FileFilter caseMetadataFileFilter;
55 
59  public CaseOpenAction() {
60  caseMetadataFileFilter = new FileNameExtensionFilter(NbBundle.getMessage(CaseOpenAction.class, "CaseOpenAction.autFilter.title", Version.getName(), CaseMetadata.getFileExtension()), CaseMetadata.getFileExtension().substring(1));
61  fileChooser.setDragEnabled(false);
62  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
63  fileChooser.setMultiSelectionEnabled(false);
64  fileChooser.setFileFilter(caseMetadataFileFilter);
65  if (null != ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE)) {
66  fileChooser.setCurrentDirectory(new File(ModuleSettings.getConfigSetting("Case", PROP_BASECASE))); //NON-NLS
67  }
68  }
69 
76  @Override
77  public void actionPerformed(ActionEvent e) {
78  /*
79  * If ingest is running, do a dialog to warn the user and confirm the
80  * intent to close the current case and leave the ingest process
81  * incomplete.
82  */
84  NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(
85  NbBundle.getMessage(this.getClass(), "CloseCaseWhileIngesting.Warning"),
86  NbBundle.getMessage(this.getClass(), "CloseCaseWhileIngesting.Warning.title"),
87  NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
88  descriptor.setValue(NotifyDescriptor.NO_OPTION);
89  Object res = DialogDisplayer.getDefault().notify(descriptor);
90  if (res != null && res == DialogDescriptor.YES_OPTION) {
91  Case currentCase = null;
92  try {
93  currentCase = Case.getCurrentCase();
94  currentCase.closeCase();
95  } catch (IllegalStateException ignored) {
96  /*
97  * No current case.
98  */
99  } catch (CaseActionException ex) {
100  logger.log(Level.SEVERE, String.format("Error closing case at %s while ingest was running", (null != currentCase ? currentCase.getCaseDirectory() : "?")), ex); //NON-NLS
101  }
102  } else {
103  return;
104  }
105  }
106 
111  int retval = fileChooser.showOpenDialog(WindowManager.getDefault().getMainWindow());
112  if (retval == JFileChooser.APPROVE_OPTION) {
113  /*
114  * Close the startup window, if it is open.
115  */
117 
118  /*
119  * Try to open the case associated with the case metadata file the
120  * user selected.
121  */
122  final String path = fileChooser.getSelectedFile().getPath();
123  String dirPath = fileChooser.getSelectedFile().getParent();
124  ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE, dirPath.substring(0, dirPath.lastIndexOf(File.separator)));
125  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
126  new Thread(() -> {
127  try {
128  Case.open(path);
129  } catch (CaseActionException ex) {
130  logger.log(Level.SEVERE, String.format("Error opening case with metadata file path %s", path), ex); //NON-NLS
131  SwingUtilities.invokeLater(() -> {
132  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
133  JOptionPane.showMessageDialog(
134  WindowManager.getDefault().getMainWindow(),
135  ex.getMessage(), // Should be user-friendly
136  NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"), //NON-NLS
137  JOptionPane.ERROR_MESSAGE);
138  if (!Case.isCaseOpen()) {
140  }
141  });
142  }
143  }).start();
144  }
145  }
146 
147  @Override
148  public void performAction() {
149  }
150 
151  @Override
152  public String getName() {
153  return NbBundle.getMessage(CaseOpenAction.class, "CTL_OpenAction");
154  }
155 
156  @Override
157  public HelpCtx getHelpCtx() {
158  return HelpCtx.DEFAULT_HELP;
159  }
160 }
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:1144
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jan 2 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.