#include #include #include #include #include "appdatastorage.h" namespace Ember { boost::filesystem::path AppDataStorage::s_appData; boost::filesystem::path AppDataStorage::s_recentProjects; void AppDataStorage::initialize() { QString appData = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); s_appData = appData.toStdString(); s_recentProjects = s_appData; s_recentProjects += RECENT_PROJECTS_FILENAME; } void AppDataStorage::readRecentProjects(std::vector &projects) { if (boost::filesystem::exists(s_recentProjects)) { pugi::xml_document doc; doc.load_file(s_recentProjects.c_str()); for (auto& node : doc.document_element()) { if (strcmp(node.name(), "recentProject") == 0) { RecentProject recent; recent.name = node.attribute("name").as_string(); recent.path = node.attribute("path").as_string(); recent.access = static_cast(node.attribute("access").as_llong()); recent.pinned = node.attribute("pinned").as_bool(); projects.push_back(recent); } } } } void AppDataStorage::storeRecentProjects(const std::vector &projects) { pugi::xml_document doc; doc.append_child(pugi::node_declaration); auto root = doc.append_child("recentProjects"); for (RecentProject recent : projects) { auto node = root.append_child("recentProject"); node.append_attribute("name").set_value(recent.name.c_str()); node.append_attribute("path").set_value(recent.path.c_str()); node.append_attribute("access").set_value(static_cast(recent.access)); node.append_attribute("pinned").set_value(recent.pinned); } // Save file, ensure directory exists boost::filesystem::create_directories(s_appData); doc.save_file(s_recentProjects.string().c_str()); } }