Skip to content

Commit

Permalink
_valid for contentJson
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Oct 3, 2023
1 parent 6760cb5 commit 3a7f572
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions include/contentJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ typedef struct
uint32_t _version;
bool_t _updated;

bool_t _valid;

} contentJson_t;

#define CONTENT_JSON_VERSION 4
Expand Down
6 changes: 6 additions & 0 deletions src/contentJson.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
24 changes: 14 additions & 10 deletions src/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3a7f572

Please sign in to comment.