1
0
mirror of https://github.com/elisspace/autopsy.git synced 2026-08-31 16:33:52 +00:00

Add cache folder to case, start caching thumbnails

This commit is contained in:
Dick Fickling
2012-04-26 13:29:22 -04:00
parent 35be56d87a
commit dee46749b2
4 changed files with 80 additions and 9 deletions

View File

@@ -270,7 +270,7 @@ public class Case {
boolean allFilesExist = true;
String pathString = "";
for (String s : paths) {
allFilesExist &= new File(s).exists();
allFilesExist &= isPhysicalDrive(s) || new File(s).exists();
pathString += s + "\n";
}
if (!allFilesExist) {
@@ -564,6 +564,18 @@ public class Case {
return xmlcm.getTempDir();
}
}
/**
* Gets the full path to the cache directory of this case
* @return cacheDirectoryPath
*/
public String getCacheDirectory() {
if (xmlcm == null) {
return "";
} else {
return xmlcm.getCacheDir();
}
}
/**
* get the created date of this case
@@ -755,7 +767,8 @@ public class Case {
// create the folders inside the case directory
result = result && (new File(caseDir + File.separator + XMLCaseManagement.EXPORT_FOLDER_RELPATH)).mkdir()
&& (new File(caseDir + File.separator + XMLCaseManagement.LOG_FOLDER_RELPATH)).mkdir()
&& (new File(caseDir + File.separator + XMLCaseManagement.TEMP_FOLDER_RELPATH)).mkdir();
&& (new File(caseDir + File.separator + XMLCaseManagement.TEMP_FOLDER_RELPATH)).mkdir()
&& (new File(caseDir + File.separator + XMLCaseManagement.CACHE_FOLDER_RELPATH)).mkdir();
return result;
} catch (Exception e) {

View File

@@ -50,9 +50,9 @@ public final class CaseOpenAction implements ActionListener {
fc.setDragEnabled(false);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
//fc.setAcceptAllFileFilterUsed(false);
fc.addChoosableFileFilter(autFilter);
fc.addChoosableFileFilter(fc.getAcceptAllFileFilter());
//fc.addChoosableFileFilter(fc.getAcceptAllFileFilter());
if(AutopsyProperties.getProperty(PROP_BASECASE) != null)
fc.setCurrentDirectory(new File(AutopsyProperties.getProperty(PROP_BASECASE)));
}

View File

@@ -79,6 +79,8 @@ public class XMLCaseManagement implements CaseConfigFileInterface{
final static String TEMP_FOLDER_RELPATH = "Temp";
final static String EXPORT_FOLDER_NAME = "ExportFolder";
final static String EXPORT_FOLDER_RELPATH = "Export";
final static String CACHE_FOLDER_NAME = "CacheFolder";
final static String CACHE_FOLDER_RELPATH = "Cache";
// folders attribute
final static String RELATIVE_NAME = "Relative"; // relevant path info
@@ -450,6 +452,26 @@ public class XMLCaseManagement implements CaseConfigFileInterface{
return ""; // should throw error or exception
}
}
/**
* Gets the full path to the Cache directory
*
* @return cacheDir the full path of the "Cache" directory
*/
protected String getCacheDir(){
if(doc != null){
Element cacheElement = (Element)getCaseElement().getElementsByTagName(CACHE_FOLDER_NAME).item(0);
if(cacheElement.getAttribute(RELATIVE_NAME).equals(RELATIVE_TRUE)){
return caseDirPath + File.separator + cacheElement.getTextContent();
}
else{
return cacheElement.getTextContent();
}
}
else{
return ""; // should throw error or exception
}
}
/**
* Gets image Element from the document handler
@@ -720,6 +742,11 @@ public class XMLCaseManagement implements CaseConfigFileInterface{
tempElement.appendChild(doc.createTextNode(TEMP_FOLDER_RELPATH));
tempElement.setAttribute(RELATIVE_NAME, "true");
caseElement.appendChild(tempElement);
Element cacheElement = doc.createElement(CACHE_FOLDER_NAME); // <CacheFolder> ... </CacheFolder>
cacheElement.appendChild(doc.createTextNode(CACHE_FOLDER_RELPATH));
cacheElement.setAttribute(RELATIVE_NAME, "true");
caseElement.appendChild(cacheElement);
// create the new images
Element imagesElement = doc.createElement(IMAGES_NAME); // <Images> ... </Images>

View File

@@ -24,12 +24,16 @@ import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.lang.ref.SoftReference;
import java.util.logging.Level;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import org.openide.nodes.FilterNode;
import org.openide.nodes.Node;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.coreutils.Log;
import org.sleuthkit.datamodel.Content;
import org.sleuthkit.datamodel.TskException;
@@ -65,15 +69,26 @@ class ThumbnailViewNode extends FilterNode {
icon = iconCache.get();
}
if (icon == null) {
Content content = this.getLookup().lookup(Content.class);
if (content != null) {
try {
System.out.println("generate");
icon = generateIcon(content);
} catch (TskException ex) {
icon = ThumbnailViewNode.defaultIcon;
if (getFile(content.getId()).exists()) {
try {
icon = ImageIO.read(getFile(content.getId()));
} catch (IOException ex) {
icon = ThumbnailViewNode.defaultIcon;
}
} else {
try {
icon = generateIcon(content);
ImageIO.write(toBufferedImage(icon), "jpg", getFile(content.getId()));
} catch (TskException ex) {
icon = ThumbnailViewNode.defaultIcon;
} catch (IOException ex) {
}
}
} else {
icon = ThumbnailViewNode.defaultIcon;
@@ -134,4 +149,20 @@ class ThumbnailViewNode extends FilterNode {
return Toolkit.getDefaultToolkit().createImage(combined.getSource());
}
private static BufferedImage toBufferedImage(Image src) {
int w = src.getWidth(null);
int h = src.getHeight(null);
int type = BufferedImage.TYPE_INT_RGB; // other options
BufferedImage dest = new BufferedImage(w, h, type);
Graphics2D g2 = dest.createGraphics();
g2.drawImage(src, 0, 0, null);
g2.dispose();
return dest;
}
private static File getFile(long id) {
return new File(Case.getCurrentCase().getCacheDirectory() + File.separator + id + ".jpg");
}
}