Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CasePreferences.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2018 Basis Technology Corp.
5 * Contact: carrier <at> sleuthkit <dot> org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package org.sleuthkit.autopsy.casemodule;
20
21import java.beans.PropertyChangeEvent;
22import java.io.IOException;
23import java.io.InputStream;
24import java.io.OutputStream;
25import java.nio.file.Files;
26import java.nio.file.Path;
27import java.nio.file.Paths;
28import java.util.EnumSet;
29import java.util.Properties;
30import java.util.logging.Level;
31import org.sleuthkit.autopsy.coreutils.Logger;
32import org.sleuthkit.autopsy.directorytree.DirectoryTreeTopComponent;
33
37public final class CasePreferences {
38
39 private static final String SETTINGS_FILE = "CasePreferences.properties"; //NON-NLS
40 private static final String KEY_GROUP_BY_DATA_SOURCE = "groupByDataSource"; //NON-NLS
41 private static final String VALUE_TRUE = "true"; //NON-NLS
42 private static final String VALUE_FALSE = "false"; //NON-NLS
43
44 private static final Logger logger = Logger.getLogger(CasePreferences.class.getName());
45
46 private static Boolean groupItemsInTreeByDataSource = false;
47
51 private CasePreferences() {
52 }
53
54 static {
55 Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> {
56 if (evt.getNewValue() != null) {
57 loadFromStorage((Case) evt.getNewValue());
58 } else {
59 saveToStorage((Case) evt.getOldValue());
60 clear();
61 }
62 });
63 try {
64 loadFromStorage(Case.getCurrentCaseThrows());
65 } catch (NoCurrentCaseException ex) {
66 logger.log(Level.SEVERE, "No current case open.", ex);
67 }
68 }
69
76 public static Boolean getGroupItemsInTreeByDataSource() {
78 }
79
91
95 private static void loadFromStorage(Case currentCase) {
96 Path settingsFile = Paths.get(currentCase.getConfigDirectory(), SETTINGS_FILE); //NON-NLS
97 if (settingsFile.toFile().exists()) {
98 // Read the settings
99 try (InputStream inputStream = Files.newInputStream(settingsFile)) {
100 Properties props = new Properties();
101 props.load(inputStream);
102 String groupByDataSourceValue = props.getProperty(KEY_GROUP_BY_DATA_SOURCE);
103 if (groupByDataSourceValue != null) {
104 switch (groupByDataSourceValue) {
105 case VALUE_TRUE:
107 break;
108 case VALUE_FALSE:
110 break;
111 default:
112 logger.log(Level.WARNING, String.format("Unexpected value '%s' for key '%s'. Using 'null' instead.",
113 groupByDataSourceValue, KEY_GROUP_BY_DATA_SOURCE));
115 break;
116 }
117 } else {
119 }
120 } catch (IOException ex) {
121 logger.log(Level.SEVERE, "Error reading settings file", ex);
122 }
123 }
124 }
125
129 private static void clear() {
131 }
132
136 private static void saveToStorage(Case currentCase) {
137 Path settingsFile = Paths.get(currentCase.getConfigDirectory(), SETTINGS_FILE); //NON-NLS
138 Properties props = new Properties();
139 if (groupItemsInTreeByDataSource != null) {
141 }
142
143 try (OutputStream fos = Files.newOutputStream(settingsFile)) {
144 props.store(fos, ""); //NON-NLS
145 } catch (IOException ex) {
146 logger.log(Level.SEVERE, "Error writing settings file", ex);
147 }
148 }
149}
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition Case.java:712
static void setGroupItemsInTreeByDataSource(boolean value)
synchronized static Logger getLogger(String name)
Definition Logger.java:124

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.