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;
38 import org.openide.util.NbBundle.Messages;
63 public void extract(ActionEvent event, Collection<? extends AbstractFile> selectedFiles) {
64 if (selectedFiles.size() > 1) {
66 }
else if (selectedFiles.size() == 1) {
67 AbstractFile source = selectedFiles.iterator().next();
71 extractFile(event, selectedFiles.iterator().next());
82 @NbBundle.Messages({
"ExtractActionHelper.noOpenCase.errMsg=No open case available."})
83 private void extractFile(ActionEvent event, AbstractFile selectedFile) {
88 JOptionPane.showMessageDialog((Component) event.getSource(), Bundle.ExtractActionHelper_noOpenCase_errMsg());
89 logger.log(Level.INFO,
"Exception while getting open case.", ex);
92 JFileChooser fileChooser =
new JFileChooser();
96 if (fileChooser.showSaveDialog((Component) event.getSource()) == JFileChooser.APPROVE_OPTION) {
99 ArrayList<FileExtractionTask> fileExtractionTasks =
new ArrayList<>();
100 fileExtractionTasks.add(
new FileExtractionTask(selectedFile, fileChooser.getSelectedFile()));
101 runExtractionTasks(event, fileExtractionTasks, fileChooser.getSelectedFile().getName());
111 private void extractFiles(ActionEvent event, Collection<? extends AbstractFile> selectedFiles) {
116 JOptionPane.showMessageDialog((Component) event.getSource(), Bundle.ExtractActionHelper_noOpenCase_errMsg());
117 logger.log(Level.INFO,
"Exception while getting open case.", ex);
120 JFileChooser folderChooser =
new JFileChooser();
121 folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
123 if (folderChooser.showSaveDialog((Component) event.getSource()) == JFileChooser.APPROVE_OPTION) {
124 File destinationFolder = folderChooser.getSelectedFile();
125 if (!destinationFolder.exists()) {
127 destinationFolder.mkdirs();
128 }
catch (Exception ex) {
129 JOptionPane.showMessageDialog((Component) event.getSource(), NbBundle.getMessage(this.getClass(),
130 "ExtractAction.extractFiles.cantCreateFolderErr.msg"));
131 logger.log(Level.INFO,
"Unable to create folder(s) for user " + destinationFolder.getAbsolutePath(), ex);
143 Set<AbstractFile> uniqueFiles =
new HashSet<>(selectedFiles);
146 ArrayList<FileExtractionTask> fileExtractionTasks =
new ArrayList<>();
147 for (AbstractFile source : uniqueFiles) {
165 if (userDefinedExportPath == null) {
166 return caseExportPath;
169 File file =
new File(userDefinedExportPath);
170 if (file.exists() ==
false || file.isDirectory() ==
false) {
171 return caseExportPath;
188 userDefinedExportPath = null;
190 userDefinedExportPath = exportPath;
203 private void runExtractionTasks(ActionEvent event, List<FileExtractionTask> fileExtractionTasks, String destName) {
206 for (Iterator<FileExtractionTask> it = fileExtractionTasks.iterator(); it.hasNext();) {
218 if (task.destination.exists()) {
219 if (JOptionPane.showConfirmDialog((Component) event.getSource(),
220 NbBundle.getMessage(this.getClass(),
"ExtractActionHelper.confDlg.destFileExist.msg", task.destination.getAbsolutePath()),
221 NbBundle.getMessage(
this.getClass(),
"ExtractActionHelper.confDlg.destFileExist.title"),
222 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
224 JOptionPane.showMessageDialog((Component) event.getSource(),
225 NbBundle.getMessage(this.getClass(),
"ExtractActionHelper.msgDlg.cantOverwriteFile.msg", task.destination.getAbsolutePath()));
235 if (!fileExtractionTasks.isEmpty()) {
239 }
catch (Exception ex) {
240 logger.log(Level.WARNING,
"Unable to start background file extraction thread", ex);
244 NbBundle.getMessage(
this.getClass(),
"ExtractActionHelper.notifyDlg.noFileToExtr.msg"));
263 this.source = source;
264 this.destination = destination;
285 FileExtracter(List<FileExtractionTask> extractionTasks, String destName) {
292 "# {0} - outputFolderName",
293 "ExtractActionHelper.progress.extracting=Extracting to {0}",
295 "ExtractActionHelper.progress.fileExtracting=Extracting file: {0}"
298 if (extractionTasks.isEmpty()) {
303 final String displayName = Bundle.ExtractActionHelper_progress_extracting(destName);
304 progress = ProgressHandle.createHandle(displayName,
new Cancellable() {
306 public boolean cancel() {
307 if (progress != null) {
308 progress.setDisplayName(
309 NbBundle.getMessage(
this.getClass(),
"ExtractActionHelper.progress.cancellingExtraction", displayName));
315 progress.switchToIndeterminate();
319 progress.progress(Bundle.ExtractActionHelper_progress_fileExtracting(task.destination.getName()));
329 boolean msgDisplayed =
false;
332 }
catch (InterruptedException | ExecutionException ex) {
333 logger.log(Level.SEVERE,
"Fatal error during file extraction", ex);
335 NbBundle.getMessage(
this.getClass(),
"ExtractActionHelper.done.notifyMsg.extractErr", ex.getMessage()));
339 if (!this.isCancelled() && !msgDisplayed) {
341 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)