# HG changeset patch # User John "Elwin" Edwards # Date 1430566274 14400 # Node ID 443c8bd3e29080b0fd84f44a8601700bd4aa63e9 # Parent 1fbdefa8253365e93d08a093188d3044901cbf1e xrogue: restrict changes to the save file location. When using the -n option, disallow changing file_name or whoami via options or dialogs. diff -r 1fbdefa82533 -r 443c8bd3e290 xrogue/options.c --- a/xrogue/options.c Wed Apr 22 16:03:00 2015 -0400 +++ b/xrogue/options.c Sat May 02 07:31:14 2015 -0400 @@ -51,6 +51,9 @@ put_quest(), get_default(); +int get_str_prot(char *opt, WINDOW *win); +bool allowchange(OPTION *op); + OPTION optlist[] = { {"terse", "Terse output: ", (int *) &terse, put_bool, get_bool }, @@ -67,11 +70,11 @@ {"overlay", "Overlay menu: ", (int *) &menu_overlay, put_bool, get_bool }, {"name", "Name: ", - (int *) whoami, put_str, get_str }, + (int *) whoami, put_str, get_str_prot }, {"file", "Save file: ", - (int *) file_name, put_str, get_str }, + (int *) file_name, put_str, get_str_prot }, {"score", "Score file: ", - (int *) score_file, put_str, get_str }, + (int *) score_file, put_str, get_str_prot }, {"class", "Character type: ", (int *) &char_type, put_abil, get_abil }, {"quest", "Quest item: ", @@ -407,8 +410,10 @@ strucpy(start, str, (char *) sp - str); /* Put the value into the option field */ - if (op->o_putfunc != put_abil) - strcpy((char *)op->o_opt, value); + if (op->o_putfunc != put_abil) { + if (allowchange(op)) + strcpy((char *)op->o_opt, value); + } else if (*op->o_opt == -1) { /* Only init ability once */ register int len = strlen(value); @@ -500,3 +505,32 @@ waddstr(win, str); } +/* Like get_str, but disallows changes when use_savedir is set. */ +int +get_str_prot(char *opt, WINDOW *win) +{ + int oy, ox; + + if (use_savedir) { + getyx(win, oy, ox); + waddstr(win, opt); + return get_ro(win, oy, ox); + } + else { + return get_str(opt, win); + } +} + +bool +allowchange(OPTION *op) +{ + if (!use_savedir) + return TRUE; + if (!strcmp(op->o_name, "name")) + return FALSE; + if (!strcmp(op->o_name, "file")) + return FALSE; + if (!strcmp(op->o_name, "score")) + return FALSE; + return TRUE; +} diff -r 1fbdefa82533 -r 443c8bd3e290 xrogue/save.c --- a/xrogue/save.c Wed Apr 22 16:03:00 2015 -0400 +++ b/xrogue/save.c Sat May 02 07:31:14 2015 -0400 @@ -43,7 +43,10 @@ mpos = 0; if (file_name[0] != '\0') { - msg("Save file (%s)? ", file_name); + if (use_savedir) + msg("Save game? "); + else + msg("Save file (%s)? ", file_name); do { c = wgetch(cw); @@ -59,6 +62,11 @@ else goto gotfile; /* must save to file restored from */ + if (use_savedir) { + msg(""); + return FALSE; + } + do { msg("File name: "); @@ -72,8 +80,11 @@ strcpy(file_name, buf); gotfile: - if ((savef = fopen(file_name, "wb")) == NULL) + if ((savef = fopen(file_name, "wb")) == NULL) { msg(strerror(errno)); + if (use_savedir) + return FALSE; + } } while (savef == NULL); msg("");