From a980217708c904656e7989ac34a4bd4fb700c468 Mon Sep 17 00:00:00 2001 From: Willard <4367282+TheWillard@users.noreply.github.com> Date: Sat, 23 Mar 2024 17:59:48 +0100 Subject: [PATCH] empty checks for house, rivers & roads (#45) * empty checks for house & rivers * fix: check for not extracted road files --- src/geojsons.cpp | 16 ++++++++++++++-- src/main.cpp | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/geojsons.cpp b/src/geojsons.cpp index 5bc6a1b..1358598 100644 --- a/src/geojsons.cpp +++ b/src/geojsons.cpp @@ -161,7 +161,10 @@ void writeHouses(rvff::cxx::OprwCxx& wrp, std::filesystem::path& basePathGeojson mapFeature["properties"] = { { "color", color }, { "height", houseHeight }, { "position", housePos } }; house.push_back(mapFeature); } - writeGZJson("house.geojson.gz", basePathGeojson, house); + + if (!house.is_null() && house.is_array() && !house.empty()) { + writeGZJson("house.geojson.gz", basePathGeojson, house); + } } void writeObjects(rvff::cxx::OprwCxx& wrp, std::filesystem::path& basePathGeojson) @@ -226,12 +229,19 @@ void writeRoads( auto prefix = roads_pbo->get_prefix(); + bool noRoadFilesExtracted = true; for (auto& entry : roads_pbo->get_pbo().entries) { if (boost::istarts_with((((fs::path)static_cast(prefix)) / static_cast(entry.filename)).string(), roadsPathDir)) { roads_pbo->extract_single_file(static_cast(entry.filename), basePathGeojsonTemp.string(), false); + noRoadFilesExtracted = false; } } + if (noRoadFilesExtracted) { + PLOG_ERROR << "Couldn't find or extract any road files. No roads will be exported!"; + return; + } + auto gdalPath = getDllPath(); #ifdef _WIN32 // get appdata path @@ -811,7 +821,9 @@ void writeRiver(rvff::cxx::OprwCxx& wrp, std::filesystem::path& basePathGeojson) rivers.push_back(river); } - writeGZJson("river.geojson.gz", basePathGeojson, rivers); + if (!rivers.is_null() && rivers.is_array() && !rivers.empty()) { + writeGZJson("river.geojson.gz", basePathGeojson, rivers); + } } void writeMounts(rvff::cxx::OprwCxx& wrp, fs::path& basePathGeojson) { diff --git a/src/main.cpp b/src/main.cpp index 08949ca..8a44517 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -209,6 +209,7 @@ void extractMap(const std::string &worldName, const std::string &worldPath, std: startMsg << "]"; prettyDiagLog(startMsg.str()); + PLOG_INFO << startMsg.str(); if (!fs::exists(basePath)) {