#include "project.h" #include #include #include constexpr std::string_view entry("mason.json"); Project::Project(const std::filesystem::path& location): location(location), status(Status::unknown), name() {} bool Project::read() { if (status == Status::read) return true; std::filesystem::path entryPointPath; try { entryPointPath = std::filesystem::canonical(location) / entry; } catch (const std::exception& e) { log(e.what()); status = Status::error; return false; } std::ifstream file(entryPointPath); if (!file.is_open()) { log("couldn't open " + std::string(entryPointPath)); status = Status::error; return false; } try { nlohmann::json data = nlohmann::json::parse(file); name = data.at("name"); } catch (const std::exception& e) { log(e.what()); status = Status::error; return false; } return true; } void Project::log(const std::string& message) const { logStorage.emplace_back(message); } Project::Log Project::getLog() const { return logStorage; } Project::Status Project::getStatus() const { return status; } std::string Project::getName() const { return name; }