45 lines
No EOL
1.2 KiB
C++
45 lines
No EOL
1.2 KiB
C++
//SPDX-License-Identifier: LGPL-3.0-only
|
|
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
|
|
|
module;
|
|
|
|
#include "../lib/json.hpp"
|
|
#include <cerrno>
|
|
#include <fcntl.h>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
#include <fstream>
|
|
|
|
module Nostro:Connector_impl;
|
|
import std;
|
|
import :Connector;
|
|
import :Banks;
|
|
import :File;
|
|
|
|
using namespace Nostro;
|
|
using namespace nlohmann;
|
|
namespace fs = std::filesystem;
|
|
|
|
void Connector::SaveConnectors() {
|
|
const fs::path path = configPath/"connectors.json";
|
|
CreatePrivateFile(path);
|
|
|
|
json jsonConnectors = json::object();
|
|
tuple_for<EnabledBanks>([&jsonConnectors]<typename Bank>() {
|
|
jsonConnectors[Bank::connectorId] = Bank::connectors;
|
|
});
|
|
|
|
std::ofstream out(path, std::ios::binary);
|
|
out << jsonConnectors.dump(4);
|
|
}
|
|
|
|
void Connector::LoadConnectors() {
|
|
std::ifstream f(configPath/"connectors.json");
|
|
const json jsonConnectors = json::parse(f);
|
|
tuple_for<EnabledBanks>([&jsonConnectors]<typename Bank>() {
|
|
Bank::connectors = std::move(jsonConnectors.at(Bank::connectorId).template get<std::vector<Bank>>());
|
|
for(Bank& bank : Bank::connectors) {
|
|
bank.RefreshAccounts();
|
|
}
|
|
});
|
|
} |