2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 6f6b7d21 authored by Daniel Lehmberg's avatar Daniel Lehmberg
Browse files

solve #256 , adapt existing config file keys to default configuration

parent a345e775
......@@ -80,7 +80,7 @@ public class ActionLoadProject extends AbstractAction {
} else {
logger.info(String.format("user canceled loadFromFilesystem project."));
logger.info("User canceled loadFromFilesystem project.");
}
} catch (IOException e1) {
e1.printStackTrace();
......@@ -88,24 +88,27 @@ public class ActionLoadProject extends AbstractAction {
}
public static void addToRecentProjects(String path) {
String listStr = VadereConfig.getConfig().getString("History.recentProjects", "");
String str = path; // make sure the new one is at top position
if (listStr.length() > 0) {
String[] list = listStr.split(",");
for (int i = 0; i < list.length; i++) {
String existingStoredPaths = VadereConfig.getConfig().getString("History.recentProjects", "");
String csvPaths = path; // make sure the new one is at top position -- comma separated paths
if (existingStoredPaths.length() > 0) {
String[] list = existingStoredPaths.split(",");
for(int i = 0; i < list.length; i++) {
String entry = list[i];
if (i < 10 && !entry.equals(path) && Files.exists(Paths.get(entry)))
str += "," + entry;
csvPaths += "," + entry;
}
}
VadereConfig.getConfig().setProperty("History.lastUsedProject", path);
VadereConfig.getConfig().setProperty("History.recentProjects", str);
VadereConfig.getConfig().setProperty("History.recentProjects", csvPaths);
ProjectView.getMainWindow().updateRecentProjectsMenu();
}
public static void loadProjectByPath(ProjectViewModel projectViewModel, String projectFilePath){
loadProjectByPath(projectViewModel, projectFilePath, MigrationOptions.defaultOptions());
}
public static void loadProjectByPath(ProjectViewModel projectViewModel, String projectFilePath, MigrationOptions options) {
try {
VadereProject project = IOVadere.readProjectJson(projectFilePath, options);
......
......@@ -13,6 +13,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -58,6 +59,8 @@ public class VadereConfig {
private VadereConfig() {
createDefaultConfigIfNonExisting();
LOGGER.info(String.format("Use config file %s", CONFIG_PATH));
// If Vadere was started like "vadere-console.jar --config-file here.txt", search in current working directory.
String basePath = (CONFIG_PATH.getParent() == null) ? System.getProperty("user.dir") : CONFIG_PATH.getParent().toString() ;
......@@ -77,6 +80,9 @@ public class VadereConfig {
LOGGER.error(String.format("Error while reading config file \"%s\": %s", CONFIG_PATH.toString(), ex.getMessage()));
LOGGER.info("Create and use default config");
}
compareAndChangeDefaultKeysInExistingFile();
}
private void createDefaultConfigIfNonExisting() {
......@@ -106,6 +112,33 @@ public class VadereConfig {
}
}
private void compareAndChangeDefaultKeysInExistingFile(){
// The keys of the default config have to match the keys from the existing file!
Map<String, String> defaultConfig = getDefaultConfig();
// first case: if key is missing in existing file then add it but added in to the defaultConfig
// -- usually happens when a new key was introduced
for(String key : defaultConfig.keySet()){
if(! vadereConfig.containsKey(key)){
vadereConfig.setProperty(key, defaultConfig.get(key));
LOGGER.info(String.format("Added key %s to file %s with default value because the key was not present "
+ "in the file before.", key, CONFIG_PATH));
}
}
// Second case: if key was removed from defaultConfig, then it is also removed from the current file
// -- usually happens when a key was removed
for(Iterator<String> iter = vadereConfig.getKeys(); iter.hasNext();){
String key = iter.next();
if(! defaultConfig.containsKey(key)){
vadereConfig.clearProperty(key);
LOGGER.info(String.format("Removed key %s in file %s because there is no entry in the " +
"\"defaultConfig\" in class VadereConfig.java", key, CONFIG_PATH));
}
}
}
// Static setters
/**
* With this setter one can inject a different config file instead of using "~/.config/vadere.conf".
......@@ -142,12 +175,14 @@ public class VadereConfig {
String defaultSearchDirectory = System.getProperty("user.home");
defaultConfig.put("Gui.dataProcessingViewMode", "gui");
defaultConfig.put("Gui.toolbar.size", "40");
defaultConfig.put("Gui.lastSavePoint", defaultSearchDirectory);
defaultConfig.put("Density.measurementScale", "10.0");
defaultConfig.put("Density.measurementRadius", "15");
defaultConfig.put("Density.standardDeviation", "0.5");
defaultConfig.put("Gui.dataProcessingViewMode", "gui");
defaultConfig.put("Gui.toolbar.size", "40");
defaultConfig.put("Gui.lastSavePoint", defaultSearchDirectory);
defaultConfig.put("History.lastUsedProject", null);
defaultConfig.put("History.recentProjects", null);
defaultConfig.put("Messages.language", Locale.ENGLISH.getLanguage());
defaultConfig.put("Pedestrian.radius", "0.195");
defaultConfig.put("PostVis.SVGWidth", "1024");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment