19 package org.sleuthkit.autopsy.datamodel;
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24 import java.util.Arrays;
25 import java.util.Calendar;
26 import java.util.List;
27 import java.util.logging.Level;
29 import org.openide.nodes.ChildFactory;
30 import org.openide.nodes.Node;
32 import org.
sleuthkit.datamodel.SleuthkitCase.CaseDbQuery;
39 class RecentFilesChildren
extends ChildFactory<RecentFiles.RecentFilesFilter> {
41 private SleuthkitCase skCase;
42 private Calendar lastDay;
43 private final static Logger logger = Logger.getLogger(RecentFilesChildren.class.getName());
45 public RecentFilesChildren(SleuthkitCase skCase) {
50 protected boolean createKeys(List<RecentFiles.RecentFilesFilter> list) {
51 list.addAll(Arrays.asList(RecentFiles.RecentFilesFilter.values()));
52 lastDay = Calendar.getInstance();
53 lastDay.setTimeInMillis(getLastTime() * 1000);
54 lastDay.set(Calendar.HOUR_OF_DAY, 0);
55 lastDay.set(Calendar.MINUTE, 0);
56 lastDay.set(Calendar.SECOND, 0);
57 lastDay.set(Calendar.MILLISECOND, 0);
62 protected Node createNodeForKey(RecentFiles.RecentFilesFilter key) {
63 return new RecentFilesFilterNode(skCase, key, lastDay);
66 private long getLastTime() {
67 String query = createMaxQuery(
"crtime");
68 long maxcr = runTimeQuery(query);
69 query = createMaxQuery(
"ctime");
70 long maxc = runTimeQuery(query);
71 query = createMaxQuery(
"mtime");
72 long maxm = runTimeQuery(query);
76 return Math.max(maxcr, Math.max(maxc, maxm));
80 private String createMaxQuery(String attr) {
81 return "SELECT MAX(" + attr +
") FROM tsk_files WHERE " + attr +
" < " + System.currentTimeMillis() / 1000;
84 @SuppressWarnings(
"deprecation")
85 private
long runTimeQuery(String query) {
88 try (CaseDbQuery dbQuery = skCase.executeQuery(query)) {
89 ResultSet resultSet = dbQuery.getResultSet();
91 result = resultSet.getLong(1);
92 }
catch (TskCoreException | SQLException ex) {
93 logger.log(Level.WARNING,
"Couldn't get recent files results: ", ex);