Skip to content

Commit

Permalink
Fix multitheftauto#3635 meta.xml file path patterns don't work on htm…
Browse files Browse the repository at this point in the history
…l files (multitheftauto#3780)

Add patterns for html
  • Loading branch information
FileEX authored Oct 13, 2024
1 parent 1fcd732 commit 7e6b4d0
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions Server/mods/deathmatch/logic/CResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,44 +1465,55 @@ bool CResource::ReadIncludedHTML(CXMLNode* pRoot)

if (!strFilename.empty())
{
std::string strFullFilename;
ReplaceSlashes(strFilename);

if (IsFilenameUsed(strFilename, false))
if (!IsValidFilePath(strFilename.c_str()))
{
CLogger::LogPrintf("WARNING: Duplicate html file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
m_strFailureReason = SString("Couldn't find html %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
}

// Try to find the file
if (IsValidFilePath(strFilename.c_str()) && GetFilePath(strFilename.c_str(), strFullFilename))
std::vector<std::string> vecFiles = GetFilePaths(strFilename.c_str());
if (vecFiles.empty())
{
// This one is supposed to be default, but there's already a default page
if (bFoundDefault && bIsDefault)
if (glob::has_magic(strFilename))
{
CLogger::LogPrintf("Only one html item can be default per resource, ignoring %s in %s\n", strFilename.c_str(),
m_strResourceName.c_str());
bIsDefault = false;
m_ResourceFilesCountPerDir[strFilename] = vecFiles.size();
continue;
}

// If this is supposed to be default, we've now found our default page
if (bIsDefault)
bFoundDefault = true;

// Create a new resource HTML file and add it to the list
auto pResourceFile = new CResourceHTMLItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes, bIsDefault, bIsRaw,
bIsRestricted, m_bOOPEnabledInMetaXml);
m_ResourceFiles.push_back(pResourceFile);

// This is the first HTML file? Remember it
if (!pFirstHTML)
pFirstHTML = pResourceFile;
}
else
{
m_strFailureReason = SString("Couldn't find html %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
}

for (const std::string& strFilePath : vecFiles)
{
std::string strFullFilename;

if (GetFilePath(strFilePath.c_str(), strFullFilename))
{
// This one is supposed to be default, but there's already a default page
if (bFoundDefault && bIsDefault)
{
CLogger::LogPrintf("Only one html item can be default per resource, ignoring %s in %s\n", strFilename.c_str(), m_strResourceName.c_str());
bIsDefault = false;
}

// If this is supposed to be default, we've now found our default page
if (bIsDefault)
bFoundDefault = true;

// Create a new resource HTML file and add it to the list
auto pResourceFile = new CResourceHTMLItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes, bIsDefault, bIsRaw, bIsRestricted, m_bOOPEnabledInMetaXml);
m_ResourceFiles.push_back(pResourceFile);

// This is the first HTML file? Remember it
if (!pFirstHTML)
pFirstHTML = pResourceFile;
}
}
}
else
{
Expand Down

0 comments on commit 7e6b4d0

Please sign in to comment.