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;
67 public void extract(ActionEvent event, Collection<? extends AbstractFile> selectedFiles) {
68 if (selectedFiles.size() > 1) {
70 }
else if (selectedFiles.size() == 1) {
71 AbstractFile source = selectedFiles.iterator().next();
75 extractFile(event, selectedFiles.iterator().next());
86 @NbBundle.Messages({
"ExtractActionHelper.noOpenCase.errMsg=No open case available."})
87 private void extractFile(ActionEvent event, AbstractFile selectedFile) {
92 JOptionPane.showMessageDialog((Component) event.getSource(), Bundle.ExtractActionHelper_noOpenCase_errMsg());
93 logger.log(Level.INFO,
"Exception while getting open case.", ex);
96 JFileChooser fileChooser = extractFileHelper.
getChooser();
100 if (fileChooser.showSaveDialog((Component) event.getSource()) == JFileChooser.APPROVE_OPTION) {
103 ArrayList<FileExtractionTask> fileExtractionTasks =
new ArrayList<>();
104 fileExtractionTasks.add(
new FileExtractionTask(selectedFile, fileChooser.getSelectedFile()));
105 runExtractionTasks(event, fileExtractionTasks, fileChooser.getSelectedFile().getName());
115 private void extractFiles(ActionEvent event, Collection<? extends AbstractFile> selectedFiles) {
120 JOptionPane.showMessageDialog((Component) event.getSource(), Bundle.ExtractActionHelper_noOpenCase_errMsg());
121 logger.log(Level.INFO,
"Exception while getting open case.", ex);
124 JFileChooser folderChooser = extractFilesHelper.
getChooser();
125 folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
127 if (folderChooser.showSaveDialog((Component) event.getSource()) == JFileChooser.APPROVE_OPTION) {
128 File destinationFolder = folderChooser.getSelectedFile();
129 if (!destinationFolder.exists()) {
131 destinationFolder.mkdirs();
132 }
catch (Exception ex) {
133 JOptionPane.showMessageDialog((Component) event.getSource(), NbBundle.getMessage(this.getClass(),
134 "ExtractAction.extractFiles.cantCreateFolderErr.msg"));
135 logger.log(Level.INFO,
"Unable to create folder(s) for user " + destinationFolder.getAbsolutePath(), ex);
147 Set<AbstractFile> uniqueFiles =
new HashSet<>(selectedFiles);
150 ArrayList<FileExtractionTask> fileExtractionTasks =
new ArrayList<>();
151 for (AbstractFile source : uniqueFiles) {
169 if (userDefinedExportPath == null) {
170 return caseExportPath;
173 File file =
new File(userDefinedExportPath);
174 if (file.exists() ==
false || file.isDirectory() ==
false) {
175 return caseExportPath;
192 userDefinedExportPath = null;
194 userDefinedExportPath = exportPath;
207 private void runExtractionTasks(ActionEvent event, List<FileExtractionTask> fileExtractionTasks, String destName) {
210 for (Iterator<FileExtractionTask> it = fileExtractionTasks.iterator(); it.hasNext();) {
222 if (task.destination.exists()) {
223 if (JOptionPane.showConfirmDialog((Component) event.getSource(),
224 NbBundle.getMessage(this.getClass(),
"ExtractActionHelper.confDlg.destFileExist.msg", task.destination.getAbsolutePath()),
225 NbBundle.getMessage(
this.getClass(),
"ExtractActionHelper.confDlg.destFileExist.title"),
226 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
228 JOptionPane.showMessageDialog((Component) event.getSource(),
229 NbBundle.getMessage(this.getClass(),
"ExtractActionHelper.msgDlg.cantOverwriteFile.msg", task.destination.getAbsolutePath()));
239 if (!fileExtractionTasks.isEmpty()) {
243 }
catch (Exception ex) {
244 logger.log(Level.WARNING,
"Unable to start background file extraction thread", ex);
248 NbBundle.getMessage(
this.getClass(),
"ExtractActionHelper.notifyDlg.noFileToExtr.msg"));
267 this.source = source;
268 this.destination = destination;
289 FileExtracter(List<FileExtractionTask> extractionTasks, String destName) {
296 "# {0} - outputFolderName",
297 "ExtractActionHelper.progress.extracting=Extracting to {0}",
299 "ExtractActionHelper.progress.fileExtracting=Extracting file: {0}"
302 if (extractionTasks.isEmpty()) {
307 final String displayName = Bundle.ExtractActionHelper_progress_extracting(destName);
308 progress = ProgressHandle.createHandle(displayName,
new Cancellable() {
310 public boolean cancel() {
311 if (progress != null) {
312 progress.setDisplayName(
313 NbBundle.getMessage(
this.getClass(),
"ExtractActionHelper.progress.cancellingExtraction", displayName));
319 progress.switchToIndeterminate();
323 progress.progress(Bundle.ExtractActionHelper_progress_fileExtracting(task.destination.getName()));
333 boolean msgDisplayed =
false;
336 }
catch (InterruptedException | ExecutionException ex) {
337 logger.log(Level.SEVERE,
"Fatal error during file extraction", ex);
339 NbBundle.getMessage(
this.getClass(),
"ExtractActionHelper.done.notifyMsg.extractErr", ex.getMessage()));
343 if (!this.isCancelled() && !msgDisplayed) {
345 NbBundle.getMessage(
this.getClass(),
"ExtractActionHelper.done.notifyMsg.fileExtr.text"));
static boolean deleteFileDir(File path)
JFileChooser getChooser()
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)