| 37 | } |
| 38 | |
| 39 | bool CrossPointState::loadFromFile() { |
| 40 | // Try JSON first |
| 41 | if (Storage.exists(STATE_FILE_JSON)) { |
| 42 | String json = Storage.readFile(STATE_FILE_JSON); |
| 43 | if (!json.isEmpty()) { |
| 44 | return JsonSettingsIO::loadState(*this, json.c_str()); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // Fall back to binary migration |
| 49 | if (Storage.exists(STATE_FILE_BIN)) { |
| 50 | if (loadFromBinaryFile()) { |
| 51 | if (saveToFile()) { |
| 52 | Storage.rename(STATE_FILE_BIN, STATE_FILE_BAK); |
| 53 | LOG_DBG("CPS", "Migrated state.bin to state.json"); |
| 54 | return true; |
| 55 | } else { |
| 56 | LOG_ERR("CPS", "Failed to save state during migration"); |
| 57 | return false; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | bool CrossPointState::loadFromBinaryFile() { |
| 66 | HalFile inputFile; |