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;
29 import org.openide.util.NbBundle;
31 import javax.swing.AbstractAction;
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.netbeans.api.progress.ProgressHandleFactory;
37 import org.openide.util.Cancellable;
38 import org.openide.util.Utilities;
61 if (null == instance) {
68 super(NbBundle.getMessage(
ExtractAction.class,
"ExtractAction.title.extractFiles.text"));
79 Collection<? extends AbstractFile> selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class);
80 if (selectedFiles.size() > 1) {
82 }
else if (selectedFiles.size() == 1) {
83 AbstractFile source = selectedFiles.iterator().next();
98 private void extractFile(ActionEvent e, AbstractFile selectedFile) {
99 JFileChooser fileChooser =
new JFileChooser();
103 if (fileChooser.showSaveDialog((Component) e.getSource()) == JFileChooser.APPROVE_OPTION) {
104 ArrayList<FileExtractionTask> fileExtractionTasks =
new ArrayList<>();
105 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();
125 }
catch (Exception ex) {
126 JOptionPane.showMessageDialog((Component) e.getSource(), NbBundle.getMessage(this.getClass(),
127 "ExtractAction.extractFiles.cantCreateFolderErr.msg"));
128 logger.log(Level.INFO,
"Unable to create folder(s) for user " + destinationFolder.getAbsolutePath(), ex);
134 ArrayList<FileExtractionTask> fileExtractionTasks =
new ArrayList<>();
135 for (AbstractFile source : selectedFiles) {
146 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()));
178 if (!fileExtractionTasks.isEmpty()) {
182 }
catch (Exception ex) {
183 logger.log(Level.WARNING,
"Unable to start background file extraction thread", ex);
187 NbBundle.getMessage(
this.getClass(),
"ExtractAction.notifyDlg.noFileToExtr.msg"));
197 this.source = source;
198 this.destination = destination;
211 FileExtracter(ArrayList<FileExtractionTask> extractionTasks) {
217 if (extractionTasks.isEmpty()) {
222 final String displayName = NbBundle.getMessage(this.getClass(),
"ExtractAction.progress.extracting");
223 progress = ProgressHandleFactory.createHandle(displayName,
new Cancellable() {
225 public boolean cancel() {
226 if (progress != null) {
227 progress.setDisplayName(
228 NbBundle.getMessage(
this.getClass(),
"ExtractAction.progress.cancellingExtraction", displayName));
234 progress.switchToIndeterminate();
253 boolean msgDisplayed =
false;
256 }
catch (Exception ex) {
257 logger.log(Level.SEVERE,
"Fatal error during file extraction", ex);
259 NbBundle.getMessage(
this.getClass(),
"ExtractAction.done.notifyMsg.extractErr", ex.getMessage()));
263 if (!this.isCancelled() && !msgDisplayed) {
265 NbBundle.getMessage(
this.getClass(),
"ExtractAction.done.notifyMsg.fileExtr.text"));
273 workUnits += file.getSize();
276 for (Content child : file.getChildren()) {
277 if (child instanceof AbstractFile) {
281 }
catch (TskCoreException ex) {
282 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)