forked from 0ad/0ad
Add XMB file format version to the XMB files and check it when loading a file.
This was SVN commit r15358.
This commit is contained in:
parent
f460057700
commit
e12d4b880a
@ -24,6 +24,9 @@
|
||||
// external linkage (also used by Xeromyces.cpp)
|
||||
const char* HeaderMagicStr = "XMB0";
|
||||
const char* UnfinishedHeaderMagicStr = "XMBu";
|
||||
// Arbitrary version number - change this if we update the code and
|
||||
// need to invalidate old users' caches
|
||||
const u32 XMBVersion = 3;
|
||||
|
||||
// Warning: May contain traces of pointer abuse
|
||||
|
||||
@ -38,6 +41,11 @@ bool XMBFile::Initialise(const char* FileData)
|
||||
return false;
|
||||
ENSURE(!strcmp(Header, HeaderMagicStr) && "Invalid XMB header!");
|
||||
|
||||
u32 Version = *(u32*)m_Pointer;
|
||||
m_Pointer += 4;
|
||||
if (Version != XMBVersion)
|
||||
return false;
|
||||
|
||||
int i;
|
||||
|
||||
// FIXME Check that m_Pointer doesn't end up past the end of the buffer
|
||||
|
@ -42,6 +42,7 @@ Theoretical file structure:
|
||||
|
||||
XMB_File {
|
||||
char Header[4]; // because everyone has one; currently "XMB0"
|
||||
u32 Version;
|
||||
|
||||
int ElementNameCount;
|
||||
ZStr8 ElementNames[];
|
||||
@ -104,6 +105,7 @@ XMB_Text {
|
||||
// File headers, to make sure it doesn't try loading anything other than an XMB
|
||||
extern const char* HeaderMagicStr;
|
||||
extern const char* UnfinishedHeaderMagicStr;
|
||||
extern const u32 XMBVersion;
|
||||
|
||||
class XMBElement;
|
||||
class XMBElementList;
|
||||
@ -122,6 +124,7 @@ public:
|
||||
// @return indication of success; main cause for failure is attempting to
|
||||
// load a partially valid XMB file (e.g. if the game was interrupted
|
||||
// while writing it), which we detect by checking the magic string.
|
||||
// It also fails when trying to load an XMB file with a different version.
|
||||
bool Initialise(const char* FileData);
|
||||
|
||||
// Returns the root element
|
||||
|
@ -68,12 +68,8 @@ PSRETURN CXeromyces::Load(const PIVFS& vfs, const VfsPath& filename)
|
||||
|
||||
CCacheLoader cacheLoader(vfs, L".xmb");
|
||||
|
||||
// Arbitrary version number - change this if we update the code and
|
||||
// need to invalidate old users' caches
|
||||
u32 version = 2;
|
||||
|
||||
VfsPath xmbPath;
|
||||
Status ret = cacheLoader.TryLoadingCached(filename, MD5(), version, xmbPath);
|
||||
Status ret = cacheLoader.TryLoadingCached(filename, MD5(), XMBVersion, xmbPath);
|
||||
|
||||
if (ret == INFO::OK)
|
||||
{
|
||||
@ -313,6 +309,8 @@ PSRETURN CXeromyces::CreateXMB(const xmlDocPtr doc, WriteBuffer& writeBuffer)
|
||||
{
|
||||
// Header
|
||||
writeBuffer.Append(UnfinishedHeaderMagicStr, 4);
|
||||
// Version
|
||||
writeBuffer.Append(&XMBVersion, 4);
|
||||
|
||||
std::set<std::string>::iterator it;
|
||||
u32 i;
|
||||
|
Loading…
Reference in New Issue
Block a user