improve selectsave handling for Windows

If there were outdated savefiles encountered during
startup, each individual one was getting a wait_synch
that required a <return> even though a message window
wasn't being used at that point.

Allow suppression of the individual per-file wait_synch()
calls on Windows, so that a single one can be done once
the selectsave processing is overwith.

This was a little messy because an indicator had to flow
down through validate(), uptodate(), etc.

There shouldn't be any change in how things behave on
any non-Windows platforms.
This commit is contained in:
nhmall
2023-09-22 15:14:53 -04:00
parent c868feb383
commit 14faa682c4
11 changed files with 41 additions and 61 deletions

View File

@@ -939,7 +939,7 @@ extern void paniclog(const char *, const char *);
extern void testinglog(const char *, const char *, const char *);
extern int validate_prefix_locations(char *);
#ifdef SELECTSAVED
extern char *plname_from_file(const char *);
extern char *plname_from_file(const char *, boolean);
#endif
extern char **get_saved_games(void);
extern void free_saved_games(char **);
@@ -2421,7 +2421,7 @@ extern int restore_menu(winid);
#endif
extern void minit(void);
extern boolean lookup_id_mapping(unsigned, unsigned *);
extern int validate(NHFILE *, const char *);
extern int validate(NHFILE *, const char *, boolean);
extern void reset_restpref(void);
extern void set_restpref(const char *);
extern void set_savepref(const char *);

View File

@@ -830,6 +830,7 @@ typedef struct {
#define UTD_CHECKFIELDCOUNTS 0x02
#define UTD_SKIP_SANITY1 0x04
#define UTD_SKIP_SAVEFILEINFO 0x08
#define UTD_WITHOUT_WAITSYNCH_PERFILE 0x10
#define ENTITIES 2
struct valuable_data {

View File

@@ -613,7 +613,7 @@ getbones(void)
return 0;
}
if (validate(nhfp, gb.bones) != 0) {
if (validate(nhfp, gb.bones, FALSE) != 0) {
if (!wizard)
pline("Discarding unusable bones; no need to panic...");
ok = FALSE;

View File

@@ -1200,7 +1200,7 @@ restore_saved_game(void)
nh_uncompress(fq_save);
if ((nhfp = open_savefile()) != 0) {
if (validate(nhfp, fq_save) != 0) {
if (validate(nhfp, fq_save, FALSE) != 0) {
close_nhfile(nhfp);
nhfp = (NHFILE *)0;
(void) delete_savefile();
@@ -1210,8 +1210,9 @@ restore_saved_game(void)
}
#if defined(SELECTSAVED)
char *
plname_from_file(const char *filename)
plname_from_file(const char *filename, boolean without_wait_synch_per_file)
{
NHFILE *nhfp = (NHFILE *) 0;
char *result = 0;
@@ -1229,7 +1230,7 @@ plname_from_file(const char *filename)
#endif
nh_uncompress(gs.SAVEF);
if ((nhfp = open_savefile()) != 0) {
if (validate(nhfp, filename) == 0) {
if (validate(nhfp, filename, without_wait_synch_per_file) == 0) {
char tplname[PL_NSIZ];
get_plname_from_file(nhfp, tplname);
@@ -1272,6 +1273,9 @@ plname_from_file(const char *filename)
}
#endif /* defined(SELECTSAVED) */
#define SUPPRESS_WAITSYNCH_PERFILE TRUE
#define ALLOW_WAITSYNCH_PERFILE FALSE
char **
get_saved_games(void)
{
@@ -1281,6 +1285,7 @@ get_saved_games(void)
#endif
int j = 0;
char **result = 0;
#ifdef WIN32
{
char *foundfile;
@@ -1288,7 +1293,7 @@ get_saved_games(void)
const char *fq_new_save;
const char *fq_old_save;
char **files = 0;
int i;
int i, count_failures = 0;
Strcpy(gp.plname, "*");
set_savefile_name(FALSE);
@@ -1321,10 +1326,9 @@ get_saved_games(void)
(void) memset((genericptr_t) result, 0, (n + 1) * sizeof(char *));
for(i = 0; i < n; i++) {
char *r;
r = plname_from_file(files[i]);
r = plname_from_file(files[i], SUPPRESS_WAITSYNCH_PERFILE);
if (r) {
/* rename file if it is not named as expected */
Strcpy(gp.plname, r);
set_savefile_name(TRUE);
@@ -1336,12 +1340,15 @@ get_saved_games(void)
(void) rename(fq_old_save, fq_new_save);
result[j++] = r;
} else {
count_failures++;
}
}
}
free_saved_games(files);
if (count_failures)
wait_synch();
}
#endif
#ifdef UNIX
@@ -1373,7 +1380,7 @@ get_saved_games(void)
char *r;
Sprintf(filename, "save/%d%s", uid, name);
r = plname_from_file(filename);
r = plname_from_file(filename, ALLOW_WAITSYNCH_PERFILE);
if (r)
result[j++] = r;
}
@@ -1398,8 +1405,11 @@ get_saved_games(void)
free_saved_games(result);
}
#endif /* SELECTSAVED */
return 0;
}
#undef SUPPRESS_WAITSYNCH_PERFILE
#undef ALLOW_WAITSYNCH_PERFILE
void
free_saved_games(char **saved)

View File

@@ -812,7 +812,7 @@ dorecover(NHFILE *nhfp)
}
restoreinfo.mread_flags = 0;
rewind_nhfile(nhfp); /* return to beginning of file */
(void) validate(nhfp, (char *) 0);
(void) validate(nhfp, (char *) 0, FALSE);
get_plname_from_file(nhfp, gp.plname);
getlev(nhfp, 0, (xint8) 0);
@@ -1456,7 +1456,7 @@ restore_menu(
#endif /* SELECTSAVED */
int
validate(NHFILE *nhfp, const char *name)
validate(NHFILE *nhfp, const char *name, boolean without_waitsynch_perfile)
{
readLenType rlen = 0;
struct savefile_info sfi;
@@ -1465,6 +1465,8 @@ validate(NHFILE *nhfp, const char *name)
if (nhfp->structlevel)
utdflags |= UTD_CHECKSIZES;
if (without_waitsynch_perfile)
utdflags |= UTD_WITHOUT_WAITSYNCH_PERFILE;
if (!(reslt = uptodate(nhfp, name, utdflags)))
return 1;

View File

@@ -311,7 +311,8 @@ check_version(
) {
if (complain) {
pline("Version mismatch for file \"%s\".", filename);
display_nhwindow(WIN_MESSAGE, TRUE);
if (WIN_MESSAGE != WIN_ERR)
display_nhwindow(WIN_MESSAGE, TRUE);
}
return FALSE;
} else if (
@@ -358,14 +359,17 @@ uptodate(NHFILE *nhfp, const char *name, unsigned long utdflags)
if (rlen == 0) {
if (verbose) {
pline("File \"%s\" is empty?", name);
wait_synch();
if ((utdflags & UTD_WITHOUT_WAITSYNCH_PERFILE) == 0)
wait_synch();
}
return FALSE;
}
if (!check_version(&vers_info, name, verbose, utdflags)) {
if (verbose)
wait_synch();
if (verbose) {
if ((utdflags & UTD_WITHOUT_WAITSYNCH_PERFILE) == 0)
wait_synch();
}
return FALSE;
}
return TRUE;

View File

@@ -34,44 +34,6 @@ static struct stat hbuf;
static int eraseoldlocks(void);
#endif
#if 0
int
uptodate(int fd)
{
#ifdef WANT_GETHDATE
if(fstat(fd, &buf)) {
pline("Cannot get status of saved level? ");
return(0);
}
if(buf.st_mtime < hbuf.st_mtime) {
pline("Saved level is out of date. ");
return(0);
}
#else
#if (defined(MICRO)) && !defined(NO_FSTAT)
if(fstat(fd, &buf)) {
if(gm.moves > 1) pline("Cannot get status of saved level? ");
else pline("Cannot get status of saved game.");
return(0);
}
if(comp_times(buf.st_mtime)) {
if(gm.moves > 1) pline("Saved level is out of date.");
else pline("Saved game is out of date. ");
/* This problem occurs enough times we need to give the player
* some more information about what causes it, and how to fix.
*/
#ifdef MSDOS
pline("Make sure that your system's date and time are correct.");
pline("They must be more current than NetHack.EXE's date/time stamp.");
#endif /* MSDOS */
return(0);
}
#endif /* MICRO */
#endif /* WANT_GETHDATE */
return(1);
}
#endif
#if defined(PC_LOCKING)
#if !defined(SELF_RECOVER)
static int

View File

@@ -629,7 +629,7 @@ vms_get_saved_games(const char *savetemplate, /* wildcarded save file name in na
if (filename[l - 1] != ' ')
break;
filename[l] = '\0';
if ((charname = plname_from_file(filename)) != 0)
if ((charname = plname_from_file(filename, FALSE)) != 0)
savefile(charname, count++, &asize, outarray);
}
(void) lib$find_file_end(&context);

View File

@@ -39,7 +39,7 @@
#endif
#endif
extern boolean getreturn_enabled; /* from sys/share/pcsys.c */
extern boolean getreturn_enabled; /* from windmain.c */
extern int redirect_stdout;
#ifdef TTY_GRAPHICS

View File

@@ -552,8 +552,8 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
chdir(gf.fqn_prefix[HACKPREFIX]);
#endif
if (GUILaunched || IsDebuggerPresent())
getreturn_enabled = TRUE;
/* if (GUILaunched || IsDebuggerPresent()) */
getreturn_enabled = TRUE;
check_recordfile((char *) 0);
iflags.windowtype_deferred = TRUE;

View File

@@ -491,7 +491,7 @@ nethack_exit(int code)
/* use our custom version which works
a little cleaner than the stdio one */
windowprocs.win_nhgetch = windows_console_custom_nhgetch;
}
} else
#endif
if (getreturn_enabled) {
raw_print("\n");
@@ -525,7 +525,8 @@ getreturn(const char *str)
raw_print(buf);
if (WINDOWPORT(tty))
windows_console_custom_nhgetch();
wait_synch();
else
wait_synch();
in_getreturn = FALSE;
return;
}