mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
GTK: stop referring to &thegame in prefs I/O functions.
I had to do this in the Windows front end to cope with compiling in both COMBINED and one-puzzle mode: you can't refer to &thegame because it might not exist in this build, so instead, if you want to load/save preferences for a given midend, you ask that midend for _its_ game structure, and use that to make the necessary file names. On Unix, we don't have COMBINED mode. But now I've thought of it, this seems like a good idiom anyway, for the sake of futureproofing against the day someone decides to implement combined mode on Unix. delete_prefs() doesn't get passed a frontend _or_ a midend, so that just has to take a bare 'const game *' parameter, and in main() we pass &thegame to it. So that will still need changing in a combined mode, if one is ever added.
This commit is contained in:
28
gtk.c
28
gtk.c
@ -2988,7 +2988,7 @@ static char *prefs_dir(void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *prefs_path_general(const char *suffix)
|
static char *prefs_path_general(const game *game, const char *suffix)
|
||||||
{
|
{
|
||||||
char *dir, *path;
|
char *dir, *path;
|
||||||
|
|
||||||
@ -2996,25 +2996,26 @@ static char *prefs_path_general(const char *suffix)
|
|||||||
if (!dir)
|
if (!dir)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
path = make_prefs_path(dir, "/", &thegame, suffix);
|
path = make_prefs_path(dir, "/", game, suffix);
|
||||||
|
|
||||||
sfree(dir);
|
sfree(dir);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *prefs_path(void)
|
static char *prefs_path(const game *game)
|
||||||
{
|
{
|
||||||
return prefs_path_general(".conf");
|
return prefs_path_general(game, ".conf");
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *prefs_tmp_path(void)
|
static char *prefs_tmp_path(const game *game)
|
||||||
{
|
{
|
||||||
return prefs_path_general(".conf.tmp");
|
return prefs_path_general(game, ".conf.tmp");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void load_prefs(frontend *fe)
|
static void load_prefs(frontend *fe)
|
||||||
{
|
{
|
||||||
char *path = prefs_path();
|
const game *game = midend_which_game(fe->me);
|
||||||
|
char *path = prefs_path(game);
|
||||||
if (!path)
|
if (!path)
|
||||||
return;
|
return;
|
||||||
FILE *fp = fopen(path, "r");
|
FILE *fp = fopen(path, "r");
|
||||||
@ -3030,9 +3031,10 @@ static void load_prefs(frontend *fe)
|
|||||||
|
|
||||||
static char *save_prefs(frontend *fe)
|
static char *save_prefs(frontend *fe)
|
||||||
{
|
{
|
||||||
|
const game *game = midend_which_game(fe->me);
|
||||||
char *dir_path = prefs_dir();
|
char *dir_path = prefs_dir();
|
||||||
char *file_path = prefs_path();
|
char *file_path = prefs_path(game);
|
||||||
char *tmp_path = prefs_tmp_path();
|
char *tmp_path = prefs_tmp_path(game);
|
||||||
struct savefile_write_ctx wctx[1];
|
struct savefile_write_ctx wctx[1];
|
||||||
int fd;
|
int fd;
|
||||||
bool cleanup_dir = false, cleanup_tmpfile = false;
|
bool cleanup_dir = false, cleanup_tmpfile = false;
|
||||||
@ -3102,11 +3104,11 @@ static char *save_prefs(frontend *fe)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool delete_prefs(char **msg)
|
static bool delete_prefs(const game *game, char **msg)
|
||||||
{
|
{
|
||||||
char *dir_path = prefs_dir();
|
char *dir_path = prefs_dir();
|
||||||
char *file_path = prefs_path();
|
char *file_path = prefs_path(game);
|
||||||
char *tmp_path = prefs_tmp_path();
|
char *tmp_path = prefs_tmp_path(game);
|
||||||
char *msgs[3];
|
char *msgs[3];
|
||||||
int i, len, nmsgs = 0;
|
int i, len, nmsgs = 0;
|
||||||
char *p;
|
char *p;
|
||||||
@ -4339,7 +4341,7 @@ int main(int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
} else if (delete_prefs_action) {
|
} else if (delete_prefs_action) {
|
||||||
char *msg = NULL;
|
char *msg = NULL;
|
||||||
bool ok = delete_prefs(&msg);
|
bool ok = delete_prefs(&thegame, &msg);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
fputs(msg, stderr);
|
fputs(msg, stderr);
|
||||||
return 1;
|
return 1;
|
||||||
|
Reference in New Issue
Block a user