Don't make empty savestate files when loading savestates
Jeffrey Pfau jeffrey@endrift.com
Wed, 23 Jul 2014 00:19:50 -0700
2 files changed,
8 insertions(+),
19 deletions(-)
M
src/gba/gba-serialize.c
→
src/gba/gba-serialize.c
@@ -68,11 +68,11 @@ GBAVideoDeserialize(&gba->video, state);
GBAAudioDeserialize(&gba->audio, state); } -static struct VFile* _getStateVf(struct GBA* gba, int slot) { +static struct VFile* _getStateVf(struct GBA* gba, int slot, bool write) { char path[PATH_MAX]; path[PATH_MAX - 1] = '\0'; snprintf(path, PATH_MAX - 1, "%s.ss%d", gba->activeFile, slot); - struct VFile* vf = VFileOpen(path, O_CREAT | O_RDWR); + struct VFile* vf = VFileOpen(path, write ? (O_CREAT | O_RDWR) : O_RDONLY); if (vf) { vf->truncate(vf, sizeof(struct GBASerializedState)); }@@ -80,35 +80,27 @@ return vf;
} bool GBASaveState(struct GBA* gba, int slot) { - struct VFile* vf = _getStateVf(gba, slot); + struct VFile* vf = _getStateVf(gba, slot, true); if (!vf) { return false; } - struct GBASerializedState* state = GBAMapState(vf); + struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_WRITE); GBASerialize(gba, state); - GBAUnmapState(vf, state); + vf->unmap(vf, state, sizeof(struct GBASerializedState)); vf->close(vf); return true; } bool GBALoadState(struct GBA* gba, int slot) { - struct VFile* vf = _getStateVf(gba, slot); + struct VFile* vf = _getStateVf(gba, slot, false); if (!vf) { return false; } - struct GBASerializedState* state = GBAMapState(vf); + struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_READ); GBADeserialize(gba, state); - GBAUnmapState(vf, state); + vf->unmap(vf, state, sizeof(struct GBASerializedState)); vf->close(vf); return true; -} - -struct GBASerializedState* GBAMapState(struct VFile* vf) { - return vf->map(vf, sizeof(struct GBASerializedState), MAP_WRITE); -} - -void GBAUnmapState(struct VFile* vf, struct GBASerializedState* state) { - vf->unmap(vf, state, sizeof(struct GBASerializedState)); } struct GBASerializedState* GBAAllocateState(void) {
M
src/gba/gba-serialize.h
→
src/gba/gba-serialize.h
@@ -266,9 +266,6 @@
bool GBASaveState(struct GBA* gba, int slot); bool GBALoadState(struct GBA* gba, int slot); -struct GBASerializedState* GBAMapState(struct VFile* vf); -void GBAUnmapState(struct VFile* vf, struct GBASerializedState* state); - struct GBASerializedState* GBAAllocateState(void); void GBADeallocateState(struct GBASerializedState* state);