MeshCore/src/helpers/IdentityStore.h

30 lines
859 B
C
Raw Normal View History

2025-01-13 14:07:48 +11:00
#pragma once
#if defined(ESP32) || defined(RP2040_PLATFORM)
2025-01-20 20:22:40 +11:00
#include <FS.h>
#define FILESYSTEM fs::FS
2025-05-11 09:26:32 +02:00
#elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
2025-07-29 20:06:35 +10:00
#include <Adafruit_LittleFS.h>
#define FILESYSTEM Adafruit_LittleFS
2025-01-20 20:22:40 +11:00
2025-07-29 20:06:35 +10:00
using namespace Adafruit_LittleFS_Namespace;
2025-01-20 20:22:40 +11:00
#endif
2025-01-13 14:07:48 +11:00
#include <Identity.h>
class IdentityStore {
2025-01-20 20:22:40 +11:00
FILESYSTEM* _fs;
2025-01-13 14:07:48 +11:00
const char* _dir;
public:
2025-01-20 20:22:40 +11:00
IdentityStore(FILESYSTEM& fs, const char* dir): _fs(&fs), _dir(dir) { }
2025-01-13 14:07:48 +11:00
2025-07-29 20:06:35 +10:00
void begin() {
if (_dir && _dir[0] == '/') { _fs->mkdir(_dir); }
}
2025-01-13 14:07:48 +11:00
bool load(const char *name, mesh::LocalIdentity& id);
bool load(const char *name, mesh::LocalIdentity& id, char display_name[], int max_name_sz);
2025-01-13 14:07:48 +11:00
bool save(const char *name, const mesh::LocalIdentity& id);
bool save(const char *name, const mesh::LocalIdentity& id, const char display_name[]);
2025-01-13 14:07:48 +11:00
};