Skip to content

Commit

Permalink
19953: Fixes bug where version string was not returned on successful …
Browse files Browse the repository at this point in the history
…file loads (#119)
  • Loading branch information
howsohazard authored Apr 12, 2024
1 parent cba3d15 commit bd0311b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions src/Amalgam/importexport/FileSupportCAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,31 @@ std::tuple<std::string, std::string, bool> FileSupportCAML::ReadHeader(std::ifst
header_size += sizeof(magic);

auto num_bytes_read = stream.gcount();
std::string version;
if(num_bytes_read != sizeof(magic))
return std::make_tuple("Cannot read CAML header", "", false);
else if(memcmp(magic, s_magic_number, sizeof(magic)) == 0)
{
return std::make_tuple("Cannot read CAML header", version, false);
}
else if(std::memcmp(&magic[0], &s_magic_number[0], sizeof(magic)) != 0)
{
return std::make_tuple("CAML does not contain a valid header", version, false);
}
else
{
uint32_t major = 0, minor = 0, patch = 0;
if(!ReadVersion(stream, major, minor, patch))
return std::make_tuple("Cannot read CAML version", "", false);
return std::make_tuple("Cannot read CAML version", version, false);
header_size += sizeof(major) * 3;
std::string version = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch);
version = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch);

//validate version
auto [error_message, success] = AssetManager::ValidateVersionAgainstAmalgam(version);
if(!success)
return std::make_tuple(error_message, version, false);
}
else
{
return std::make_tuple("CAML does not contain a valid header", "", false);
}


return std::make_tuple("", "", true);
return std::make_tuple("", version, true);
}

bool FileSupportCAML::WriteHeader(std::ofstream &stream)
Expand Down
2 changes: 1 addition & 1 deletion src/Amalgam/importexport/FileSupportCAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace FileSupportCAML
{
//read the header from the stream
//if successfully: returns empty strings and true
//if successfully: returns an empty string indicating no error, file version, and true
//if failure: returns error message, file version, and false
std::tuple<std::string, std::string, bool> ReadHeader(std::ifstream &stream, size_t &header_size);

Expand Down

0 comments on commit bd0311b

Please sign in to comment.