VError VMacResFile::GetResourceListNames(const VString& inType, VArrayString& outNames) const { OSErr macError = noErr; outNames.SetCount(0); if (!testAssert(fRefNum != -1)) return VE_STREAM_NOT_OPENED; ResType type = inType.GetOsType(); if (type == 0) return VE_INVALID_PARAMETER; sWORD oldref = ::CurResFile(); sWORD ref = fRefNum; while(ref != -1 && ref != 0) { ::UseResFile(ref); sWORD count = ::Count1Resources(type); ::UseResFile(oldref); for(sWORD i = 1 ; i <= count ; ++i) { ::UseResFile(ref); ::SetResLoad(false); Handle data = ::Get1IndResource(type, i); macError = ::ResError(); ::SetResLoad(true); ::UseResFile(oldref); // one must restore proper context before calling VArrayValue::AppendWord if (data != NULL) { ResType type2; sWORD id; Str255 spName; ::GetResInfo(data, &id, &type2, spName); macError = ::ResError(); if (macError == noErr && spName[0] > 0) { VString name; name.MAC_FromMacPString(spName); if (outNames.Find(name) == -1) outNames.AppendString(name); } } } if (!fUseResourceChain) break; else { macError = ::GetNextResourceFile(ref, &ref); // returns ref = 0 and noerror at the end if (!testAssert(macError == noErr)) break; } } return VE_OK; }
VError VMacResFile::GetResourceListTypes(VArrayString& outTypes) const { outTypes.SetCount(0); if (!testAssert(fRefNum != -1)) return VE_STREAM_NOT_OPENED; sWORD oldref = ::CurResFile(); sWORD ref = fRefNum; while(ref != -1 && ref != 0) { ::UseResFile(ref); sWORD count = ::Count1Types(); ::UseResFile(oldref); for(sWORD i = 1 ; i <= count ; ++i) { ResType type; ::UseResFile(ref); ::Get1IndType(&type, i); ::UseResFile(oldref); // one must restore proper context before calling outTypes.AppendVString outTypes.AppendString(VResTypeString(type)); } if (!fUseResourceChain) break; else { OSErr macError = ::GetNextResourceFile(ref, &ref); // returns ref = 0 and noerror at the end if (!testAssert(macError == noErr)) break; } } return VE_OK; }