1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-11 07:17:58 +00:00

Write unix configuration to .cgminer/cgminer.conf by default and prompt to overwrite if given a filename from the menu that exists.

This commit is contained in:
Con Kolivas 2011-10-17 13:25:57 +11:00
parent 09f6736ab0
commit 6d004ddfad

41
main.c
View File

@ -25,6 +25,10 @@
#include <stdarg.h> #include <stdarg.h>
#include <assert.h> #include <assert.h>
#include <signal.h> #include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
#ifndef WIN32 #ifndef WIN32
#include <sys/resource.h> #include <sys/resource.h>
#endif #endif
@ -45,9 +49,7 @@
#if defined(unix) #if defined(unix)
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/types.h>
#endif #endif
#ifdef __linux /* Linux specific policy and affinity management */ #ifdef __linux /* Linux specific policy and affinity management */
@ -1726,9 +1728,17 @@ static char *load_config(const char *arg, void *unused)
static void load_default_config(void) static void load_default_config(void)
{ {
char buf[PATH_MAX]; char buf[PATH_MAX];
#if defined(unix)
strcpy(buf, getenv("HOME")); strcpy(buf, getenv("HOME"));
if (*buf) if (*buf)
strcat(buf, "/"); strcat(buf, "/");
else
strcpy(buf, "");
strcat(buf, ".cgminer/");
#else
strcpy(buf, "");
#endif
strcat(buf, def_conf); strcat(buf, def_conf);
if (!access(buf, R_OK)) if (!access(buf, R_OK))
load_config(buf, NULL); load_config(buf, NULL);
@ -3387,16 +3397,35 @@ retry:
opt_fail_pause = selected; opt_fail_pause = selected;
goto retry; goto retry;
} else if (!strncasecmp(&input, "w", 1)) { } else if (!strncasecmp(&input, "w", 1)) {
char filename[PATH_MAX], prompt[PATH_MAX+50]; FILE *fcfg;
char *str, filename[PATH_MAX], prompt[PATH_MAX + 50];
#if defined(unix)
strcpy(filename, getenv("HOME")); strcpy(filename, getenv("HOME"));
if (*filename) if (*filename)
strcat(filename, "/"); strcat(filename, "/");
else
strcpy(filename, "");
strcat(filename, ".cgminer/");
mkdir(filename, 0777);
#else
strcpy(filename, "");
#endif
strcat(filename, def_conf); strcat(filename, def_conf);
sprintf(prompt, "Config filename to write (Enter for default) [%s]", filename); sprintf(prompt, "Config filename to write (Enter for default) [%s]", filename);
char *str = curses_input(prompt); str = curses_input(prompt);
if (strcmp(str, "-1")) if (strcmp(str, "-1")) {
struct stat statbuf;
strcpy(filename, str); strcpy(filename, str);
FILE *fcfg = fopen(filename, "w"); if (!stat(filename, &statbuf)) {
wlogprint("File exists, overwrite?\n");
input = getch();
if (strncasecmp(&input, "y", 1))
goto retry;
}
}
fcfg = fopen(filename, "w");
if (!fcfg) { if (!fcfg) {
wlogprint("Cannot open or create file\n"); wlogprint("Cannot open or create file\n");
goto retry; goto retry;