From 3542fab909bb92be490d88443c9a1b6e6c2a4551 Mon Sep 17 00:00:00 2001 From: "U-BASIS\\zhaohui" Date: Tue, 6 Mar 2018 10:24:48 -0500 Subject: [PATCH 1/2] 2229: Part 24: Use getOpenCase() instead of getCurrentCase() in contentviewers, modules, casemodule... --- .../casemodule/CaseInformationPanel.java | 8 +++++- .../casemodule/CasePropertiesPanel.java | 11 +++++--- .../autopsy/contentviewers/FXVideoPanel.java | 11 ++++++-- .../autopsy/contentviewers/GstVideoPanel.java | 26 ++++++++++++++++--- .../autopsy/coreutils/VideoUtils.java | 15 ++++++++--- .../hashdatabase/HashDbIngestModule.java | 8 +++++- .../PhotoRecCarverOutputParser.java | 7 ++--- 7 files changed, 69 insertions(+), 17 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/CaseInformationPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/CaseInformationPanel.java index 04632e76ba..f600dd3b55 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/CaseInformationPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/CaseInformationPanel.java @@ -20,9 +20,11 @@ package org.sleuthkit.autopsy.casemodule; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.logging.Level; import javax.swing.JDialog; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import org.sleuthkit.autopsy.coreutils.Logger; import org.openide.util.NbBundle.Messages; import org.openide.windows.WindowManager; @@ -51,7 +53,11 @@ class CaseInformationPanel extends javax.swing.JPanel { "CaseInformationPanel.editDetailsDialog.title=Edit Case Details" }) private void customizeComponents() { - propertiesPanel = new CasePropertiesPanel(Case.getCurrentCase()); + try { + propertiesPanel = new CasePropertiesPanel(Case.getOpenCase()); + } catch (NoCurrentCaseException ex) { + Logger.getLogger(CaseInformationPanel.class.getName()).log(Level.INFO, "Exception while getting open case.", ex); + } propertiesPanel.setSize(propertiesPanel.getPreferredSize()); this.tabbedPane.addTab(Bundle.CaseInformationPanel_caseDetails_header(), propertiesPanel); this.tabbedPane.addTab(Bundle.CaseInformationPanel_ingestJobInfo_header(), new IngestJobInfoPanel()); diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/CasePropertiesPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/CasePropertiesPanel.java index 101f8688dd..d07f850868 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/CasePropertiesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/CasePropertiesPanel.java @@ -49,7 +49,12 @@ final class CasePropertiesPanel extends javax.swing.JPanel { } void updateCaseInfo() { - theCase = Case.getCurrentCase(); + try { + theCase = Case.getOpenCase(); + } catch (NoCurrentCaseException ex) { + LOGGER.log(Level.SEVERE, "Exception while getting open case.", ex); + return; + } lbCaseNameText.setText(theCase.getDisplayName()); lbCaseNumberText.setText(theCase.getNumber()); lbExaminerNameText.setText(theCase.getExaminer()); @@ -78,9 +83,9 @@ final class CasePropertiesPanel extends javax.swing.JPanel { try { EamDb dbManager = EamDb.getInstance(); if (dbManager != null) { - CorrelationCase correlationCase = dbManager.getCase(Case.getCurrentCase()); + CorrelationCase correlationCase = dbManager.getCase(theCase); if (null == correlationCase) { - correlationCase = dbManager.newCase(Case.getCurrentCase()); + correlationCase = dbManager.newCase(theCase); } currentOrg = correlationCase.getOrg(); } diff --git a/Core/src/org/sleuthkit/autopsy/contentviewers/FXVideoPanel.java b/Core/src/org/sleuthkit/autopsy/contentviewers/FXVideoPanel.java index 64203d674b..ef6acc1fd4 100644 --- a/Core/src/org/sleuthkit/autopsy/contentviewers/FXVideoPanel.java +++ b/Core/src/org/sleuthkit/autopsy/contentviewers/FXVideoPanel.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013-15 Basis Technology Corp. + * Copyright 2013-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -59,6 +59,7 @@ import org.openide.util.NbBundle; import org.openide.util.lookup.ServiceProvider; import org.openide.util.lookup.ServiceProviders; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.core.Installer; import org.sleuthkit.autopsy.corecomponents.FrameCapture; import org.sleuthkit.autopsy.corecomponents.VideoFrame; @@ -136,7 +137,13 @@ public class FXVideoPanel extends MediaViewVideoPanel { mediaPane.setInfoLabelText(path); mediaPane.setInfoLabelToolTipText(path); - final File tempFile = VideoUtils.getTempVideoFile(currentFile); + final File tempFile; + try { + tempFile = VideoUtils.getTempVideoFile(currentFile); + } catch (NoCurrentCaseException ex) { + logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS + return; + } new Thread(mediaPane.new ExtractMedia(currentFile, tempFile)).start(); diff --git a/Core/src/org/sleuthkit/autopsy/contentviewers/GstVideoPanel.java b/Core/src/org/sleuthkit/autopsy/contentviewers/GstVideoPanel.java index e32c551d65..c686471a41 100644 --- a/Core/src/org/sleuthkit/autopsy/contentviewers/GstVideoPanel.java +++ b/Core/src/org/sleuthkit/autopsy/contentviewers/GstVideoPanel.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013-15 Basis Technology Corp. + * Copyright 2013-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -55,6 +55,7 @@ import org.netbeans.api.progress.ProgressHandle; import org.openide.util.NbBundle; import org.openide.util.lookup.ServiceProvider; import org.openide.util.lookup.ServiceProviders; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.corecomponents.FrameCapture; import org.sleuthkit.autopsy.corecomponents.VideoFrame; import org.sleuthkit.autopsy.coreutils.Logger; @@ -181,6 +182,7 @@ public class GstVideoPanel extends MediaViewVideoPanel { } @Override + @NbBundle.Messages ({"GstVideoPanel.noOpenCase.errMsg=No open case available."}) void setupVideo(final AbstractFile file, final Dimension dims) { reset(); infoLabel.setText(""); @@ -194,6 +196,18 @@ public class GstVideoPanel extends MediaViewVideoPanel { return; } + java.io.File ioFile; + try { + ioFile = VideoUtils.getTempVideoFile(file); + } catch (NoCurrentCaseException ex) { + logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS + infoLabel.setText(Bundle.GstVideoPanel_noOpenCase_errMsg()); + pauseButton.setEnabled(false); + progressSlider.setEnabled(false); + + return; + } + String path = ""; try { path = file.getUniquePath(); @@ -205,7 +219,6 @@ public class GstVideoPanel extends MediaViewVideoPanel { pauseButton.setEnabled(true); progressSlider.setEnabled(true); - java.io.File ioFile = VideoUtils.getTempVideoFile(file); gstVideoComponent = new VideoComponent(); synchronized (playbinLock) { @@ -537,7 +550,14 @@ public class GstVideoPanel extends MediaViewVideoPanel { return; } } else if (state.equals(State.READY)) { - final File tempVideoFile = VideoUtils.getTempVideoFile(currentFile); + final File tempVideoFile; + try { + tempVideoFile = VideoUtils.getTempVideoFile(currentFile); + } catch (NoCurrentCaseException ex) { + logger.log(Level.WARNING, "Exception while getting open case."); //NON-NLS + infoLabel.setText(MEDIA_PLAYER_ERROR_STRING); + return; + } new ExtractMedia(currentFile, tempVideoFile).execute(); diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/VideoUtils.java b/Core/src/org/sleuthkit/autopsy/coreutils/VideoUtils.java index 81670a878c..59d16ac5f3 100644 --- a/Core/src/org/sleuthkit/autopsy/coreutils/VideoUtils.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/VideoUtils.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2015-16 Basis Technology Corp. + * Copyright 2015-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,6 +34,7 @@ import org.opencv.core.Mat; import org.opencv.highgui.VideoCapture; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.corelibs.ScalrWrapper; import static org.sleuthkit.autopsy.coreutils.ImageUtils.isMediaThumbnailSupported; import org.sleuthkit.autopsy.datamodel.ContentUtils; @@ -90,8 +91,8 @@ public class VideoUtils { private VideoUtils() { } - public static File getTempVideoFile(AbstractFile file) { - return Paths.get(Case.getCurrentCase().getTempDirectory(), "videos", file.getId() + "." + file.getNameExtension()).toFile(); //NON-NLS + public static File getTempVideoFile(AbstractFile file) throws NoCurrentCaseException { + return Paths.get(Case.getOpenCase().getTempDirectory(), "videos", file.getId() + "." + file.getNameExtension()).toFile(); //NON-NLS } public static boolean isVideoThumbnailSupported(AbstractFile file) { @@ -101,7 +102,13 @@ public class VideoUtils { @NbBundle.Messages({"# {0} - file name", "VideoUtils.genVideoThumb.progress.text=extracting temporary file {0}"}) static BufferedImage generateVideoThumbnail(AbstractFile file, int iconSize) { - java.io.File tempFile = getTempVideoFile(file); + java.io.File tempFile; + try { + tempFile = getTempVideoFile(file); + } catch (NoCurrentCaseException ex) { + LOGGER.log(Level.WARNING, "Exception while getting open case.", ex); //NON-NLS + return null; + } if (tempFile.exists() == false || tempFile.length() < file.getSize()) { ProgressHandle progress = ProgressHandle.createHandle(Bundle.VideoUtils_genVideoThumb_progress_text(file.getName())); progress.start(100); diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java index 022cda8a9c..1a11c6702f 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java @@ -29,6 +29,7 @@ import java.util.logging.Level; import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.casemodule.services.Blackboard; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; @@ -144,7 +145,12 @@ public class HashDbIngestModule implements FileIngestModule { @Override public ProcessResult process(AbstractFile file) { - blackboard = Case.getCurrentCase().getServices().getBlackboard(); + try { + blackboard = Case.getOpenCase().getServices().getBlackboard(); + } catch (NoCurrentCaseException ex) { + logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS + return ProcessResult.ERROR; + } // Skip unallocated space files. if ((file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS) || diff --git a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverOutputParser.java b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverOutputParser.java index 01d19b84d1..6c1975f5a8 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverOutputParser.java +++ b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverOutputParser.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2016 Basis Technology Corp. + * Copyright 2011-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,6 +29,7 @@ import java.util.List; import java.util.logging.Level; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.casemodule.services.FileManager; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; @@ -99,7 +100,7 @@ class PhotoRecCarverOutputParser { NodeList fileRanges; Element entry; Path filePath; - FileManager fileManager = Case.getCurrentCase().getServices().getFileManager(); + FileManager fileManager = Case.getOpenCase().getServices().getFileManager(); // create and initialize the list to put into the database List carvedFiles = new ArrayList<>(); @@ -156,7 +157,7 @@ class PhotoRecCarverOutputParser { } } return fileManager.addCarvedFiles(new CarvingResult(af, carvedFiles)); - } catch (NumberFormatException | TskCoreException ex) { + } catch (NumberFormatException | TskCoreException | NoCurrentCaseException ex) { logger.log(Level.SEVERE, "Error parsing PhotoRec output and inserting it into the database", ex); //NON-NLS } From b5d4935f6b4361ac6bb92658604978114b361ff7 Mon Sep 17 00:00:00 2001 From: "U-BASIS\\zhaohui" Date: Tue, 6 Mar 2018 10:56:42 -0500 Subject: [PATCH 2/2] 2229: Catch the NoCurrentCaseException in VideoFile.java --- .../autopsy/imagegallery/datamodel/VideoFile.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/VideoFile.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/VideoFile.java index 7e963e512b..f5f322a65c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/VideoFile.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/VideoFile.java @@ -29,6 +29,7 @@ import javafx.scene.media.Media; import javafx.scene.media.MediaException; import org.netbeans.api.progress.ProgressHandle; import org.openide.util.NbBundle; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.coreutils.ImageUtils; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.VideoUtils; @@ -64,7 +65,7 @@ public class VideoFile extends DrawableFile { private SoftReference mediaRef; @NbBundle.Messages({"VideoFile.getMedia.progress=writing temporary file to disk"}) - public Media getMedia() throws IOException, MediaException { + public Media getMedia() throws IOException, MediaException, NoCurrentCaseException { Media media = (mediaRef != null) ? mediaRef.get() : null; if (media != null) { @@ -90,7 +91,7 @@ public class VideoFile extends DrawableFile { Double getWidth() { try { return (double) getMedia().getWidth(); - } catch (IOException | MediaException ex) { + } catch (IOException | MediaException | NoCurrentCaseException ex) { return -1.0; } } @@ -104,7 +105,7 @@ public class VideoFile extends DrawableFile { Double getHeight() { try { return (double) getMedia().getHeight(); - } catch (IOException | MediaException ex) { + } catch (IOException | MediaException | NoCurrentCaseException ex) { return -1.0; } }