|
|
@@ -44,6 +44,36 @@ |
|
|
|
|
|
|
|
namespace CodeDweller {
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
char const FilePath::DirectorySeparator = '\\';
|
|
|
|
#else
|
|
|
|
char const FilePath::DirectorySeparator = '/';
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::string FilePath::join(std::initializer_list<std::string> components) {
|
|
|
|
|
|
|
|
std::string path;
|
|
|
|
|
|
|
|
for (auto &component : components) {
|
|
|
|
|
|
|
|
if (!path.empty() &&
|
|
|
|
path.back() != FilePath::DirectorySeparator) {
|
|
|
|
path += FilePath::DirectorySeparator;
|
|
|
|
}
|
|
|
|
|
|
|
|
path += component;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!path.empty() &&
|
|
|
|
path.back() == FilePath::DirectorySeparator) {
|
|
|
|
path.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
FileReference::FileReference(std::string fileName) :
|
|
|
|
name(fileName),
|
|
|
|
modTimestamp(0),
|
|
|
@@ -189,6 +219,7 @@ namespace CodeDweller { |
|
|
|
bool (*dirFilter)(std::string)) :
|
|
|
|
name(dirName),
|
|
|
|
filter(dirFilter) {
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
@@ -197,6 +228,36 @@ namespace CodeDweller { |
|
|
|
// Clear any entries in this object.
|
|
|
|
this->clear();
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
HANDLE hDirList;
|
|
|
|
WIN32_FIND_DATA dirListData;
|
|
|
|
std::string searchString = FilePath::join({name, "*"});
|
|
|
|
|
|
|
|
hDirList = FindFirstFile(searchString.c_str(), &dirListData);
|
|
|
|
if (INVALID_HANDLE_VALUE == hDirList) {
|
|
|
|
throw std::runtime_error("Error getting file list for \"" + name +
|
|
|
|
"\": " + FileReference::getErrorText());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string tempName;
|
|
|
|
|
|
|
|
while (INVALID_HANDLE_VALUE != hDirList) {
|
|
|
|
|
|
|
|
tempName = FilePath::join({name, dirListData.cFileName});
|
|
|
|
|
|
|
|
if ( (0 == filter) || (*filter)(dirListData.cFileName)) {
|
|
|
|
emplace_back(tempName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FindNextFile(hDirList, &dirListData)) {
|
|
|
|
FindClose(hDirList);
|
|
|
|
hDirList = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
// Get new list.
|
|
|
|
struct dirent **entries;
|
|
|
|
|
|
|
@@ -211,13 +272,16 @@ namespace CodeDweller { |
|
|
|
while (nEntries--) {
|
|
|
|
std::string tempName;
|
|
|
|
|
|
|
|
tempName = name + "/" + entries[nEntries]->d_name;
|
|
|
|
tempName = FilePath::join({name, entries[nEntries]->d_name});
|
|
|
|
if ( (0 == filter) || (*filter)(entries[nEntries]->d_name)) {
|
|
|
|
emplace_back(tempName);
|
|
|
|
}
|
|
|
|
free(entries[nEntries]);
|
|
|
|
}
|
|
|
|
free(entries);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|