19 package org.sleuthkit.autopsy.casemodule;
22 import java.nio.file.Paths;
23 import java.util.Calendar;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.JFileChooser;
27 import javax.swing.JPanel;
28 import org.openide.util.NbBundle;
42 "LocalDiskPanel.errorMessage.noOpenCaseTitle=No open case available",
43 "LocalDiskPanel.errorMessage.noOpenCaseBody=LocalDiskPanel listener couldn't get the open case.",
44 "LocalDiskPanel.imageWriterError.directoryNotExist=Error - directory does not exist",
45 "LocalDiskPanel.imageWriterError.emptyPath=Error - enter path for VHD",
46 "LocalDiskPanel.imageWriterError.isDirectory=Error - VHD path is a directory",
47 "LocalDiskPanel.imageWriterError.fileExists=Error - VHD path already exists",
48 "LocalDiskPanel.moduleErrorMessage.title=Module Error",
49 "LocalDiskPanel.moduleErrorMessage.body=A module caused an error listening to LocalDiskPanel updates. See log to determine which module. Some data could be incomplete.",
50 "LocalDiskPanel.localDiskMessage.unspecified=Unspecified"
52 @SuppressWarnings(
"PMD.SingularField")
53 final class LocalDiskPanel
extends JPanel {
55 private static final Logger logger = Logger.getLogger(LocalDiskPanel.class.getName());
56 private static final String[] SECTOR_SIZE_CHOICES = {
"Auto Detect",
"512",
"1024",
"2048",
"4096"};
57 private static LocalDiskPanel instance;
58 private static final long serialVersionUID = 1L;
59 private LocalDisk localDisk;
60 private boolean enableNext =
false;
61 private final JFileChooser fc =
new JFileChooser();
70 createSectorSizeList();
76 static synchronized LocalDiskPanel getDefault() {
77 if (instance == null) {
78 instance =
new LocalDiskPanel();
83 @SuppressWarnings(
"unchecked")
84 private
void customInit() {
85 imageWriterErrorLabel.setVisible(
false);
86 imageWriterErrorLabel.setText(
"");
87 if (!PlatformUtil.isWindowsOS()) {
88 copyImageCheckbox.setSelected(
false);
89 copyImageCheckbox.setEnabled(
false);
91 pathTextField.setEnabled(copyImageCheckbox.isSelected());
92 browseButton.setEnabled(copyImageCheckbox.isSelected());
93 changeDatabasePathCheckbox.setEnabled(copyImageCheckbox.isSelected());
101 @SuppressWarnings(
"unchecked")
103 private
void initComponents() {
105 timeZoneLabel =
new javax.swing.JLabel();
106 timeZoneComboBox =
new javax.swing.JComboBox<>();
107 noFatOrphansCheckbox =
new javax.swing.JCheckBox();
108 descLabel =
new javax.swing.JLabel();
109 copyImageCheckbox =
new javax.swing.JCheckBox();
110 pathTextField =
new javax.swing.JTextField();
111 browseButton =
new javax.swing.JButton();
112 jLabel1 =
new javax.swing.JLabel();
113 imageWriterErrorLabel =
new javax.swing.JLabel();
114 changeDatabasePathCheckbox =
new javax.swing.JCheckBox();
115 sectorSizeLabel =
new javax.swing.JLabel();
116 sectorSizeComboBox =
new javax.swing.JComboBox<>();
117 selectDiskButton =
new javax.swing.JButton();
118 localDiskLabel =
new javax.swing.JLabel();
119 localDiskNameTextField =
new javax.swing.JTextField();
121 setMinimumSize(
new java.awt.Dimension(0, 420));
122 setPreferredSize(
new java.awt.Dimension(485, 410));
124 org.openide.awt.Mnemonics.setLocalizedText(timeZoneLabel,
org.openide.util.NbBundle.getMessage(LocalDiskPanel.class,
"LocalDiskPanel.timeZoneLabel.text"));
126 timeZoneComboBox.setMaximumRowCount(30);
128 org.openide.awt.Mnemonics.setLocalizedText(noFatOrphansCheckbox,
org.openide.util.NbBundle.getMessage(LocalDiskPanel.class,
"LocalDiskPanel.noFatOrphansCheckbox.text"));
129 noFatOrphansCheckbox.setToolTipText(
org.openide.util.NbBundle.getMessage(LocalDiskPanel.class,
"LocalDiskPanel.noFatOrphansCheckbox.toolTipText"));
131 org.openide.awt.Mnemonics.setLocalizedText(descLabel,
org.openide.util.NbBundle.getMessage(LocalDiskPanel.class,
"LocalDiskPanel.descLabel.text"));
133 org.openide.awt.Mnemonics.setLocalizedText(copyImageCheckbox,
org.openide.util.NbBundle.getMessage(LocalDiskPanel.class,
"LocalDiskPanel.copyImageCheckbox.text"));
134 copyImageCheckbox.addActionListener(
new java.awt.event.ActionListener() {
135 public void actionPerformed(java.awt.event.ActionEvent evt) {
136 copyImageCheckboxActionPerformed(evt);
140 pathTextField.setText(
org.openide.util.NbBundle.getMessage(LocalDiskPanel.class,
"LocalDiskPanel.pathTextField.text"));
141 pathTextField.addKeyListener(
new java.awt.event.KeyAdapter() {
142 public void keyReleased(java.awt.event.KeyEvent evt) {
143 pathTextFieldKeyReleased(evt);
147 org.openide.awt.Mnemonics.setLocalizedText(browseButton,
org.openide.util.NbBundle.getMessage(LocalDiskPanel.class,
"LocalDiskPanel.browseButton.text"));
148 browseButton.addActionListener(
new java.awt.event.ActionListener() {
149 public void actionPerformed(java.awt.event.ActionEvent evt) {
150 browseButtonActionPerformed(evt);
154 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(LocalDiskPanel.class,
"LocalDiskPanel.jLabel1.text"));
156 imageWriterErrorLabel.setForeground(
new java.awt.Color(255, 0, 0));
157 org.openide.awt.Mnemonics.setLocalizedText(imageWriterErrorLabel,
org.openide.util.NbBundle.getMessage(LocalDiskPanel.class,
"LocalDiskPanel.imageWriterErrorLabel.text"));
159 org.openide.awt.Mnemonics.setLocalizedText(changeDatabasePathCheckbox,
org.openide.util.NbBundle.getMessage(LocalDiskPanel.class,
"LocalDiskPanel.changeDatabasePathCheckbox.text"));
161 org.openide.awt.Mnemonics.setLocalizedText(sectorSizeLabel,
org.openide.util.NbBundle.getMessage(LocalDiskPanel.class,
"LocalDiskPanel.sectorSizeLabel.text"));
163 org.openide.awt.Mnemonics.setLocalizedText(selectDiskButton,
org.openide.util.NbBundle.getMessage(LocalDiskPanel.class,
"LocalDiskPanel.selectDiskButton.text"));
164 selectDiskButton.addActionListener(
new java.awt.event.ActionListener() {
165 public void actionPerformed(java.awt.event.ActionEvent evt) {
166 selectDiskButtonActionPerformed(evt);
170 org.openide.awt.Mnemonics.setLocalizedText(localDiskLabel,
org.openide.util.NbBundle.getMessage(LocalDiskPanel.class,
"LocalDiskPanel.localDiskLabel.text"));
172 localDiskNameTextField.setEditable(
false);
174 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
175 this.setLayout(layout);
176 layout.setHorizontalGroup(
177 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
178 .addGroup(layout.createSequentialGroup()
179 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
180 .addGroup(layout.createSequentialGroup()
181 .addComponent(localDiskLabel)
182 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
183 .addComponent(localDiskNameTextField)
184 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
185 .addComponent(selectDiskButton))
186 .addGroup(layout.createSequentialGroup()
187 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
188 .addGroup(layout.createSequentialGroup()
189 .addComponent(timeZoneLabel)
190 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
191 .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE))
192 .addComponent(noFatOrphansCheckbox)
193 .addComponent(copyImageCheckbox)
194 .addGroup(layout.createSequentialGroup()
196 .addComponent(pathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE)
197 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
198 .addComponent(browseButton))
199 .addGroup(layout.createSequentialGroup()
201 .addComponent(sectorSizeLabel)
202 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
203 .addComponent(sectorSizeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
204 .addGroup(layout.createSequentialGroup()
206 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
207 .addComponent(descLabel)
208 .addComponent(changeDatabasePathCheckbox)
209 .addGroup(layout.createSequentialGroup()
211 .addComponent(jLabel1))
212 .addComponent(imageWriterErrorLabel))))
213 .addGap(0, 39, Short.MAX_VALUE)))
216 layout.setVerticalGroup(
217 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
218 .addGroup(layout.createSequentialGroup()
219 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
220 .addComponent(localDiskLabel)
221 .addComponent(selectDiskButton)
222 .addComponent(localDiskNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
224 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
225 .addComponent(timeZoneLabel)
226 .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
228 .addComponent(noFatOrphansCheckbox)
229 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
230 .addComponent(descLabel)
232 .addComponent(copyImageCheckbox)
233 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
234 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
235 .addComponent(pathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
236 .addComponent(browseButton))
238 .addComponent(changeDatabasePathCheckbox)
239 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
240 .addComponent(jLabel1)
241 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
242 .addComponent(imageWriterErrorLabel)
244 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
245 .addComponent(sectorSizeLabel)
246 .addComponent(sectorSizeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
247 .addContainerGap(127, Short.MAX_VALUE))
251 private void copyImageCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
252 pathTextField.setEnabled(copyImageCheckbox.isSelected());
253 browseButton.setEnabled(copyImageCheckbox.isSelected());
254 changeDatabasePathCheckbox.setEnabled(copyImageCheckbox.isSelected());
255 changeDatabasePathCheckbox.setSelected(copyImageCheckbox.isSelected());
259 private void pathTextFieldKeyReleased(java.awt.event.KeyEvent evt) {
263 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
264 String oldText = pathTextField.getText();
266 File currentFile =
new File(oldText);
267 if ((currentFile.getParentFile() != null) && (currentFile.getParentFile().exists())) {
268 fc.setSelectedFile(currentFile);
271 int retval = fc.showOpenDialog(
this);
272 if (retval == JFileChooser.APPROVE_OPTION) {
273 String path = fc.getSelectedFile().getPath();
274 pathTextField.setText(path);
279 private void selectDiskButtonActionPerformed(java.awt.event.ActionEvent evt) {
280 LocalDiskSelectionDialog selectionDialog =
new LocalDiskSelectionDialog();
281 selectionDialog.display();
282 LocalDisk selectedLocalDisk = selectionDialog.getLocalDiskSelection();
283 if (selectedLocalDisk != null) {
284 localDisk = selectedLocalDisk;
285 localDiskNameTextField.setText(selectedLocalDisk.getName());
289 setPotentialImageWriterPath(localDisk);
290 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
291 }
catch (NoCurrentCaseException ex) {
292 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
293 MessageNotifyUtil.Notify.show(Bundle.LocalDiskPanel_errorMessage_noOpenCaseTitle(),
294 Bundle.LocalDiskPanel_errorMessage_noOpenCaseBody(),
295 MessageNotifyUtil.MessageType.ERROR);
296 }
catch (Exception ex) {
297 logger.log(Level.SEVERE,
"LocalDiskPanel listener threw exception", ex);
298 MessageNotifyUtil.Notify.show(Bundle.LocalDiskPanel_moduleErrorMessage_title(),
299 Bundle.LocalDiskPanel_moduleErrorMessage_body(),
300 MessageNotifyUtil.MessageType.ERROR);
306 private javax.swing.JButton browseButton;
307 private javax.swing.JCheckBox changeDatabasePathCheckbox;
308 private javax.swing.JCheckBox copyImageCheckbox;
309 private javax.swing.JLabel descLabel;
310 private javax.swing.JLabel imageWriterErrorLabel;
311 private javax.swing.JLabel jLabel1;
312 private javax.swing.JLabel localDiskLabel;
313 private javax.swing.JTextField localDiskNameTextField;
314 private javax.swing.JCheckBox noFatOrphansCheckbox;
315 private javax.swing.JTextField pathTextField;
316 private javax.swing.JComboBox<String> sectorSizeComboBox;
317 private javax.swing.JLabel sectorSizeLabel;
318 private javax.swing.JButton selectDiskButton;
319 private javax.swing.JComboBox<String> timeZoneComboBox;
320 private javax.swing.JLabel timeZoneLabel;
323 private void fireUpdateEvent() {
325 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
326 }
catch (Exception e) {
327 logger.log(Level.SEVERE,
"LocalDiskPanel listener threw exception", e);
328 MessageNotifyUtil.Notify.show(Bundle.LocalDiskPanel_moduleErrorMessage_title(),
329 Bundle.LocalDiskPanel_moduleErrorMessage_body(),
330 MessageNotifyUtil.MessageType.ERROR);
337 void resetLocalDiskSelection() {
339 localDiskNameTextField.setText(Bundle.LocalDiskPanel_localDiskMessage_unspecified());
348 String getContentPath() {
349 if (localDisk != null) {
350 return localDisk.getPath();
361 int getSectorSize() {
362 int sectorSizeSelectionIndex = sectorSizeComboBox.getSelectedIndex();
364 if (sectorSizeSelectionIndex == 0) {
368 return Integer.valueOf((String) sectorSizeComboBox.getSelectedItem());
371 String getTimeZone() {
372 String tz = timeZoneComboBox.getSelectedItem().toString();
373 return tz.substring(tz.indexOf(
")") + 2).trim();
377 boolean getNoFatOrphans() {
378 return noFatOrphansCheckbox.isSelected();
381 private static String getDefaultImageWriterFolder() throws NoCurrentCaseException {
382 return Paths.get(Case.getCurrentCaseThrows().getModuleDirectory(),
"Image Writer").toString();
385 private void setPotentialImageWriterPath(LocalDisk disk)
throws NoCurrentCaseException {
387 File subDirectory = Paths.get(getDefaultImageWriterFolder()).toFile();
388 if (!subDirectory.exists()) {
389 subDirectory.mkdirs();
392 String path = disk.getName();
396 path = path.replaceAll(
"[^0-9A-Za-z _()]",
"");
397 if (path.isEmpty() || path.startsWith(
" ")) {
398 path =
"localDisk" + path;
401 path +=
" " + System.currentTimeMillis();
403 pathTextField.setText(Paths.get(getDefaultImageWriterFolder(), path).toString());
406 private boolean imageWriterPathIsValid() {
407 if ((!copyImageCheckbox.isSelected()) || localDisk == null) {
408 imageWriterErrorLabel.setVisible(
false);
409 imageWriterErrorLabel.setText(
"");
413 if (pathTextField.getText().isEmpty()) {
414 imageWriterErrorLabel.setVisible(
true);
415 imageWriterErrorLabel.setText(Bundle.LocalDiskPanel_imageWriterError_emptyPath());
419 File f =
new File(pathTextField.getText());
420 if (((f.getParentFile() != null) && (!f.getParentFile().exists()))
421 || (f.getParentFile() == null)) {
422 imageWriterErrorLabel.setVisible(
true);
423 imageWriterErrorLabel.setText(Bundle.LocalDiskPanel_imageWriterError_directoryNotExist());
426 if (f.isDirectory()) {
427 imageWriterErrorLabel.setVisible(
true);
428 imageWriterErrorLabel.setText(Bundle.LocalDiskPanel_imageWriterError_isDirectory());
432 imageWriterErrorLabel.setVisible(
true);
433 imageWriterErrorLabel.setText(Bundle.LocalDiskPanel_imageWriterError_fileExists());
436 imageWriterErrorLabel.setVisible(
false);
437 imageWriterErrorLabel.setText(
"");
441 boolean getImageWriterEnabled() {
442 return copyImageCheckbox.isSelected();
445 ImageWriterSettings getImageWriterSettings() {
446 return new ImageWriterSettings(pathTextField.getText(), changeDatabasePathCheckbox.isSelected());
455 boolean validatePanel() {
456 if (!imageWriterPathIsValid()) {
466 public void createTimeZoneList() {
467 List<String> timeZoneList = TimeZoneUtils.createTimeZoneList();
468 for (String timeZone : timeZoneList) {
469 timeZoneComboBox.addItem(timeZone);
473 timeZoneComboBox.setSelectedItem(TimeZoneUtils.createTimeZoneString(Calendar.getInstance().getTimeZone()));
480 private void createSectorSizeList() {
481 for (String choice : SECTOR_SIZE_CHOICES) {
482 sectorSizeComboBox.addItem(choice);
484 sectorSizeComboBox.setSelectedIndex(0);