atm-admin/src/XMLStorage.cpp

56 lines
1.4 KiB
C++
Raw Normal View History

2025-06-13 09:15:55 +00:00
#include <iomanip>
#include <iostream>
#include "../libs/XMLStorage.h"
namespace AtmAdmin {
void XMLStorage::initXMLDoc () {
pugi::xml_parse_result res = m_doc.load_file("./data/users.xml");
if (!res) {
std::cerr << "Error occurred: " << res.description();
exit(EXIT_FAILURE);
}
}
// getXMLData retrieves the data required by XMLStorage.
pugi::xml_node XMLStorage::initAccountNode (const std::string& toSearch) {
2025-06-13 09:15:55 +00:00
pugi::xml_node data = m_doc.first_child().child("accounts").find_child_by_attribute("account", "owner", toSearch.c_str());
if (data.empty()) {
std::cerr << "Account not found, exiting.";
std::cout << data.name();
exit(EXIT_FAILURE);
}
return data;
}
void XMLStorage::updateNameData () {
m_data.child("name").text().set(this->name);
std::cout.flags (std::ios::boolalpha);
bool saveSuccess {m_doc.save_file("./data/users.xml")};
if (!saveSuccess) {
std::cerr << "Failed to apply. Aborting...";
std::exit(1);
}
}
void XMLStorage::updatePinData () {
m_data.child("pin").text().set(this->pin);
std::cout.flags (std::ios::boolalpha);
bool saveSuccess {m_doc.save_file("./data/users.xml")};
if (!saveSuccess) {
std::cerr << "Failed to apply. Aborting...";
std::exit(1);
}
}
2025-06-13 09:15:55 +00:00
}