* 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-861f7616d084master
parent
96e737fb03
commit
48f32faccf
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue