19 package org.sleuthkit.autopsy.directorytree;
21 import java.awt.Desktop;
22 import java.awt.event.ActionEvent;
24 import java.io.IOException;
25 import java.util.logging.Level;
26 import javax.swing.AbstractAction;
27 import javax.swing.JOptionPane;
28 import org.openide.nodes.Node;
29 import org.openide.util.NbBundle.Messages;
44 final static String[] EXECUTABLE_EXT = {
".exe",
".dll",
".com",
".bat",
".msi",
".reg",
".scr",
".cmd"};
52 int extPos = fileName.lastIndexOf(
'.');
54 boolean isExecutable =
false;
56 String extension = fileName.substring(extPos, fileName.length()).toLowerCase();
57 fileObjectExt = extension;
58 for (
int i = 0; i < EXECUTABLE_EXT.length; ++i) {
59 if (EXECUTABLE_EXT[i].equals(extension)) {
71 if (!(size > 0) || extPos == -1 || isExecutable) {
72 this.setEnabled(
false);
76 @Messages({
"ExternalViewerAction.actionPerformed.failure.message=Could not find a viewer for the given file.",
77 "ExternalViewerAction.actionPerformed.failure.title=Open Failure"})
82 tempPath = tempPath + File.separator + this.
fileObject.getName();
85 File tempFile =
new File(tempPath);
86 if (tempFile.exists()) {
90 tempFile.createNewFile();
92 }
catch (IOException ex) {
93 logger.log(Level.WARNING,
"Can't save to temporary file.", ex);
100 String exePath = ExternalViewerRulesManager.getInstance().getExePathForName(
fileObject.getMIMEType());
101 if (exePath.equals(
"")) {
102 exePath = ExternalViewerRulesManager.getInstance().getExePathForName(fileObjectExt);
104 if (!exePath.equals(
"")) {
105 Runtime runtime = Runtime.getRuntime();
106 String[] s =
new String[]{exePath, tempFile.getAbsolutePath()};
109 }
catch (IOException ex) {
110 logger.log(Level.WARNING,
"Could not open the specified viewer for the given file: " + tempFile.getName(), ex);
111 JOptionPane.showMessageDialog(null, Bundle.ExternalViewerAction_actionPerformed_failure_message(), Bundle.ExternalViewerAction_actionPerformed_failure_title(), JOptionPane.ERROR_MESSAGE);
115 Desktop.getDesktop().open(tempFile);
116 }
catch (IOException ex) {
117 logger.log(Level.WARNING,
"Could not find a viewer for the given file: " + tempFile.getName(), ex);
118 JOptionPane.showMessageDialog(null, Bundle.ExternalViewerAction_actionPerformed_failure_message(), Bundle.ExternalViewerAction_actionPerformed_failure_title(), JOptionPane.ERROR_MESSAGE);
122 tempFile.deleteOnExit();
String getTempDirectory()
static< T > long writeToFile(Content content, java.io.File outputFile, ProgressHandle progress, Future< T > worker, boolean source)
static final Logger logger
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
org.sleuthkit.datamodel.AbstractFile fileObject
ExternalViewerAction(String title, Node fileNode)
void actionPerformed(ActionEvent e)