|
@@ -249,7 +249,43 @@ cmPrNode_t* _cmPrefsPathToNodePtr( cmPr_t* p, const cmChar_t* pathStr, bool repo
|
249
|
249
|
return _cmPrefsIdToNodePtr(p,id, reportErrFl);
|
250
|
250
|
}
|
251
|
251
|
|
252
|
|
-cmPrRC_t cmPrefsInitialize( cmPrH_t* hp, const cmChar_t* fn, cmPrefsOnChangeFunc_t cbFunc, void* cbDataPtr, cmCtx_t* ctx )
|
|
252
|
+cmPrRC_t cmPrefsInit( cmCtx_t* ctx, cmPrH_t* prefsH, const cmChar_t* fnName, const cmChar_t* fnExt, cmPrefsOnChangeFunc_t cbFunc, void* cbDataPtr )
|
|
253
|
+{
|
|
254
|
+ cmPrRC_t rc = kOkPrRC;
|
|
255
|
+
|
|
256
|
+ const cmChar_t* prefsDir = cmFsPrefsDir();
|
|
257
|
+ const cmChar_t* prefsFn = NULL;
|
|
258
|
+
|
|
259
|
+ if( fnName == NULL )
|
|
260
|
+ fnName = cmFsAppName();
|
|
261
|
+
|
|
262
|
+ if( fnExt == NULL )
|
|
263
|
+ fnExt = ".js";
|
|
264
|
+
|
|
265
|
+ // if the prefs directory does not exist then create it
|
|
266
|
+ if( cmFsIsDir(prefsDir) == false )
|
|
267
|
+ {
|
|
268
|
+ if( cmFsMkDir(prefsDir) != kOkFsRC )
|
|
269
|
+ {
|
|
270
|
+ rc = cmErrMsg(&ctx->err,kFileSysFailPrRC,"The preference directory '%s' could not be created.",prefsDir);
|
|
271
|
+ goto errLabel;
|
|
272
|
+ }
|
|
273
|
+ }
|
|
274
|
+
|
|
275
|
+ // create the preference file name
|
|
276
|
+ if((prefsFn = cmFsMakeFn( prefsDir, fnName, fnExt, NULL )) == NULL )
|
|
277
|
+ {
|
|
278
|
+ rc = cmErrMsg(&ctx->err,kFileSysFailPrRC,"The preference file name could not be formed.");
|
|
279
|
+ goto errLabel;
|
|
280
|
+ }
|
|
281
|
+
|
|
282
|
+ // initialize the preference manager
|
|
283
|
+ rc = cmPrefsInitialize(ctx,prefsH,prefsFn,cbFunc,cbDataPtr);
|
|
284
|
+
|
|
285
|
+ errLabel:
|
|
286
|
+ return rc;
|
|
287
|
+}
|
|
288
|
+cmPrRC_t cmPrefsInitialize( cmCtx_t* ctx, cmPrH_t* hp, const cmChar_t* fn, cmPrefsOnChangeFunc_t cbFunc, void* cbDataPtr )
|
253
|
289
|
{
|
254
|
290
|
cmPrRC_t rc = kOkPrRC;
|
255
|
291
|
|
|
@@ -1238,7 +1274,7 @@ cmPrRC_t _cmPrefsCreateJsonNode(
|
1238
|
1274
|
if( boolVal != NULL )
|
1239
|
1275
|
jsTypeId = *boolVal ? kTrueTId : kFalseTId;
|
1240
|
1276
|
|
1241
|
|
- if((jsnp = cmJsonInsertPair( p->jsH, jsnp, pathEleStr,jsTypeId, sv, rv, iv )) == NULL )
|
|
1277
|
+ if((jsnp = cmJsonInsertPair( p->jsH, jsnp, pathEleStr,jsTypeId, sv, iv, rv )) == NULL )
|
1242
|
1278
|
{
|
1243
|
1279
|
rc = cmErrMsg(&p->err,kInvalidIdPrRC,"Preference node create failed for '%s'",cmStringNullGuard(pathString));
|
1244
|
1280
|
goto errLabel;
|
|
@@ -1434,6 +1470,12 @@ cmPrRC_t cmPrefsWrite( cmPrH_t h, const cmChar_t* fn )
|
1434
|
1470
|
return rc;
|
1435
|
1471
|
}
|
1436
|
1472
|
|
|
1473
|
+void cmPrefsReport( cmPrH_t h )
|
|
1474
|
+{
|
|
1475
|
+ cmPr_t* p = _cmPrefsHandleToPtr(h);
|
|
1476
|
+ cmJsonReport(p->jsH);
|
|
1477
|
+}
|
|
1478
|
+
|
1437
|
1479
|
//=============================================================================================
|
1438
|
1480
|
// cmPrefsTest()
|
1439
|
1481
|
//
|
|
@@ -1494,7 +1536,7 @@ void _cmPrintNodes( const cmPrNode_t* np )
|
1494
|
1536
|
void cmPrefsTest( cmCtx_t* ctx, const char* ifn, const char* ofn )
|
1495
|
1537
|
{
|
1496
|
1538
|
cmPrH_t h = cmPrNullHandle;
|
1497
|
|
- if( cmPrefsInitialize(&h,ifn,NULL,NULL,ctx) != kOkPrRC )
|
|
1539
|
+ if( cmPrefsInitialize(ctx,&h,ifn,NULL,NULL) != kOkPrRC )
|
1498
|
1540
|
return;
|
1499
|
1541
|
|
1500
|
1542
|
cmPr_t* p = _cmPrefsHandleToPtr(h);
|