mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-14 17:06:16 +00:00
Perform optional report deletion from disk
This commit is contained in:
parent
a73cbbd642
commit
04bf322b98
@ -1196,30 +1196,36 @@ public class Case implements SleuthkitCase.ErrorObserver {
|
||||
/**
|
||||
* Deletes reports from the case - deletes it from the disk as well as the
|
||||
* database.
|
||||
*
|
||||
* @param reports Collection of Report to be deleted from the case.
|
||||
* @param deleteFromDisk Set true to perform reports file deletion from
|
||||
* disk.
|
||||
* @throws TskCoreException
|
||||
*/
|
||||
public void deleteReports(Collection<? extends Report> reports) throws TskCoreException {
|
||||
public void deleteReports(Collection<? extends Report> reports, boolean deleteFromDisk) throws TskCoreException {
|
||||
|
||||
String pathToReportsFolder = Paths.get(this.db.getDbDirPath(), "Reports").normalize().toString();
|
||||
String pathToReportsFolder = Paths.get(this.db.getDbDirPath(), "Reports").normalize().toString(); // NON-NLS
|
||||
for (Report report : reports) {
|
||||
// traverse to the root directory of Report report.
|
||||
String reportPath = report.getPath();
|
||||
while (!Paths.get(reportPath, "..").normalize().toString().equals(pathToReportsFolder)) {
|
||||
reportPath = Paths.get(reportPath, "..").normalize().toString();
|
||||
}
|
||||
|
||||
// delete from the disk.
|
||||
try {
|
||||
FileUtils.deleteDirectory(new File(reportPath));
|
||||
} catch (IOException | SecurityException ex) {
|
||||
logger.log(Level.WARNING, NbBundle.getMessage(Case.class, "Case.deleteReports.deleteFromDiskException.log.msg"), ex);
|
||||
JOptionPane.showMessageDialog(null, NbBundle.getMessage(Case.class, "Case.deleteReports.deleteFromDiskException.msg", report.getReportName(), reportPath));
|
||||
}
|
||||
|
||||
// delete from the database.
|
||||
this.db.deleteReport(report);
|
||||
|
||||
if (deleteFromDisk) {
|
||||
// traverse to the root directory of Report report.
|
||||
String reportPath = report.getPath();
|
||||
while (!Paths.get(reportPath, "..").normalize().toString().equals(pathToReportsFolder)) { // NON-NLS
|
||||
reportPath = Paths.get(reportPath, "..").normalize().toString(); // NON-NLS
|
||||
}
|
||||
|
||||
// delete from the disk.
|
||||
try {
|
||||
FileUtils.deleteDirectory(new File(reportPath));
|
||||
} catch (IOException | SecurityException ex) {
|
||||
logger.log(Level.WARNING, NbBundle.getMessage(Case.class, "Case.deleteReports.deleteFromDiskException.log.msg"), ex);
|
||||
JOptionPane.showMessageDialog(null, NbBundle.getMessage(Case.class, "Case.deleteReports.deleteFromDiskException.msg", report.getReportName(), reportPath));
|
||||
}
|
||||
}
|
||||
|
||||
// fire property change event.
|
||||
try {
|
||||
Case.pcs.firePropertyChange(Events.REPORTS_DELETED.toString(), null, null);
|
||||
|
@ -280,6 +280,9 @@ VolumeNode.createSheet.flags.displayName=Flags
|
||||
VolumeNode.createSheet.flags.desc=no description
|
||||
AbstractAbstractFileNode.objectId=Object ID
|
||||
ArtifactStringContent.getStr.artifactId.text=Artifact ID
|
||||
DeleteReportAction.actionDisplayName=Delete Report(s)
|
||||
DeleteReportAction.actionDisplayName.singleReport=Delete Report
|
||||
DeleteReportAction.actionDisplayName.multipleReports=Delete Reports
|
||||
DeleteReportAction.actionPerformed.showConfirmDialog.title=Confirm Deletion
|
||||
DeleteReportAction.actionPerformed.showConfirmDialog.msg=Delete {0} reports.\nClick OK to proceed.
|
||||
DeleteReportAction.actionPerformed.showConfirmDialog.single.msg=Do you want to delete 1 report?
|
||||
DeleteReportAction.actionPerformed.showConfirmDialog.multiple.msg=Do you want to delete {0} reports?
|
||||
DeleteReportAction.actionPerformed.showConfirmDialog.checkbox.msg=Check to delete reports from the disk.
|
||||
|
@ -32,6 +32,7 @@ import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JOptionPane;
|
||||
import org.openide.nodes.ChildFactory;
|
||||
import org.openide.nodes.Children;
|
||||
@ -207,6 +208,11 @@ public final class Reports implements AutopsyVisitableItem {
|
||||
if (instance == null) {
|
||||
instance = new DeleteReportAction();
|
||||
}
|
||||
if (Utilities.actionsGlobalContext().lookupAll(Report.class).size() == 1) {
|
||||
instance.putValue(Action.NAME, NbBundle.getMessage(Reports.class, "DeleteReportAction.actionDisplayName.singleReport"));
|
||||
} else {
|
||||
instance.putValue(Action.NAME, NbBundle.getMessage(Reports.class, "DeleteReportAction.actionDisplayName.multipleReports"));
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -215,18 +221,25 @@ public final class Reports implements AutopsyVisitableItem {
|
||||
* DeleteReportAction.getInstance(), instead.
|
||||
*/
|
||||
private DeleteReportAction() {
|
||||
super(NbBundle.getMessage(DeleteReportAction.class, "DeleteReportAction.actionDisplayName"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Collection<? extends Report> selectedReportsCollection = Utilities.actionsGlobalContext().lookupAll(Report.class);
|
||||
if (JOptionPane.showConfirmDialog(null,
|
||||
NbBundle.getMessage(DeleteReportAction.class, "DeleteReportAction.actionPerformed.showConfirmDialog.title"),
|
||||
NbBundle.getMessage(DeleteReportAction.class, "DeleteReportAction.actionPerformed.showConfirmDialog.msg", selectedReportsCollection.size()),
|
||||
JOptionPane.OK_CANCEL_OPTION) == 0) {
|
||||
|
||||
String jOptionPaneMessage = selectedReportsCollection.size() > 1
|
||||
? NbBundle.getMessage(Reports.class, "DeleteReportAction.actionPerformed.showConfirmDialog.multiple.msg", selectedReportsCollection.size())
|
||||
: NbBundle.getMessage(Reports.class, "DeleteReportAction.actionPerformed.showConfirmDialog.single.msg");
|
||||
JCheckBox checkbox = new JCheckBox(NbBundle.getMessage(Reports.class, "DeleteReportAction.actionPerformed.showConfirmDialog.checkbox.msg"));
|
||||
checkbox.setSelected(false);
|
||||
|
||||
Object[] jOptionPaneContent = {jOptionPaneMessage, checkbox};
|
||||
|
||||
if (JOptionPane.showConfirmDialog(null, jOptionPaneContent,
|
||||
NbBundle.getMessage(Reports.class, "DeleteReportAction.actionPerformed.showConfirmDialog.title"),
|
||||
JOptionPane.YES_NO_OPTION) == 0) {
|
||||
try {
|
||||
Case.getCurrentCase().deleteReports(selectedReportsCollection);
|
||||
Case.getCurrentCase().deleteReports(selectedReportsCollection, checkbox.isSelected());
|
||||
DataContentTopComponent.findInstance().repaint();
|
||||
} catch (TskCoreException | IllegalStateException ex) {
|
||||
Logger.getLogger(DeleteReportAction.class.getName()).log(Level.INFO, "Error deleting the reports. ", ex); // NON-NLS - Provide solution to the user?
|
||||
@ -234,6 +247,7 @@ public final class Reports implements AutopsyVisitableItem {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class OpenReportAction extends AbstractAction {
|
||||
|
||||
private OpenReportAction() {
|
||||
|
@ -208,7 +208,6 @@ class ReportKML implements GeneralReportModule {
|
||||
}
|
||||
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
progressPanel.increment();
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user