Added an alpha argument for drawing fonts.
[supertux.git] / lib / utils / configfile.cpp
index 4634422..bbbb501 100644 (file)
@@ -28,7 +28,7 @@
 using namespace SuperTux;
 
 #ifdef WIN32
-const char * config_filename = "/st_config.dat";
+const char * config_filename = ("/"+ package_symbol_name + "_config.dat").c_str();
 #else
 const char * config_filename = "/config";
 #endif
@@ -49,32 +49,25 @@ static void defaults ()
   SoundManager::get()->enable_music(true);
 }
 
-FILE * SuperTux::opendata(const char * rel_filename, const char * mode)
+FILE * SuperTux::opendata(const std::string& rel_filename, const char *mode)
 {
-  char * filename = NULL;
+  std::string filename;
   FILE * fi;
 
-  filename = (char *) malloc(sizeof(char) * (strlen(st_dir) +
-                                             strlen(rel_filename) + 1));
-
-  strcpy(filename, st_dir);
-  /* Open the high score file: */
-
-  strcat(filename, rel_filename);
+  filename = st_dir + rel_filename;
 
   /* Try opening the file: */
-  fi = fopen(filename, mode);
+  fi = fopen(filename.c_str(), mode);
 
   if (fi == NULL)
     {
-      fprintf(stderr, "Warning: Unable to open the file \"%s\" ", filename);
+      fprintf(stderr, "Warning: Unable to open the file \"%s\" ", filename.c_str());
 
       if (strcmp(mode, "r") == 0)
         fprintf(stderr, "for read!!!\n");
       else if (strcmp(mode, "w") == 0)
         fprintf(stderr, "for write!!!\n");
     }
-  free( filename );
 
   return(fi);
 }
@@ -103,7 +96,7 @@ void Config::load()
   if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR)
     return;
 
-  if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-config") != 0)
+  if (strcmp(lisp_symbol(lisp_car(root_obj)), (package_symbol_name+"-config").c_str()) != 0)
     return;
 
   LispReader reader(lisp_cdr(root_obj));
@@ -138,6 +131,7 @@ void Config::load()
   customload(reader);
 
   lisp_free(root_obj);
+  fclose(file);
 }
 
 void Config::save ()
@@ -147,7 +141,7 @@ void Config::save ()
 
   if(config)
     {
-      fprintf(config, "(supertux-config\n");
+      fprintf(config, ("("+package_symbol_name+"-config\n").c_str());
       fprintf(config, "\t;; the following options can be set to #t or #f:\n");
       fprintf(config, "\t(fullscreen %s)\n", use_fullscreen ? "#t" : "#f");
       fprintf(config, "\t(sound      %s)\n", SoundManager::get()->sound_enabled()      ? "#t" : "#f");
@@ -173,6 +167,7 @@ void Config::save ()
        customsave(config);
 
       fprintf(config, ")\n");
+      fclose(config);
     }
 }