Merge pull request #1036 from oltaco/datastore-refactor
Refactor DataStore to use openRead() and openWrite()
This commit is contained in:
@@ -197,11 +197,7 @@ void DataStore::loadPrefs(NodePrefs& prefs, double& node_lat, double& node_lon)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& node_lat, double& node_lon) {
|
void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& node_lat, double& node_lon) {
|
||||||
#if defined(RP2040_PLATFORM)
|
File file = openRead(_fs, filename);
|
||||||
File file = _fs->open(filename, "r");
|
|
||||||
#else
|
|
||||||
File file = _fs->open(filename);
|
|
||||||
#endif
|
|
||||||
if (file) {
|
if (file) {
|
||||||
uint8_t pad[8];
|
uint8_t pad[8];
|
||||||
|
|
||||||
@@ -262,16 +258,7 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DataStore::loadContacts(DataStoreHost* host) {
|
void DataStore::loadContacts(DataStoreHost* host) {
|
||||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
File file = openRead(_getContactsChannelsFS(), "/contacts3");
|
||||||
if (_getContactsChannelsFS()->exists("/contacts3")) {
|
|
||||||
File file = _getContactsChannelsFS()->open("/contacts3");
|
|
||||||
#elif defined(RP2040_PLATFORM)
|
|
||||||
if (_fs->exists("/contacts3")) {
|
|
||||||
File file = _fs->open("/contacts3", "r");
|
|
||||||
#else
|
|
||||||
if (_fs->exists("/contacts3")) {
|
|
||||||
File file = _fs->open("/contacts3", "r", false);
|
|
||||||
#endif
|
|
||||||
if (file) {
|
if (file) {
|
||||||
bool full = false;
|
bool full = false;
|
||||||
while (!full) {
|
while (!full) {
|
||||||
@@ -299,7 +286,6 @@ void DataStore::loadContacts(DataStoreHost* host) {
|
|||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataStore::saveContacts(DataStoreHost* host) {
|
void DataStore::saveContacts(DataStoreHost* host) {
|
||||||
@@ -332,16 +318,7 @@ void DataStore::saveContacts(DataStoreHost* host) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DataStore::loadChannels(DataStoreHost* host) {
|
void DataStore::loadChannels(DataStoreHost* host) {
|
||||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
File file = openRead(_getContactsChannelsFS(), "/channels2");
|
||||||
if (_getContactsChannelsFS()->exists("/channels2")) {
|
|
||||||
File file = _getContactsChannelsFS()->open("/channels2");
|
|
||||||
#elif defined(RP2040_PLATFORM)
|
|
||||||
if (_fs->exists("/channels2")) {
|
|
||||||
File file = _fs->open("/channels2", "r");
|
|
||||||
#else
|
|
||||||
if (_fs->exists("/channels2")) {
|
|
||||||
File file = _fs->open("/channels2", "r", false);
|
|
||||||
#endif
|
|
||||||
if (file) {
|
if (file) {
|
||||||
bool full = false;
|
bool full = false;
|
||||||
uint8_t channel_idx = 0;
|
uint8_t channel_idx = 0;
|
||||||
@@ -363,7 +340,6 @@ void DataStore::loadChannels(DataStoreHost* host) {
|
|||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataStore::saveChannels(DataStoreHost* host) {
|
void DataStore::saveChannels(DataStoreHost* host) {
|
||||||
@@ -520,7 +496,7 @@ void DataStore::migrateToSecondaryFS() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]) {
|
uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]) {
|
||||||
File file = _getContactsChannelsFS()->open("/adv_blobs");
|
File file = openRead(_getContactsChannelsFS(), "/adv_blobs");
|
||||||
uint8_t len = 0; // 0 = not found
|
uint8_t len = 0; // 0 = not found
|
||||||
if (file) {
|
if (file) {
|
||||||
BlobRec tmp;
|
BlobRec tmp;
|
||||||
@@ -583,11 +559,7 @@ uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_b
|
|||||||
sprintf(path, "/bl/%s", fname);
|
sprintf(path, "/bl/%s", fname);
|
||||||
|
|
||||||
if (_fs->exists(path)) {
|
if (_fs->exists(path)) {
|
||||||
#if defined(RP2040_PLATFORM)
|
File f = openRead(_fs, path);
|
||||||
File f = _fs->open(path, "r");
|
|
||||||
#else
|
|
||||||
File f = _fs->open(path);
|
|
||||||
#endif
|
|
||||||
if (f) {
|
if (f) {
|
||||||
int len = f.read(dest_buf, 255); // currently MAX 255 byte blob len supported!!
|
int len = f.read(dest_buf, 255); // currently MAX 255 byte blob len supported!!
|
||||||
f.close();
|
f.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user