* new "contacts2" file format

This commit is contained in:
Scott Powell
2025-01-29 00:51:52 +11:00
parent dc11fe85cb
commit fe306a311e

View File

@@ -123,8 +123,8 @@ class MyMesh : public BaseChatMesh {
uint8_t out_frame[MAX_FRAME_SIZE+1]; uint8_t out_frame[MAX_FRAME_SIZE+1];
void loadContacts() { void loadContacts() {
if (_fs->exists("/contacts")) { if (_fs->exists("/contacts2")) {
File file = _fs->open("/contacts"); File file = _fs->open("/contacts2");
if (file) { if (file) {
bool full = false; bool full = false;
while (!full) { while (!full) {
@@ -142,6 +142,7 @@ class MyMesh : public BaseChatMesh {
success = success && (file.read((uint8_t *) &c.out_path_len, 1) == 1); success = success && (file.read((uint8_t *) &c.out_path_len, 1) == 1);
success = success && (file.read((uint8_t *) &c.last_advert_timestamp, 4) == 4); success = success && (file.read((uint8_t *) &c.last_advert_timestamp, 4) == 4);
success = success && (file.read(c.out_path, 64) == 64); success = success && (file.read(c.out_path, 64) == 64);
success = success && (file.read((uint8_t *) c.lastmod, 4) == 4);
if (!success) break; // EOF if (!success) break; // EOF
@@ -155,10 +156,10 @@ class MyMesh : public BaseChatMesh {
void saveContacts() { void saveContacts() {
#if defined(NRF52_PLATFORM) #if defined(NRF52_PLATFORM)
File file = _fs->open("/contacts", FILE_O_WRITE); File file = _fs->open("/contacts2", FILE_O_WRITE);
if (file) { file.seek(0); file.truncate(); } if (file) { file.seek(0); file.truncate(); }
#else #else
File file = _fs->open("/contacts", "w", true); File file = _fs->open("/contacts2", "w", true);
#endif #endif
if (file) { if (file) {
ContactsIterator iter; ContactsIterator iter;
@@ -176,6 +177,7 @@ class MyMesh : public BaseChatMesh {
success = success && (file.write((uint8_t *) &c.out_path_len, 1) == 1); success = success && (file.write((uint8_t *) &c.out_path_len, 1) == 1);
success = success && (file.write((uint8_t *) &c.last_advert_timestamp, 4) == 4); success = success && (file.write((uint8_t *) &c.last_advert_timestamp, 4) == 4);
success = success && (file.write(c.out_path, 64) == 64); success = success && (file.write(c.out_path, 64) == 64);
success = success && (file.write((uint8_t *) &c.lastmod, 4) == 4);
if (!success) break; // write failed if (!success) break; // write failed
} }
@@ -479,13 +481,13 @@ public:
ContactInfo* recipient = lookupContactByPubKey(pub_key, PUB_KEY_SIZE); ContactInfo* recipient = lookupContactByPubKey(pub_key, PUB_KEY_SIZE);
if (recipient) { if (recipient) {
updateContactFromFrame(*recipient, cmd_frame); updateContactFromFrame(*recipient, cmd_frame);
recipient->lastmod = 0; //recipient->lastmod = ?? shouldn't be needed, app already has this version of contact
saveContacts(); saveContacts();
writeOKFrame(); writeOKFrame();
} else { } else {
ContactInfo contact; ContactInfo contact;
updateContactFromFrame(contact, cmd_frame); updateContactFromFrame(contact, cmd_frame);
contact.lastmod = 0; contact.lastmod = getRTCClock()->getCurrentTime();
if (addContact(contact)) { if (addContact(contact)) {
saveContacts(); saveContacts();
writeOKFrame(); writeOKFrame();