diff --git a/include/contentJson.h b/include/contentJson.h index 012ba933..37fe6812 100644 --- a/include/contentJson.h +++ b/include/contentJson.h @@ -21,6 +21,8 @@ typedef struct uint32_t _version; bool_t _updated; + bool_t _valid; + } contentJson_t; #define CONTENT_JSON_VERSION 4 diff --git a/src/contentJson.c b/src/contentJson.c index 23d6613b..5708e112 100644 --- a/src/contentJson.c +++ b/src/contentJson.c @@ -174,6 +174,11 @@ error_t load_content_json(const char *content_path, contentJson_t *content_json) osFreeMem(jsonPath); + if (error == NO_ERROR) + { + content_json->_valid = true; + } + return error; } @@ -229,6 +234,7 @@ error_t save_content_json(const char *content_path, contentJson_t *content_json) void free_content_json(contentJson_t *content_json) { + content_json->_valid = false; if (content_json->source) { osFreeMem(content_json->source); diff --git a/src/handler.c b/src/handler.c index 3a5cfa08..207a1c9c 100644 --- a/src/handler.c +++ b/src/handler.c @@ -245,6 +245,7 @@ tonie_info_t getTonieInfo(const char *contentPath, settings_t *settings) tonieInfo.contentConfig.cloud_auth = NULL; tonieInfo.contentConfig.cloud_auth_len = 0; tonieInfo.contentConfig.tonie_model = NULL; + tonieInfo.contentConfig._valid = false; if (osStrstr(contentPath, ".json") == NULL) { @@ -275,19 +276,22 @@ tonie_info_t getTonieInfo(const char *contentPath, settings_t *settings) { tonieInfo.valid = true; toniesJson_item_t *toniesJson = tonies_byAudioId(tonieInfo.tafHeader->audio_id); - if (toniesJson != NULL && osStrcmp(tonieInfo.contentConfig.tonie_model, "") == 0) + if (tonieInfo.contentConfig._valid) { - if (osStrcmp(tonieInfo.contentConfig.tonie_model, toniesJson->model) != 0) + if (toniesJson != NULL && osStrcmp(tonieInfo.contentConfig.tonie_model, "") == 0) { - osFreeMem(tonieInfo.contentConfig.tonie_model); - tonieInfo.contentConfig.tonie_model = strdup(toniesJson->model); - tonieInfo.contentConfig._updated = true; + if (osStrcmp(tonieInfo.contentConfig.tonie_model, toniesJson->model) != 0) + { + osFreeMem(tonieInfo.contentConfig.tonie_model); + tonieInfo.contentConfig.tonie_model = strdup(toniesJson->model); + tonieInfo.contentConfig._updated = true; + } + } + else if (toniesJson == NULL && osStrcmp(tonieInfo.contentConfig.tonie_model, "") != 0) + { + // TODO add to tonies.custom.json + report + TRACE_WARNING("Audio-id %08X unknown but previous content known by model %s.\r\n", tonieInfo.tafHeader->audio_id, tonieInfo.contentConfig.tonie_model); } - } - else if (toniesJson == NULL && osStrcmp(tonieInfo.contentConfig.tonie_model, "") != 0) - { - // TODO add to tonies.custom.json + report - TRACE_WARNING("Audio-id %08X unknown but previous content known by model %s.\r\n", tonieInfo.tafHeader->audio_id, tonieInfo.contentConfig.tonie_model); } if (tonieInfo.tafHeader->num_bytes == TONIE_LENGTH_MAX)