mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-14 17:06:16 +00:00
Modified ExternalViewerAction to accomodate opening reports
This commit is contained in:
parent
8d639a29e4
commit
6d86bf48c8
@ -44,6 +44,7 @@ import org.openide.util.lookup.Lookups;
|
|||||||
import org.sleuthkit.autopsy.casemodule.Case;
|
import org.sleuthkit.autopsy.casemodule.Case;
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
|
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
|
||||||
|
import org.sleuthkit.autopsy.directorytree.ExternalViewerAction;
|
||||||
import org.sleuthkit.datamodel.Report;
|
import org.sleuthkit.datamodel.Report;
|
||||||
import org.sleuthkit.datamodel.TskCoreException;
|
import org.sleuthkit.datamodel.TskCoreException;
|
||||||
|
|
||||||
@ -292,30 +293,16 @@ public final class Reports implements AutopsyVisitableItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
File file = new File(ReportNode.this.report.getPath());
|
String reportPath = ReportNode.this.report.getPath();
|
||||||
try {
|
String extension = "";
|
||||||
Desktop.getDesktop().open(file);
|
int extPosition = reportPath.lastIndexOf('.');
|
||||||
} catch (IOException ex) {
|
|
||||||
JOptionPane.showMessageDialog(null,
|
if (extPosition != -1) {
|
||||||
NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.NoAssociatedEditorMessage"),
|
extension = reportPath.substring(extPosition, reportPath.length()).toLowerCase();
|
||||||
NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MessageBoxTitle"),
|
}
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
} catch (UnsupportedOperationException ex) {
|
File file = new File(reportPath);
|
||||||
JOptionPane.showMessageDialog(null,
|
ExternalViewerAction.openFile("", extension, file);
|
||||||
NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.NoOpenInEditorSupportMessage"),
|
|
||||||
NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MessageBoxTitle"),
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
JOptionPane.showMessageDialog(null,
|
|
||||||
NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MissingReportFileMessage"),
|
|
||||||
NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MessageBoxTitle"),
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
} catch (SecurityException ex) {
|
|
||||||
JOptionPane.showMessageDialog(null,
|
|
||||||
NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.ReportFileOpenPermissionDeniedMessage"),
|
|
||||||
NbBundle.getMessage(OpenReportAction.class, "OpenReportAction.actionPerformed.MessageBoxTitle"),
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,8 +73,6 @@ public class ExternalViewerAction extends AbstractAction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Messages({"ExternalViewerAction.actionPerformed.failure.message=Could not find a viewer for the given file.",
|
|
||||||
"ExternalViewerAction.actionPerformed.failure.title=Open Failure"})
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
// Get the temp folder path of the case
|
// Get the temp folder path of the case
|
||||||
@ -93,32 +91,73 @@ public class ExternalViewerAction extends AbstractAction {
|
|||||||
logger.log(Level.WARNING, "Can't save to temporary file.", ex); //NON-NLS
|
logger.log(Level.WARNING, "Can't save to temporary file.", ex); //NON-NLS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExternalViewerAction.openFile(fileObject.getMIMEType(), fileObjectExt, tempFile);
|
||||||
|
|
||||||
|
// delete the temporary file on exit
|
||||||
|
tempFile.deleteOnExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a file, taking into account user preferences and then the default
|
||||||
|
* associated application.
|
||||||
|
*
|
||||||
|
* @param mimeType MIME type of the file
|
||||||
|
* @param ext extension of the file
|
||||||
|
* @param file the file object
|
||||||
|
*/
|
||||||
|
@Messages({
|
||||||
|
"ExternalViewerAction.actionPerformed.failure.title=Open File Failure",
|
||||||
|
"ExternalViewerAction.actionPerformed.failure.IO.message=There is no associated editor for files of this type or the associated application failed to launch.",
|
||||||
|
"ExternalViewerAction.actionPerformed.failure.support.message=This platform (operating system) does not support opening a file in an editor this way.",
|
||||||
|
"ExternalViewerAction.actionPerformed.failure.missingFile.message=The file no longer exists.",
|
||||||
|
"ExternalViewerAction.actionPerformed.failure.permission.message=Permission to open the file was denied."})
|
||||||
|
public static void openFile(String mimeType, String ext, File file) {
|
||||||
/**
|
/**
|
||||||
* Check if the file MIME type or extension exists in the user defined
|
* Check if the file MIME type or extension exists in the user defined
|
||||||
* settings. Otherwise open with the default associated application.
|
* settings. Otherwise open with the default associated application.
|
||||||
*/
|
*/
|
||||||
String exePath = ExternalViewerRulesManager.getInstance().getExePathForName(fileObject.getMIMEType());
|
String exePath = ExternalViewerRulesManager.getInstance().getExePathForName(mimeType);
|
||||||
if (exePath.equals("")) {
|
if (exePath.equals("")) {
|
||||||
exePath = ExternalViewerRulesManager.getInstance().getExePathForName(fileObjectExt);
|
exePath = ExternalViewerRulesManager.getInstance().getExePathForName(ext);
|
||||||
}
|
}
|
||||||
if (!exePath.equals("")) {
|
if (!exePath.equals("")) {
|
||||||
Runtime runtime = Runtime.getRuntime();
|
Runtime runtime = Runtime.getRuntime();
|
||||||
String[] s = new String[]{exePath, tempFile.getAbsolutePath()};
|
String[] s = new String[]{exePath, file.getAbsolutePath()};
|
||||||
try {
|
try {
|
||||||
runtime.exec(s);
|
runtime.exec(s);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.log(Level.WARNING, "Could not open the specified viewer for the given file: " + tempFile.getName(), ex); //NON-NLS
|
logger.log(Level.WARNING, "Could not open the specified viewer for the given file: " + file.getName(), ex); //NON-NLS
|
||||||
JOptionPane.showMessageDialog(null, Bundle.ExternalViewerAction_actionPerformed_failure_message(), Bundle.ExternalViewerAction_actionPerformed_failure_title(), JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(null, Bundle.ExternalViewerAction_actionPerformed_failure_message(), Bundle.ExternalViewerAction_actionPerformed_failure_title(), JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
Desktop.getDesktop().open(tempFile);
|
Desktop.getDesktop().open(file);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.log(Level.WARNING, "Could not find a viewer for the given file: " + tempFile.getName(), ex); //NON-NLS
|
logger.log(Level.WARNING, "Could not find a viewer for the given file: " + file.getName(), ex); //NON-NLS
|
||||||
JOptionPane.showMessageDialog(null, Bundle.ExternalViewerAction_actionPerformed_failure_message(), Bundle.ExternalViewerAction_actionPerformed_failure_title(), JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(null,
|
||||||
|
Bundle.ExternalViewerAction_actionPerformed_failure_IO_message(),
|
||||||
|
Bundle.ExternalViewerAction_actionPerformed_failure_title(),
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
} catch (UnsupportedOperationException ex) {
|
||||||
|
logger.log(Level.WARNING, "Platform cannot open " + file.getName() + " in the defined editor.", ex); //NON-NLS
|
||||||
|
JOptionPane.showMessageDialog(null,
|
||||||
|
Bundle.ExternalViewerAction_actionPerformed_failure_support_message(),
|
||||||
|
Bundle.ExternalViewerAction_actionPerformed_failure_title(),
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
logger.log(Level.WARNING, "Could not find the given file: " + file.getName(), ex); //NON-NLS
|
||||||
|
JOptionPane.showMessageDialog(null,
|
||||||
|
Bundle.ExternalViewerAction_actionPerformed_failure_missingFile_message(),
|
||||||
|
Bundle.ExternalViewerAction_actionPerformed_failure_title(),
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
} catch (SecurityException ex) {
|
||||||
|
logger.log(Level.WARNING, "Could not get permission to open the given file: " + file.getName(), ex); //NON-NLS
|
||||||
|
JOptionPane.showMessageDialog(null,
|
||||||
|
Bundle.ExternalViewerAction_actionPerformed_failure_permission_message(),
|
||||||
|
Bundle.ExternalViewerAction_actionPerformed_failure_title(),
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// delete the file on exit
|
|
||||||
tempFile.deleteOnExit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user