GBA: Add GBADeleteState

This commit is contained in:
Jeffrey Pfau 2016-01-31 21:59:43 -08:00
parent 6af9a742bd
commit ed84d5cff0
3 changed files with 10 additions and 4 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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));
};