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;
27 import org.openide.util.NbBundle;
29 import javax.swing.JOptionPane;
30 import javax.swing.SwingWorker;
31 import org.netbeans.api.progress.ProgressHandle;
32 import org.netbeans.api.progress.ProgressHandleFactory;
33 import org.openide.util.Cancellable;
36 class HashDbSearchThread
extends SwingWorker<Object, Void> {
38 private Logger logger = Logger.getLogger(HashDbSearchThread.class.getName());
39 private ProgressHandle progress;
40 private Map<String, List<AbstractFile>> map;
41 private ArrayList<String> hashes =
new ArrayList<>();
42 private AbstractFile file;
44 HashDbSearchThread(AbstractFile file) {
46 this.hashes.add(this.file.getMd5Hash());
49 HashDbSearchThread(ArrayList<String> hashes) {
54 protected Object doInBackground() throws Exception {
55 logger.log(Level.INFO,
"Starting background processing for file search by MD5 hash.");
58 final String displayName = NbBundle.getMessage(this.getClass(),
"HashDbSearchThread.name.searching");
59 progress = ProgressHandleFactory.createHandle(displayName,
new Cancellable() {
61 public boolean cancel() {
62 if (progress != null) {
63 progress.setDisplayName(
64 NbBundle.getMessage(
this.getClass(),
"HashDbSearchThread.progress.cancellingSearch",
67 return HashDbSearchThread.this.cancel(
true);
72 progress.switchToIndeterminate();
75 map = HashDbSearcher.findFilesBymd5(hashes, progress,
this);
76 logger.log(Level.INFO,
"Done background processing");
82 protected void done() {
85 }
catch (CancellationException ex) {
86 logger.log(Level.INFO,
"File search by MD5 hash was canceled.");
87 }
catch (InterruptedException ex) {
88 logger.log(Level.INFO,
"File search by MD5 hash was interrupted.");
89 }
catch (Exception ex) {
90 logger.log(Level.SEVERE,
"Fatal error during file search by MD5 hash.", ex);
93 if (!this.isCancelled()) {
94 logger.log(Level.INFO,
"File search by MD5 hash completed without cancellation.");
99 for (List<AbstractFile> files : map.values()) {
101 if (!files.isEmpty()) {
106 JOptionPane.showMessageDialog(null,
107 NbBundle.getMessage(
this.getClass(),
108 "HashDbSearchThread.noMoreFilesWithMD5Msg"));
112 HashDbSearchManager man =
new HashDbSearchManager(map);
115 logger.log(Level.INFO,
"File search by MD5 hash was canceled.");