19 package org.sleuthkit.autopsy.modules.hashdatabase;
21 import java.util.ArrayList;
22 import java.util.List;
24 import java.util.concurrent.CancellationException;
25 import java.util.logging.Level;
26 import javax.swing.JOptionPane;
27 import javax.swing.SwingWorker;
28 import org.netbeans.api.progress.ProgressHandle;
29 import org.openide.util.Cancellable;
30 import org.openide.util.NbBundle;
31 import org.openide.windows.WindowManager;
35 class HashDbSearchThread
extends SwingWorker<Object, Void> {
37 private Logger logger = Logger.getLogger(HashDbSearchThread.class.getName());
38 private ProgressHandle progress;
39 private Map<String, List<AbstractFile>> map;
40 private ArrayList<String> hashes =
new ArrayList<>();
41 private AbstractFile file;
43 HashDbSearchThread(AbstractFile file) {
45 this.hashes.add(this.file.getMd5Hash());
48 HashDbSearchThread(ArrayList<String> hashes) {
53 protected Object doInBackground() throws Exception {
54 logger.log(Level.INFO,
"Starting background processing for file search by MD5 hash.");
57 final String displayName = NbBundle.getMessage(this.getClass(),
"HashDbSearchThread.name.searching");
58 progress = ProgressHandle.createHandle(displayName,
new Cancellable() {
60 public boolean cancel() {
61 if (progress != null) {
62 progress.setDisplayName(
63 NbBundle.getMessage(
this.getClass(),
"HashDbSearchThread.progress.cancellingSearch",
66 return HashDbSearchThread.this.cancel(
true);
71 progress.switchToIndeterminate();
74 map = HashDbSearcher.findFilesBymd5(hashes, progress,
this);
75 logger.log(Level.INFO,
"Done background processing");
81 protected void done() {
84 }
catch (CancellationException ex) {
85 logger.log(Level.INFO,
"File search by MD5 hash was canceled.");
86 }
catch (InterruptedException ex) {
87 logger.log(Level.INFO,
"File search by MD5 hash was interrupted.");
88 }
catch (Exception ex) {
89 logger.log(Level.SEVERE,
"Fatal error during file search by MD5 hash.", ex);
92 if (!this.isCancelled()) {
93 logger.log(Level.INFO,
"File search by MD5 hash completed without cancellation.");
98 for (List<AbstractFile> files : map.values()) {
100 if (!files.isEmpty()) {
105 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
106 NbBundle.getMessage(this.getClass(),
107 "HashDbSearchThread.noMoreFilesWithMD5Msg"));
111 HashDbSearchManager man =
new HashDbSearchManager(map);
114 logger.log(Level.INFO,
"File search by MD5 hash was canceled.");