void * GetResourceData (uio_Stream *fp, DWORD length) { void *result; DWORD compLen; // Resource data used to be prefixed by its length in package files. // A valid length prefix indicated compressed data, and // a length prefix ~0 meant uncompressed. // Currently, .ct and .xlt files still carry a ~0 length prefix. if (ReadResFile (&compLen, sizeof (compLen), 1, fp) != 1) return NULL; if (compLen != ~(DWORD)0) { log_add (log_Warning, "LZ-compressed binary data not supported"); return NULL; } length -= sizeof (DWORD); result = AllocResourceData (length); if (!result) return NULL; if (ReadResFile (result, 1, length, fp) != length) { FreeResourceData (result); result = NULL; } return result; }
DIRENTRY_REF LoadDirEntryTable (uio_DirHandle *dirHandle, const char *path, const char *pattern, match_MatchType matchType, PCOUNT pnum_entries) { uio_DirList *dirList; COUNT num_entries, length; COUNT i; COUNT slen; uio_DirHandle *dir; STRING_TABLE StringTable; STRING_TABLEPTR lpST; PSTR lpStr; PDWORD lpLastOffs; dir = uio_openDirRelative (dirHandle, path, 0); assert(dir != NULL); dirList = uio_getDirList (dir, "", pattern, matchType); assert(dirList != NULL); num_entries = 0; length = 0; // First, count the amount of space needed for (i = 0; i < dirList->numNames; i++) { struct stat sb; if (dirList->names[i][0] == '.') { dirList->names[i] = NULL; continue; } if (uio_stat (dir, dirList->names[i], &sb) == -1) { dirList->names[i] = NULL; continue; } if (!S_ISREG (sb.st_mode)) { dirList->names[i] = NULL; continue; } length += strlen (dirList->names[i]) + 1; num_entries++; } uio_closeDir (dir); if (num_entries == 0) { uio_DirList_free(dirList); *pnum_entries = 0; return ((DIRENTRY_REF) 0); } slen = sizeof (STRING_TABLE_DESC) + (num_entries * sizeof (DWORD)); StringTable = AllocResourceData (slen + length, 0); LockStringTable (StringTable, &lpST); if (lpST == 0) { FreeStringTable (StringTable); uio_DirList_free(dirList); *pnum_entries = 0; return ((DIRENTRY_REF) 0); } lpST->StringCount = num_entries; lpLastOffs = &lpST->StringOffsets[0]; *lpLastOffs = slen; lpStr = (PSTR)lpST + slen; for (i = 0; i < dirList->numNames; i++) { int size; if (dirList->names[i] == NULL) continue; size = strlen (dirList->names[i]) + 1; memcpy (lpStr, dirList->names[i], size); lpLastOffs[1] = lpLastOffs[0] + size; lpLastOffs++; lpStr += size; } uio_DirList_free(dirList); *pnum_entries = num_entries; UnlockStringTable (StringTable); return ((DIRENTRY_REF) StringTable); }