Something went wrong. Try again.
art software for the rest of us
drawing paint image sdl art
Something went wrong. Try again.
1.4 kB · 42 lines
C++
12345678910111213141516171819202122232425262728293031323334353637383940414243#include "ArtworkManagementContext.h"#include "../UserData.h"#include <filesystem>#include <algorithm>
std::vector<Artwork*> ArtworkManagementContext::artworks;
std::vector<Artwork*> ArtworkManagementContext::GetLatest(size_t amount) { if (artworks.size() > amount) { std::vector<Artwork*> result(amount); std::copy(artworks.rbegin(), artworks.rbegin() + amount, result.begin()); return result; } return artworks;}
std::vector<Artwork*> 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()); });}