Merge pull request #1295 from asmorkalov:winrt_ptr_usage_fix

This commit is contained in:
Roman Donchenko 2013-08-21 18:28:35 +04:00 committed by OpenCV Buildbot
commit ebb6c842f9
3 changed files with 30 additions and 33 deletions

View File

@ -11,7 +11,7 @@
namespace cv
{
std::vector<std::string> Directory::GetListFiles( const std::string& path, const std::string & exten, bool addPath )
std::vector<std::string> Directory::GetListFiles( const std::string& path, const std::string & exten, bool addPath )
{
std::vector<std::string> list;
list.clear();
@ -25,10 +25,9 @@ namespace cv
HANDLE hFind;
#ifdef HAVE_WINRT
size_t size = mbstowcs(NULL, path_f.c_str(), path_f.size());
Ptr<wchar_t> wpath = new wchar_t[size+1];
wpath[size] = 0;
mbstowcs(wpath, path_f.c_str(), path_f.size());
wchar_t wpath[MAX_PATH];
size_t copied = mbstowcs(wpath, path_f.c_str(), MAX_PATH);
CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
hFind = FindFirstFileExW(wpath, FindExInfoStandard, &FindFileData, FindExSearchNameMatch, NULL, 0);
#else
hFind = FindFirstFileA((LPCSTR)path_f.c_str(), &FindFileData);
@ -47,12 +46,12 @@ namespace cv
FindFileData.dwFileAttributes == FILE_ATTRIBUTE_SYSTEM ||
FindFileData.dwFileAttributes == FILE_ATTRIBUTE_READONLY)
{
cv::Ptr<char> fname;
char* fname;
#ifdef HAVE_WINRT
size_t asize = wcstombs(NULL, FindFileData.cFileName, 0);
fname = new char[asize+1];
fname[asize] = 0;
wcstombs(fname, FindFileData.cFileName, asize);
char fname_tmp[MAX_PATH] = {0};
size_t copied = wcstombs(fname_tmp, FindFileData.cFileName, MAX_PATH);
CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
fname = fname_tmp;
#else
fname = FindFileData.cFileName;
#endif
@ -109,10 +108,10 @@ namespace cv
HANDLE hFind;
#ifdef HAVE_WINRT
size_t size = mbstowcs(NULL, path_f.c_str(), path_f.size());
Ptr<wchar_t> wpath = new wchar_t[size+1];
wpath[size] = 0;
mbstowcs(wpath, path_f.c_str(), path_f.size());
wchar_t wpath [MAX_PATH];
size_t copied = mbstowcs(wpath, path_f.c_str(), path_f.size());
CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
hFind = FindFirstFileExW(wpath, FindExInfoStandard, &FindFileData, FindExSearchNameMatch, NULL, 0);
#else
hFind = FindFirstFileA((LPCSTR)path_f.c_str(), &FindFileData);
@ -135,12 +134,12 @@ namespace cv
strcmp(FindFileData.cFileName, "..") != 0)
#endif
{
cv::Ptr<char> fname;
char* fname;
#ifdef HAVE_WINRT
size_t asize = wcstombs(NULL, FindFileData.cFileName, 0);
fname = new char[asize+1];
fname[asize] = 0;
wcstombs(fname, FindFileData.cFileName, asize);
char fname_tmp[MAX_PATH];
size_t copied = wcstombs(fname, FindFileData.cFileName, MAX_PATH);
CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
fname = fname_tmp;
#else
fname = FindFileData.cFileName;
#endif

View File

@ -79,10 +79,9 @@ namespace
dir->ent.d_name = 0;
#ifdef HAVE_WINRT
cv::String full_path = cv::String(path) + "\\*";
size_t size = mbstowcs(NULL, full_path.c_str(), full_path.size());
cv::Ptr<wchar_t> wfull_path = new wchar_t[size+1];
wfull_path[size] = 0;
mbstowcs(wfull_path, full_path.c_str(), full_path.size());
wchar_t wfull_path[MAX_PATH];
size_t copied = mbstowcs(wfull_path, full_path.c_str(), MAX_PATH);
CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
dir->handle = ::FindFirstFileExW(wfull_path, FindExInfoStandard,
&dir->data, FindExSearchNameMatch, NULL, 0);
#else
@ -106,6 +105,7 @@ namespace
return 0;
}
size_t asize = wcstombs(NULL, dir->data.cFileName, 0);
CV_Assert((asize != 0) && (asize != (size_t)-1));
char* aname = new char[asize+1];
aname[asize] = 0;
wcstombs(aname, dir->data.cFileName, asize);
@ -146,10 +146,9 @@ static bool isDir(const cv::String& path, DIR* dir)
{
WIN32_FILE_ATTRIBUTE_DATA all_attrs;
#ifdef HAVE_WINRT
size_t size = mbstowcs(NULL, path.c_str(), path.size());
cv::Ptr<wchar_t> wpath = new wchar_t[size+1];
wpath[size] = 0;
mbstowcs(wpath, path.c_str(), path.size());
wchar_t wpath[MAX_PATH];
size_t copied = mbstowcs(wpath, path.c_str(), MAX_PATH);
CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
::GetFileAttributesExW(wpath, GetFileExInfoStandard, &all_attrs);
#else
::GetFileAttributesExA(path.c_str(), GetFileExInfoStandard, &all_attrs);

View File

@ -411,15 +411,14 @@ string tempfile( const char* suffix )
temp_file = temp_dir + std::wstring(L"\\") + temp_file;
DeleteFileW(temp_file.c_str());
size_t asize = wcstombs(NULL, temp_file.c_str(), 0);
Ptr<char> aname = new char[asize+1];
aname[asize] = 0;
wcstombs(aname, temp_file.c_str(), asize);
char aname[MAX_PATH];
size_t copied = wcstombs(aname, temp_file.c_str(), MAX_PATH);
CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
fname = std::string(aname);
RoUninitialize();
#else
char temp_dir2[MAX_PATH + 1] = { 0 };
char temp_file[MAX_PATH + 1] = { 0 };
char temp_dir2[MAX_PATH] = { 0 };
char temp_file[MAX_PATH] = { 0 };
if (temp_dir == 0 || temp_dir[0] == 0)
{