From ed84d5cff09717ada956753b806435be4e74e248 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 31 Jan 2016 21:59:43 -0800 Subject: [PATCH] GBA: Add GBADeleteState --- src/gba/serialize.c | 8 ++++++++ src/gba/serialize.h | 1 + src/platform/qt/GameController.cpp | 5 +---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/gba/serialize.c b/src/gba/serialize.c index 1e6c48061..44daecda5 100644 --- a/src/gba/serialize.c +++ b/src/gba/serialize.c @@ -206,6 +206,14 @@ struct VFile* GBAGetState(struct GBA* gba, struct VDir* dir, int slot, bool writ return dir->openFile(dir, path, write ? (O_CREAT | O_TRUNC | O_RDWR) : O_RDONLY); } +void GBADeleteState(struct GBA* gba, struct VDir* dir, int slot) { + char basename[PATH_MAX]; + separatePath(gba->activeFile, 0, basename, 0); + char path[PATH_MAX]; + snprintf(path, sizeof(path), "%s.ss%i", basename, slot); + dir->deleteFile(dir, path); +} + #ifdef USE_PNG static bool _savePNGState(struct GBA* gba, struct VFile* vf, struct GBAExtdata* extdata) { unsigned stride; diff --git a/src/gba/serialize.h b/src/gba/serialize.h index 97d4a6ee8..dd4b29c8b 100644 --- a/src/gba/serialize.h +++ b/src/gba/serialize.h @@ -366,6 +366,7 @@ bool GBADeserialize(struct GBA* gba, const struct GBASerializedState* state); bool GBASaveState(struct GBAThread* thread, struct VDir* dir, int slot, int flags); bool GBALoadState(struct GBAThread* thread, struct VDir* dir, int slot, int flags); struct VFile* GBAGetState(struct GBA* gba, struct VDir* dir, int slot, bool write); +void GBADeleteState(struct GBA* thread, struct VDir* dir, int slot); bool GBASaveStateNamed(struct GBA* gba, struct VFile* vf, int flags); bool GBALoadStateNamed(struct GBA* gba, struct VFile* vf, int flags); diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index 7722b7715..c409d8103 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -115,10 +115,7 @@ GameController::GameController(QObject* parent) controller->m_fpsTarget = context->fpsTarget; if (context->dirs.state && GBALoadState(context, context->dirs.state, 0, controller->m_loadStateFlags)) { - VFile* vf = GBAGetState(context->gba, context->dirs.state, 0, true); - if (vf) { - vf->truncate(vf, 0); - } + GBADeleteState(context->gba, context->dirs.state, 0); } QMetaObject::invokeMethod(controller, "gameStarted", Q_ARG(GBAThread*, context)); };