Qt: Add load/saveState VFile functions, flags parameter to explicit state functions
Vicki Pfau vi@endrift.com
Tue, 08 Dec 2020 22:57:39 -0800
2 files changed,
66 insertions(+),
4 deletions(-)
M
src/platform/qt/CoreController.cpp
→
src/platform/qt/CoreController.cpp
@@ -509,8 +509,12 @@ }
}); } -void CoreController::loadState(const QString& path) { +void CoreController::loadState(const QString& path, int flags) { m_statePath = path; + int savedFlags = m_loadStateFlags; + if (flags != -1) { + m_loadStateFlags = flags; + } mCoreThreadRunFunction(&m_threadContext, [](mCoreThread* context) { CoreController* controller = static_cast<CoreController*>(context->userData); VFile* vf = VFileDevice::open(controller->m_statePath, O_RDONLY);@@ -527,6 +531,35 @@ emit controller->stateLoaded();
} vf->close(vf); }); + m_loadStateFlags = savedFlags; +} + +void CoreController::loadState(QIODevice* iodev, int flags) { + m_stateVf = VFileDevice::wrap(iodev, QIODevice::ReadOnly); + if (!m_stateVf) { + return; + } + int savedFlags = m_loadStateFlags; + if (flags != -1) { + m_loadStateFlags = flags; + } + mCoreThreadRunFunction(&m_threadContext, [](mCoreThread* context) { + CoreController* controller = static_cast<CoreController*>(context->userData); + VFile* vf = controller->m_stateVf; + if (!vf) { + return; + } + if (!controller->m_backupLoadState.isOpen()) { + controller->m_backupLoadState = VFileDevice::openMemory(); + } + mCoreSaveStateNamed(context->core, controller->m_backupLoadState, controller->m_saveStateFlags); + if (mCoreLoadStateNamed(context->core, vf, controller->m_loadStateFlags)) { + emit controller->frameAvailable(); + emit controller->stateLoaded(); + } + vf->close(vf); + }); + m_loadStateFlags = savedFlags; } void CoreController::saveState(int slot) {@@ -545,8 +578,12 @@ mCoreSaveState(context->core, controller->m_stateSlot, controller->m_saveStateFlags);
}); } -void CoreController::saveState(const QString& path) { +void CoreController::saveState(const QString& path, int flags) { m_statePath = path; + int savedFlags = m_saveStateFlags; + if (flags != -1) { + m_saveStateFlags = flags; + } mCoreThreadRunFunction(&m_threadContext, [](mCoreThread* context) { CoreController* controller = static_cast<CoreController*>(context->userData); VFile* vf = VFileDevice::open(controller->m_statePath, O_RDONLY);@@ -562,6 +599,28 @@ }
mCoreSaveStateNamed(context->core, vf, controller->m_saveStateFlags); vf->close(vf); }); + m_saveStateFlags = savedFlags; +} + +void CoreController::saveState(QIODevice* iodev, int flags) { + m_stateVf = VFileDevice::wrap(iodev, QIODevice::WriteOnly | QIODevice::Truncate); + if (!m_stateVf) { + return; + } + int savedFlags = m_saveStateFlags; + if (flags != -1) { + m_saveStateFlags = flags; + } + mCoreThreadRunFunction(&m_threadContext, [](mCoreThread* context) { + CoreController* controller = static_cast<CoreController*>(context->userData); + VFile* vf = controller->m_stateVf; + if (!vf) { + return; + } + mCoreSaveStateNamed(context->core, vf, controller->m_saveStateFlags); + vf->close(vf); + }); + m_saveStateFlags = savedFlags; } void CoreController::loadBackupState() {
M
src/platform/qt/CoreController.h
→
src/platform/qt/CoreController.h
@@ -120,9 +120,11 @@ void setFastForward(bool);
void forceFastForward(bool); void loadState(int slot = 0); - void loadState(const QString& path); + void loadState(const QString& path, int flags = -1); + void loadState(QIODevice* iodev, int flags = -1); void saveState(int slot = 0); - void saveState(const QString& path); + void saveState(const QString& path, int flags = -1); + void saveState(QIODevice* iodev, int flags = -1); void loadBackupState(); void saveBackupState();@@ -225,6 +227,7 @@ VFileDevice m_backupLoadState;
QByteArray m_backupSaveState{nullptr}; int m_stateSlot = 1; QString m_statePath; + VFile* m_stateVf; int m_loadStateFlags; int m_saveStateFlags;