#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 ### */
* 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"
#include <errno.h>
#endif
+#if defined(UNIX)
+#include <dirent.h>
+#endif
+
#if defined(UNIX) || defined(VMS)
#include <errno.h>
# ifndef SKIP_ERRNO
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 ----------- */
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)) {
(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);
#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);
(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);
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)
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();
if ( ch >= 0 )
strcpy(plname,saved[ch]);
}
- free_saved_names(saved);
+ free_saved_games(saved);
switch (ch) {
case -1:
window=new NetHackQtTextWindow(keybuffer);
}
+ window->nhid = id;
+
// Note: use of isHidden does not work with Qt 2.1
if ( splash
#if QT_VERSION >= 300
{
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()