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> {
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());
47 HashDbSearchThread(ArrayList<String> hashes) {
52 protected Object doInBackground() throws Exception {
53 logger.log(Level.INFO,
"Starting background processing for file search by MD5 hash.");
56 final String displayName = NbBundle.getMessage(this.getClass(),
"HashDbSearchThread.name.searching");
57 progress = ProgressHandleFactory.createHandle(displayName,
new Cancellable() {
59 public boolean cancel() {
61 progress.setDisplayName(
62 NbBundle.getMessage(
this.getClass(),
"HashDbSearchThread.progress.cancellingSearch",
64 return HashDbSearchThread.this.cancel(
true);
69 progress.switchToIndeterminate();
72 map = HashDbSearcher.findFilesBymd5(hashes, progress,
this);
73 logger.log(Level.INFO,
"Done background processing");
79 protected void done() {
82 }
catch (CancellationException ex) {
83 logger.log(Level.INFO,
"File search by MD5 hash was canceled.");
84 }
catch (InterruptedException ex) {
85 logger.log(Level.INFO,
"File search by MD5 hash was interrupted.");
86 }
catch (Exception ex) {
87 logger.log(Level.SEVERE,
"Fatal error during file search by MD5 hash.", ex);
90 if (!this.isCancelled()) {
91 logger.log(Level.INFO,
"File search by MD5 hash completed without cancellation.");
96 for(List<AbstractFile> files: map.values()) {
98 if(!files.isEmpty()) {
103 JOptionPane.showMessageDialog(null,
104 NbBundle.getMessage(
this.getClass(),
105 "HashDbSearchThread.noMoreFilesWithMD5Msg"));
109 HashDbSearchManager man =
new HashDbSearchManager(map);
112 logger.log(Level.INFO,
"File search by MD5 hash was canceled.");