Self-recover for linux

Compile-time option SELF_RECOVER was implemented for Windows;
add it to unix systems too, with it being on by default when
compiling with the linux hints file.
This commit is contained in:
Pasi Kallinen
2024-02-08 11:34:55 +02:00
parent 5212e4b3db
commit b37f1408d8
4 changed files with 37 additions and 0 deletions

View File

@@ -2211,6 +2211,7 @@ sound: add 'qtsound' soundlib implementation for use on any platform
documentation: when building plain text Guidebook.txt from Guidebook.mn, avoid
attempting to use CR font; change doesn't affect building Guidebook.ps
which utilizes CR to get various instances of fixed-width text
Unix: implement SELF_RECOVER compile-time option, on by default on linux
General New Features

View File

@@ -131,6 +131,7 @@ NHCFLAGS+=-DCOMPRESS=\"/bin/gzip\" -DCOMPRESS_EXTENSION=\".gz\"
#NHCFLAGS+=-DTTY_SOUND_ESCCODES
#NHCFLAGS+=-DNO_CHRONICLE
#NHCFLAGS+=-DLIVELOG
NHCFLAGS+=-DSELF_RECOVER
ifdef WANT_WIN_CURSES
ifeq "$(HAVE_NCURSESW)" "1"
NHCFLAGS+=-DCURSES_UNICODE

View File

@@ -276,6 +276,9 @@ main(int argc, char *argv[])
}
}
}
if (gp.program_state.in_self_recover) {
gp.program_state.in_self_recover = FALSE;
}
}
if (!resuming) {

View File

@@ -102,8 +102,10 @@ eraseoldlocks(void)
void
getlock(void)
{
#ifndef SELF_RECOVER
static const char destroy_old_game_prompt[] =
"There is already a game in progress under your name. Destroy old game?";
#endif
int i = 0, fd, c, too_old;
const char *fq_lock;
@@ -176,10 +178,27 @@ getlock(void)
if (too_old && eraseoldlocks())
goto gotlock;
/* drop the "perm" lock while the user decides */
unlock_file(HLOCK);
if (iflags.window_inited) {
#ifdef SELF_RECOVER
c = yn_function("Old game in progress. Destroy [y], Recover [r], or Cancel [n]?", "ynr", 'n', FALSE);
#else
/* this is a candidate for paranoid_confirmation */
c = y_n(destroy_old_game_prompt);
#endif
} else {
#ifdef SELF_RECOVER
(void) raw_printf("\nThere is already a game in progress under your name. Do what?\n");
(void) raw_printf("\n y - Destroy old game");
(void) raw_printf("\n r - Try to recover it");
(void) raw_printf("\n n - Cancel");
(void) raw_printf("\n\n => ");
(void) fflush(stdout);
do {
c = getchar();
} while (!strchr("rRyYnN", c) && c != -1);
#else
(void) raw_printf("\n%s [yn] ", destroy_old_game_prompt);
(void) fflush(stdout);
if ((c = getchar()) != EOF) {
@@ -190,7 +209,20 @@ getlock(void)
while ((tmp = getchar()) != '\n' && tmp != EOF)
; /* eat rest of line and newline */
}
#endif
}
#ifdef SELF_RECOVER
if (c == 'r' || c == 'R') {
if (recover_savefile() && gp.program_state.in_self_recover) {
set_levelfile_name(gl.lock, 0);
fq_lock = fqname(gl.lock, LEVELPREFIX, 0);
goto gotlock;
} else {
unlock_file(HLOCK);
error("Couldn't recover old game.");
}
} else
#endif
if (c == 'y' || c == 'Y') {
if (eraseoldlocks()) {
goto gotlock;