code review comments

This commit is contained in:
Karl Mortensen 2015-05-19 14:57:30 -04:00
parent 9917381b92
commit 7dff89d8fb
11 changed files with 189 additions and 166 deletions

View File

@ -49,10 +49,12 @@ GetTagNameDialog.taggingErr=Tagging Error
GetTagNameDialog.tagNameAlreadyDef.msg=A {0} tag name has already been defined.
GetTagNameDialog.dupTagErr=Duplicate Tag Error
OpenLogFolder.error1=Log File Not Found: {0}
OpenLogFolder.CouldNotOpenLogFolder=Could not open log folder
CTL_OpenLogFolder=Open Log Folder
CTL_OpenOutputFolder=Open Output Folder
OpenOutputFolder.error1=Output Folder Not Found: {0}
OpenOutputFolder.noCaseOpen=No open case, therefore no current output folder available.
OpenOutputFolder.CouldNotOpenOutputFolder=Could not open output folder
ShowIngestProgressSnapshotAction.actionName.text=Get Ingest Progress Snapshot
OpenPythonModulesFolderAction.actionName.text=Python Plugins
OpenPythonModulesFolderAction.errorMsg.folderNotFound=Python plugins folder not found: {0}

View File

@ -23,16 +23,16 @@ import java.awt.event.ActionListener;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.modules.Places;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.coreutils.Logger;
/**
* Action in menu to open the folder containing the log files
@ -43,19 +43,20 @@ import org.sleuthkit.autopsy.casemodule.Case;
@ActionID(id = "org.sleuthkit.autopsy.actions.OpenLogFolderAction", category = "Help")
public final class OpenLogFolderAction implements ActionListener {
private static final Logger logger = Logger.getLogger(OpenLogFolderAction.class.getName());
@Override
public void actionPerformed(ActionEvent e) {
try {
File logDir;
if (Case.isCaseOpen()) {
logDir = new File(Case.getCurrentCase().getLogDirectoryPath());
}
else {
} else {
logDir = new File(Places.getUserDirectory().getAbsolutePath() + File.separator + "var" + File.separator + "log");
}
if (logDir.exists() == false) {
NotifyDescriptor d =
new NotifyDescriptor.Message(
NotifyDescriptor d
= new NotifyDescriptor.Message(
NbBundle.getMessage(this.getClass(), "OpenLogFolder.error1", logDir.getAbsolutePath()),
NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(d);
@ -63,7 +64,8 @@ public final class OpenLogFolderAction implements ActionListener {
Desktop.getDesktop().open(logDir);
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
logger.log(Level.WARNING, NbBundle.getMessage(this.getClass(), "OpenLogFolder.CouldNotOpenLogFolder"), ex); //NON-NLS
}
}
}

View File

@ -23,15 +23,16 @@ import java.awt.event.ActionListener;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import javax.swing.JOptionPane;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.coreutils.Logger;
/**
* Action in menu to open the folder containing the output files
@ -42,6 +43,8 @@ import org.sleuthkit.autopsy.casemodule.Case;
@ActionID(id = "org.sleuthkit.autopsy.actions.OpenOutputFolderAction", category = "Help")
public final class OpenOutputFolderAction implements ActionListener {
private static final Logger logger = Logger.getLogger(OpenOutputFolderAction.class.getName());
@Override
public void actionPerformed(ActionEvent e) {
@ -52,7 +55,7 @@ public final class OpenOutputFolderAction implements ActionListener {
if (outputDir.exists() == false) {
NotifyDescriptor d
= new NotifyDescriptor.Message(NbBundle.getMessage(this.getClass(),
"OpenOutputFolder.error1", outputDir.getAbsolutePath()),
"OpenOutputFolder.error1", outputDir.getAbsolutePath()),
NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(d);
} else {
@ -62,7 +65,7 @@ public final class OpenOutputFolderAction implements ActionListener {
JOptionPane.showMessageDialog(null, NbBundle.getMessage(this.getClass(), "OpenOutputFolder.noCaseOpen"));
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
logger.log(Level.WARNING, NbBundle.getMessage(this.getClass(),"OpenOutputFolder.CouldNotOpenOutputFolder") , ex); //NON-NLS
}
}
}

View File

@ -216,7 +216,6 @@ public class Case implements SleuthkitCase.ErrorObserver {
this.caseType = type;
this.db = db;
this.services = new Services(db);
setHostName();
}
/**
@ -755,11 +754,7 @@ public class Case implements SleuthkitCase.ErrorObserver {
* @return tempDirectoryPath
*/
public String getTempDirectory() {
File tempPath = new File(getHostDirectory() + File.separator + TEMP_FOLDER);
if (!tempPath.exists()) {
tempPath.mkdirs();
}
return tempPath.toString();
return getDirectory(TEMP_FOLDER);
}
/**
@ -769,11 +764,7 @@ public class Case implements SleuthkitCase.ErrorObserver {
* @return cacheDirectoryPath
*/
public String getCacheDirectory() {
File cachePath = new File(getHostDirectory() + File.separator + CACHE_FOLDER);
if (!cachePath.exists()) {
cachePath.mkdirs();
}
return cachePath.toString();
return getDirectory(CACHE_FOLDER);
}
/**
@ -783,11 +774,7 @@ public class Case implements SleuthkitCase.ErrorObserver {
* @return exportDirectoryPath
*/
public String getExportDirectory() {
File exportPath = new File(getHostDirectory() + File.separator + EXPORT_FOLDER);
if (!exportPath.exists()) {
exportPath.mkdirs();
}
return exportPath.toString();
return getDirectory(EXPORT_FOLDER);
}
/**
@ -797,11 +784,143 @@ public class Case implements SleuthkitCase.ErrorObserver {
* @return logDirectoryPath
*/
public String getLogDirectoryPath() {
File logPath = new File(getHostDirectory() + File.separator + LOG_FOLDER);
if (!logPath.exists()) {
logPath.mkdirs();
return getDirectory(LOG_FOLDER);
}
/**
* Get the reports directory path where modules should save their reports.
* Will create it if it does not already exist.
*
* @return absolute path to the report output directory
*/
public String getReportDirectory() {
return getDirectory(REPORTS_FOLDER);
}
/**
* Get module output directory path where modules should save their
* permanent data.
*
* @return absolute path to the module output directory
*/
public String getModuleDirectory() {
return getDirectory(MODULE_FOLDER);
}
/**
* Get the output directory path where modules should save their permanent
* data. If single-user case, the directory is a subdirectory of the case
* directory. If multi-user case, the directory is a subdirectory of
* HostName, which is a subdirectory of the case directory.
*
* @return the path to the host output directory
*/
public String getOutputDirectory() {
return getHostDirectory();
}
/**
* Get the specified directory path, create it if it does not already exist.
*
* @return absolute path to the directory
*/
private String getDirectory(String input) {
File theDirectory = new File(getHostDirectory() + File.separator + input);
if (!theDirectory.exists()) { // Create it if it doesn't exist already.
theDirectory.mkdirs();
}
return logPath.toString();
return theDirectory.toString();
}
/**
* Get relative (with respect to case dir) module output directory path
* where modules should save their permanent data. The directory is a
* subdirectory of this case dir.
*
* @return relative path to the module output dir
*/
public String getModuleOutputDirectoryRelativePath() {
Path thePath;
if (getCaseType() == CaseType.MULTI_USER_CASE) {
thePath = Paths.get(getLocalHostName(), MODULE_FOLDER);
} else {
thePath = Paths.get(MODULE_FOLDER);
}
// Do not autocreate this relative path. It will have already been
// created when the case was made.
return thePath.toString();
}
/**
* Get the host output directory path where modules should save their
* permanent data. If single-user case, the directory is a subdirectory of
* the case directory. If multi-user case, the directory is a subdirectory
* of HostName, which is a subdirectory of the case directory.
*
* @return the path to the host output directory
*/
private String getHostDirectory() {
String caseDirectory = getCaseDirectory();
Path hostPath;
if (caseType == CaseType.MULTI_USER_CASE) {
hostPath = Paths.get(caseDirectory, getLocalHostName());
} else {
hostPath = Paths.get(caseDirectory);
}
if (!hostPath.toFile().exists()) {
hostPath.toFile().mkdirs();
}
return hostPath.toString();
}
/**
* Get module output directory path where modules should save their
* permanent data.
*
* @return absolute path to the module output directory
* @deprecated Use getModuleDirectory() instead.
*/
@Deprecated
public String getModulesOutputDirAbsPath() {
return getModuleDirectory();
}
/**
* Get relative (with respect to case dir) module output directory path
* where modules should save their permanent data. The directory is a
* subdirectory of this case dir.
*
* @return relative path to the module output dir
* @deprecated Use getModuleOutputDirectoryRelativePath() instead
*/
@Deprecated
public static String getModulesOutputDirRelPath() {
return "ModuleOutput"; //NON-NLS
}
/**
* Gets a PropertyChangeSupport object. The PropertyChangeSupport object
* returned is not used by instances of this class and does not have any
* PropertyChangeListeners.
*
* @return A new PropertyChangeSupport object.
* @deprecated Do not use.
*/
@Deprecated
public static PropertyChangeSupport getPropertyChangeSupport() {
return new PropertyChangeSupport(Case.class);
}
/**
* Get the data model Content objects in the root of this case's hierarchy.
*
* @return a list of the root objects
* @throws org.sleuthkit.datamodel.TskCoreException
*/
public List<Content> getDataSources() throws TskCoreException {
List<Content> list = db.getRootObjects();
hasData = (list.size() > 0);
return list;
}
/**
@ -830,113 +949,6 @@ public class Case implements SleuthkitCase.ErrorObserver {
}
}
/**
* Get the host output directory path where modules should save their
* permanent data. If single-user case, the directory is a subdirectory of
* the case directory. If multi-user case, the directory is a subdirectory
* of HostName, which is a subdirectory of the case directory.
*
* @return the path to the host output directory
*/
private String getHostDirectory() {
String caseDirectory = getCaseDirectory();
Path hostPath;
if (caseType == CaseType.MULTI_USER_CASE) {
hostPath = Paths.get(caseDirectory, HostName);
} else {
hostPath = Paths.get(caseDirectory);
}
if (!hostPath.toFile().exists()) {
hostPath.toFile().mkdirs();
}
return hostPath.toString();
}
/**
* Get the output directory path where modules should save their
* permanent data. If single-user case, the directory is a subdirectory of
* the case directory. If multi-user case, the directory is a subdirectory
* of HostName, which is a subdirectory of the case directory.
*
* @return the path to the host output directory
*/
public String getOutputDirectory() {
return getHostDirectory();
}
/**
* Get the reports directory path where modules should save their reports.
* Will create it if it does not already exist.
*
* @return absolute path to the report output directory
*/
public String getReportDirectory() {
File reportPath = new File(getHostDirectory() + File.separator + REPORTS_FOLDER);
if (!reportPath.exists()) {
reportPath.mkdirs();
}
return reportPath.toString();
}
/**
* Get module output directory path where modules should save their
* permanent data.
*
* @return absolute path to the module output dir
*/
public String getModulesOutputDirAbsPath() {
File modulePath = new File(this.getHostDirectory() + File.separator + MODULE_FOLDER);
if (!modulePath.exists()) {
modulePath.mkdirs();
}
return modulePath.toString();
}
/**
* Get relative (with respect to case dir) module output directory path
* where modules should save their permanent data. The directory is a
* subdirectory of this case dir.
*
* @return relative path to the module output dir
*/
public String getModulesOutputDirRelPath() {
Path thePath;
if (getCaseType() == CaseType.MULTI_USER_CASE) {
thePath = Paths.get(HostName, MODULE_FOLDER);
} else {
thePath = Paths.get(MODULE_FOLDER);
}
// Do not autocreate this relative path. It will have already been
// created when the case was made.
return thePath.toString();
}
/**
* Gets a PropertyChangeSupport object. The PropertyChangeSupport object
* returned is not used by instances of this class and does not have any
* PropertyChangeListeners.
*
* @return A new PropertyChangeSupport object.
* @deprecated Do not use.
*/
@Deprecated
public static PropertyChangeSupport getPropertyChangeSupport() {
return new PropertyChangeSupport(Case.class);
}
/**
* Get the data model Content objects in the root of this case's hierarchy.
*
* @return a list of the root objects
* @throws org.sleuthkit.datamodel.TskCoreException
*/
public List<Content> getDataSources() throws TskCoreException {
List<Content> list = db.getRootObjects();
hasData = (list.size() > 0);
return list;
}
/**
* Gets the time zone(s) of the image(s) in this case.
*
@ -1150,18 +1162,15 @@ public class Case implements SleuthkitCase.ErrorObserver {
}
// create the folders inside the case directory
String hostClause = "";
if (HostName == null || HostName.isEmpty()) {
setHostName();
}
String hostClause="";
if (caseType == CaseType.MULTI_USER_CASE) {
hostClause = File.separator + HostName;
hostClause = File.separator + getLocalHostName();
}
result = result && (new File(caseDir + hostClause + File.separator + XMLCaseManagement.EXPORT_FOLDER_RELPATH)).mkdirs()
&& (new File(caseDir + hostClause + File.separator + XMLCaseManagement.LOG_FOLDER_RELPATH)).mkdirs()
&& (new File(caseDir + hostClause + File.separator + XMLCaseManagement.TEMP_FOLDER_RELPATH)).mkdirs()
&& (new File(caseDir + hostClause + File.separator + XMLCaseManagement.CACHE_FOLDER_RELPATH)).mkdirs();
result = result && (new File(caseDir + hostClause + File.separator + EXPORT_FOLDER)).mkdirs()
&& (new File(caseDir + hostClause + File.separator + LOG_FOLDER)).mkdirs()
&& (new File(caseDir + hostClause + File.separator + TEMP_FOLDER)).mkdirs()
&& (new File(caseDir + hostClause + File.separator + CACHE_FOLDER)).mkdirs();
if (result == false) {
throw new CaseActionException(
@ -1258,7 +1267,7 @@ public class Case implements SleuthkitCase.ErrorObserver {
* @param openedCase
*/
private static void checkSubFolders(Case openedCase) {
String modulesOutputDir = openedCase.getModulesOutputDirAbsPath();
String modulesOutputDir = openedCase.getModuleDirectory();
File modulesOutputDirF = new File(modulesOutputDir);
if (!modulesOutputDirF.exists()) {
logger.log(Level.INFO, "Creating modules output dir for the case."); //NON-NLS
@ -1377,18 +1386,21 @@ public class Case implements SleuthkitCase.ErrorObserver {
* Have it read the environment variable if getHostName() is unsuccessful.
* Also note that some calls into the Case class are static via Case.*, so
* anywhere we use HOSTNAME prior to a Case class being instantiated, we
* must call setHostName() first.
* must call getLocalHostName() first.
*/
private static void setHostName() {
try {
HostName = java.net.InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ex) {
// getLocalHost().getHostName() can fail in some situations.
// Use environment variable if so.
HostName = System.getenv("COMPUTERNAME");
}
private static String getLocalHostName() {
if (HostName == null || HostName.isEmpty()) {
HostName = System.getenv("COMPUTERNAME");
try {
HostName = java.net.InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ex) {
// getLocalHost().getHostName() can fail in some situations.
// Use environment variable if so.
HostName = System.getenv("COMPUTERNAME");
}
if (HostName == null || HostName.isEmpty()) {
HostName = System.getenv("COMPUTERNAME");
}
}
return HostName;
}
}

View File

@ -84,7 +84,7 @@ public class SampleExecutableDataSourceIngestModule implements DataSourceIngestM
this.context = context;
if (refCounter.incrementAndGet(context.getJobId()) == 1) {
// Create an output directory for this job.
outputDirPath = Case.getCurrentCase().getModulesOutputDirAbsPath() + File.separator + moduleName; //NON-NLS
outputDirPath = Case.getCurrentCase().getModuleDirectory() + File.separator + moduleName; //NON-NLS
File outputDir = new File(outputDirPath);
if (outputDir.exists() == false) {
outputDir.mkdirs();

View File

@ -280,7 +280,7 @@ final class PhotoRecCarverFileIngestModule implements FileIngestModule {
* @throws org.sleuthkit.autopsy.ingest.IngestModule.IngestModuleException
*/
synchronized static Path createModuleOutputDirectoryForCase() throws IngestModule.IngestModuleException {
Path path = Paths.get(Case.getCurrentCase().getModulesOutputDirAbsPath(), PhotoRecCarverIngestModuleFactory.getModuleName());
Path path = Paths.get(Case.getCurrentCase().getModuleDirectory(), PhotoRecCarverIngestModuleFactory.getModuleName());
try {
Files.createDirectory(path);
}

View File

@ -105,8 +105,8 @@ public final class SevenZipIngestModule implements FileIngestModule {
final Case currentCase = Case.getCurrentCase();
moduleDirRelative = currentCase.getModulesOutputDirRelPath() + File.separator + ArchiveFileExtractorModuleFactory.getModuleName();
moduleDirAbsolute = currentCase.getModulesOutputDirAbsPath() + File.separator + ArchiveFileExtractorModuleFactory.getModuleName();
moduleDirRelative = currentCase.getModuleOutputDirectoryRelativePath() + File.separator + ArchiveFileExtractorModuleFactory.getModuleName();
moduleDirAbsolute = currentCase.getModuleDirectory() + File.separator + ArchiveFileExtractorModuleFactory.getModuleName();
File unpackDirPathFile = new File(moduleDirAbsolute);

View File

@ -110,7 +110,7 @@ public class EventsRepository {
public EventsRepository(ReadOnlyObjectProperty<ZoomParams> currentStateProperty) {
//TODO: we should check that case is open, or get passed a case object/directory -jm
File thePath = new File(Case.getCurrentCase().getModulesOutputDirAbsPath() + File.separator + TIMELINE);
File thePath = new File(Case.getCurrentCase().getModuleDirectory() + File.separator + TIMELINE);
if (!thePath.exists()) {
thePath.mkdirs();
}

View File

@ -85,7 +85,7 @@ public final class ImageGalleryController {
private static final Logger LOGGER = Logger.getLogger(ImageGalleryController.class.getName());
private static final String TIMELINE = "Timeline";
private static final String IMAGEGALLERY = "ImageGallery";
private final Region infoOverLayBackground = new Region() {
{
@ -335,7 +335,7 @@ public final class ImageGalleryController {
*/
public synchronized void setCase(Case c) {
this.db = DrawableDB.getDrawableDB(c.getModulesOutputDirAbsPath() + File.separator + TIMELINE, this);
this.db = DrawableDB.getDrawableDB(c.getModulesOutputDirAbsPath() + File.separator + IMAGEGALLERY, this);
setListeningEnabled(ImageGalleryModule.isEnabledforCase(c));
setStale(ImageGalleryModule.isCaseStale(c));

View File

@ -278,6 +278,10 @@ public class DrawableDB {
public static DrawableDB getDrawableDB(String dbPath, ImageGalleryController controller) {
try {
File db = new File(dbPath);
if (!db.exists()) {
db.mkdirs();
}
DrawableDB drawableDB = new DrawableDB(dbPath + File.separator + "drawable.db");
drawableDB.controller = controller;
return drawableDB;

View File

@ -262,7 +262,7 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
}
public static String getRelModuleOutputPath() {
return Case.getCurrentCase().getModulesOutputDirRelPath() + File.separator
return Case.getCurrentCase().getModuleOutputDirectoryRelativePath() + File.separator
+ EmailParserModuleFactory.getModuleName();
}