summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 86f561a)
raw | patch | inline | side by side (parent: 86f561a)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 7 Apr 2021 10:00:29 +0000 (13:00 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 7 Apr 2021 10:00:29 +0000 (13:00 +0300) |
src/files.c | patch | blob | history | |
src/files.h | patch | blob | history | |
src/save.c | patch | blob | history | |
src/save.h | patch | blob | history |
diff --git a/src/files.c b/src/files.c
index 8189375ee5814b9cba20e68889608cbfdaa85b90..2eab3a877e8a1cd07c4a1e82ada8ec1b6bf2b8a6 100644 (file)
--- a/src/files.c
+++ b/src/files.c
#include "error.h"
#include "map.h" // MAP_load
+#include "save.h" // SAVE_getname
+
+#ifdef UNIX
+# include <sys/stat.h>
+#endif
#include "common/streams.h"
#include "common/files.h"
#include "common/cp866.h"
int d_start, d_end;
+
+char savname[SAVE_MAX][SAVE_MAXLEN];
+char savok[SAVE_MAX];
+
static int m_start, m_end;
static int s_start, s_end;
ERR_fatal("Failed to load map: resource %.8s not found", n);
}
}
+
+static char *getsavfpname (int n, int ro) {
+ static char fn[] = "savgame0.dat";
+ static char p[100];
+ fn[7] = n + '0';
+#ifdef UNIX
+ char *e = getenv("HOME");
+ strncpy(p, e, 60);
+ strcat(p, "/.flatwaifu");
+ if (!ro) {
+ mkdir(p, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
+ }
+ strcat(p, "/");
+ strcat(p, fn);
+#else
+ strcpy(p, fn);
+#endif
+ return p;
+}
+
+void F_getsavnames (void) {
+ FILE_Stream rd;
+ for (int i = 0; i < SAVE_MAX; ++i) {
+ savok[i] = 0;
+ char *p = getsavfpname(i, 1);
+ if (FILE_Open(&rd, p, "rb")) {
+ savok[i] = SAVE_getname(&rd.base, savname[i]);
+ FILE_Close(&rd);
+ }
+ if (!savok[i]) {
+ memset(savname[i], 0, 24);
+ } else {
+ savname[i][23] = 0;
+ }
+ }
+}
+
+void F_loadgame (int n) {
+ FILE_Stream rd;
+ char *p = getsavfpname(n, 1);
+ if (FILE_Open(&rd, p, "rb")) {
+ SAVE_load(&rd.base);
+ FILE_Close(&rd);
+ }
+}
+
+void F_savegame (int n, char *s) {
+ FILE_Stream wr;
+ char *p = getsavfpname(n, 0);
+ if (FILE_Open(&wr, p, "wb")) {
+ SAVE_save(&wr.base, s);
+ FILE_Close(&wr);
+ }
+}
diff --git a/src/files.h b/src/files.h
index e1b30b56609cc41dafc45b2b3cec5076beceb54d..1fa7db86695d01cf5b96bee5d9e9b8caef36e639 100644 (file)
--- a/src/files.h
+++ b/src/files.h
#include "glob.h"
+#define SAVE_MAX 7
+#define SAVE_MAXLEN 24
+
+extern char savname[SAVE_MAX][SAVE_MAXLEN];
+extern char savok[SAVE_MAX];
extern int d_start, d_end;
void F_startup (void);
void F_getresname (char n[8], int r);
int F_getsprid (const char n[4], int s, int d, char *dir);
int F_getreslen (int r);
+
void F_nextmus (char *s);
void F_randmus (char *s);
void F_loadmap (char n[8]);
+void F_getsavnames (void);
+void F_savegame (int n, char *s);
+void F_loadgame (int n);
+
#endif /* FILES_H_INCLUDED */
diff --git a/src/save.c b/src/save.c
index a40160df359f3ab815a7e10754888ce2d25be655..a219fdf234bccbcd40c189b3d4cae54b40b1d763 100644 (file)
--- a/src/save.c
+++ b/src/save.c
#include "render.h"
#include "music.h"
-
#include <string.h>
-#ifdef UNIX
-# include <sys/stat.h>
-#endif
#include <assert.h>
-#include "files.h"
#include "common/streams.h"
#include "common/files.h"
-char savname[SAVE_MAX][SAVE_MAXLEN];
-char savok[SAVE_MAX];
-
static void DOT_savegame (Stream *h) {
int i, n;
for (i = n = 0; i < MAXDOT; ++i) {
}
}
-static char *getsavfpname (int n, int ro) {
- static char fn[] = "savgame0.dat";
- static char p[100];
- fn[7] = n + '0';
-#ifdef UNIX
- char *e = getenv("HOME");
- strncpy(p, e, 60);
- strcat(p, "/.flatwaifu");
- if (!ro) {
- mkdir(p, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
- }
- strcat(p, "/");
- strcat(p, fn);
-#else
- strcpy(p, fn);
-#endif
- return p;
-}
-
void SAVE_save (Stream *w, const char name[24]) {
assert(w != NULL);
stream_write(name, 24, 1, w); // slot name
WP_savegame(w);
}
-void F_savegame (int n, char *s) {
- FILE_Stream wr;
- char *p = getsavfpname(n, 0);
- if (FILE_Open(&wr, p, "wb")) {
- SAVE_save(&wr.base, s);
- FILE_Close(&wr);
- }
-}
-
void SAVE_load (Stream *h) {
int16_t version;
stream_setpos(h, 24); // skip name
}
}
-void F_getsavnames (void) {
- int i;
- char *p;
- FILE_Stream rd;
- int16_t version;
- for (i = 0; i < 7; ++i) {
- p = getsavfpname(i, 1);
- memset(savname[i], 0, 24);
- savok[i] = 0;
- if (FILE_Open(&rd, p, "rb")) {
- version = -1;
- stream_read(savname[i], 24, 1, &rd.base);
- version = stream_read16(&rd.base);
- savname[i][23] = 0;
- savok[i] = version == 3;
- FILE_Close(&rd);
- }
- }
-}
-
-void F_loadgame (int n) {
- FILE_Stream rd;
- char *p = getsavfpname(n, 1);
- if (FILE_Open(&rd, p, "rb")) {
- SAVE_load(&rd.base);
- FILE_Close(&rd);
- }
+int SAVE_getname (Stream *r, char name[24]) {
+ stream_read(name, 24, 1, r);
+ int16_t version = stream_read16(r);
+ return version == 3;
}
diff --git a/src/save.h b/src/save.h
index 5f98bfee54ea34ca0c04c2ef4f7b6ea08487b736..272107f26bbfa4a13fe9a04d9c5638cfa251e328 100644 (file)
--- a/src/save.h
+++ b/src/save.h
#include "common/streams.h"
-#define SAVE_MAX 7
-#define SAVE_MAXLEN 24
-
-extern char savname[SAVE_MAX][SAVE_MAXLEN];
-extern char savok[SAVE_MAX];
-
-void F_getsavnames (void);
-void F_savegame (int n, char *s);
-void F_loadgame (int n);
-
+int SAVE_getname (Stream *r, char name[24]);
void SAVE_save (Stream *w, const char name[24]);
void SAVE_load (Stream *r);