예제 #1
0
int __PHYSFS_platformIsSymLink(const char *fname)
{
	/* !!! FIXME:
	* Windows Vista can have NTFS symlinks. Can older Windows releases have
	*  them when talking to a network file server? What happens when you
	*  mount a NTFS partition on XP that was plugged into a Vista install
	*  that made a symlink?
	*/

	int retval = 0;
	LPWSTR wpath;
	HANDLE dir;
	WIN32_FIND_DATAW entw;

	/* no unicode entry points? Probably no symlinks. */
	BAIL_IF_MACRO(pFindFirstFileW == NULL, NULL, 0);

	UTF8_TO_UNICODE_STACK_MACRO(wpath, fname);
	BAIL_IF_MACRO(wpath == NULL, ERR_OUT_OF_MEMORY, 0);

	/* !!! FIXME: filter wildcard chars? */
	dir = pFindFirstFileW(wpath, &entw);
	if (dir != INVALID_HANDLE_VALUE)
	{
		retval = isSymlinkAttrs(entw.dwFileAttributes, entw.dwReserved0);
		FindClose(dir);
	} /* if */

	__PHYSFS_smallFree(wpath);
	return(retval);
} /* __PHYSFS_platformIsSymlink */
예제 #2
0
void __PHYSFS_platformEnumerateFiles(const char *dirname,
                                     int omitSymLinks,
                                     PHYSFS_EnumFilesCallback callback,
                                     const char *origdir,
                                     void *callbackdata)
{
    HANDLE dir = INVALID_HANDLE_VALUE;
    WIN32_FIND_DATAW entw;
    size_t len = strlen(dirname);
    char *searchPath = NULL;
    WCHAR *wSearchPath = NULL;

    /* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
    searchPath = (char *) __PHYSFS_smallAlloc(len + 3);
    if (searchPath == NULL)
        return;

    /* Copy current dirname */
    strcpy(searchPath, dirname);

    /* if there's no '\\' at the end of the path, stick one in there. */
    if (searchPath[len - 1] != '\\')
    {
        searchPath[len++] = '\\';
        searchPath[len] = '\0';
    } /* if */

    /* Append the "*" to the end of the string */
    strcat(searchPath, "*");

    UTF8_TO_UNICODE_STACK_MACRO(wSearchPath, searchPath);
    if (!wSearchPath)
        return;  /* oh well. */

    dir = FindFirstFileW(wSearchPath, &entw);

    __PHYSFS_smallFree(wSearchPath);
    __PHYSFS_smallFree(searchPath);
    if (dir == INVALID_HANDLE_VALUE)
        return;

    do
    {
        const DWORD attr = entw.dwFileAttributes;
        const DWORD tag = entw.dwReserved0;
        const WCHAR *fn = entw.cFileName;
        char *utf8;

        if ((fn[0] == '.') && (fn[1] == '\0'))
            continue;
        if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\0'))
            continue;
        if ((omitSymLinks) && (isSymlinkAttrs(attr, tag)))
            continue;

        utf8 = unicodeToUtf8Heap(fn);
        if (utf8 != NULL)
        {
            callback(callbackdata, origdir, utf8);
            allocator.Free(utf8);
        } /* if */
    } while (FindNextFileW(dir, &entw) != 0);

    FindClose(dir);
} /* __PHYSFS_platformEnumerateFiles */
예제 #3
0
void __PHYSFS_platformEnumerateFiles(const char *dirname,
	int omitSymLinks,
	PHYSFS_EnumFilesCallback callback,
	const char *origdir,
	void *callbackdata)
{
	const int unicode = (pFindFirstFileW != NULL) && (pFindNextFileW != NULL);
	HANDLE dir = INVALID_HANDLE_VALUE;
	WIN32_FIND_DATA ent;
	WIN32_FIND_DATAW entw;
	size_t len = strlen(dirname);
	char *searchPath = NULL;
	WCHAR *wSearchPath = NULL;
	char *utf8 = NULL;

	/* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
	searchPath = (char *)__PHYSFS_smallAlloc(len + 3);
	if (searchPath == NULL)
		return;

	/* Copy current dirname */
	strcpy(searchPath, dirname);

	/* if there's no '\\' at the end of the path, stick one in there. */
	if (searchPath[len - 1] != '\\')
	{
		searchPath[len++] = '\\';
		searchPath[len] = '\0';
	} /* if */

	  /* Append the "*" to the end of the string */
	strcat(searchPath, "*");

	UTF8_TO_UNICODE_STACK_MACRO(wSearchPath, searchPath);
	if (wSearchPath == NULL)
		return;  /* oh well. */

	if (unicode)
		dir = pFindFirstFileW(wSearchPath, &entw);
	else
	{
		const int len = (int)(wStrLen(wSearchPath) + 1);
		char *cp = (char *)__PHYSFS_smallAlloc(len);
		if (cp != NULL)
		{
			WideCharToMultiByte(CP_ACP, 0, wSearchPath, len, cp, len, 0, 0);
			//dir = FindFirstFileA(cp, &ent);
			dir = FindFirstFileExA(cp, FindExInfoStandard, &ent, FindExSearchNameMatch, NULL, 0);
			__PHYSFS_smallFree(cp);
		} /* if */
	} /* else */

	__PHYSFS_smallFree(wSearchPath);
	__PHYSFS_smallFree(searchPath);
	if (dir == INVALID_HANDLE_VALUE)
		return;

	if (unicode)
	{
		do
		{
			const DWORD attr = entw.dwFileAttributes;
			const DWORD tag = entw.dwReserved0;
			const WCHAR *fn = entw.cFileName;
			if ((fn[0] == '.') && (fn[1] == '\0'))
				continue;
			if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\0'))
				continue;
			if ((omitSymLinks) && (isSymlinkAttrs(attr, tag)))
				continue;

			utf8 = unicodeToUtf8Heap(fn);
			if (utf8 != NULL)
			{
				callback(callbackdata, origdir, utf8);
				allocator.Free(utf8);
			} /* if */
		} while (pFindNextFileW(dir, &entw) != 0);
	} /* if */

	else  /* ANSI fallback. */
	{
		do
		{
			const DWORD attr = ent.dwFileAttributes;
			const DWORD tag = ent.dwReserved0;
			const char *fn = ent.cFileName;
			if ((fn[0] == '.') && (fn[1] == '\0'))
				continue;
			if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\0'))
				continue;
			if ((omitSymLinks) && (isSymlinkAttrs(attr, tag)))
				continue;

			utf8 = codepageToUtf8Heap(fn);
			if (utf8 != NULL)
			{
				callback(callbackdata, origdir, utf8);
				allocator.Free(utf8);
			} /* if */
		} while (FindNextFileA(dir, &ent) != 0);
	} /* else */

	FindClose(dir);
} /* __PHYSFS_platformEnumerateFiles */