VArrayString *VFolder::GetContents(FolderFilter inFolderFilter) const
{
	if (!Exists())
		return NULL;
	
	FileIteratorOptions flags = FI_WANT_NONE;
	switch( inFolderFilter) {
		case FF_NO_FILTER:		flags = FI_WANT_FILES | FI_WANT_FOLDERS; break;
		case FF_NO_FOLDERS:		flags = FI_WANT_FILES; break;
		case FF_NO_FILES:		flags = FI_WANT_FOLDERS; break;
		default:
			xbox_assert( false);
	}

	VArrayString *names = new VArrayString;
	VString name;

	if( flags & FI_WANT_FILES )
		for( VFileIterator i( this, FI_WANT_FILES) ; i.IsValid() ; ++i)
		{
			i->GetName( name);
			names->AppendString( name);
		}

	if( flags & FI_WANT_FOLDERS )
		for( VFolderIterator i( this, FI_WANT_FOLDERS) ; i.IsValid() ; ++i)
		{
			i->GetName( name);
			names->AppendString( name);
		}

	return names;
}
Example #2
0
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;
}
Example #3
0
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;
}