+ /**
+ * Prepares all properties, the file is written if it is not found
+ */
+ private void initProperties () {
+ try {
+ // Try to read it
+ this.properties.load(new BufferedReader(new InputStreamReader(new FileInputStream(FrameworkInterface.PROPERTIES_CONFIG_FILE))));
+ } catch (final FileNotFoundException ex) {
+ /*
+ * The file is not found which is normal for first run, so
+ * initialize default values.
+ */
+ this.initPropertiesWithDefault();
+
+ // Write file
+ this.writePropertiesFile();
+ } catch (final IOException ex) {
+ // Something else didn't work
+ this.abortProgramWithException(ex);
+ }
+ }
+
+ /**
+ * Initializes properties with default values
+ */
+ private void initPropertiesWithDefault () {
+ // Init default values:
+ // Default database backend
+ this.properties.put("org.mxchange.addressbook.database.backendType", "base64csv");
+
+ // For MySQL backend
+ this.properties.put("org.mxchange.addressbook.database.mysql.host", "localhost");
+ this.properties.put("org.mxchange.addressbook.database.mysql.login", "");
+ this.properties.put("org.mxchange.addressbook.database.mysql.password", "");
+ }
+
+ /**
+ * Writes the properties file to disk
+ */
+ private void writePropertiesFile () {
+ try {
+ // Write it
+ this.properties.store(new PrintWriter(FrameworkInterface.PROPERTIES_CONFIG_FILE), "This file is automatically generated. You may wish to alter it.");
+ } catch (final IOException ex) {
+ this.abortProgramWithException(ex);
+ }
+ }
+