Fix bug 56275

This commit is contained in:
Oleg Korshul
2022-03-30 21:22:15 +03:00
parent 286eb3fe9a
commit 8eb21889bf
2 changed files with 62 additions and 2 deletions

View File

@ -85,11 +85,71 @@ public:
{
write(path, (BYTE*)xml.c_str(), (DWORD)xml.length());
}
bool existsXml(const std::wstring& path)
{
if (exists(path))
return true;
std::vector<std::wstring> arPieces = getFiles(path, false);
if (0 < arPieces.size())
{
std::sort(arPieces.begin(), arPieces.end());
std::vector<std::wstring>::iterator iter = arPieces.begin();
while (iter != arPieces.end())
{
std::wstring::size_type len = iter->length();
std::wstring::size_type pos = iter->rfind(L".piece");
if (std::wstring::npos != pos && ((pos + 6) == len))
{
return true;
}
}
}
return false;
}
std::string readXml(const std::wstring& path)
{
CBuffer* buffer = NULL;
if (!read(path, buffer))
{
std::vector<std::wstring> arPieces = getFiles(path, false);
if (0 < arPieces.size())
{
std::sort(arPieces.begin(), arPieces.end());
std::vector<std::wstring>::iterator iter = arPieces.begin();
while (iter != arPieces.end())
{
std::wstring::size_type len = iter->length();
std::wstring::size_type pos = iter->rfind(L".piece");
if (std::wstring::npos != pos && ((pos + 6) == len))
{
iter++;
continue;
}
else
{
iter = arPieces.erase(iter);
}
}
}
if (0 < arPieces.size())
{
std::string sResult;
for (std::vector<std::wstring>::iterator iter = arPieces.begin(); iter != arPieces.end(); iter++)
{
CBuffer* bufferPiece = NULL;
if (read(*iter, bufferPiece))
{
sResult += std::string((char*)bufferPiece->Buffer, (size_t)bufferPiece->Size);
}
delete bufferPiece;
}
return sResult;
}
return "";
}
std::string sXmlUtf8((char*)buffer->Buffer, (size_t)buffer->Size);
delete buffer;
return sXmlUtf8;

View File

@ -236,10 +236,10 @@ namespace XPS
ReadAttribute(oReader, L"Source", wsSource);
std::wstring wsPagePath = wsSource;
if (!m_wsPath->exists(wsPagePath))
if (!m_wsPath->existsXml(wsPagePath))
{
wsPagePath = wsFilePath + wsSource;
if (!m_wsPath->exists(wsPagePath))
if (!m_wsPath->existsXml(wsPagePath))
continue;
}