10namespace fs = std::filesystem;
12static const char *
const TAG =
"preferences";
17 const char *home = getenv(
"HOME");
18 if (home ==
nullptr) {
19 ESP_LOGE(TAG,
"HOME environment variable is not set");
29 FILE *fp = fopen(this->
filename_.c_str(),
"rb");
34 if (fread(&key,
sizeof(key), 1, fp) != 1)
36 if (fread(&
len,
sizeof(
len), 1, fp) != 1)
39 if (fread(
data,
sizeof(uint8_t),
len, fp) !=
len)
42 this->data[key] = vec;
51 FILE *fp = fopen(this->
filename_.c_str(),
"wb");
53 ESP_LOGE(TAG,
"Failed to open preferences file for writing: %s", this->
filename_.c_str());
57 for (
auto it = this->
data.begin(); it != this->data.end(); ++it) {
58 fwrite(&it->first,
sizeof(
uint32_t), 1, fp);
59 uint8_t
len = it->second.size();
60 fwrite(&
len,
sizeof(
len), 1, fp);
61 fwrite(it->second.data(),
sizeof(uint8_t), it->second.size(), fp);
const StringRef & get_name() const
Get the name of this Application set by pre_setup().
bool load(uint8_t *data, size_t len)
bool save(const uint8_t *data, size_t len)
bool load(uint32_t key, uint8_t *data, size_t len)
bool save(uint32_t key, const uint8_t *data, size_t len)
ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)
std::map< uint32_t, std::vector< uint8_t > > data
HostPreferences * get_preferences()
HostPreferences * host_preferences
Providing packet encoding functions for exchanging data with a remote host.
ESPPreferences * global_preferences
Application App
Global storage of Application pointer - only one Application can exist.