added reading optional platform setup file
authorHolger Schemel <info@artsoft.org>
Fri, 29 Apr 2022 23:18:45 +0000 (01:18 +0200)
committerHolger Schemel <info@artsoft.org>
Fri, 29 Apr 2022 23:18:45 +0000 (01:18 +0200)
src/files.c
src/libgame/setup.c
src/libgame/setup.h

index 044dcbcc5f1110765abde36978323aa5d5de2166..b0e376d295c568cf0493e1d1570fdc91e2e40c43 100644 (file)
@@ -10838,6 +10838,12 @@ void LoadSetup_Default(void)
   // try to load setup values from default setup file
   filename = getDefaultSetupFilename();
 
+  if (fileExists(filename))
+    LoadSetupFromFilename(filename);
+
+  // try to load setup values from platform setup file
+  filename = getPlatformSetupFilename();
+
   if (fileExists(filename))
     LoadSetupFromFilename(filename);
 
index 0382a4d7a2e53b315d4fe68d68e7770238bd1e5f..8da478a3656126dc45d00570b53e3db3ee3562ea 100644 (file)
@@ -593,6 +593,34 @@ char *getProgramConfigFilename(char *command_filename)
   return config_filename_3;
 }
 
+static char *getPlatformConfigFilename(char *config_filename)
+{
+  static char *platform_config_filename = NULL;
+  static boolean initialized = FALSE;
+
+  if (!initialized)
+  {
+    char *config_basepath = getBasePath(config_filename);
+    char *config_basename = getBaseNameNoSuffix(config_filename);
+    char *config_filename_prefix = getPath2(config_basepath, config_basename);
+    char *platform_string_lower = getStringToLower(PLATFORM_STRING);
+    char *platform_suffix = getStringCat2("-", platform_string_lower);
+
+    platform_config_filename = getStringCat3(config_filename_prefix,
+                                            platform_suffix, ".conf");
+
+    checked_free(config_basepath);
+    checked_free(config_basename);
+    checked_free(config_filename_prefix);
+    checked_free(platform_string_lower);
+    checked_free(platform_suffix);
+
+    initialized = TRUE;
+  }
+
+  return platform_config_filename;
+}
+
 char *getTapeFilename(int nr)
 {
   static char *filename = NULL;
@@ -749,6 +777,11 @@ char *getDefaultSetupFilename(void)
   return program.config_filename;
 }
 
+char *getPlatformSetupFilename(void)
+{
+  return getPlatformConfigFilename(program.config_filename);
+}
+
 char *getEditorSetupFilename(void)
 {
   static char *filename = NULL;
index 1e785a956c2f7eeb42ca9fd8999864351b73ca50..62145becf7c638fbfaadce6304457cc55620fc44 100644 (file)
@@ -275,6 +275,7 @@ char *getScoreTapeFilename(char *, int);
 char *getScoreCacheTapeFilename(char *, int);
 char *getSetupFilename(void);
 char *getDefaultSetupFilename(void);
+char *getPlatformSetupFilename(void);
 char *getEditorSetupFilename(void);
 char *getHelpAnimFilename(void);
 char *getHelpTextFilename(void);