From: warwick Date: Mon, 22 Jul 2002 06:25:52 +0000 (+0000) Subject: Store plname in save files (and restore it). X-Git-Tag: MOVE2GIT~2614 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=16b7d4a09987b48bdf25d0810b10e4e1e7dba6f0;p=nethack Store plname in save files (and restore it). Move get_saved_games() functionality to files.c Use moved get_saved_games() functionality in Qt windowport. [also some non-enabled perminv code in Qt windowport] --- diff --git a/include/extern.h b/include/extern.h index 5db8db548..b0d9001c0 100644 --- a/include/extern.h +++ b/include/extern.h @@ -642,6 +642,8 @@ E void NDECL(read_wizkit); #endif E void FDECL(paniclog, (const char *, const char *)); E int FDECL(validate_prefix_locations, (char *)); +E char** NDECL(get_saved_games); +E void FDECL(free_saved_games, (char**)); /* ### fountain.c ### */ diff --git a/include/patchlevel.h b/include/patchlevel.h index a09bd0cf5..6bcdc2faf 100644 --- a/include/patchlevel.h +++ b/include/patchlevel.h @@ -13,7 +13,7 @@ * Incrementing EDITLEVEL can be used to force invalidation of old bones * and save files. */ -#define EDITLEVEL 0 +#define EDITLEVEL 1 #define COPYRIGHT_BANNER_A \ "NetHack, Copyright 1985-2002" diff --git a/src/files.c b/src/files.c index 068f16ea3..7e9e91ac2 100644 --- a/src/files.c +++ b/src/files.c @@ -19,6 +19,10 @@ #include #endif +#if defined(UNIX) +#include +#endif + #if defined(UNIX) || defined(VMS) #include # ifndef SKIP_ERRNO @@ -804,6 +808,77 @@ restore_saved_game() return fd; } +static char* +plname_from_file(filename) +const char* filename; +{ + int fd; + char* result = 0; + + Strcpy(SAVEF,filename); +#ifdef COMPRESS_EXTENSION + SAVEF[strlen(SAVEF)-strlen(COMPRESS_EXTENSION)] = '\0'; +#endif + uncompress(SAVEF); + if ((fd = open_savefile()) >= 0) { + if (uptodate(fd, filename)) { + char tplname[PL_NSIZ]; + mread(fd, (genericptr_t) tplname, PL_NSIZ); + result = strdup(tplname); + } + (void) close(fd); + } + compress(SAVEF); + + return result; +} + +char** +get_saved_games() +{ +#ifdef UNIX + int myuid=getuid(); + struct dirent **namelist; + int n = scandir("save", &namelist, 0, alphasort);; + if ( n > 0 ) { + int i,j=0; + char** result = (char**)malloc((n+1)*sizeof(char*)); /* at most */ + for (i=0; id_name, "%d%s", &uid, name ) == 2 ) { + if ( uid == myuid ) { + char filename[BUFSZ]; + char* r; + Sprintf(filename,"save/%d%s",uid,name); + r = plname_from_file(filename); + if ( r ) { + result[j++] = r; + } + } + } + } + result[j++] = 0; + return result; + } else +#endif + { + return 0; + } +} + +void +free_saved_games(saved) +char** saved; +{ + if ( saved ) { + int i=0; + while (saved[i]) free(saved[i++]); + free(saved); + } +} + + /* ---------- END SAVE FILE HANDLING ----------- */ diff --git a/src/restore.c b/src/restore.c index 826283077..86e078851 100644 --- a/src/restore.c +++ b/src/restore.c @@ -542,6 +542,8 @@ register int fd; int rtmp; struct obj *otmp; + mread(fd, (genericptr_t) plname, PL_NSIZ); + restoring = TRUE; getlev(fd, 0, (xchar)0, FALSE); if (!restgamestate(fd, &stuckid, &steedid)) { @@ -621,6 +623,7 @@ register int fd; (void) lseek(fd, (off_t)0, 0); #endif (void) uptodate(fd, (char *)0); /* skip version info */ + mread(fd, (genericptr_t) plname, PL_NSIZ); getlev(fd, 0, (xchar)0, FALSE); (void) close(fd); diff --git a/src/save.c b/src/save.c index a8f5272f0..42a29f099 100644 --- a/src/save.c +++ b/src/save.c @@ -204,6 +204,7 @@ dosave0() #endif /* MFLOPPY */ store_version(fd); + bwrite(fd, (genericptr_t) plname, PL_NSIZ); ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); #ifdef STEED usteed_id = (u.usteed ? u.usteed->m_id : 0); @@ -372,6 +373,7 @@ savestateinlock() (void) write(fd, (genericptr_t) &currlev, sizeof(currlev)); save_savefile_name(fd); store_version(fd); + bwrite(fd, (genericptr_t) plname, PL_NSIZ); ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); #ifdef STEED usteed_id = (u.usteed ? u.usteed->m_id : 0); diff --git a/win/Qt/qt_win.cpp b/win/Qt/qt_win.cpp index 97b436c81..81aa76d5e 100644 --- a/win/Qt/qt_win.cpp +++ b/win/Qt/qt_win.cpp @@ -2844,7 +2844,10 @@ int NetHackQtMenuWindow::SelectMenu(int h, MENU_ITEM_P **menu_list) if (dialog->result()<0) qApp->enter_loop(); } - dialog->hide(); + //if ( (nhid != WIN_INVEN || !flags.perm_invent) ) // doesn't work yet + { + dialog->hide(); + } int result=dialog->result(); // Consume ^M (which QDialog steals for default button) @@ -4463,57 +4466,13 @@ int NetHackQtSavedGameSelector::choose() return exec()-2; } -static char** get_saved_names() -{ - int myuid=getuid(); - struct dirent **namelist; - int n = scandir("save", &namelist, 0, alphasort);; - if ( n > 0 ) { - int i,j=0; - char** result = (char**)malloc((n+1)*sizeof(char*)); /* at most */ - for (i=0; id_name, "%d%s", &uid, name ) == 2 ) { - if ( uid == myuid ) { - /* Name should be stored in save file, but currently we - have to extract it from the filename, which loses - information (eg. "/", "_", and "." characters are lost. */ - int k; - char* end = strstr(name,".gz"); - if ( !end ) end = strstr(name,".Z"); - if ( end ) *end = 0; - /* "_" most likely means " ", which certainly looks nicer */ - for (k=0; name[k]; k++) - if ( name[k]=='_' ) - name[k]=' '; - result[j++] = strdup(name); - } - } - } - result[j++] = 0; - return result; - } else { - return 0; - } -} - -static void free_saved_names(char** saved) -{ - if ( saved ) { - int i=0; - while (saved[i]) free(saved[i++]); - free(saved); - } -} - void NetHackQtBind::qt_askname() { have_asked = TRUE; // We do it all here, and nothing in askname - char** saved = get_saved_names(); + char** saved = get_saved_games(); int ch = -1; if ( saved && *saved ) { if ( splash ) splash->hide(); @@ -4522,7 +4481,7 @@ void NetHackQtBind::qt_askname() if ( ch >= 0 ) strcpy(plname,saved[ch]); } - free_saved_names(saved); + free_saved_games(saved); switch (ch) { case -1: @@ -4606,6 +4565,8 @@ winid NetHackQtBind::qt_create_nhwindow(int type) window=new NetHackQtTextWindow(keybuffer); } + window->nhid = id; + // Note: use of isHidden does not work with Qt 2.1 if ( splash #if QT_VERSION >= 300 @@ -4736,6 +4697,10 @@ void NetHackQtBind::qt_update_inventory() { if (main) main->updateInventory(); + /* doesn't work yet + if (program_state.something_worth_saving && flags.perm_invent) + display_inventory(NULL, FALSE); + */ } void NetHackQtBind::qt_mark_synch()