19 package org.sleuthkit.autopsy.directorytree.actionhelpers;
21 import java.awt.Component;
22 import java.awt.event.ActionEvent;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.HashSet;
27 import java.util.Iterator;
28 import java.util.List;
30 import java.util.concurrent.ExecutionException;
31 import java.util.logging.Level;
32 import javax.swing.JFileChooser;
33 import javax.swing.JOptionPane;
34 import javax.swing.SwingWorker;
35 import org.netbeans.api.progress.ProgressHandle;
36 import org.openide.util.Cancellable;
37 import org.openide.util.NbBundle;
62 public void extract(ActionEvent event, Collection<? extends AbstractFile> selectedFiles) {
63 if (selectedFiles.size() > 1) {
65 }
else if (selectedFiles.size() == 1) {
66 AbstractFile source = selectedFiles.iterator().next();
70 extractFile(event, selectedFiles.iterator().next());
81 @NbBundle.Messages({
"ExtractActionHelper.noOpenCase.errMsg=No open case available."})
82 private void extractFile(ActionEvent event, AbstractFile selectedFile) {
87 JOptionPane.showMessageDialog((Component) event.getSource(), Bundle.ExtractActionHelper_noOpenCase_errMsg());
88 logger.log(Level.INFO,
"Exception while getting open case.", ex);
91 JFileChooser fileChooser =
new JFileChooser();
95 if (fileChooser.showSaveDialog((Component) event.getSource()) == JFileChooser.APPROVE_OPTION) {
98 ArrayList<FileExtractionTask> fileExtractionTasks =
new ArrayList<>();
99 fileExtractionTasks.add(
new FileExtractionTask(selectedFile, fileChooser.getSelectedFile()));
110 private void extractFiles(ActionEvent event, Collection<? extends AbstractFile> selectedFiles) {
115 JOptionPane.showMessageDialog((Component) event.getSource(), Bundle.ExtractActionHelper_noOpenCase_errMsg());
116 logger.log(Level.INFO,
"Exception while getting open case.", ex);
119 JFileChooser folderChooser =
new JFileChooser();
120 folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
122 if (folderChooser.showSaveDialog((Component) event.getSource()) == JFileChooser.APPROVE_OPTION) {
123 File destinationFolder = folderChooser.getSelectedFile();
124 if (!destinationFolder.exists()) {
126 destinationFolder.mkdirs();
127 }
catch (Exception ex) {
128 JOptionPane.showMessageDialog((Component) event.getSource(), NbBundle.getMessage(this.getClass(),
129 "ExtractAction.extractFiles.cantCreateFolderErr.msg"));
130 logger.log(Level.INFO,
"Unable to create folder(s) for user " + destinationFolder.getAbsolutePath(), ex);
142 Set<AbstractFile> uniqueFiles =
new HashSet<>(selectedFiles);
145 ArrayList<FileExtractionTask> fileExtractionTasks =
new ArrayList<>();
146 for (AbstractFile source : uniqueFiles) {
164 if (userDefinedExportPath == null) {
165 return caseExportPath;
168 File file =
new File(userDefinedExportPath);
169 if (file.exists() ==
false || file.isDirectory() ==
false) {
170 return caseExportPath;
187 userDefinedExportPath = null;
189 userDefinedExportPath = exportPath;
203 for (Iterator<FileExtractionTask> it = fileExtractionTasks.iterator(); it.hasNext();) {
215 if (task.destination.exists()) {
216 if (JOptionPane.showConfirmDialog((Component) event.getSource(),
217 NbBundle.getMessage(this.getClass(),
"ExtractActionHelper.confDlg.destFileExist.msg", task.destination.getAbsolutePath()),
218 NbBundle.getMessage(
this.getClass(),
"ExtractActionHelper.confDlg.destFileExist.title"),
219 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
221 JOptionPane.showMessageDialog((Component) event.getSource(),
222 NbBundle.getMessage(this.getClass(),
"ExtractActionHelper.msgDlg.cantOverwriteFile.msg", task.destination.getAbsolutePath()));
232 if (!fileExtractionTasks.isEmpty()) {
236 }
catch (Exception ex) {
237 logger.log(Level.WARNING,
"Unable to start background file extraction thread", ex);
241 NbBundle.getMessage(
this.getClass(),
"ExtractActionHelper.notifyDlg.noFileToExtr.msg"));
260 this.source = source;
261 this.destination = destination;
285 if (extractionTasks.isEmpty()) {
290 final String displayName = NbBundle.getMessage(this.getClass(),
"ExtractActionHelper.progress.extracting");
291 progress = ProgressHandle.createHandle(displayName,
new Cancellable() {
293 public boolean cancel() {
294 if (progress != null) {
295 progress.setDisplayName(
296 NbBundle.getMessage(
this.getClass(),
"ExtractActionHelper.progress.cancellingExtraction", displayName));
302 progress.switchToIndeterminate();
321 boolean msgDisplayed =
false;
324 }
catch (InterruptedException | ExecutionException ex) {
325 logger.log(Level.SEVERE,
"Fatal error during file extraction", ex);
327 NbBundle.getMessage(
this.getClass(),
"ExtractActionHelper.done.notifyMsg.extractErr", ex.getMessage()));
331 if (!this.isCancelled() && !msgDisplayed) {
333 NbBundle.getMessage(
this.getClass(),
"ExtractActionHelper.done.notifyMsg.fileExtr.text"));
static boolean deleteFileDir(File path)
static String escapeFileName(String fileName)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
String getExportDirectory()
static void info(String message)
static boolean isDotDirectory(AbstractFile dir)