Skip to content

Commit

Permalink
fix #124 auto upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
yakumo-saki committed Jan 23, 2023
1 parent 8a911ef commit 461750f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions include/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "config_values.h"
#include "ConfigClass.h"

extern const String CFG_VERSION_INVALID;

enum struct CFG_VALIDATE_RESULT {
// 存在していて、バージョンも一致している
VALID,
Expand Down
6 changes: 4 additions & 2 deletions src/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "config_names.h"

const unsigned int CONF_JSON_SIZE = 4000;
extern const String CFG_VERSION_INVALID = "INVALID";


DynamicJsonDocument _create_config_json(bool save, const std::vector<String> &keyArray) {

Expand Down Expand Up @@ -119,12 +121,12 @@ String read_config_setting_id(File f) {
DeserializationError error = deserializeJson(doc, f);

if (error) {
return "INVALID";
return CFG_VERSION_INVALID;
}

JsonVariant value = doc[ConfigNames::SETTING_ID];
if (value.isNull()) {
return "INVALID"; // JSON not contains SETTING_ID
return CFG_VERSION_INVALID; // JSON not contains SETTING_ID
}

return value.as<String>();
Expand Down
8 changes: 6 additions & 2 deletions src/config/config_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ CFG_VALIDATE_RESULT has_valid_config_file() {
settingId = read_config_setting_id(f);
f.close();

if (String(SETTING_ID).equals(settingId)) {
if (settingId.equals(CFG_VERSION_INVALID)) {
cfglog("SETTING_ID not found. INVALID config.");
return CFG_VALIDATE_RESULT::ERROR;
} else if (String(SETTING_ID).equals(settingId)) {
cfglog("SETTING_ID verified. " + settingId);
return CFG_VALIDATE_RESULT::VALID;
} else {
Expand All @@ -80,7 +83,7 @@ CFG_VALIDATE_RESULT has_valid_config_file() {
}
}

cfglog("Unknown state. Assuming config not found");
cfglog("Unknown state. Assuming config not found. " + settingId);
return CFG_VALIDATE_RESULT::ERROR;
}

Expand All @@ -102,6 +105,7 @@ bool has_configured_file() {
return true;
}

/** ファイルシステムのマウント */
void config_setup() {

if (!LittleFS.begin()) {
Expand Down
5 changes: 4 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ void setup()
if (validateResult == CFG_VALIDATE_RESULT::VALID) {
mainlog(F("Config file is valid."));
} else if (validateResult == CFG_VALIDATE_RESULT::NEED_UPGRADE) {
mainlog(F("Config file needs upgrade."));
sectionlog(F("Config file needs upgrade. upgrading..."));
read_config();
save_config(); // upgrade means json + default, so only saving is needed.
sectionlog(F("Config file upgrade done!"));
} else {
mainlog(F("Config file validation error. dropping to setup mode."));
isNormal = false;
Expand Down
2 changes: 1 addition & 1 deletion src/main_normal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void setup_normal() {
sectionlog(F("Start watchdog"));
setup_watchdog();

// setupモードに入りやすくするための処理
// setupモードに入りやすくするための処理(deprecated)
if (config->get(ConfigNames::DISPLAY_RECONFIG) == ConfigValues::DISPLAY_RECONFIG_ON) {
sectionlog(F("Reset to reconfig start."));
remove_configure_flag_file();
Expand Down

0 comments on commit 461750f

Please sign in to comment.