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.Iterator;
27 import java.util.logging.Level;
28 import javax.swing.AbstractAction;
29 import javax.swing.JFileChooser;
30 import javax.swing.JOptionPane;
31 import javax.swing.SwingWorker;
32 import org.netbeans.api.progress.ProgressHandle;
33 import org.openide.util.Cancellable;
34 import org.openide.util.NbBundle;
35 import org.openide.util.Utilities;
59 if (null == instance) {
66 super(NbBundle.getMessage(
ExtractAction.class,
"ExtractAction.title.extractFiles.text"));
77 Collection<? extends AbstractFile> selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class);
78 if (selectedFiles.size() > 1) {
80 }
else if (selectedFiles.size() == 1) {
81 AbstractFile source = selectedFiles.iterator().next();
96 private void extractFile(ActionEvent e, AbstractFile selectedFile) {
97 JFileChooser fileChooser =
new JFileChooser();
101 if (fileChooser.showSaveDialog((Component) e.getSource()) == JFileChooser.APPROVE_OPTION) {
102 ArrayList<FileExtractionTask> fileExtractionTasks =
new ArrayList<>();
103 fileExtractionTasks.add(
new FileExtractionTask(selectedFile, fileChooser.getSelectedFile()));
114 private void extractFiles(ActionEvent e, Collection<? extends AbstractFile> selectedFiles) {
115 JFileChooser folderChooser =
new JFileChooser();
116 folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
118 if (folderChooser.showSaveDialog((Component) e.getSource()) == JFileChooser.APPROVE_OPTION) {
119 File destinationFolder = folderChooser.getSelectedFile();
120 if (!destinationFolder.exists()) {
122 destinationFolder.mkdirs();
123 }
catch (Exception ex) {
124 JOptionPane.showMessageDialog((Component) e.getSource(), NbBundle.getMessage(this.getClass(),
125 "ExtractAction.extractFiles.cantCreateFolderErr.msg"));
126 logger.log(Level.INFO,
"Unable to create folder(s) for user " + destinationFolder.getAbsolutePath(), ex);
132 ArrayList<FileExtractionTask> fileExtractionTasks =
new ArrayList<>();
133 for (AbstractFile source : selectedFiles) {
144 for (Iterator<FileExtractionTask> it = fileExtractionTasks.iterator(); it.hasNext();) {
159 if (task.destination.exists()) {
160 if (JOptionPane.showConfirmDialog((Component) e.getSource(),
161 NbBundle.getMessage(this.getClass(),
"ExtractAction.confDlg.destFileExist.msg", task.destination.getAbsolutePath()),
162 NbBundle.getMessage(
this.getClass(),
"ExtractAction.confDlg.destFileExist.title"),
163 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
165 JOptionPane.showMessageDialog((Component) e.getSource(),
166 NbBundle.getMessage(this.getClass(),
"ExtractAction.msgDlg.cantOverwriteFile.msg", task.destination.getAbsolutePath()));
176 if (!fileExtractionTasks.isEmpty()) {
180 }
catch (Exception ex) {
181 logger.log(Level.WARNING,
"Unable to start background file extraction thread", ex);
185 NbBundle.getMessage(
this.getClass(),
"ExtractAction.notifyDlg.noFileToExtr.msg"));
195 this.source = source;
196 this.destination = destination;
209 FileExtracter(ArrayList<FileExtractionTask> extractionTasks) {
215 if (extractionTasks.isEmpty()) {
220 final String displayName = NbBundle.getMessage(this.getClass(),
"ExtractAction.progress.extracting");
221 progress = ProgressHandle.createHandle(displayName,
new Cancellable() {
223 public boolean cancel() {
224 if (progress != null) {
225 progress.setDisplayName(
226 NbBundle.getMessage(
this.getClass(),
"ExtractAction.progress.cancellingExtraction", displayName));
232 progress.switchToIndeterminate();
251 boolean msgDisplayed =
false;
254 }
catch (Exception ex) {
255 logger.log(Level.SEVERE,
"Fatal error during file extraction", ex);
257 NbBundle.getMessage(
this.getClass(),
"ExtractAction.done.notifyMsg.extractErr", ex.getMessage()));
261 if (!this.isCancelled() && !msgDisplayed) {
263 NbBundle.getMessage(
this.getClass(),
"ExtractAction.done.notifyMsg.fileExtr.text"));
271 workUnits += file.getSize();
274 for (Content child : file.getChildren()) {
275 if (child instanceof AbstractFile) {
279 }
catch (TskCoreException ex) {
280 logger.log(Level.SEVERE,
"Could not get children of content", ex);
static boolean deleteFileDir(File path)
static String escapeFileName(String fileName)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
String getExportDirectory()
static void info(String message)
static boolean isDotDirectory(AbstractFile dir)