Skip to content

Commit

Permalink
🤏 [Projet] Store version as the first line of the file instead of a r…
Browse files Browse the repository at this point in the history
…egular cereal field

Allows the launcher to parse it easily, no matter what serialization format the project will use
  • Loading branch information
JulesFouchy committed Jul 31, 2024
1 parent 0bec278 commit 78d9cc6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cool
5 changes: 0 additions & 5 deletions src/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "Cool/StrongTypes/Camera2D.h"
#include "Cool/Time/Clock_Realtime.h"
#include "Dependencies/Camera3DManager.h"
#include "Dump/coollab_version.h"
#include "ModulesGraph/ModulesGraph.h"

namespace Lab {
Expand All @@ -26,8 +25,6 @@ struct Project {
Cool::AudioManager audio;
Cool::OSCConnectionEndpoint osc_endpoint{};

std::string debug_info_coollab_version{}; // Only used to generate an error message when deserialization fails.

[[nodiscard]] auto is_empty() const -> bool;
[[nodiscard]] auto current_clock() const -> Cool::Clock const& { return exporter.is_exporting() ? exporter.clock() : clock; }

Expand All @@ -37,12 +34,10 @@ struct Project {
template<class Archive>
void serialize(Archive& archive)
{
debug_info_coollab_version = coollab_version();
#if defined(__linux__)
history.set_max_saved_size(0); // TODO HACK to avoid a crash when deserializing the history: https://github.com/orgs/CoolLibs/projects/1/views/1?pane=issue&itemId=46983814
#endif
archive(
ser20::make_nvp("Coollab version", debug_info_coollab_version), // Must be first, purely informative, so that users can know what version of Coollab a project was built with.
ser20::make_nvp("Time", clock),
ser20::make_nvp("View Constraint", view_constraint),
ser20::make_nvp("Exporter (Image and Video)", exporter),
Expand Down
7 changes: 4 additions & 3 deletions src/ProjectManager/Command_OpenProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ namespace Lab {

void Command_OpenProject::execute(CommandExecutionContext_Ref const& ctx) const
{
auto project = Project{};
auto const error = do_load(project, path);
auto project = Project{};
auto coollab_version = ""s;
auto const error = do_load(project, path, coollab_version);
if (error)
{
error.send_error_if_any(
Expand All @@ -21,7 +22,7 @@ void Command_OpenProject::execute(CommandExecutionContext_Ref const& ctx) const
.category = "Loading Project failed",
.message = fmt::format(
"Incompatible version. Use Coollab **{}** instead. You can download it from [https://github.com/CoolLibs/Lab/releases](https://github.com/CoolLibs/Lab/releases).",
project.debug_info_coollab_version
coollab_version
),
.severity = Cool::MessageSeverity::Warning,
};
Expand Down
2 changes: 1 addition & 1 deletion src/Serialization/SProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
namespace Lab {

auto do_save(Project const&, std::filesystem::path const&) -> bool;
auto do_load(Project&, std::filesystem::path const&) -> Cool::OptionalErrorMessage;
auto do_load(Project&, std::filesystem::path const&, std::string& coollab_version) -> Cool::OptionalErrorMessage;

} // namespace Lab
7 changes: 4 additions & 3 deletions src/Serialization/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
///
#include <ser20/types/polymorphic.hpp>
#include "Cool/Serialization/Serialization.h"
#include "Dump/coollab_version.h"
#include "SNodesCategoryConfig.h"
#include "SNodesClipboard.h"
#include "SProject.h"
Expand All @@ -16,11 +17,11 @@ namespace Lab {

auto do_save(Project const& project, std::filesystem::path const& path) -> bool
{
return Cool::Serialization::save<Project, ser20::JSONOutputArchive>(project, path, "Project");
return Cool::Serialization::save<Project, ser20::JSONOutputArchive>(project, path, "Project", coollab_version());
}
auto do_load(Project& project, std::filesystem::path const& path) -> Cool::OptionalErrorMessage
auto do_load(Project& project, std::filesystem::path const& path, std::string& coollab_version) -> Cool::OptionalErrorMessage
{
return Cool::Serialization::load<Project, ser20::JSONInputArchive>(project, path);
return Cool::Serialization::load<Project, ser20::JSONInputArchive>(project, path, &coollab_version);
}

auto do_save(NodesCategoryConfig const& config, std::filesystem::path const& path) -> bool
Expand Down

0 comments on commit 78d9cc6

Please sign in to comment.