X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fsave.c;h=1fc44415cf329780581292c7d95eb48c66b2df72;hb=HEAD;hp=a40160df359f3ab815a7e10754888ce2d25be655;hpb=65130d9f6581e4bd39ceae50d820c9774e4972a9;p=flatwaifu.git diff --git a/src/save.c b/src/save.c index a40160d..1fc4441 100644 --- a/src/save.c +++ b/src/save.c @@ -30,20 +30,12 @@ #include "render.h" #include "music.h" - #include -#ifdef UNIX -# include -#endif #include -#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) { @@ -119,6 +111,7 @@ static void FX_loadgame (Stream *h) { } static void G_savegame (Stream *h) { + int i = 0; stream_write8(_2pl, h); stream_write8(g_dm, h); stream_write8(g_exit, h); @@ -127,7 +120,6 @@ static void G_savegame (Stream *h) { stream_write32(dm_pl1p, h); stream_write32(dm_pl2p, h); stream_write32(dm_pnum, h); - int i = 0; while (i < dm_pnum) { stream_write32(dm_pos[i].x, h); stream_write32(dm_pos[i].y, h); @@ -139,6 +131,7 @@ static void G_savegame (Stream *h) { } static void G_loadgame (Stream *h) { + int i = 0; _2pl = stream_read8(h); g_dm = stream_read8(h); g_exit = stream_read8(h); @@ -147,7 +140,6 @@ static void G_loadgame (Stream *h) { dm_pl1p = stream_read32(h); dm_pl2p = stream_read32(h); dm_pnum = stream_read32(h); - int i = 0; while (i < dm_pnum) { dm_pos[i].x = stream_read32(h); dm_pos[i].y = stream_read32(h); @@ -540,25 +532,6 @@ static void WP_loadgame (Stream *h) { } } -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 @@ -575,15 +548,6 @@ void SAVE_save (Stream *w, const char name[24]) { 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 @@ -602,31 +566,9 @@ void SAVE_load (Stream *h) { } } -void F_getsavnames (void) { - int i; - char *p; - FILE_Stream rd; +int SAVE_getname (Stream *r, char name[24]) { 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); - } + stream_read(name, 24, 1, r); + version = stream_read16(r); + return version == 3; }