From 412c4547cd49e50bb84dfbaf92cd75bf535e7f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 28 Aug 2023 16:34:58 +0200 Subject: [PATCH] textures.ini loader logging improvement --- Common/Data/Format/IniFile.cpp | 11 +++++++++++ Common/Data/Format/IniFile.h | 1 + GPU/Common/TextureReplacer.cpp | 10 +++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Common/Data/Format/IniFile.cpp b/Common/Data/Format/IniFile.cpp index ba5055983b..ed601a38e2 100644 --- a/Common/Data/Format/IniFile.cpp +++ b/Common/Data/Format/IniFile.cpp @@ -403,6 +403,17 @@ std::map Section::ToMap() const return outMap; } +std::vector> Section::ToVec() const { + std::vector> outVec; + for (std::vector::const_iterator iter = lines.begin(); iter != lines.end(); ++iter) + { + std::string lineKey, lineValue; + if (ParseLine(*iter, &lineKey, &lineValue, NULL)) { + outVec.push_back(std::pair(lineKey, lineValue)); + } + } + return outVec; +} bool Section::Delete(const char *key) { diff --git a/Common/Data/Format/IniFile.h b/Common/Data/Format/IniFile.h index 528ece1f1c..8860161337 100644 --- a/Common/Data/Format/IniFile.h +++ b/Common/Data/Format/IniFile.h @@ -28,6 +28,7 @@ public: void Clear(); std::map ToMap() const; + std::vector> ToVec() const; // Often more appropriate than ToMap() - doesn't artifically remove duplicates. std::string *GetLine(const char* key, std::string* valueOut, std::string* commentOut); const std::string *GetLine(const char* key, std::string* valueOut, std::string* commentOut) const; diff --git a/GPU/Common/TextureReplacer.cpp b/GPU/Common/TextureReplacer.cpp index 5e7b471c62..087d59f3aa 100644 --- a/GPU/Common/TextureReplacer.cpp +++ b/GPU/Common/TextureReplacer.cpp @@ -231,13 +231,15 @@ bool TextureReplacer::LoadIniValues(IniFile &ini, VFSBackend *dir, bool isOverri std::map> filenameMap; if (ini.HasSection("hashes")) { - auto hashes = ini.GetOrCreateSection("hashes")->ToMap(); + auto hashes = ini.GetOrCreateSection("hashes")->ToVec(); // Format: hashname = filename.png bool checkFilenames = g_Config.bSaveNewTextures && !g_Config.bIgnoreTextureFilenames && !vfsIsZip_; for (const auto &item : hashes) { ReplacementCacheKey key(0, 0); - int level = 0; // sscanf might fail to pluck the level, but that's ok, we default to 0. sscanf doesn't write to non-matched outputs. + // sscanf might fail to pluck the level if omitted from the line, but that's ok, we default level to 0. + // sscanf doesn't write to non-matched outputs. + int level = 0; if (sscanf(item.first.c_str(), "%16llx%8x_%d", &key.cachekey, &key.hash, &level) >= 1) { filenameMap[key][level] = item.second; if (checkFilenames) { @@ -249,8 +251,10 @@ bool TextureReplacer::LoadIniValues(IniFile &ini, VFSBackend *dir, bool isOverri filenameWarning = filenameWarning || item.second.find_first_of("\\:<>|?*") != std::string::npos; #endif } + } else if (item.first.empty()) { + INFO_LOG(G3D, "Ignoring [hashes] line with empty key: '= %s'", item.second.c_str()); } else { - ERROR_LOG(G3D, "Unsupported syntax under [hashes]: %s", item.first.c_str()); + ERROR_LOG(G3D, "Unsupported syntax under [hashes], ignoring: %s = ", item.first.c_str()); } } }