Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Jan 17, 2023
1 parent 0dfbc0d commit 0800d60
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions ScriptEngine/src/utils/JsonHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,25 @@ inline fifo_json CreateJson(const std::string& path, const std::string& defConte
fifo_json jsonConf;
if (!filesystem::exists(str2wstr(path)))
{
//创建新的
CreateDirs(path);
if (path.find('/') != std::string::npos) {
std::size_t pos = path.find_last_of('/');
if (pos != std::string::npos) {
std::string dirPath = path.substr(0, pos);
CreateDirs(dirPath);
}
} else if(path.find('\\') != std::string::npos) {
std::size_t pos = path.find_last_of('\\');
if (pos != std::string::npos) {
std::string dirPath = path.substr(0, pos);
CreateDirs(dirPath);
}
} else {
logger.error("Fail in create json file!");
logger.error("invalid path");
jsonConf = fifo_json::object();
}

if (defContent != "")
if (!defContent.empty())
{
try
{
Expand All @@ -42,7 +57,7 @@ inline fifo_json CreateJson(const std::string& path, const std::string& defConte
}

ofstream jsonFile(path);
if (jsonFile.is_open() && defContent != "")
if (jsonFile.is_open() && !defContent.empty())
jsonFile << jsonConf.dump(4);
jsonFile.close();
}
Expand Down

0 comments on commit 0800d60

Please sign in to comment.