19package org.sleuthkit.autopsy.coreutils;
22import java.io.FileInputStream;
23import java.io.FileOutputStream;
24import java.io.IOException;
25import java.io.InputStream;
26import java.nio.file.Paths;
27import java.util.HashMap;
29import java.util.Properties;
31import java.util.logging.Level;
71 File propPath =
new File(getSettingsFilePath(moduleName));
72 File parent =
new File(propPath.getParent());
73 if (!parent.exists()) {
77 Properties props =
new Properties();
79 propPath.createNewFile();
80 try (FileOutputStream fos =
new FileOutputStream(propPath)) {
81 props.store(fos,
"Created module settings file");
83 }
catch (IOException ex) {
84 logger.log(Level.SEVERE, String.format(
"Failed to create module settings file at %s)", propPath), ex);
99 public static synchronized boolean configExists(String moduleName) {
100 return new File(getSettingsFilePath(moduleName)).exists();
113 public static synchronized boolean settingExists(String moduleName, String settingName) {
120 return (props.getProperty(settingName) !=
null);
121 }
catch (IOException ex) {
122 logger.log(Level.SEVERE, String.format(
"Failed to get %s setting from module settings file at %s)", settingName, getSettingsFilePath(moduleName)), ex);
134 static String getSettingsFilePath(String moduleName) {
149 public static synchronized String
getConfigSetting(String moduleName, String settingName) {
156 return props.getProperty(settingName);
157 }
catch (IOException ex) {
158 logger.log(Level.SEVERE, String.format(
"Failed to get %s setting from module settings file at %s)", settingName, getSettingsFilePath(moduleName)), ex);
180 Set<String> keys = props.stringPropertyNames();
181 Map<String, String> map =
new HashMap<>();
182 for (String s : keys) {
183 map.put(s, props.getProperty(s));
186 }
catch (IOException ex) {
187 logger.log(Level.SEVERE, String.format(
"Failed to get settings from module settings file at %s)", getSettingsFilePath(moduleName)), ex);
201 public static synchronized void setConfigSettings(String moduleName, Map<String, String> settings) {
208 for (Map.Entry<String, String> kvp : settings.entrySet()) {
209 props.setProperty(kvp.getKey(), kvp.getValue());
212 File path =
new File(getSettingsFilePath(moduleName));
213 try (FileOutputStream fos =
new FileOutputStream(path)) {
214 props.store(fos,
"Set settings (batch)");
216 }
catch (IOException ex) {
217 logger.log(Level.SEVERE, String.format(
"Error writing to module settings file at %s)", getSettingsFilePath(moduleName)), ex);
230 public static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal) {
236 props.setProperty(settingName, settingVal);
237 File path =
new File(getSettingsFilePath(moduleName));
238 try (FileOutputStream fos =
new FileOutputStream(path)) {
239 props.store(fos,
"Set " + settingName);
241 }
catch (IOException ex) {
242 logger.log(Level.SEVERE, String.format(
"Error writing %s setting to module settings file at %s)", settingName, getSettingsFilePath(moduleName)), ex);
252 public static synchronized void removeProperty(String moduleName, String settingName) {
256 props.remove(settingName);
257 File path =
new File(getSettingsFilePath(moduleName));
258 try (FileOutputStream fos =
new FileOutputStream(path)) {
259 props.store(fos,
"Removed " + settingName);
262 }
catch (IOException ex) {
263 logger.log(Level.SEVERE, String.format(
"Error removing %s setting from module settings file at %s)", settingName, getSettingsFilePath(moduleName)), ex);
276 private static synchronized Properties
fetchProperties(String moduleName)
throws IOException {
278 try (InputStream inputStream =
new FileInputStream(getSettingsFilePath(moduleName))) {
279 props =
new Properties();
280 props.load(inputStream);
293 File configFile =
null;
295 configFile =
new File(getSettingsFilePath(moduleName));
synchronized static Logger getLogger(String name)
static synchronized void setConfigSettings(String moduleName, Map< String, String > settings)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static final String MAIN_SETTINGS
static final String MODULE_DIR_PATH
static final String CURRENT_CASE_TYPE
static synchronized Map< String, String > getConfigSettings(String moduleName)
static synchronized File getPropertyFile(String moduleName)
static synchronized boolean configExists(String moduleName)
static final String SETTINGS_FILE_EXT
static synchronized String getConfigSetting(String moduleName, String settingName)
static synchronized Properties fetchProperties(String moduleName)
static final String DEFAULT_CONTEXT
static synchronized void removeProperty(String moduleName, String settingName)
static synchronized boolean makeConfigFile(String moduleName)
static final Logger logger
static synchronized boolean settingExists(String moduleName, String settingName)