Add support to read tags color/userdata from crash sessions from v1.2 and v1.3

This commit is contained in:
David Capello 2020-08-23 15:10:01 -03:00
parent 0ec8efd366
commit ab4accb60d
3 changed files with 24 additions and 6 deletions

View File

@ -502,7 +502,8 @@ private:
}
Tag* readTag(std::ifstream& s) {
return read_tag(s, false);
const bool oldVersion = (m_docFormatVer < DOC_FORMAT_VERSION_1);
return read_tag(s, false, oldVersion);
}
Slice* readSlice(std::ifstream& s) {

View File

@ -36,19 +36,34 @@ void write_tag(std::ostream& os, const Tag* tag)
write_user_data(os, tag->userData());
}
Tag* read_tag(std::istream& is, bool setId)
Tag* read_tag(std::istream& is,
const bool setId,
const bool oldVersion)
{
ObjectId id = read32(is);
frame_t from = read32(is);
frame_t to = read32(is);
// If we are reading a session from v1.2.x, there is a color field
color_t color;
if (oldVersion)
color = read32(is);
AniDir aniDir = (AniDir)read8(is);
std::string name = read_string(is);
UserData userData = read_user_data(is);
UserData userData;
// If we are reading the new v1.3.x version, there is a user data with the color + text
if (!oldVersion)
userData = read_user_data(is);
std::unique_ptr<Tag> tag(new Tag(from, to));
tag->setAniDir(aniDir);
tag->setName(name);
tag->setUserData(userData);
if (oldVersion)
tag->setColor(color);
else
tag->setUserData(userData);
if (setId)
tag->setId(id);
return tag.release();

View File

@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
@ -16,7 +16,9 @@ namespace doc {
class Tag;
void write_tag(std::ostream& os, const Tag* tag);
Tag* read_tag(std::istream& is, bool setId = true);
Tag* read_tag(std::istream& is,
const bool setId = true,
const bool oldVersion = false);
} // namespace doc