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