1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-31 18:07:14 +01:00
SqMod/vendor/POCO/Foundation/src/DirectoryIterator_WIN32U.cpp
Sandu Liviu Catalin 4a6bfc086c Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
2021-01-30 08:51:39 +02:00

76 lines
1.4 KiB
C++

//
// DirectoryIterator_WIN32U.cpp
//
// Library: Foundation
// Package: Filesystem
// Module: DirectoryIterator
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/DirectoryIterator_WIN32U.h"
#if defined(_WIN32_WCE)
#include "Poco/File_WINCE.h"
#else
#include "Poco/File_WIN32U.h"
#endif
#include "Poco/Path.h"
#include "Poco/UnicodeConverter.h"
#include <cstring>
namespace Poco {
DirectoryIteratorImpl::DirectoryIteratorImpl(const std::string& path): _fh(INVALID_HANDLE_VALUE), _rc(1)
{
Path p(path);
p.makeDirectory();
std::string findPath = p.toString();
findPath.append("*");
std::wstring uFindPath;
FileImpl::convertPath(findPath, uFindPath);
_fh = FindFirstFileW(uFindPath.c_str(), &_fd);
if (_fh == INVALID_HANDLE_VALUE)
{
if (GetLastError() != ERROR_NO_MORE_FILES)
File::handleLastError(path);
}
else
{
UnicodeConverter::toUTF8(_fd.cFileName, _current);
if (_current == "." || _current == "..")
next();
}
}
DirectoryIteratorImpl::~DirectoryIteratorImpl()
{
if (_fh != INVALID_HANDLE_VALUE)
FindClose(_fh);
}
const std::string& DirectoryIteratorImpl::next()
{
do
{
_current.clear();
if (FindNextFileW(_fh, &_fd) != 0)
{
UnicodeConverter::toUTF8(_fd.cFileName, _current);
}
}
while (_current == "." || _current == "..");
return _current;
}
} // namespace Poco