Browse Source

Use appdata_file_call to find BFGMiner config file(s)

Luke Dashjr 11 years ago
parent
commit
264daa16d3
1 changed files with 19 additions and 19 deletions
  1. 19 19
      miner.c

+ 19 - 19
miner.c

@@ -2584,28 +2584,28 @@ static char *load_config(const char *arg, void __maybe_unused *unused)
 	return parse_config(config, true, &cfginfo->fileconf_load);
 }
 
-static void load_default_config(void)
+static
+bool _load_default_configs(const char * const filepath, void * __maybe_unused userp)
 {
-	char cnfbuf[PATH_MAX];
+	bool * const found_defcfg_p = userp;
+	*found_defcfg_p = true;
+	
+	load_config(filepath, NULL);
+	
+	// Regardless of status of loading the config file, we should continue loading other defaults
+	return false;
+}
 
-#if defined(unix)
-	if (getenv("HOME") && *getenv("HOME")) {
-	        strcpy(cnfbuf, getenv("HOME"));
-		strcat(cnfbuf, "/");
-	} else
-		strcpy(cnfbuf, "");
-	char *dirp = cnfbuf + strlen(cnfbuf);
-	strcpy(dirp, ".bfgminer/");
-	strcat(dirp, def_conf);
-	if (access(cnfbuf, R_OK))
+static void load_default_config(void)
+{
+	bool found_defcfg = false;
+	appdata_file_call("BFGMiner", def_conf, _load_default_configs, &found_defcfg);
+	
+	if (!found_defcfg)
+	{
 		// No BFGMiner config, try Cgminer's...
-		strcpy(dirp, ".cgminer/cgminer.conf");
-#else
-	strcpy(cnfbuf, "");
-	strcat(cnfbuf, def_conf);
-#endif
-	if (!access(cnfbuf, R_OK))
-		load_config(cnfbuf, NULL);
+		appdata_file_call("cgminer", "cgminer.conf", _load_default_configs, &found_defcfg);
+	}
 }
 
 extern const char *opt_argv0;