Skip to content

Commit

Permalink
Add patterns for html
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX committed Oct 8, 2024
1 parent 2318836 commit eed5399
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 @@ -1462,44 +1462,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 eed5399

Please sign in to comment.