From cc75ce55cbff29b8ef99ea17ae34af84ee80ed99 Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Sun, 22 Dec 2024 02:55:31 +0100 Subject: [PATCH] RMG-Core: fix crash on windows when opening an archive in Rom.cpp --- Source/RMG-Core/Rom.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Source/RMG-Core/Rom.cpp b/Source/RMG-Core/Rom.cpp index 918cd9a5..72554c36 100644 --- a/Source/RMG-Core/Rom.cpp +++ b/Source/RMG-Core/Rom.cpp @@ -196,7 +196,18 @@ static bool read_zip_file(std::filesystem::path file, std::filesystem::path& ext // make sure file has supported file format, // if it does, read it in memory - std::filesystem::path fileNamePath(fileName); + std::filesystem::path fileNamePath; + // Windows sometimes throws an exception when assigning a string to a path + // due to being unable to convert the character sequence. + // so we have to catch the exception and do nothing + try + { + fileNamePath = fileName; + } + catch (...) + { + // ignore exception + } std::string fileExtension = fileNamePath.has_extension() ? fileNamePath.extension().string() : ""; fileExtension = to_lower_str(fileExtension); if (fileExtension == ".z64" || @@ -355,7 +366,18 @@ static bool read_7zip_file(std::filesystem::path file, std::filesystem::path& ex SzArEx_GetFileNameUtf16(&db, i, fileName); - std::filesystem::path fileNamePath((char16_t*)fileName); + std::filesystem::path fileNamePath; + // Windows sometimes throws an exception when assigning a string to a path + // due to being unable to convert the character sequence. + // so we have to catch the exception and do nothing + try + { + fileNamePath = (char16_t*)fileName; + } + catch (...) + { + // ignore exception + } std::string fileExtension = fileNamePath.has_extension() ? fileNamePath.extension().string() : ""; fileExtension = to_lower_str(fileExtension); if (fileExtension == ".z64" ||