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]
This commit is contained in:
75
src/files.c
75
src/files.c
@@ -19,6 +19,10 @@
|
||||
#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 ----------- */
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user