diff --git a/client/globalLobby/GlobalLobbyClient.cpp b/client/globalLobby/GlobalLobbyClient.cpp index 9b58d782f..018af2334 100644 --- a/client/globalLobby/GlobalLobbyClient.cpp +++ b/client/globalLobby/GlobalLobbyClient.cpp @@ -43,7 +43,7 @@ void GlobalLobbyClient::onPacketReceived(const std::shared_ptr"); if(json["type"].String() == "accountCreated") return receiveAccountCreated(json); diff --git a/client/render/CAnimation.cpp b/client/render/CAnimation.cpp index 93549f333..9feaf51a4 100644 --- a/client/render/CAnimation.cpp +++ b/client/render/CAnimation.cpp @@ -191,7 +191,7 @@ void CAnimation::init() std::unique_ptr textData(new ui8[stream->getSize()]); stream->read(textData.get(), stream->getSize()); - const JsonNode config(reinterpret_cast(textData.get()), stream->getSize()); + const JsonNode config(reinterpret_cast(textData.get()), stream->getSize(), jsonResource.getName()); initFromJson(config); } diff --git a/launcher/jsonutils.cpp b/launcher/jsonutils.cpp index 4635e9f50..e4eb884d6 100644 --- a/launcher/jsonutils.cpp +++ b/launcher/jsonutils.cpp @@ -89,7 +89,7 @@ QVariant JsonFromFile(QString filename) } const auto data = file.readAll(); - JsonNode node(reinterpret_cast(data.data()), data.size()); + JsonNode node(reinterpret_cast(data.data()), data.size(), filename.toStdString()); return toVariant(node); } diff --git a/launcher/updatedialog_moc.cpp b/launcher/updatedialog_moc.cpp index 6c9825868..2de3aba7d 100644 --- a/launcher/updatedialog_moc.cpp +++ b/launcher/updatedialog_moc.cpp @@ -67,7 +67,7 @@ UpdateDialog::UpdateDialog(bool calledManually, QWidget *parent): } auto byteArray = response->readAll(); - JsonNode node(reinterpret_cast(byteArray.constData()), byteArray.size()); + JsonNode node(reinterpret_cast(byteArray.constData()), byteArray.size(), ""); loadFromJson(node); }); } diff --git a/lib/campaign/CampaignHandler.cpp b/lib/campaign/CampaignHandler.cpp index f4099a827..5de4f9c7b 100644 --- a/lib/campaign/CampaignHandler.cpp +++ b/lib/campaign/CampaignHandler.cpp @@ -46,7 +46,7 @@ void CampaignHandler::readCampaign(Campaign * ret, const std::vector & inpu } else // text format (json) { - JsonNode jsonCampaign(reinterpret_cast(input.data()), input.size()); + JsonNode jsonCampaign(reinterpret_cast(input.data()), input.size(), filename); readHeaderFromJson(*ret, jsonCampaign, filename, modName, encoding); for(auto & scenario : jsonCampaign["scenarios"].Vector()) diff --git a/lib/filesystem/Filesystem.cpp b/lib/filesystem/Filesystem.cpp index 7b4821c5c..b873e0718 100644 --- a/lib/filesystem/Filesystem.cpp +++ b/lib/filesystem/Filesystem.cpp @@ -117,7 +117,7 @@ void CFilesystemGenerator::loadJsonMap(const std::string &mountPoint, const Json if (filename) { auto configData = CResourceHandler::get("initial")->load(JsonPath::builtin(URI))->readAll(); - const JsonNode configInitial(reinterpret_cast(configData.first.get()), configData.second); + const JsonNode configInitial(reinterpret_cast(configData.first.get()), configData.second, URI); filesystem->addLoader(new CMappedFileLoader(mountPoint, configInitial), false); } } @@ -212,7 +212,7 @@ void CResourceHandler::load(const std::string &fsConfigURI, bool extractArchives { auto fsConfigData = get("initial")->load(JsonPath::builtin(fsConfigURI))->readAll(); - const JsonNode fsConfig(reinterpret_cast(fsConfigData.first.get()), fsConfigData.second); + const JsonNode fsConfig(reinterpret_cast(fsConfigData.first.get()), fsConfigData.second, fsConfigURI); addFilesystem("data", ModScope::scopeBuiltin(), createFileSystem("", fsConfig["filesystem"], extractArchives)); } diff --git a/lib/json/JsonNode.cpp b/lib/json/JsonNode.cpp index 32712c85a..4d0e7ddd5 100644 --- a/lib/json/JsonNode.cpp +++ b/lib/json/JsonNode.cpp @@ -86,15 +86,15 @@ JsonNode::JsonNode(const std::string & string) { } -JsonNode::JsonNode(const std::byte * data, size_t datasize) - : JsonNode(data, datasize, JsonParsingSettings()) +JsonNode::JsonNode(const std::byte * data, size_t datasize, const std::string & fileName) + : JsonNode(data, datasize, JsonParsingSettings(), fileName) { } -JsonNode::JsonNode(const std::byte * data, size_t datasize, const JsonParsingSettings & parserSettings) +JsonNode::JsonNode(const std::byte * data, size_t datasize, const JsonParsingSettings & parserSettings, const std::string & fileName) { JsonParser parser(data, datasize, parserSettings); - *this = parser.parse(""); + *this = parser.parse(fileName); } JsonNode::JsonNode(const JsonPath & fileURI) diff --git a/lib/json/JsonNode.h b/lib/json/JsonNode.h index c4afbcae1..7ed8ae9ae 100644 --- a/lib/json/JsonNode.h +++ b/lib/json/JsonNode.h @@ -72,8 +72,8 @@ public: explicit JsonNode(const std::string & string); /// Create tree from Json-formatted input - explicit JsonNode(const std::byte * data, size_t datasize); - explicit JsonNode(const std::byte * data, size_t datasize, const JsonParsingSettings & parserSettings); + explicit JsonNode(const std::byte * data, size_t datasize, const std::string & fileName); + explicit JsonNode(const std::byte * data, size_t datasize, const JsonParsingSettings & parserSettings, const std::string & fileName); /// Create tree from JSON file explicit JsonNode(const JsonPath & fileURI); diff --git a/lib/json/JsonParser.cpp b/lib/json/JsonParser.cpp index 320005b25..f3ad1ab9b 100644 --- a/lib/json/JsonParser.cpp +++ b/lib/json/JsonParser.cpp @@ -55,7 +55,7 @@ JsonNode JsonParser::parse(const std::string & fileName) if(!errors.empty()) { - logMod->warn("File %s is not a valid JSON file!", fileName); + logMod->warn("%s is not valid JSON!", fileName); logMod->warn(errors); } return root; diff --git a/lib/json/JsonUtils.cpp b/lib/json/JsonUtils.cpp index f2ea7a78e..f1680e11f 100644 --- a/lib/json/JsonUtils.cpp +++ b/lib/json/JsonUtils.cpp @@ -269,7 +269,7 @@ JsonNode JsonUtils::assembleFromFiles(const std::string & filename) for(auto & loader : CResourceHandler::get()->getResourcesWithName(resID)) { auto textData = loader->load(resID)->readAll(); - JsonNode section(reinterpret_cast(textData.first.get()), textData.second); + JsonNode section(reinterpret_cast(textData.first.get()), textData.second, resID.getName()); merge(result, section); } return result; diff --git a/lib/mapping/MapFormatJson.cpp b/lib/mapping/MapFormatJson.cpp index eaa966959..cc6ba42f5 100644 --- a/lib/mapping/MapFormatJson.cpp +++ b/lib/mapping/MapFormatJson.cpp @@ -813,7 +813,7 @@ JsonNode CMapLoaderJson::getFromArchive(const std::string & archiveFilename) auto data = loader.load(resource)->readAll(); - JsonNode res(reinterpret_cast(data.first.get()), data.second); + JsonNode res(reinterpret_cast(data.first.get()), data.second, archiveFilename); return res; } diff --git a/lobby/LobbyServer.cpp b/lobby/LobbyServer.cpp index 6ee3afba1..7f1a08635 100644 --- a/lobby/LobbyServer.cpp +++ b/lobby/LobbyServer.cpp @@ -213,7 +213,7 @@ static JsonNode loadLobbyGameRoomToJson(const LobbyGameRoom & gameRoom) jsonEntry["playerLimit"].Integer() = gameRoom.playerLimit; jsonEntry["ageSeconds"].Integer() = gameRoom.age.count(); if (!gameRoom.modsJson.empty()) // not present in match history - jsonEntry["mods"] = JsonNode(reinterpret_cast(gameRoom.modsJson.data()), gameRoom.modsJson.size()); + jsonEntry["mods"] = JsonNode(reinterpret_cast(gameRoom.modsJson.data()), gameRoom.modsJson.size(), ""); for(const auto & account : gameRoom.participants) jsonEntry["participants"].Vector().push_back(loadLobbyAccountToJson(account)); @@ -348,7 +348,7 @@ JsonNode LobbyServer::parseAndValidateMessage(const std::vector & mes JsonNode json; try { - JsonNode jsonTemp(message.data(), message.size()); + JsonNode jsonTemp(message.data(), message.size(), ""); json = std::move(jsonTemp); } catch (const JsonFormatException & e) diff --git a/mapeditor/Animation.cpp b/mapeditor/Animation.cpp index 16019a65a..94e217610 100644 --- a/mapeditor/Animation.cpp +++ b/mapeditor/Animation.cpp @@ -599,7 +599,7 @@ void Animation::init() std::unique_ptr textData(new ui8[stream->getSize()]); stream->read(textData.get(), stream->getSize()); - const JsonNode config(reinterpret_cast(textData.get()), stream->getSize()); + const JsonNode config(reinterpret_cast(textData.get()), stream->getSize(), resID.getName()); initFromJson(config); } diff --git a/mapeditor/jsonutils.cpp b/mapeditor/jsonutils.cpp index f7ce677bb..5ab2335af 100644 --- a/mapeditor/jsonutils.cpp +++ b/mapeditor/jsonutils.cpp @@ -97,7 +97,7 @@ QVariant JsonFromFile(QString filename) } else { - JsonNode node(reinterpret_cast(data.data()), data.size()); + JsonNode node(reinterpret_cast(data.data()), data.size(), filename.toStdString()); return toVariant(node); } } diff --git a/server/GlobalLobbyProcessor.cpp b/server/GlobalLobbyProcessor.cpp index 7effca617..15fd376f7 100644 --- a/server/GlobalLobbyProcessor.cpp +++ b/server/GlobalLobbyProcessor.cpp @@ -67,7 +67,7 @@ void GlobalLobbyProcessor::onPacketReceived(const std::shared_ptr"); if(json["type"].String() == "operationFailed") return receiveOperationFailed(json); diff --git a/test/map/CMapFormatTest.cpp b/test/map/CMapFormatTest.cpp index 176d5d916..21dec61b0 100644 --- a/test/map/CMapFormatTest.cpp +++ b/test/map/CMapFormatTest.cpp @@ -95,7 +95,7 @@ static JsonNode getFromArchive(CZipLoader & archive, const std::string & archive auto data = archive.load(resource)->readAll(); - JsonNode res(reinterpret_cast(data.first.get()), data.second); + JsonNode res(reinterpret_cast(data.first.get()), data.second, resource.getName()); return res; }