Make it possible to version DoState sections.

This will have the more important benefit of bailing if anything goes
awry.
This commit is contained in:
Unknown W. Brackets committed 2013-09-14 20:19:58 -07:00
1 parent 2ac5bcff1f
commit d2f2f8d7ad
1 file changed
+48
+48
View File
@@ -70,6 +70,32 @@ struct LinkedListItem : public T
LinkedListItem<T> *next;
};
class PointerWrap;
class PointerWrapSection
{
public:
PointerWrapSection(PointerWrap &p, int ver, const char *title) : p_(p), ver_(ver), title_(title) {
}
~PointerWrapSection();
bool operator == (const int &v) const { return ver_ == v; }
bool operator != (const int &v) const { return ver_ != v; }
bool operator <= (const int &v) const { return ver_ <= v; }
bool operator >= (const int &v) const { return ver_ >= v; }
bool operator < (const int &v) const { return ver_ < v; }
bool operator > (const int &v) const { return ver_ > v; }
operator bool() const {
return ver_ > 0;
}
private:
PointerWrap &p_;
int ver_;
const char *title_;
};
// Wrapper class
class PointerWrap
{
@@ -130,6 +156,24 @@ public:
PointerWrap(u8 **ptr_, Mode mode_) : ptr(ptr_), mode(mode_), error(ERROR_NONE) {}
PointerWrap(unsigned char **ptr_, int mode_) : ptr((u8**)ptr_), mode((Mode)mode_), error(ERROR_NONE) {}
PointerWrapSection Section(const char *title, int ver) {
return Section(title, ver, ver);
}
// The returned object can be compared against the version that was loaded.
// This can be used to support versions as old as minVer.
PointerWrapSection Section(const char *title, int minVer, int ver) {
int foundVersion = ver;
Do(foundVersion);
DoMarker(title);
if (error == ERROR_FAILURE || foundVersion < minVer || foundVersion > ver) {
WARN_LOG(COMMON, "Savestate failure: wrong version %d found for %s", foundVersion, title);
SetError(ERROR_FAILURE);
return PointerWrapSection(*this, -1, title);
}
return PointerWrapSection(*this, foundVersion, title);
}
void SetMode(Mode mode_) {mode = mode_;}
Mode GetMode() const {return mode;}
u8 **GetPPtr() {return ptr;}
@@ -577,6 +621,10 @@ public:
}
};
inline PointerWrapSection::~PointerWrapSection() {
p_.DoMarker(title_);
}
class CChunkFileReader
{