From 02f39840c2749414c138bfbfaf3a2bcc72c4ef29 Mon Sep 17 00:00:00 2001 From: elexis Date: Mon, 20 Jan 2020 09:58:03 +0000 Subject: [PATCH] Show an error message instead of triggering a debug breakpoint if a GUI page attempts to include a directory or file from an invalid path. Differential Revision: https://code.wildfiregames.com/D2363 Patch By: nani This was SVN commit r23420. --- source/gui/CGUI.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index d4a45bb400..22b463aa59 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -858,22 +858,32 @@ void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, std::unor // If there is a file specified, open and execute it if (!file.empty()) { - Paths.insert(file); - m_ScriptInterface->LoadGlobalScriptFile(file); + if (!VfsPath(file).IsDirectory()) + { + Paths.insert(file); + m_ScriptInterface->LoadGlobalScriptFile(file); + } + else + LOGERROR("GUI: Script path %s is not a file path", file.ToUTF8().c_str()); } // If it has a directory attribute, read all JS files in that directory CStrW directory(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("directory")).FromUTF8()); if (!directory.empty()) { - VfsPaths pathnames; - vfs::GetPathnames(g_VFS, directory, L"*.js", pathnames); - for (const VfsPath& path : pathnames) + if (VfsPath(directory).IsDirectory()) { - // Only load new files (so when the insert succeeds) - if (Paths.insert(path).second) - m_ScriptInterface->LoadGlobalScriptFile(path); + VfsPaths pathnames; + vfs::GetPathnames(g_VFS, directory, L"*.js", pathnames); + for (const VfsPath& path : pathnames) + { + // Only load new files (so when the insert succeeds) + if (Paths.insert(path).second) + m_ScriptInterface->LoadGlobalScriptFile(path); + } } + else + LOGERROR("GUI: Script path %s is not a directory path", directory.ToUTF8().c_str()); } CStr code(Element.GetText());