#include "ArtworkManagementContext.h" #include "../UserData.h" #include #include std::vector ArtworkManagementContext::artworks; std::vector ArtworkManagementContext::GetLatest(size_t amount) { if (artworks.size() > amount) { std::vector result(amount); std::copy(artworks.rbegin(), artworks.rbegin() + amount, result.begin()); return result; } return artworks; } std::vector ArtworkManagementContext::GetAll() { return artworks; } void ArtworkManagementContext::Reload() { artworks.clear(); if (!std::filesystem::exists(UserData::GetProjectsDir())) { return; } for (auto& project : std::filesystem::directory_iterator(UserData::GetProjectsDir())) { if (project.is_directory() || project.path().extension() != ".grdn") { continue; } try { artworks.push_back(new Artwork(project.path().string())); } catch (const std::exception& e) { std::printf("Did not load artwork %s because: %s\n", project.path().c_str(), e.what()); } } std::sort(artworks.rbegin(), artworks.rend(), [](const Artwork* lhs, const Artwork* rhs) { return std::filesystem::last_write_time(lhs->GetPath()) < std::filesystem::last_write_time(rhs->GetPath()); }); }