fix: revert graph version to 2

add: allow loading of graphs with different versions for future bot versions.
This commit is contained in:
jeefo 2022-10-03 11:20:06 +03:00
commit e1d64b62ce
No known key found for this signature in database
GPG key ID: D85B0637366787C3
2 changed files with 10 additions and 13 deletions

View file

@ -70,7 +70,7 @@ CR_DECLARE_SCOPED_ENUM (StorageOption,
// storage header versions // storage header versions
CR_DECLARE_SCOPED_ENUM (StorageVersion, CR_DECLARE_SCOPED_ENUM (StorageVersion,
Graph = 3, Graph = 2,
Practice = 1, Practice = 1,
Vistable = 1, Vistable = 1,
Matrix = 1, Matrix = 1,

View file

@ -1744,10 +1744,10 @@ template <typename U> bool BotGraph::loadStorage (StringRef ext, StringRef name,
} }
// check the version // check the version
if (hdr.version > version) { if (hdr.version > version && isGraph) {
if (tryReload ()) { ctrl.msg ("Graph version mismatch %s (filename: '%s'). Version number differs (got: '%d', need: '%d') Please, upgrade %s.", name, filename, hdr.version, version, product.name);
return true; }
} else if (hdr.version > version && !isGraph) {
return raiseLoadingError (isGraph, file, "Damaged %s (filename: '%s'). Version number differs (got: '%d', need: '%d').", name, filename, hdr.version, version); return raiseLoadingError (isGraph, file, "Damaged %s (filename: '%s'). Version number differs (got: '%d', need: '%d').", name, filename, hdr.version, version);
} }
@ -1782,17 +1782,13 @@ template <typename U> bool BotGraph::loadStorage (StringRef ext, StringRef name,
// author of graph.. save // author of graph.. save
if ((hdr.options & StorageOption::Exten) && exten != nullptr) { if ((hdr.options & StorageOption::Exten) && exten != nullptr) {
size_t extenSize = sizeof (ExtenHeader); auto extenSize = sizeof (ExtenHeader);
auto actuallyRead = file.read (exten, extenSize) * extenSize;
if (hdr.version < 3) {
extenSize -= sizeof (char[32]); // modified by
}
file.read (exten, extenSize);
if (isGraph) { if (isGraph) {
strings.copy (m_extenHeader.author, exten->author, cr::bufsize (exten->author)); strings.copy (m_extenHeader.author, exten->author, cr::bufsize (exten->author));
if (hdr.version > 2) { if (extenSize <= actuallyRead) {
strings.copy (m_extenHeader.modified, exten->modified, cr::bufsize (exten->modified)); strings.copy (m_extenHeader.modified, exten->modified, cr::bufsize (exten->modified));
} }
else { else {
@ -1837,8 +1833,9 @@ bool BotGraph::loadGraphData () {
else { else {
m_graphAuthor.assign (exten.author); m_graphAuthor.assign (exten.author);
} }
StringRef modified = exten.modified;
if (m_graphHeader.version > 2) { if (!modified.empty () && !modified.contains ("(none)")) {
m_graphModified.assign (exten.modified); m_graphModified.assign (exten.modified);
} }