66#include  <cJSON.h> 
77
88static  cJSON  * config_root  =  NULL ;
9+ static  bool  safe_mode  =  false;
910
1011
1112static  cJSON  * json_root (const  char  * name , bool  set_dirty )
@@ -30,23 +31,25 @@ static cJSON *json_root(const char *name, bool set_dirty)
3031        branch  =  cJSON_AddObjectToObject (config_root , name );
3132        cJSON_AddStringToObject (branch , "namespace" , name );
3233        cJSON_AddNumberToObject (branch , "changed" , 0 );
33- 
34-         char  * data ; size_t  data_len ;
35-         char  pathbuf [RG_PATH_MAX ];
36-         snprintf (pathbuf , RG_PATH_MAX , "%s/%s.json" , RG_BASE_PATH_CONFIG , name );
37-         if  (rg_storage_read_file (pathbuf , (void  * * )& data , & data_len , 0 ))
34+         if  (!safe_mode )
3835        {
39-             cJSON   * values   =   cJSON_Parse ( data ) ;
40-             if  (! values )  // Parse failure, clean the markup and try again 
41-                  values   =   cJSON_Parse ( rg_json_fixup ( data ) );
42-             if  (values )
36+             char   * data ;  size_t   data_len ;
37+             char   pathbuf [ RG_PATH_MAX ]; 
38+             snprintf ( pathbuf ,  RG_PATH_MAX ,  "%s/%s.json" ,  RG_BASE_PATH_CONFIG ,  name );
39+             if  (rg_storage_read_file ( pathbuf , ( void   * * ) & data ,  & data_len ,  0 ) )
4340            {
44-                 RG_LOGI ("Config file loaded: '%s'" , pathbuf );
45-                 cJSON_AddItemToObject (branch , "values" , values );
41+                 cJSON  * values  =  cJSON_Parse (data );
42+                 if  (!values ) // Parse failure, clean the markup and try again 
43+                     values  =  cJSON_Parse (rg_json_fixup (data ));
44+                 if  (values )
45+                 {
46+                     RG_LOGI ("Config file loaded: '%s'" , pathbuf );
47+                     cJSON_AddItemToObject (branch , "values" , values );
48+                 }
49+                 else 
50+                     RG_LOGE ("Config file parsing failed: '%s'" , pathbuf );
51+                 free (data );
4652            }
47-             else 
48-                 RG_LOGE ("Config file parsing failed: '%s'" , pathbuf );
49-             free (data );
5053        }
5154    }
5255
@@ -76,16 +79,17 @@ static void update_value(const char *section, const char *key, cJSON *new_value)
7679        cJSON_Delete (new_value );
7780}
7881
79- void  rg_settings_init (void )
82+ void  rg_settings_init (bool   _safe_mode )
8083{
8184    config_root  =  cJSON_CreateObject ();
85+     safe_mode  =  _safe_mode ;
8286    json_root (NS_GLOBAL , 0 );
8387    json_root (NS_BOOT , 0 );
8488}
8589
8690void  rg_settings_commit (void )
8791{
88-     if  (!config_root )
92+     if  (!config_root   ||   safe_mode )
8993        return ;
9094
9195    for  (cJSON  * branch  =  config_root -> child ; branch ; branch  =  branch -> next )
0 commit comments