62 lines
1.9 KiB
C++
62 lines
1.9 KiB
C++
#include <boost/filesystem.hpp>
|
|
#include <QStandardPaths>
|
|
#include <pugixml.hpp>
|
|
|
|
#include <properties/config.h>
|
|
#include "appdatastorage.h"
|
|
|
|
namespace Ember
|
|
{
|
|
|
|
AppDataStorage::AppDataStorage()
|
|
{
|
|
QString appData = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
|
m_appData = appData.toStdString();
|
|
m_recentProjects = m_appData;
|
|
m_recentProjects += RECENT_PROJECTS_FILENAME;
|
|
}
|
|
|
|
void AppDataStorage::readRecentProjects(std::vector<RecentProject> &projects)
|
|
{
|
|
if (boost::filesystem::exists(m_recentProjects))
|
|
{
|
|
pugi::xml_document doc;
|
|
doc.load_file(m_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<time_t>(node.attribute("access").as_llong());
|
|
recent.pinned = node.attribute("pinned").as_bool();
|
|
projects.push_back(recent);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void AppDataStorage::storeRecentProjects(const std::vector<RecentProject> &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<long long>(recent.access));
|
|
node.append_attribute("pinned").set_value(recent.pinned);
|
|
}
|
|
|
|
// Save file, ensure directory exists
|
|
boost::filesystem::create_directories(m_appData);
|
|
doc.save_file(m_recentProjects.string().c_str());
|
|
}
|
|
|
|
}
|