]> granicus.if.org Git - nethack/commitdiff
Store plname in save files (and restore it).
authorwarwick <warwick>
Mon, 22 Jul 2002 06:25:52 +0000 (06:25 +0000)
committerwarwick <warwick>
Mon, 22 Jul 2002 06:25:52 +0000 (06:25 +0000)
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]

include/extern.h
include/patchlevel.h
src/files.c
src/restore.c
src/save.c
win/Qt/qt_win.cpp

index 5db8db5480ce5c71731a9046f1ae2fb43abe3a35..b0d9001c0092b07e84ff0669043b6adaa5cb8afa 100644 (file)
@@ -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 ### */
 
index a09bd0cf5ca3c29208f7e08b64e443904d08b452..6bcdc2faf255dd1957ef0bb1c219c0c033639b28 100644 (file)
@@ -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"
index 068f16ea3f2a7bf00be69b2b44c35d3928418c50..7e9e91ac26db946be8f78fac8497cbe649d7a444 100644 (file)
 #include <errno.h>
 #endif
 
+#if defined(UNIX)
+#include <dirent.h>
+#endif
+
 #if defined(UNIX) || defined(VMS)
 #include <errno.h>
 # 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; i<n; i++) {
+           int uid;
+           char name[NAME_MAX];
+           if ( sscanf( namelist[i]->d_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 ----------- */
 
 
index 8262830774ebac7333e6e2f10d100318c3cf79ca..86e07885110e1b509f6cf8ca2edf446eabf36b09 100644 (file)
@@ -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);
 
index a8f5272f0517514113a5055d27b90a4db0b3d385..42a29f099a3cebe81fe88d75af77904677e7edbd 100644 (file)
@@ -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);
index 97b436c81787db6ed40e9c32c77bd49cda6d56ee..81aa76d5eae1dbd0a381ce72495d3e2d04db238f 100644 (file)
@@ -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; i<n; i++) {
-           int uid;
-           char name[NAME_MAX];
-           if ( sscanf( namelist[i]->d_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()