* Add function resGetNamefromData which complements resGetNamefromData and allows you to retrieve the resource ID (usually filename) for a resource (IMD, IMG, TEXPAGE, WAV, etc.)

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3324 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-01-03 00:35:57 +00:00
parent 96e737fb03
commit 48f32faccf
2 changed files with 54 additions and 0 deletions

View File

@ -640,6 +640,52 @@ BOOL resGetHashfromData(const char *pType, const void *pData, UDWORD *pHash)
return TRUE;
}
const char* resGetNamefromData(const char* type, const void *data)
{
RES_TYPE *psT;
RES_DATA *psRes;
UDWORD HashedType;
if (type == NULL || data == NULL)
{
return "";
}
// Find the correct type
HashedType = HashString(type);
// Find the resource table for the given type
for (psT = psResTypes; psT != NULL; psT = psT->psNext)
{
if (psT->HashedType == HashedType)
{
break;
}
}
if (psT == NULL)
{
ASSERT( FALSE, "resGetHashfromData: Unknown type: %x", HashedType );
return "";
}
// Find the resource in the resource table
for(psRes = psT->psRes; psRes; psRes = psRes->psNext)
{
if (psRes->pData == data)
{
break;
}
}
if (psRes == NULL)
{
ASSERT( FALSE, "resGetHashfromData:: couldn't find data for type %x\n", HashedType );
return "";
}
return psRes->aID;
}
/* Simply returns true if a resource is present */
BOOL resPresent(const char *pType, const char *pID)

View File

@ -124,6 +124,14 @@ void resToLower(char *pStr);
/** Return the HashedID string for a piece of data. */
extern BOOL resGetHashfromData(const char *pType, const void *pData, UDWORD *pHash);
/** Retrieve the resource ID string
* \param type the resource type string (e.g. "IMG", "IMD", "TEXPAGE", "WAV", etc.)
* \param data the resource pointer to retrieve the ID string for
* \return the from the ID string (usually its filename without directory)
* \note passing a NULL pointer for either \c type or \c data is valid (the result will be an empty string though)
*/
extern const char* resGetNamefromData(const char* type, const void *data);
/** Return last imd resource */
const char *GetLastResourceFilename(void) WZ_DECL_PURE;