Return first res by ID, not by name

This commit is contained in:
elasota
2020-03-09 01:40:26 -04:00
parent 46f7a7cc69
commit e0fb300766

View File

@@ -311,73 +311,102 @@ namespace PortabilityLayer
resPrefix[4] = '/'; resPrefix[4] = '/';
resPrefix[5] = '\0'; resPrefix[5] = '\0';
size_t fileIndex = 0; size_t firstFileIndex = 0;
if (!m_zipFileProxy->FindFirstWithPrefix(resPrefix, fileIndex)) if (!m_zipFileProxy->FindFirstWithPrefix(resPrefix, firstFileIndex))
return false; return false;
const char *resName = nullptr; const size_t numFiles = m_zipFileProxy->NumFiles();
size_t fnLength = 0;
m_zipFileProxy->GetFileName(fileIndex, resName, fnLength);
assert(fnLength > 5); bool haveAny = false;
int16_t lowestID = 32767;
const char *idChars = resName + 5; for (size_t fileIndex = firstFileIndex; fileIndex < numFiles; fileIndex++)
size_t idCharsRemaining = fnLength - 5;
const size_t extLength = strlen(kPICTExtension);
if (idCharsRemaining <= extLength)
return false;
if (memcmp(idChars + idCharsRemaining - extLength, kPICTExtension, extLength))
return false;
idCharsRemaining -= extLength;
bool isNegative = false;
if (idChars[0] == '-')
{ {
isNegative = true; const char *resName = nullptr;
idCharsRemaining--; size_t fnLength = 0;
idChars++; m_zipFileProxy->GetFileName(fileIndex, resName, fnLength);
}
if (idCharsRemaining == 0) if (fnLength <= 5 || memcmp(resName, resPrefix, 5))
return false; break;
if (idChars[0] == '0' && (idCharsRemaining > 1 || isNegative)) const char *idChars = resName + 5;
return false; size_t idCharsRemaining = fnLength - 5;
int32_t resID = 0; const size_t extLength = strlen(kPICTExtension);
while (idCharsRemaining)
{
const char idChar = *idChars;
if (idChar < '0' || idChar > '9') if (idCharsRemaining <= extLength)
return false; continue;
resID = resID * 10; if (memcmp(idChars + idCharsRemaining - extLength, kPICTExtension, extLength))
if (isNegative) continue;
idCharsRemaining -= extLength;
bool isNegative = false;
if (idChars[0] == '-')
{ {
resID -= (idChar - '0'); isNegative = true;
if (resID < -32768) idCharsRemaining--;
return false; idChars++;
}
else
{
resID += (idChar - '0');
if (resID > 32767)
return false;
} }
idChars++; if (idCharsRemaining == 0)
idCharsRemaining--; continue;
if (idChars[0] == '0' && (idCharsRemaining > 1 || isNegative))
continue;
int32_t resID = 0;
bool failedName = false;
while (idCharsRemaining)
{
const char idChar = *idChars;
if (idChar < '0' || idChar > '9')
{
failedName = true;
break;
}
resID = resID * 10;
if (isNegative)
{
resID -= (idChar - '0');
if (resID < -32768)
{
failedName = true;
break;
}
}
else
{
resID += (idChar - '0');
if (resID > 32767)
{
failedName = true;
break;
}
}
idChars++;
idCharsRemaining--;
}
if (failedName)
continue;
if (haveAny == false || resID < lowestID)
{
lowestID = resID;
haveAny = true;
}
} }
outID = static_cast<int16_t>(resID); if (haveAny)
outID = static_cast<int16_t>(lowestID);
return true; return haveAny;
} }
bool ResourceArchive::IndexResource(const ResTypeID &resTypeID, int id, size_t &outIndex, int &outValidationRule) const bool ResourceArchive::IndexResource(const ResTypeID &resTypeID, int id, size_t &outIndex, int &outValidationRule) const