From a35a2838b6bd2681d87d3ecd15b9fec2427bc968 Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 13 Sep 2020 19:57:35 +0200 Subject: [PATCH] Fix XML loading not handling UTF-8 paths --- src/frontend-common/game_list.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/frontend-common/game_list.cpp b/src/frontend-common/game_list.cpp index 0cd9c88f7..d2a3ff126 100644 --- a/src/frontend-common/game_list.cpp +++ b/src/frontend-common/game_list.cpp @@ -740,8 +740,12 @@ void GameList::LoadDatabase() if (m_database_filename.empty()) return; + auto fp = FileSystem::OpenManagedCFile(m_database_filename.c_str(), "rb"); + if (!fp) + return; + tinyxml2::XMLDocument doc; - tinyxml2::XMLError error = doc.LoadFile(m_database_filename.c_str()); + tinyxml2::XMLError error = doc.LoadFile(fp.get()); if (error != tinyxml2::XML_SUCCESS) { Log_ErrorPrintf("Failed to parse redump dat '%s': %s", m_database_filename.c_str(), @@ -858,8 +862,12 @@ void GameList::LoadCompatibilityList() if (m_compatibility_list_filename.empty()) return; + auto fp = FileSystem::OpenManagedCFile(m_compatibility_list_filename.c_str(), "rb"); + if (!fp) + return; + tinyxml2::XMLDocument doc; - tinyxml2::XMLError error = doc.LoadFile(m_compatibility_list_filename.c_str()); + tinyxml2::XMLError error = doc.LoadFile(fp.get()); if (error != tinyxml2::XML_SUCCESS) { Log_ErrorPrintf("Failed to parse compatibility list '%s': %s", m_compatibility_list_filename.c_str(), @@ -989,11 +997,12 @@ bool GameList::SaveCompatibilityDatabaseForEntry(const GameListCompatibilityEntr if (m_compatibility_list_filename.empty()) return false; - if (!FileSystem::FileExists(m_compatibility_list_filename.c_str())) + auto fp = FileSystem::OpenManagedCFile(m_compatibility_list_filename.c_str(), "rb"); + if (!fp) return SaveCompatibilityDatabase(); tinyxml2::XMLDocument doc; - tinyxml2::XMLError error = doc.LoadFile(m_compatibility_list_filename.c_str()); + tinyxml2::XMLError error = doc.LoadFile(fp.get()); if (error != tinyxml2::XML_SUCCESS) { Log_ErrorPrintf("Failed to parse compatibility list '%s': %s", m_compatibility_list_filename.c_str(),