Add missing glob() equivalent for Windows platforms

This commit is contained in:
Pete Batard
2012-03-05 18:03:37 +00:00
parent 0074e54f97
commit a7d3059857
2 changed files with 84 additions and 0 deletions

View File

@@ -34,6 +34,9 @@
#ifdef HAVE_GLOB_H
#include <glob.h>
#endif
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif
#include <cdio/bytesex.h>
#include <cdio/ds.h>
@@ -1122,6 +1125,41 @@ _eject_media_nrg(void *obj)
return DRIVER_OP_UNSUPPORTED;
}
#if !defined(HAVE_GLOB_H) && defined(_WIN32)
static inline void Win32Glob(const char* pattern, const char* szCurPath, char ***drives, unsigned int *num_files)
{
char szPath[MAX_PATH];
WIN32_FIND_DATAA ffd;
HANDLE hFind;
BOOL bFound;
SetCurrentDirectoryA(szCurPath);
hFind = FindFirstFileA(pattern, &ffd);
bFound = (hFind != INVALID_HANDLE_VALUE);
while (bFound) {
cdio_add_device_list(drives, ffd.cFileName, num_files);
bFound = FindNextFileA(hFind, &ffd);
}
if (hFind != INVALID_HANDLE_VALUE)
FindClose(hFind);
hFind = FindFirstFileA("*", &ffd);
bFound = (hFind != INVALID_HANDLE_VALUE);
while (bFound) {
if ( (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
(strcmp(ffd.cFileName, ".") != 0) && (strcmp(ffd.cFileName, "..") != 0) ) {
GetFullPathNameA(ffd.cFileName, sizeof(szPath), szPath, NULL);
Win32Glob(pattern, szPath, drives, num_files);
SetCurrentDirectoryA(szCurPath);
}
bFound = FindNextFileA(hFind, &ffd);
}
if (hFind != INVALID_HANDLE_VALUE)
FindClose(hFind);
}
#endif
/*!
Return an array of strings giving possible NRG disk images.
*/
@@ -1139,6 +1177,10 @@ cdio_get_devices_nrg (void)
cdio_add_device_list(&drives, globbuf.gl_pathv[i], &num_files);
}
globfree(&globbuf);
#elif defined(_WIN32)
char szStartDir[MAX_PATH];
GetCurrentDirectoryA(sizeof(szStartDir), szStartDir);
Win32Glob("*.nrg", szStartDir, &drives, &num_files);
#else
cdio_add_device_list(&drives, DEFAULT_CDIO_DEVICE, &num_files);
#endif /*HAVE_GLOB_H*/