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;
 
   34 class HashDbSearchThread 
extends SwingWorker<Object, Void> {
 
   36     private Logger logger = Logger.getLogger(HashDbSearchThread.class.getName());
 
   37     private ProgressHandle progress;
 
   38     private Map<String, List<AbstractFile>> map;
 
   39     private ArrayList<String> hashes = 
new ArrayList<>();
 
   40     private AbstractFile file;
 
   42     HashDbSearchThread(AbstractFile file) {
 
   44         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 = ProgressHandle.createHandle(displayName, 
new Cancellable() {
 
   59             public boolean cancel() {
 
   60                 if (progress != null) {
 
   61                     progress.setDisplayName(
 
   62                             NbBundle.getMessage(
this.getClass(), 
"HashDbSearchThread.progress.cancellingSearch",
 
   65                 return HashDbSearchThread.this.cancel(
true);
 
   70         progress.switchToIndeterminate();
 
   73         map = HashDbSearcher.findFilesBymd5(hashes, progress, 
this);
 
   74         logger.log(Level.INFO, 
"Done background processing"); 
 
   80     protected void done() {
 
   83         } 
catch (CancellationException ex) {
 
   84             logger.log(Level.INFO, 
"File search by MD5 hash was canceled."); 
 
   85         } 
catch (InterruptedException ex) {
 
   86             logger.log(Level.INFO, 
"File search by MD5 hash was interrupted."); 
 
   87         } 
catch (Exception ex) {
 
   88             logger.log(Level.SEVERE, 
"Fatal error during file search by MD5 hash.", ex); 
 
   91             if (!this.isCancelled()) {
 
   92                 logger.log(Level.INFO, 
"File search by MD5 hash completed without cancellation."); 
 
   97                     for (List<AbstractFile> files : map.values()) {
 
   99                         if (!files.isEmpty()) {
 
  104                         JOptionPane.showMessageDialog(null,
 
  105                                 NbBundle.getMessage(
this.getClass(),
 
  106                                         "HashDbSearchThread.noMoreFilesWithMD5Msg"));
 
  110                 HashDbSearchManager man = 
new HashDbSearchManager(map);
 
  113                 logger.log(Level.INFO, 
"File search by MD5 hash was canceled.");