Browse Source

Check for the presence of the settings file #13

Bob Mottram 6 years ago
parent
commit
82dd38630c
3 changed files with 19 additions and 2 deletions
  1. 3 2
      src/main.c
  2. 15 0
      src/settings.c
  3. 1 0
      src/settings.h

+ 3 - 2
src/main.c

@@ -154,9 +154,10 @@ int main(int argc, char* argv[])
   set_language(ENGLISH_UK);
   settings_set_theme(get_text_from_identifier(THEME_NORMAL));
 
-  sprintf((char*)fin_directory,"%s/.fin",getenv("HOME"));
+  sprintf((char*)fin_directory,"%s/.fin", getenv("HOME"));
 
-  if (directory_exists((char*)fin_directory)==0) {
+  if ((directory_exists((char*)fin_directory)==0) ||
+      (settings_exist((char*)fin_directory)==0)) {
     create_sqlite_database();
     settings_set_language("English UK");
     settings_set_account(get_text_from_identifier(SETTINGS_DEFAULT_CURRENT_ACCOUNT));

+ 15 - 0
src/settings.c

@@ -129,6 +129,21 @@ int settings_load(char * directory)
   return 0;
 }
 
+int settings_exist(char * directory)
+{
+  FILE * fp;
+  char filename[STRING_BLOCK];
+
+  sprintf((char*)filename,"%s/%s",
+          directory,get_text_from_identifier(SETTINGS_FILENAME));
+  fp  =fopen(filename,"r");
+  if (fp!=0L) {
+      fclose(fp);
+      return 1;
+  }
+  return 0;
+}
+
 void settings_save(char * directory)
 {
   FILE * fp;

+ 1 - 0
src/settings.h

@@ -24,6 +24,7 @@
 #include "validation.h"
 
 
+int settings_exist(char * directory);
 int settings_load(char * directory);
 void settings_save(char * directory);