added checking for default setup file in global config directory
[rocksndiamonds.git] / src / libgame / setup.c
index d6ec2eeb175c322233dfb856b9c0b8bde9cb727a..affc9365fab104533eea93dc8e70d8535f9526ea 100644 (file)
@@ -464,27 +464,35 @@ char *getProgramMainDataPath(char *command_filename, char *base_path)
   return main_data_path;
 }
 
-char *getProgramConfigFilename(char *command_filename_ptr)
+char *getProgramConfigFilename(char *command_filename)
 {
-  char *command_filename_1 = getStringCopy(command_filename_ptr);
+  char *command_filename_1 = getStringCopy(command_filename);
 
   // strip trailing executable suffix from command filename
   if (strSuffix(command_filename_1, ".exe"))
     command_filename_1[strlen(command_filename_1) - 4] = '\0';
 
-  char *command_basepath = getBasePath(command_filename_ptr);
-  char *command_basename = getBaseNameNoSuffix(command_filename_ptr);
+  char *ro_base_path = getProgramMainDataPath(command_filename, RO_BASE_PATH);
+  char *conf_directory = getPath2(ro_base_path, CONF_DIRECTORY);
+
+  char *command_basepath = getBasePath(command_filename);
+  char *command_basename = getBaseNameNoSuffix(command_filename);
   char *command_filename_2 = getPath2(command_basepath, command_basename);
 
   char *config_filename_1 = getStringCat2(command_filename_1, ".conf");
   char *config_filename_2 = getStringCat2(command_filename_2, ".conf");
+  char *config_filename_3 = getPath2(conf_directory, SETUP_FILENAME);
 
   // 1st try: look for config file that exactly matches the binary filename
   if (fileExists(config_filename_1))
     return config_filename_1;
 
-  // 2nd try: return config filename that matches binary filename without suffix
-  return config_filename_2;
+  // 2nd try: look for config file that matches binary filename without suffix
+  if (fileExists(config_filename_2))
+    return config_filename_2;
+
+  // 3rd try: return setup config filename in global program config directory
+  return config_filename_3;
 }
 
 char *getTapeFilename(int nr)