mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
API restricted on WinRT partially removed from core.
Additional CMAKE flag WITH_WINRT added.
This commit is contained in:
@@ -56,16 +56,40 @@ namespace
|
||||
|
||||
struct DIR
|
||||
{
|
||||
#ifdef HAVE_WINRT
|
||||
WIN32_FIND_DATAW data;
|
||||
#else
|
||||
WIN32_FIND_DATA data;
|
||||
#endif
|
||||
HANDLE handle;
|
||||
dirent ent;
|
||||
#ifdef HAVE_WINRT
|
||||
DIR() {};
|
||||
~DIR()
|
||||
{
|
||||
if (ent.d_name)
|
||||
free((void*)ent.d_name);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
DIR* opendir(const char* path)
|
||||
{
|
||||
DIR* dir = new DIR;
|
||||
dir->ent.d_name = 0;
|
||||
dir->handle = ::FindFirstFileA((cv::String(path) + "\\*").c_str(), &dir->data);
|
||||
#ifdef HAVE_WINRT
|
||||
cv::String full_path = cv::String(path) + "\\*";
|
||||
size_t size = mbstowcs(NULL, full_path.c_str(), full_path.size());
|
||||
wchar_t* wfull_path = (wchar_t*)malloc((size+1)*sizeof(wchar_t));
|
||||
wfull_path[size] = 0;
|
||||
mbstowcs(wfull_path, full_path.c_str(), full_path.size());
|
||||
dir->handle = ::FindFirstFileExW(wfull_path, FindExInfoStandard,
|
||||
&dir->data, FindExSearchNameMatch, NULL, 0);
|
||||
free(wfull_path);
|
||||
#else
|
||||
dir->handle = ::FindFirstFileExA((cv::String(path) + "\\*").c_str(),
|
||||
FindExInfoStandard, &dir->data, FindExSearchNameMatch, NULL, 0);
|
||||
#endif
|
||||
if(dir->handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
/*closedir will do all cleanup*/
|
||||
@@ -76,12 +100,25 @@ namespace
|
||||
|
||||
dirent* readdir(DIR* dir)
|
||||
{
|
||||
#ifdef HAVE_WINRT
|
||||
if (dir->ent.d_name != 0)
|
||||
{
|
||||
if (::FindNextFile(dir->handle, &dir->data) != TRUE)
|
||||
if (::FindNextFileW(dir->handle, &dir->data) != TRUE)
|
||||
return 0;
|
||||
}
|
||||
size_t asize = wcstombs(NULL, dir->data.cFileName, 0);
|
||||
char* aname = (char*)malloc((asize+1)*sizeof(char));
|
||||
aname[asize] = 0;
|
||||
wcstombs(aname, dir->data.cFileName, asize);
|
||||
dir->ent.d_name = aname;
|
||||
#else
|
||||
if (dir->ent.d_name != 0)
|
||||
{
|
||||
if (::FindNextFileA(dir->handle, &dir->data) != TRUE)
|
||||
return 0;
|
||||
}
|
||||
dir->ent.d_name = dir->data.cFileName;
|
||||
#endif
|
||||
return &dir->ent;
|
||||
}
|
||||
|
||||
@@ -107,7 +144,20 @@ static bool isDir(const cv::String& path, DIR* dir)
|
||||
if (dir)
|
||||
attributes = dir->data.dwFileAttributes;
|
||||
else
|
||||
attributes = ::GetFileAttributes(path.c_str());
|
||||
{
|
||||
WIN32_FILE_ATTRIBUTE_DATA all_attrs;
|
||||
#ifdef HAVE_WINRT
|
||||
size_t size = mbstowcs(NULL, path.c_str(), path.size());
|
||||
wchar_t* wpath = (wchar_t*)malloc((size+1)*sizeof(wchar_t));
|
||||
wpath[size] = 0;
|
||||
mbstowcs(wpath, path.c_str(), path.size());
|
||||
::GetFileAttributesExW(wpath, GetFileExInfoStandard, &all_attrs);
|
||||
free(wpath);
|
||||
#else
|
||||
::GetFileAttributesExA(path.c_str(), GetFileExInfoStandard, &all_attrs);
|
||||
#endif
|
||||
attributes = all_attrs.dwFileAttributes;
|
||||
}
|
||||
|
||||
return (attributes != INVALID_FILE_ATTRIBUTES) && ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user