|
@@ -7,6 +7,8 @@
|
|
|
|
|
|
|
|
#include KWSYS_HEADER(Encoding.hxx)
|
|
#include KWSYS_HEADER(Encoding.hxx)
|
|
|
|
|
|
|
|
|
|
+#include KWSYS_HEADER(SystemTools.hxx)
|
|
|
|
|
+
|
|
|
// Work-around CMake dependency scanning limitation. This must
|
|
// Work-around CMake dependency scanning limitation. This must
|
|
|
// duplicate the above list of headers.
|
|
// duplicate the above list of headers.
|
|
|
#if 0
|
|
#if 0
|
|
@@ -16,15 +18,48 @@
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
#include <string>
|
|
#include <string>
|
|
|
|
|
+#include <utility>
|
|
|
#include <vector>
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
+#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
|
+# include <windows.h>
|
|
|
|
|
+
|
|
|
|
|
+# include <ctype.h>
|
|
|
|
|
+# include <fcntl.h>
|
|
|
|
|
+# include <io.h>
|
|
|
|
|
+# include <stdio.h>
|
|
|
|
|
+# include <stdlib.h>
|
|
|
|
|
+# include <string.h>
|
|
|
|
|
+# include <sys/stat.h>
|
|
|
|
|
+# include <sys/types.h>
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
namespace KWSYS_NAMESPACE {
|
|
namespace KWSYS_NAMESPACE {
|
|
|
|
|
|
|
|
class DirectoryInternals
|
|
class DirectoryInternals
|
|
|
{
|
|
{
|
|
|
public:
|
|
public:
|
|
|
|
|
+ struct FileData
|
|
|
|
|
+ {
|
|
|
|
|
+ std::string Name;
|
|
|
|
|
+#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
|
+ _wfinddata_t FindData;
|
|
|
|
|
+#endif
|
|
|
|
|
+ FileData(std::string name
|
|
|
|
|
+#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
|
+ ,
|
|
|
|
|
+ _wfinddata_t data
|
|
|
|
|
+#endif
|
|
|
|
|
+ )
|
|
|
|
|
+ : Name(std::move(name))
|
|
|
|
|
+#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
|
+ , FindData(std::move(data))
|
|
|
|
|
+#endif
|
|
|
|
|
+ {
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
// Array of Files
|
|
// Array of Files
|
|
|
- std::vector<std::string> Files;
|
|
|
|
|
|
|
+ std::vector<FileData> Files;
|
|
|
|
|
|
|
|
// Path to Open'ed directory
|
|
// Path to Open'ed directory
|
|
|
std::string Path;
|
|
std::string Path;
|
|
@@ -59,10 +94,45 @@ unsigned long Directory::GetNumberOfFiles() const
|
|
|
|
|
|
|
|
const char* Directory::GetFile(unsigned long dindex) const
|
|
const char* Directory::GetFile(unsigned long dindex) const
|
|
|
{
|
|
{
|
|
|
- if (dindex >= this->Internal->Files.size()) {
|
|
|
|
|
- return nullptr;
|
|
|
|
|
|
|
+ return this->Internal->Files[dindex].Name.c_str();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+std::string const& Directory::GetFileName(std::size_t i) const
|
|
|
|
|
+{
|
|
|
|
|
+ return this->Internal->Files[i].Name;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+std::string Directory::GetFilePath(std::size_t i) const
|
|
|
|
|
+{
|
|
|
|
|
+ std::string abs = this->Internal->Path;
|
|
|
|
|
+ if (!abs.empty() && abs.back() != '/') {
|
|
|
|
|
+ abs += '/';
|
|
|
}
|
|
}
|
|
|
- return this->Internal->Files[dindex].c_str();
|
|
|
|
|
|
|
+ abs += this->Internal->Files[i].Name;
|
|
|
|
|
+ return abs;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool Directory::FileIsDirectory(std::size_t i) const
|
|
|
|
|
+{
|
|
|
|
|
+#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
|
+ _wfinddata_t const& data = this->Internal->Files[i].FindData;
|
|
|
|
|
+ return (data.attrib & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
|
|
|
|
+#else
|
|
|
|
|
+ std::string const& path = this->GetFilePath(i);
|
|
|
|
|
+ return kwsys::SystemTools::FileIsDirectory(path);
|
|
|
|
|
+#endif
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool Directory::FileIsSymlink(std::size_t i) const
|
|
|
|
|
+{
|
|
|
|
|
+ std::string const& path = this->GetFilePath(i);
|
|
|
|
|
+#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
|
+ _wfinddata_t const& data = this->Internal->Files[i].FindData;
|
|
|
|
|
+ return kwsys::SystemTools::FileIsSymlinkWithAttr(
|
|
|
|
|
+ Encoding::ToWindowsExtendedPath(path), data.attrib);
|
|
|
|
|
+#else
|
|
|
|
|
+ return kwsys::SystemTools::FileIsSymlink(path);
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const char* Directory::GetPath() const
|
|
const char* Directory::GetPath() const
|
|
@@ -81,16 +151,6 @@ void Directory::Clear()
|
|
|
// First Windows platforms
|
|
// First Windows platforms
|
|
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
-# include <windows.h>
|
|
|
|
|
-
|
|
|
|
|
-# include <ctype.h>
|
|
|
|
|
-# include <fcntl.h>
|
|
|
|
|
-# include <io.h>
|
|
|
|
|
-# include <stdio.h>
|
|
|
|
|
-# include <stdlib.h>
|
|
|
|
|
-# include <string.h>
|
|
|
|
|
-# include <sys/stat.h>
|
|
|
|
|
-# include <sys/types.h>
|
|
|
|
|
|
|
|
|
|
namespace KWSYS_NAMESPACE {
|
|
namespace KWSYS_NAMESPACE {
|
|
|
|
|
|
|
@@ -133,7 +193,7 @@ Status Directory::Load(std::string const& name, std::string* errorMessage)
|
|
|
|
|
|
|
|
// Loop through names
|
|
// Loop through names
|
|
|
do {
|
|
do {
|
|
|
- this->Internal->Files.push_back(Encoding::ToNarrow(data.name));
|
|
|
|
|
|
|
+ this->Internal->Files.emplace_back(Encoding::ToNarrow(data.name), data);
|
|
|
} while (_wfindnext(srchHandle, &data) != -1);
|
|
} while (_wfindnext(srchHandle, &data) != -1);
|
|
|
this->Internal->Path = name;
|
|
this->Internal->Path = name;
|
|
|
if (_findclose(srchHandle) == -1) {
|
|
if (_findclose(srchHandle) == -1) {
|