19 package org.sleuthkit.autopsy.directorytree;
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.AbstractAction;
33 import javax.swing.JFileChooser;
34 import javax.swing.JOptionPane;
35 import javax.swing.SwingWorker;
36 import org.netbeans.api.progress.ProgressHandle;
37 import org.openide.util.Cancellable;
38 import org.openide.util.NbBundle;
39 import org.openide.util.Utilities;
64 if (null == instance) {
74 super(NbBundle.getMessage(
ExtractAction.class,
"ExtractAction.title.extractFiles.text"));
85 Collection<? extends AbstractFile> selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class);
86 if (selectedFiles.size() > 1) {
88 }
else if (selectedFiles.size() == 1) {
89 AbstractFile source = selectedFiles.iterator().next();
104 @NbBundle.Messages({
"ExtractAction.noOpenCase.errMsg=No open case available."})
105 private void extractFile(ActionEvent event, AbstractFile selectedFile) {
110 JOptionPane.showMessageDialog((Component) event.getSource(), Bundle.ExtractAction_noOpenCase_errMsg());
111 logger.log(Level.INFO,
"Exception while getting open case.", ex);
114 JFileChooser fileChooser =
new JFileChooser();
118 if (fileChooser.showSaveDialog((Component) event.getSource()) == JFileChooser.APPROVE_OPTION) {
121 ArrayList<FileExtractionTask> fileExtractionTasks =
new ArrayList<>();
122 fileExtractionTasks.add(
new FileExtractionTask(selectedFile, fileChooser.getSelectedFile()));
133 private void extractFiles(ActionEvent event, Collection<? extends AbstractFile> selectedFiles) {
138 JOptionPane.showMessageDialog((Component) event.getSource(), Bundle.ExtractAction_noOpenCase_errMsg());
139 logger.log(Level.INFO,
"Exception while getting open case.", ex);
142 JFileChooser folderChooser =
new JFileChooser();
143 folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
145 if (folderChooser.showSaveDialog((Component) event.getSource()) == JFileChooser.APPROVE_OPTION) {
146 File destinationFolder = folderChooser.getSelectedFile();
147 if (!destinationFolder.exists()) {
149 destinationFolder.mkdirs();
150 }
catch (Exception ex) {
151 JOptionPane.showMessageDialog((Component) event.getSource(), NbBundle.getMessage(this.getClass(),
152 "ExtractAction.extractFiles.cantCreateFolderErr.msg"));
153 logger.log(Level.INFO,
"Unable to create folder(s) for user " + destinationFolder.getAbsolutePath(), ex);
165 Set<AbstractFile> uniqueFiles =
new HashSet<>(selectedFiles);
168 ArrayList<FileExtractionTask> fileExtractionTasks =
new ArrayList<>();
169 for (AbstractFile source : uniqueFiles) {
187 if (userDefinedExportPath == null) {
188 return caseExportPath;
191 File file =
new File(userDefinedExportPath);
192 if (file.exists() ==
false || file.isDirectory() ==
false) {
193 return caseExportPath;
210 userDefinedExportPath = null;
212 userDefinedExportPath = exportPath;
226 for (Iterator<FileExtractionTask> it = fileExtractionTasks.iterator(); it.hasNext();) {
239 if (task.destination.exists()) {
240 if (JOptionPane.showConfirmDialog((Component) event.getSource(),
241 NbBundle.getMessage(this.getClass(),
"ExtractAction.confDlg.destFileExist.msg", task.destination.getAbsolutePath()),
242 NbBundle.getMessage(
this.getClass(),
"ExtractAction.confDlg.destFileExist.title"),
243 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
245 JOptionPane.showMessageDialog((Component) event.getSource(),
246 NbBundle.getMessage(this.getClass(),
"ExtractAction.msgDlg.cantOverwriteFile.msg", task.destination.getAbsolutePath()));
256 if (!fileExtractionTasks.isEmpty()) {
260 }
catch (Exception ex) {
261 logger.log(Level.WARNING,
"Unable to start background file extraction thread", ex);
265 NbBundle.getMessage(
this.getClass(),
"ExtractAction.notifyDlg.noFileToExtr.msg"));
284 this.source = source;
285 this.destination = destination;
309 if (extractionTasks.isEmpty()) {
314 final String displayName = NbBundle.getMessage(this.getClass(),
"ExtractAction.progress.extracting");
315 progress = ProgressHandle.createHandle(displayName,
new Cancellable() {
317 public boolean cancel() {
318 if (progress != null) {
319 progress.setDisplayName(
320 NbBundle.getMessage(
this.getClass(),
"ExtractAction.progress.cancellingExtraction", displayName));
326 progress.switchToIndeterminate();
345 boolean msgDisplayed =
false;
348 }
catch (InterruptedException | ExecutionException ex) {
349 logger.log(Level.SEVERE,
"Fatal error during file extraction", ex);
351 NbBundle.getMessage(
this.getClass(),
"ExtractAction.done.notifyMsg.extractErr", ex.getMessage()));
355 if (!this.isCancelled() && !msgDisplayed) {
357 NbBundle.getMessage(
this.getClass(),
"ExtractAction.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)