@@ -2166,6 +2166,19 @@ void NodeDB::loadFromDisk()
21662166 migrationSavePending = false ;
21672167 configDecodeFailed = false ;
21682168
2169+ #if USERPREFS_EVENT_MODE
2170+ // The event config is intentionally isolated from the ordinary config.
2171+ // We only seed it when no event file exists; a corrupt event file must not
2172+ // silently fall back to and overwrite the user's normal radio profile.
2173+ bool eventConfigMissing = false ;
2174+ #ifdef FSCom
2175+ spiLock->lock ();
2176+ eventConfigMissing = !FSCom.exists (configFileName);
2177+ spiLock->unlock ();
2178+ #endif
2179+ bool initializedEventConfig = false ;
2180+ #endif
2181+
21692182 meshtastic_Config_SecurityConfig backupSecurity = meshtastic_Config_SecurityConfig_init_zero;
21702183
21712184#ifdef ARCH_ESP32
@@ -2354,6 +2367,29 @@ void NodeDB::loadFromDisk()
23542367
23552368 state = loadProto (configFileName, meshtastic_LocalConfig_size, sizeof (meshtastic_LocalConfig), &meshtastic_LocalConfig_msg,
23562369 &config);
2370+ #if USERPREFS_EVENT_MODE
2371+ if (eventConfigMissing && state != LoadFileResult::LOAD_SUCCESS ) {
2372+ const LoadFileResult eventConfigState = state;
2373+ if (loadProto (standardConfigFileName, meshtastic_LocalConfig_size, sizeof (meshtastic_LocalConfig),
2374+ &meshtastic_LocalConfig_msg, &config) == LoadFileResult::LOAD_SUCCESS ) {
2375+ // Preserve the user's identity and non-radio preferences, then
2376+ // replace only LoRa with this event build's compiled defaults.
2377+ const meshtastic_LocalConfig standardConfig = config;
2378+ installDefaultConfig (true );
2379+ const meshtastic_Config_LoRaConfig eventLora = config.lora ;
2380+ config = standardConfig;
2381+ config.has_lora = true ;
2382+ config.lora = eventLora;
2383+ state = LoadFileResult::LOAD_SUCCESS ;
2384+ initializedEventConfig = true ;
2385+ LOG_INFO (" Initialized event config without modifying %s" , standardConfigFileName);
2386+ } else {
2387+ // loadProto() clears config before decoding. Restore the event
2388+ // outcome so the normal default/degraded path handles that safely.
2389+ state = eventConfigState;
2390+ }
2391+ }
2392+ #endif
23572393 if (state == LoadFileResult::DECODE_FAILED ) {
23582394 // Config file present but undecodable this boot (corruption / torn write / transient decrypt fail).
23592395 // loadProto() already zeroed `config`, so the keypair is gone from RAM; minting a new one would change
@@ -2415,6 +2451,15 @@ void NodeDB::loadFromDisk()
24152451 config.lora .override_frequency = USERPREFS_LORACONFIG_OVERRIDE_FREQUENCY ;
24162452#endif
24172453
2454+ #if USERPREFS_EVENT_MODE
2455+ if (initializedEventConfig) {
2456+ // This is the first durable event-profile write. A failed write is
2457+ // safe: normal files remain untouched and the next event boot retries.
2458+ if (!saveToDisk (SEGMENT_CONFIG ))
2459+ LOG_ERROR (" Unable to persist initial event config" );
2460+ }
2461+ #endif
2462+
24182463 if (backupSecurity.private_key .size > 0 ) {
24192464 LOG_DEBUG (" Restoring backup of security config" );
24202465 config.security = backupSecurity;
0 commit comments