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,15 +311,23 @@ 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 size_t numFiles = m_zipFileProxy->NumFiles();
bool haveAny = false;
int16_t lowestID = 32767;
for (size_t fileIndex = firstFileIndex; fileIndex < numFiles; fileIndex++)
{
const char *resName = nullptr; const char *resName = nullptr;
size_t fnLength = 0; size_t fnLength = 0;
m_zipFileProxy->GetFileName(fileIndex, resName, fnLength); m_zipFileProxy->GetFileName(fileIndex, resName, fnLength);
assert(fnLength > 5); if (fnLength <= 5 || memcmp(resName, resPrefix, 5))
break;
const char *idChars = resName + 5; const char *idChars = resName + 5;
size_t idCharsRemaining = fnLength - 5; size_t idCharsRemaining = fnLength - 5;
@@ -327,10 +335,10 @@ namespace PortabilityLayer
const size_t extLength = strlen(kPICTExtension); const size_t extLength = strlen(kPICTExtension);
if (idCharsRemaining <= extLength) if (idCharsRemaining <= extLength)
return false; continue;
if (memcmp(idChars + idCharsRemaining - extLength, kPICTExtension, extLength)) if (memcmp(idChars + idCharsRemaining - extLength, kPICTExtension, extLength))
return false; continue;
idCharsRemaining -= extLength; idCharsRemaining -= extLength;
@@ -344,40 +352,61 @@ namespace PortabilityLayer
} }
if (idCharsRemaining == 0) if (idCharsRemaining == 0)
return false; continue;
if (idChars[0] == '0' && (idCharsRemaining > 1 || isNegative)) if (idChars[0] == '0' && (idCharsRemaining > 1 || isNegative))
return false; continue;
int32_t resID = 0; int32_t resID = 0;
bool failedName = false;
while (idCharsRemaining) while (idCharsRemaining)
{ {
const char idChar = *idChars; const char idChar = *idChars;
if (idChar < '0' || idChar > '9') if (idChar < '0' || idChar > '9')
return false; {
failedName = true;
break;
}
resID = resID * 10; resID = resID * 10;
if (isNegative) if (isNegative)
{ {
resID -= (idChar - '0'); resID -= (idChar - '0');
if (resID < -32768) if (resID < -32768)
return false; {
failedName = true;
break;
}
} }
else else
{ {
resID += (idChar - '0'); resID += (idChar - '0');
if (resID > 32767) if (resID > 32767)
return false; {
failedName = true;
break;
}
} }
idChars++; idChars++;
idCharsRemaining--; idCharsRemaining--;
} }
outID = static_cast<int16_t>(resID); if (failedName)
continue;
return true; if (haveAny == false || resID < lowestID)
{
lowestID = resID;
haveAny = true;
}
}
if (haveAny)
outID = static_cast<int16_t>(lowestID);
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