add default json file
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include <QApplication>
|
||||
#include "json/cJSON.h"
|
||||
const char* strProductFileName = "./cfgs/usct-product.json";
|
||||
|
||||
const char* strProductFileNameDefault = "./cfgs/usct-product";
|
||||
JsonObject::JsonObject()
|
||||
{
|
||||
loadcfg();
|
||||
@@ -243,8 +243,32 @@ bool JsonObject::loadcfg()
|
||||
{
|
||||
if (m_bLoaded)
|
||||
return true;
|
||||
|
||||
std::ifstream inFile(strProductFileName);
|
||||
if (!inFile.is_open())
|
||||
{
|
||||
return loadcfgDefault();
|
||||
}
|
||||
std::stringstream ss;
|
||||
ss << inFile.rdbuf();
|
||||
std::string strJsonData = ss.str();
|
||||
json_root = cJSON_Parse(strJsonData.c_str());
|
||||
inFile.close();
|
||||
|
||||
|
||||
if (!json_root)
|
||||
return loadcfgDefault();
|
||||
|
||||
m_bLoaded = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool JsonObject::loadcfgDefault()
|
||||
{
|
||||
|
||||
std::ifstream inFile(strProductFileNameDefault);
|
||||
if (!inFile.is_open())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -252,8 +276,8 @@ bool JsonObject::loadcfg()
|
||||
ss << inFile.rdbuf();
|
||||
std::string strJsonData = ss.str();
|
||||
json_root = cJSON_Parse(strJsonData.c_str());
|
||||
|
||||
inFile.close();
|
||||
|
||||
if (!json_root)
|
||||
return false;
|
||||
|
||||
@@ -261,7 +285,6 @@ bool JsonObject::loadcfg()
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool JsonObject::savecfg()
|
||||
{
|
||||
if (!m_bLoaded)
|
||||
|
||||
@@ -110,6 +110,7 @@ private:
|
||||
|
||||
|
||||
bool loadcfg();
|
||||
bool loadcfgDefault();
|
||||
bool savecfg();
|
||||
|
||||
JsonObject();
|
||||
|
||||
Reference in New Issue
Block a user