19 package org.sleuthkit.autopsy.modules.interestingitems;
 
   22 import java.io.FilenameFilter;
 
   23 import java.util.HashMap;
 
   25 import java.util.function.Function;
 
   26 import java.util.logging.Level;
 
   27 import java.util.stream.Collectors;
 
   28 import org.openide.modules.InstalledFileLocator;
 
   29 import org.openide.modules.OnStart;
 
   30 import org.openide.util.NbBundle.Messages;
 
   44     private static final String 
CONFIG_DIR = 
"InterestingFileSetRules";
 
   48         public boolean accept(File dir, String name) {
 
   49             return name.endsWith(
".xml");
 
   55         "StandardInterestingFilesSetsLoader_cannotLoadStandard=Unable to properly read standard interesting files sets.",
 
   56         "StandardInterestingFilesSetsLoader_cannotLoadUserConfigured=Unable to properly read user-configured interesting files sets.",
 
   57         "StandardInterestingFilesSetsLoader_cannotUpdateInterestingFilesSets=Unable to write updated configuration for interesting files sets to config directory." 
   60         Map<String, FilesSet> standardInterestingFileSets = null;
 
   64             handleError(Bundle.StandardInterestingFilesSetsLoader_cannotLoadStandard(), ex);
 
   69         Map<String, FilesSet> userConfiguredSettings = null;
 
   73             LOGGER.log(Level.SEVERE, 
"Unable to properly read user-configured interesting files sets.", ex);
 
   74             handleError(Bundle.StandardInterestingFilesSetsLoader_cannotLoadStandard(), ex);
 
   79         copyOnNewer(standardInterestingFileSets, userConfiguredSettings, 
true);
 
   85             handleError(Bundle.StandardInterestingFilesSetsLoader_cannotUpdateInterestingFilesSets(), ex);
 
   95     private static void handleError(String message, Exception ex) {
 
   96         LOGGER.log(Level.SEVERE, message, ex);
 
  110         Map<String, FilesSet> standardInterestingFileSets = 
new HashMap<>();
 
  112         File configFolder = InstalledFileLocator.getDefault().locate(
 
  115         if (configFolder == null || !configFolder.exists() || !configFolder.isDirectory()) {
 
  119         File[] standardFileSets = configFolder.listFiles(DEFAULT_XML_FILTER);
 
  121         for (File standardFileSetsFile : standardFileSets) { 
 
  123                 Map<String, FilesSet> thisFilesSet = InterestingItemsFilesSetSettings.readDefinitionsXML(standardFileSetsFile);
 
  126                 thisFilesSet = thisFilesSet.values()
 
  128                         .map((filesSet) -> getAsStandardFilesSet(filesSet, 
true))
 
  131                 copyOnNewer(thisFilesSet, standardInterestingFileSets);
 
  133                 LOGGER.log(Level.WARNING, String.format(
"There was a problem importing the standard interesting file set at: %s.",
 
  134                         standardFileSetsFile.getAbsoluteFile()), ex);
 
  137         return standardInterestingFileSets;
 
  150     static FilesSet getAsStandardFilesSet(
FilesSet origFilesSet, 
boolean standardFilesSet) {
 
  158                 origFilesSet.getVersionNumber()
 
  170     private static void copyOnNewer(Map<String, FilesSet> src, Map<String, FilesSet> dest) {
 
  185     private static void copyOnNewer(Map<String, FilesSet> src, Map<String, FilesSet> dest, 
boolean appendCustom) {
 
  186         for (Map.Entry<String, 
FilesSet> srcEntry : src.entrySet()) {
 
  187             String key = srcEntry.getKey();
 
  188             FilesSet srcFileSet = srcEntry.getValue();
 
  189             FilesSet destFileSet = dest.get(key);
 
  190             if (destFileSet != null) {
 
  193                 if (appendCustom && srcFileSet.isStandardSet() != destFileSet.isStandardSet()) {
 
  194                     if (srcFileSet.isStandardSet()) {
 
  196                         dest.put(key, srcFileSet);
 
  205                 if (destFileSet.getVersionNumber() >= srcEntry.getValue().getVersionNumber()) {
 
  210             dest.put(srcEntry.getKey(), srcEntry.getValue());
 
  223         if (srcFilesSet.isStandardSet()) {
 
  224             LOGGER.log(Level.SEVERE, 
"An attempt to create a custom file that was a standard set.");
 
  231             srcToAdd = getAsCustomFileSet(srcToAdd);
 
  232         } 
while (dest.containsKey(srcToAdd.
getName()));
 
  234         dest.put(srcToAdd.
getName(), srcToAdd);
 
  246         "# {0} - filesSetName",
 
  247         "StandardInterestingFileSetsLoader.customSuffixed={0} (Custom)" 
  249     static FilesSet getAsCustomFileSet(FilesSet srcFilesSet) {
 
  250         String customKey = Bundle.StandardInterestingFileSetsLoader_customSuffixed(srcFilesSet.getName());
 
  253                 srcFilesSet.getDescription(),
 
  254                 srcFilesSet.ignoresKnownFiles(),
 
  255                 srcFilesSet.ingoresUnallocatedSpace(),
 
  256                 srcFilesSet.getRules(),
 
  258                 srcFilesSet.getVersionNumber()
 
static void copyOnNewer(Map< String, FilesSet > src, Map< String, FilesSet > dest)
 
static boolean runningWithGUI
 
static void handleError(String message, Exception ex)
 
Map< String, FilesSet > getInterestingFilesSets()
 
static synchronized FilesSetsManager getInstance()
 
static final FilenameFilter DEFAULT_XML_FILTER
 
static void copyOnNewer(Map< String, FilesSet > src, Map< String, FilesSet > dest, boolean appendCustom)
 
static final String CONFIG_DIR
 
static void addCustomFile(Map< String, FilesSet > dest, FilesSet srcFilesSet)
 
Map< String, Rule > getRules()
 
boolean ignoresKnownFiles()
 
synchronized static Logger getLogger(String name)
 
static Map< String, FilesSet > readStandardFileXML()
 
boolean ingoresUnallocatedSpace()
 
static void error(String message)
 
static final Logger LOGGER