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.concurrent.CancellationException;
28 import java.util.concurrent.ExecutionException;
29 import java.util.logging.Level;
31 import org.openide.util.NbBundle;
33 import javax.swing.AbstractAction;
34 import javax.swing.JFileChooser;
35 import javax.swing.JOptionPane;
36 import javax.swing.SwingWorker;
37 import org.netbeans.api.progress.ProgressHandle;
38 import org.netbeans.api.progress.ProgressHandleFactory;
39 import org.openide.util.Cancellable;
40 import org.openide.util.Utilities;
62 if (null == instance) {
69 super(NbBundle.getMessage(
ExtractAction.class,
"ExtractAction.title.extractFiles.text"));
79 Collection<? extends AbstractFile> selectedFiles = Utilities.actionsGlobalContext().lookupAll(
AbstractFile.class);
80 if (selectedFiles.size() > 1) {
83 else if (selectedFiles.size() == 1) {
100 JFileChooser fileChooser =
new JFileChooser();
103 fileChooser.setSelectedFile(
new File(selectedFile.
getName().replace(
':',
'_')));
104 if (fileChooser.showSaveDialog((Component)e.getSource()) == JFileChooser.APPROVE_OPTION) {
105 ArrayList<FileExtractionTask> fileExtractionTasks =
new ArrayList<>();
106 fileExtractionTasks.add(
new FileExtractionTask(selectedFile, fileChooser.getSelectedFile()));
116 private void extractFiles(ActionEvent e, Collection<? extends AbstractFile> selectedFiles) {
117 JFileChooser folderChooser =
new JFileChooser();
118 folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
120 if (folderChooser.showSaveDialog((Component)e.getSource()) == JFileChooser.APPROVE_OPTION) {
121 File destinationFolder = folderChooser.getSelectedFile();
122 if (!destinationFolder.
exists()) {
124 destinationFolder.mkdirs();
126 catch (Exception ex) {
127 JOptionPane.showMessageDialog((Component) e.getSource(), NbBundle.getMessage(this.getClass(),
128 "ExtractAction.extractFiles.cantCreateFolderErr.msg"));
129 logger.log(Level.INFO,
"Unable to create folder(s) for user " + destinationFolder.getAbsolutePath(), ex);
135 ArrayList<FileExtractionTask> fileExtractionTasks =
new ArrayList<>();
138 fileExtractionTasks.add(
new FileExtractionTask(source,
new File(destinationFolder, source.
getId() +
"-" + source.getName().replace(
':',
'_'))));
147 for (Iterator<FileExtractionTask> it = fileExtractionTasks.iterator(); it.hasNext(); ) {
161 if (task.destination.
exists()) {
162 if (JOptionPane.showConfirmDialog((Component) e.getSource(),
163 NbBundle.getMessage(this.getClass(),
"ExtractAction.confDlg.destFileExist.msg", task.destination.getAbsolutePath()),
164 NbBundle.getMessage(
this.getClass(),
"ExtractAction.confDlg.destFileExist.title"),
165 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
167 JOptionPane.showMessageDialog((Component) e.getSource(),
168 NbBundle.getMessage(this.getClass(),
"ExtractAction.msgDlg.cantOverwriteFile.msg", task.destination.getAbsolutePath()));
179 if (!fileExtractionTasks.isEmpty()) {
184 catch (Exception ex) {
185 logger.log(Level.WARNING,
"Unable to start background file extraction thread", ex);
190 NbBundle.getMessage(
this.getClass(),
"ExtractAction.notifyDlg.noFileToExtr.msg"));
199 this.source = source;
200 this.destination = destination;
212 FileExtracter(ArrayList<FileExtractionTask> extractionTasks) {
218 if (extractionTasks.isEmpty()) {
223 final String displayName = NbBundle.getMessage(this.getClass(),
"ExtractAction.progress.extracting");
224 progress = ProgressHandleFactory.createHandle(displayName,
new Cancellable() {
226 public boolean cancel() {
227 if (progress != null)
228 progress.setDisplayName(
229 NbBundle.getMessage(
this.getClass(),
"ExtractAction.progress.cancellingExtraction", displayName));
234 progress.switchToIndeterminate();
255 boolean msgDisplayed =
false;
259 catch (Exception ex) {
260 logger.log(Level.SEVERE,
"Fatal error during file extraction", ex);
262 NbBundle.getMessage(
this.getClass(),
"ExtractAction.done.notifyMsg.extractErr", ex.getMessage()));
267 if (!this.isCancelled() && !msgDisplayed) {
269 NbBundle.getMessage(
this.getClass(),
"ExtractAction.done.notifyMsg.fileExtr.text"));
288 logger.log(Level.SEVERE,
"Could not get children of content", ex);
static boolean deleteFileDir(File path)
List< Content > getChildren()
static Case getCurrentCase()
String getExportDirectory()
static void info(String message)
static boolean isDotDirectory(AbstractFile dir)
static Logger getLogger(String name)