Skip to content

Commit 2e29249

Browse files
committed
Fail file opening when the engine or the file version is greater than the current one.
1 parent 4a20c5f commit 2e29249

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

Sources/NodeUIEngine/NUIE_NodeEditor.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
namespace NUIE
1010
{
1111

12-
static const std::string NodeEditorFileMarker = "NodeEditorFile";
13-
static const int NodeEditorFileVersion = 1;
12+
static const std::string NodeEditorFileMarker = "NodeEditorFile";
1413

1514
static bool GetBoundingRect (const NodeUIManager& uiManager, NodeUIDrawingEnvironment& env, Rect& boundingRect)
1615
{
@@ -232,25 +231,28 @@ bool NodeEditor::Open (const std::string& fileName, const ExternalHeaderIO* exte
232231
bool NodeEditor::Open (NE::InputStream& inputStream, const ExternalHeaderIO* externalHeader)
233232
{
234233
if (externalHeader != nullptr) {
235-
if (DBGERROR (!externalHeader->Read (inputStream))) {
234+
if (!externalHeader->Read (inputStream)) {
236235
return false;
237236
}
238237
}
239238

240239
std::string fileMarker;
241240
inputStream.Read (fileMarker);
242-
if (DBGERROR (fileMarker != NodeEditorFileMarker)) {
241+
if (fileMarker != NodeEditorFileMarker) {
243242
return false;
244243
}
245244

246-
int fileVersion = 0;
247-
inputStream.Read (fileVersion);
248-
if (DBGERROR (fileVersion != NodeEditorFileVersion)) {
245+
int readFileVersion = 0;
246+
inputStream.Read (readFileVersion);
247+
if (readFileVersion > FileVersion) {
249248
return false;
250249
}
251250

252251
Version readVersion;
253252
readVersion.Read (inputStream);
253+
if (readVersion > EngineVersion) {
254+
return false;
255+
}
254256

255257
if (DBGERROR (!uiManager.Open (inputStream))) {
256258
return false;
@@ -287,8 +289,8 @@ bool NodeEditor::Save (NE::OutputStream& outputStream, const ExternalHeaderIO* e
287289
}
288290

289291
outputStream.Write (NodeEditorFileMarker);
290-
outputStream.Write (NodeEditorFileVersion);
291-
currentVersion.Write (outputStream);
292+
outputStream.Write (FileVersion);
293+
EngineVersion.Write (outputStream);
292294
if (DBGERROR (!uiManager.Save (outputStream))) {
293295
return false;
294296
}

Sources/NodeUIEngine/NUIE_Version.cpp

+30-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,34 @@ Version::Version (int version1, int version2, int version3) :
2020

2121
}
2222

23+
bool Version::operator< (const Version& rhs) const
24+
{
25+
if (version1 < rhs.version1) {
26+
return true;
27+
}
28+
if (version2 < rhs.version2) {
29+
return true;
30+
}
31+
if (version3 < rhs.version3) {
32+
return true;
33+
}
34+
return false;
35+
}
36+
37+
bool Version::operator> (const Version& rhs) const
38+
{
39+
if (version1 > rhs.version1) {
40+
return true;
41+
}
42+
if (version2 > rhs.version2) {
43+
return true;
44+
}
45+
if (version3 > rhs.version3) {
46+
return true;
47+
}
48+
return false;
49+
}
50+
2351
NE::Stream::Status Version::Read (NE::InputStream& inputStream)
2452
{
2553
inputStream.Read (version1);
@@ -36,6 +64,7 @@ NE::Stream::Status Version::Write (NE::OutputStream& outputStream) const
3664
return outputStream.GetStatus ();
3765
}
3866

39-
const Version currentVersion (VSE_VERSION_1, VSE_VERSION_2, VSE_VERSION_3);
67+
const Version EngineVersion (VSE_VERSION_1, VSE_VERSION_2, VSE_VERSION_3);
68+
const int FileVersion = 1;
4069

4170
}

Sources/NodeUIEngine/NUIE_Version.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class Version
1212
Version ();
1313
Version (int version1, int version2, int version3);
1414

15+
bool operator< (const Version& rhs) const;
16+
bool operator> (const Version& rhs) const;
17+
1518
NE::Stream::Status Read (NE::InputStream& inputStream);
1619
NE::Stream::Status Write (NE::OutputStream& outputStream) const;
1720

@@ -21,7 +24,8 @@ class Version
2124
int version3;
2225
};
2326

24-
extern const Version currentVersion;
27+
extern const Version EngineVersion;
28+
extern const int FileVersion;
2529

2630
}
2731

0 commit comments

Comments
 (0)