Permalink
Browse files

Merge branch master into bugfix/resource-load-perf

  • Loading branch information...
botder committed Jan 7, 2019
2 parents 369c9aa + 5c85de2 commit 1dcb4464e882f1c26cc983cf68ce935a3061466b
@@ -153,6 +153,11 @@ void CResourceManager::StopAll(void)
bool CResourceManager::ParseResourcePathInput(std::string strInput, CResource*& pResource, std::string* pStrPath, std::string* pStrMetaPath)
{
ReplaceOccurrencesInString(strInput, "\\", "/");

// Disallow file paths with a directory separator at the end
if (strInput.back() == '/')
return false;

eAccessType accessType = ACCESS_PUBLIC;
std::string strMetaPath;

@@ -699,6 +699,9 @@ bool CResource::Start(std::list<CResource*>* pDependents, bool bManualStart, con
if (m_eState != EResourceState::Loaded)
return false;

if (m_bDestroyed)
return false;

m_eState = EResourceState::Starting;

CLuaArguments PreStartArguments;
@@ -1296,43 +1299,52 @@ bool CResource::ReadIncludedHTML(CXMLNode* pRoot)
if (pSrc)
{
// If we found it grab the value
string strFilename = pSrc->GetValue();
string strFullFilename;
ReplaceSlashes(strFilename);
std::string strFilename = pSrc->GetValue();

if (IsFilenameUsed(strFilename, false))
if (!strFilename.empty())
{
CLogger::LogPrintf("WARNING: Duplicate html file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
}
std::string strFullFilename;
ReplaceSlashes(strFilename);

// Try to find the file
if (IsValidFilePath(strFilename.c_str()) && GetFilePath(strFilename.c_str(), strFullFilename))
{
// This one is supposed to be default, but there's already a default page
if (bFoundDefault && bIsDefault)
if (IsFilenameUsed(strFilename, false))
{
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;
CLogger::LogPrintf("WARNING: Duplicate html file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
}

// If this is supposed to be default, we've now found our default page
if (bIsDefault)
bFoundDefault = true;
// Try to find the file
if (IsValidFilePath(strFilename.c_str()) && GetFilePath(strFilename.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);
// 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;
// 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;
}
}
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;
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'html' node of 'meta.xml' for resource '%s', ignoring\n",
m_strResourceName.c_str());
}
}
else
@@ -1383,35 +1395,44 @@ bool CResource::ReadIncludedConfigs(CXMLNode* pRoot)
if (pSrc)
{
// Grab the filename
string strFilename = pSrc->GetValue();
string strFullFilename;
ReplaceSlashes(strFilename);
std::string strFilename = pSrc->GetValue();

if (bClient && IsFilenameUsed(strFilename, true))
{
CLogger::LogPrintf("WARNING: Ignoring duplicate client config file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
bClient = false;
}
if (bServer && IsFilenameUsed(strFilename, false))
if (!strFilename.empty())
{
CLogger::LogPrintf("WARNING: Duplicate config file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
}
std::string strFullFilename;
ReplaceSlashes(strFilename);

// Extract / grab the filepath
if (IsValidFilePath(strFilename.c_str()) && GetFilePath(strFilename.c_str(), strFullFilename))
{
// Create it and push it to the list over resource files. Depending on if it's client or server type
if (bServer)
m_ResourceFiles.push_back(new CResourceConfigItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes));
if (bClient && IsFilenameUsed(strFilename, true))
{
CLogger::LogPrintf("WARNING: Ignoring duplicate client config file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
bClient = false;
}
if (bServer && IsFilenameUsed(strFilename, false))
{
CLogger::LogPrintf("WARNING: Duplicate config file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
}

if (bClient)
m_ResourceFiles.push_back(new CResourceClientConfigItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes));
// Extract / grab the filepath
if (IsValidFilePath(strFilename.c_str()) && GetFilePath(strFilename.c_str(), strFullFilename))
{
// Create it and push it to the list over resource files. Depending on if it's client or server type
if (bServer)
m_ResourceFiles.push_back(new CResourceConfigItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes));

if (bClient)
m_ResourceFiles.push_back(new CResourceClientConfigItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes));
}
else
{
m_strFailureReason = SString("Couldn't find config %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
}
}
else
{
m_strFailureReason = SString("Couldn't find config %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'config' node of 'meta.xml' for resource '%s', ignoring\n",
m_strResourceName.c_str());
}
}
else
@@ -1438,37 +1459,46 @@ bool CResource::ReadIncludedFiles(CXMLNode* pRoot)
if (pSrc)
{
// Grab the value
string strFilename = pSrc->GetValue();
string strFullFilename;
ReplaceSlashes(strFilename);
std::string strFilename = pSrc->GetValue();

if (IsFilenameUsed(strFilename, true))
if (!strFilename.empty())
{
CLogger::LogPrintf("WARNING: Ignoring duplicate client file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
continue;
}
std::string strFullFilename;
ReplaceSlashes(strFilename);

bool bDownload = true;
CXMLAttribute* pDownload = Attributes.Find("download");
if (IsFilenameUsed(strFilename, true))
{
CLogger::LogPrintf("WARNING: Ignoring duplicate client file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
continue;
}

if (pDownload)
{
const char* szDownload = pDownload->GetValue().c_str();
bool bDownload = true;
CXMLAttribute* pDownload = Attributes.Find("download");

if (!stricmp(szDownload, "no") || !stricmp(szDownload, "false"))
bDownload = false;
}
if (pDownload)
{
const char* szDownload = pDownload->GetValue().c_str();

// Create a new resourcefile item
if (IsValidFilePath(strFilename.c_str()) && GetFilePath(strFilename.c_str(), strFullFilename))
{
m_ResourceFiles.push_back(new CResourceClientFileItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes, bDownload));
if (!stricmp(szDownload, "no") || !stricmp(szDownload, "false"))
bDownload = false;
}

// Create a new resourcefile item
if (IsValidFilePath(strFilename.c_str()) && GetFilePath(strFilename.c_str(), strFullFilename))
{
m_ResourceFiles.push_back(new CResourceClientFileItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes, bDownload));
}
else
{
m_strFailureReason = SString("Couldn't find file %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
}
}
else
{
m_strFailureReason = SString("Couldn't find file %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'file' node of 'meta.xml' for resource '%s', ignoring\n",
m_strResourceName.c_str());
}
}
else
@@ -1610,34 +1640,43 @@ bool CResource::ReadIncludedScripts(CXMLNode* pRoot)
if (pSrc)
{
// Grab the source value from the attribute
string strFilename = pSrc->GetValue();
string strFullFilename;
ReplaceSlashes(strFilename);
std::string strFilename = pSrc->GetValue();

if (bClient && IsFilenameUsed(strFilename, true))
{
CLogger::LogPrintf("WARNING: Ignoring duplicate client script file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
bClient = false;
}
if (bServer && IsFilenameUsed(strFilename, false))
if (!strFilename.empty())
{
CLogger::LogPrintf("WARNING: Duplicate script file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
}
std::string strFullFilename;
ReplaceSlashes(strFilename);

// Extract / get the filepath of the file
if (IsValidFilePath(strFilename.c_str()) && GetFilePath(strFilename.c_str(), strFullFilename))
{
// Create it depending on the type (client or server or shared) and add it to the list of resource files
if (bServer)
m_ResourceFiles.push_back(new CResourceScriptItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes));
if (bClient)
m_ResourceFiles.push_back(new CResourceClientScriptItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes));
if (bClient && IsFilenameUsed(strFilename, true))
{
CLogger::LogPrintf("WARNING: Ignoring duplicate client script file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
bClient = false;
}
if (bServer && IsFilenameUsed(strFilename, false))
{
CLogger::LogPrintf("WARNING: Duplicate script file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
}

// Extract / get the filepath of the file
if (IsValidFilePath(strFilename.c_str()) && GetFilePath(strFilename.c_str(), strFullFilename))
{
// Create it depending on the type (client or server or shared) and add it to the list of resource files
if (bServer)
m_ResourceFiles.push_back(new CResourceScriptItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes));
if (bClient)
m_ResourceFiles.push_back(new CResourceClientScriptItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes));
}
else
{
m_strFailureReason = SString("Couldn't find script %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
}
}
else
{
m_strFailureReason = SString("Couldn't find script %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'script' node of 'meta.xml' for resource '%s', ignoring\n",
m_strResourceName.c_str());
}
}
else
@@ -1675,25 +1714,34 @@ bool CResource::ReadIncludedMaps(CXMLNode* pRoot)

if (pSrc)
{
string strFilename = pSrc->GetValue();
string strFullFilename;
ReplaceSlashes(strFilename);
std::string strFilename = pSrc->GetValue();

if (IsFilenameUsed(strFilename, false))
if (!strFilename.empty())
{
CLogger::LogPrintf("WARNING: Duplicate map file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
}
std::string strFullFilename;
ReplaceSlashes(strFilename);

// Grab the file (evt extract it). Make a map item resource and put it into the resourcefiles list
if (IsValidFilePath(strFilename.c_str()) && GetFilePath(strFilename.c_str(), strFullFilename))
{
m_ResourceFiles.push_back(new CResourceMapItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes, iDimension));
if (IsFilenameUsed(strFilename, false))
{
CLogger::LogPrintf("WARNING: Duplicate map file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
}

// Grab the file (evt extract it). Make a map item resource and put it into the resourcefiles list
if (IsValidFilePath(strFilename.c_str()) && GetFilePath(strFilename.c_str(), strFullFilename))
{
m_ResourceFiles.push_back(new CResourceMapItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes, iDimension));
}
else
{
m_strFailureReason = SString("Couldn't find map %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
}
}
else
{
m_strFailureReason = SString("Couldn't find map %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'map' node of 'meta.xml' for resource '%s', ignoring\n",
m_strResourceName.c_str());
}
}
else
Oops, something went wrong.

0 comments on commit 1dcb446

Please sign in to comment.