API save default config file if none specified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
diff --git a/api.c b/api.c
index 419ae6f..0bc65e2 100644
--- a/api.c
+++ b/api.c
@@ -1976,12 +1976,13 @@ static void devdetails(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
void dosave(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
{
+ char filename[PATH_MAX];
FILE *fcfg;
char *ptr;
if (param == NULL || *param == '\0') {
- strcpy(io_buffer, message(MSG_MISFN, 0, NULL, isjson));
- return;
+ default_save_file(filename);
+ param = filename;
}
fcfg = fopen(param, "w");
diff --git a/cgminer.c b/cgminer.c
index 9565fc1..cb4f6f2 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3006,6 +3006,23 @@ retry:
}
#endif
+void default_save_file(char *filename)
+{
+#if defined(unix)
+ if (getenv("HOME") && *getenv("HOME")) {
+ strcpy(filename, getenv("HOME"));
+ strcat(filename, "/");
+ }
+ else
+ strcpy(filename, "");
+ strcat(filename, ".cgminer/");
+ mkdir(filename, 0777);
+#else
+ strcpy(filename, "");
+#endif
+ strcat(filename, def_conf);
+}
+
#ifdef HAVE_CURSES
static void set_options(void)
{
@@ -3066,19 +3083,7 @@ retry:
FILE *fcfg;
char *str, filename[PATH_MAX], prompt[PATH_MAX + 50];
-#if defined(unix)
- if (getenv("HOME") && *getenv("HOME")) {
- strcpy(filename, getenv("HOME"));
- strcat(filename, "/");
- }
- else
- strcpy(filename, "");
- strcat(filename, ".cgminer/");
- mkdir(filename, 0777);
-#else
- strcpy(filename, "");
-#endif
- strcat(filename, def_conf);
+ default_save_file(filename);
sprintf(prompt, "Config filename to write (Enter for default) [%s]", filename);
str = curses_input(prompt);
if (strcmp(str, "-1")) {
diff --git a/miner.h b/miner.h
index 4e2f752..ec9d725 100644
--- a/miner.h
+++ b/miner.h
@@ -742,6 +742,7 @@ extern void kill_work(void);
extern void switch_pools(struct pool *selected);
extern void remove_pool(struct pool *pool);
extern void write_config(FILE *fcfg);
+extern void default_save_file(char *filename);
extern void log_curses(int prio, const char *f, va_list ap);
extern void clear_logwin(void);
extern bool pool_tclear(struct pool *pool, bool *var);