bool MFFileNative_FindFirst(MFFind *pFind, const char *pSearchPattern, MFFindData *pFindData)
{
	SceIoDirent findData;
	int findStatus;

	// separate path and search pattern..
	char *pPath = (char*)MFStr("%s/%s%s", gPSPSystemPath, (char*)pFind->pMount->pFilesysData, pSearchPattern);
	const char *pPattern = pPath;

	char *pLast = MFString_RChr(pPath, '/');
	if(pLast)
	{
		*pLast = 0;
		pPattern = pLast + 1;
	}
	else
	{
		// find pattern refers to current directory..
		pPath = ".";
	}

	// open the directory
	SceUID hFind = sceIoDopen(pPath);

	if(hFind < 0)
	{
		MFDebug_Warn(2, MFStr("Couldnt open directory '%s' with search pattern '%s'", pPath, pPattern));
		return false;
	}

	findStatus = sceIoDread(hFind, &findData);

	MFDebug_Assert(findStatus >= 0, "Error reading directory.");

	if(findStatus == 0)
		return false;

	pFindData->attributes = (FIO_SO_ISDIR(findData.d_stat.st_attr) ? MFFA_Directory : 0) |
							(FIO_SO_ISLNK(findData.d_stat.st_attr) ? MFFA_SymLink : 0);
	pFindData->fileSize = (uint64)findData.d_stat.st_size;
	MFString_Copy((char*)pFindData->pFilename, findData.d_name);

	MFString_CopyCat(pFindData->pSystemPath, (char*)pFind->pMount->pFilesysData, pSearchPattern);
	pLast = MFString_RChr(pFindData->pSystemPath, '/');
	if(pLast)
		pLast[1] = 0;
	else
		pFindData->pSystemPath[0] = 0;

	pFind->pFilesystemData = (void*)hFind;

	return true;
}
bool MFFileNative_FindNext(MFFind *pFind, MFFindData *pFindData)
{
	SceIoDirent findData;
	int findStatus;

	findStatus = sceIoDread((SceUID)pFind->pFilesystemData, &findData);

	MFDebug_Assert(findStatus >= 0, "Error reading directory.");

	if(findStatus == 0)
		return false;

	pFindData->attributes = (FIO_SO_ISDIR(findData.d_stat.st_attr) ? MFFA_Directory : 0) |
							(FIO_SO_ISLNK(findData.d_stat.st_attr) ? MFFA_SymLink : 0);
	pFindData->fileSize = (uint64)findData.d_stat.st_size;
	MFString_Copy((char*)pFindData->pFilename, findData.d_name);

	return true;
}
Esempio n. 3
0
int mode2modex(int mode)
{
	int modex = 0;

	if (FIO_SO_ISLNK(mode))
		modex |= FIO_S_IFLNK;
	if (FIO_SO_ISREG(mode))
		modex |= FIO_S_IFREG;
	if (FIO_SO_ISDIR(mode))
		modex |= FIO_S_IFDIR;

	/* Convert the file access modes.  */
	if (mode & FIO_SO_IROTH)
		modex |= FIO_S_IRUSR | FIO_S_IRGRP | FIO_S_IROTH;
	if (mode & FIO_SO_IWOTH)
		modex |= FIO_S_IWUSR | FIO_S_IWGRP | FIO_S_IWOTH;
	if (mode & FIO_SO_IXOTH)
		modex |= FIO_S_IXUSR | FIO_S_IXGRP | FIO_S_IXOTH;

	return modex;
}