MCPcopy Create free account
hub / github.com/TurningWheel/Barony / writeToFile

Method writeToFile

src/mod_tools.cpp:9600–9843  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9598ClassHotbarConfig_t::ClassHotbar_t ClassHotbarConfig_t::ClassHotbars[NUMCLASSES];
9599
9600void ClassHotbarConfig_t::writeToFile(HotbarConfigType fileWriteType, HotbarConfigWriteMode writeMode)
9601{
9602 std::string outputDir = "/config/";
9603 if ( fileWriteType == HOTBAR_LAYOUT_DEFAULT_CONFIG )
9604 {
9605 outputDir = "/data/";
9606 }
9607
9608 if ( !PHYSFS_getRealDir(outputDir.c_str()) )
9609 {
9610 printlog("[JSON]: ClassHotbarConfig_t: %s directory not found", outputDir.c_str());
9611 return;
9612 }
9613 std::string outputPath = PHYSFS_getRealDir(outputDir.c_str());
9614 outputPath.append(PHYSFS_getDirSeparator());
9615 std::string fileName = "config/class_hotbars.json";
9616 if ( fileWriteType == HOTBAR_LAYOUT_DEFAULT_CONFIG )
9617 {
9618 fileName = "data/class_hotbars.json";
9619 }
9620 outputPath.append(fileName.c_str());
9621
9622 rapidjson::Document exportDocument;
9623 bool writeNewFile = true;
9624 if ( fileWriteType == HOTBAR_LAYOUT_CUSTOM_CONFIG )
9625 {
9626 File* fp = FileIO::open(outputPath.c_str(), "rb");
9627 if ( !fp )
9628 {
9629 if ( writeMode == HOTBAR_CONFIG_DELETE )
9630 {
9631 printlog("[JSON]: Could not locate json file %s, skipping deletion...", outputPath.c_str());
9632 return;
9633 }
9634 else
9635 {
9636 printlog("[JSON]: Could not locate json file %s, creating new file...", outputPath.c_str());
9637 fp = FileIO::open(outputPath.c_str(), "wb");
9638 if ( !fp )
9639 {
9640 printlog("[JSON]: Error opening json file %s for write!", outputPath.c_str());
9641 return;
9642 }
9643 exportDocument.SetObject();
9644 }
9645 }
9646 else
9647 {
9648 char buf[80000];
9649 int count = fp->read(buf, sizeof(buf[0]), sizeof(buf) - 1);
9650 buf[count] = '\0';
9651 rapidjson::StringStream is(buf);
9652 FileIO::close(fp);
9653
9654 exportDocument.ParseStream(is);
9655 printlog("[JSON]: Loaded existing file %s", outputPath.c_str());
9656 writeNewFile = false;
9657 }

Callers

nothing calls this directly

Calls 14

printlogFunction · 0.85
uidToItemFunction · 0.85
getSpellFromItemFunction · 0.85
completePathFunction · 0.85
c_strMethod · 0.80
appendMethod · 0.80
SetIntMethod · 0.80
initClassFunction · 0.70
readMethod · 0.45
ClearMethod · 0.45
clearStatsMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected