| 35 | } |
| 36 | |
| 37 | bool WifiCredentialStore::loadFromFile() { |
| 38 | // Try JSON first |
| 39 | if (Storage.exists(WIFI_FILE_JSON)) { |
| 40 | String json = Storage.readFile(WIFI_FILE_JSON); |
| 41 | if (!json.isEmpty()) { |
| 42 | bool resave = false; |
| 43 | bool result = JsonSettingsIO::loadWifi(*this, json.c_str(), &resave); |
| 44 | if (result && resave) { |
| 45 | LOG_DBG("WCS", "Resaving JSON with obfuscated passwords"); |
| 46 | saveToFile(); |
| 47 | } |
| 48 | return result; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | // Fall back to binary migration |
| 53 | if (Storage.exists(WIFI_FILE_BIN)) { |
| 54 | if (loadFromBinaryFile()) { |
| 55 | if (saveToFile()) { |
| 56 | Storage.rename(WIFI_FILE_BIN, WIFI_FILE_BAK); |
| 57 | LOG_DBG("WCS", "Migrated wifi.bin to wifi.json"); |
| 58 | return true; |
| 59 | } else { |
| 60 | LOG_ERR("WCS", "Failed to save wifi during migration"); |
| 61 | return false; |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | bool WifiCredentialStore::loadFromBinaryFile() { |
| 70 | HalFile file; |