Require SD card or >4MB flash (#545)

This commit is contained in:
Ken Van Hoeylandt
2026-07-03 23:56:03 +02:00
committed by GitHub
parent 90afba647e
commit 05720821f8
106 changed files with 403 additions and 603 deletions
@@ -181,6 +181,10 @@ bool save(const WifiApSettings& apSettings) {
}
const auto file_path = getApPropertiesFilePath(service_context->getPaths(), apSettings.ssid);
if (!file::findOrCreateParentDirectory(file_path, 0755)) {
LOGGER.error("Failed to create {}", file_path);
return false;
}
std::map<std::string, std::string> map;
@@ -124,16 +124,9 @@ void bootSplashInit() {
getMainDispatcher().dispatch([] {
LOGGER.info("bootSplashInit dispatch begin");
// First import any provisioning files placed on the system data partition.
const std::string data_settings_path = file::getChildPath(file::MOUNT_POINT_DATA, "settings");
const std::string data_settings_path = file::getChildPath(getUserDataPath(), "provisioning");
importWifiApSettingsFromDir(data_settings_path);
// Then scan attached SD cards as before.
std::string sdcard_path;
if (findFirstMountedSdCardPath((sdcard_path))) {
const std::string sd_settings_path = file::getChildPath(sdcard_path, "settings");
importWifiApSettingsFromDir(sd_settings_path);
}
if (settings::shouldEnableOnBoot()) {
LOGGER.info("Auto-enabling due to setting");
getMainDispatcher().dispatch([] -> void { setEnabled(true); });
+22 -18
View File
@@ -21,14 +21,14 @@ static WifiSettings cachedSettings {
static bool cached = false;
static bool load(WifiSettings& settings) {
auto service_context = findServiceContext();
if (service_context == nullptr) {
return false;
}
static bool hasWifiSettingsFile(std::shared_ptr<ServiceContext> context) {
std::string settings_path = context->getPaths()->getUserDataPath("settings.properties");
return file::isFile(settings_path);
}
static bool load(std::shared_ptr<ServiceContext> context, WifiSettings& settings) {
std::map<std::string, std::string> map;
std::string settings_path = service_context->getPaths()->getUserDataPath("settings.properties");
std::string settings_path = context->getPaths()->getUserDataPath("settings.properties");
if (!file::loadPropertiesFile(settings_path, map)) {
return false;
}
@@ -42,23 +42,26 @@ static bool load(WifiSettings& settings) {
return true;
}
static bool save(const WifiSettings& settings) {
auto service_context = findServiceContext();
if (service_context == nullptr) {
return false;
}
static bool save(std::shared_ptr<ServiceContext> context, const WifiSettings& settings) {
std::map<std::string, std::string> map;
map[SETTINGS_KEY_ENABLE_ON_BOOT] = settings.enableOnBoot ? "true" : "false";
std::string settings_path = service_context->getPaths()->getUserDataPath("settings.properties");
std::string settings_path = context->getPaths()->getUserDataPath("settings.properties");
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
LOGGER.error("Failed to create {}", settings_path);
return false;
}
return file::savePropertiesFile(settings_path, map);
}
WifiSettings getCachedOrLoad() {
if (!cached) {
if (!load(cachedSettings)) {
LOGGER.error("Failed to load");
} else {
cached = true;
auto context = findServiceContext();
if (context && hasWifiSettingsFile(context)) {
if (load(context, cachedSettings)) {
cached = true;
} else {
LOGGER.info("Failed to load settings, using defaults");
}
}
}
@@ -67,8 +70,9 @@ WifiSettings getCachedOrLoad() {
void setEnableOnBoot(bool enable) {
cachedSettings.enableOnBoot = enable;
if (!save(cachedSettings)) {
LOGGER.error("Failed to save");
auto context = findServiceContext();
if (context && !save(context, cachedSettings)) {
LOGGER.error("Failed to save settings");
}
}