|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace CodeDweller {
|
|
|
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) :
|
|
|
FileReference::FileReference(std::string fileName) :
|
|
|
name(fileName),
|
|
|
name(fileName),
|
|
|
modTimestamp(0),
|
|
|
modTimestamp(0),
|
|
|
|
|
|
|
|
|
bool (*dirFilter)(std::string)) :
|
|
|
bool (*dirFilter)(std::string)) :
|
|
|
name(dirName),
|
|
|
name(dirName),
|
|
|
filter(dirFilter) {
|
|
|
filter(dirFilter) {
|
|
|
|
|
|
|
|
|
refresh();
|
|
|
refresh();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Clear any entries in this object.
|
|
|
// Clear any entries in this object.
|
|
|
this->clear();
|
|
|
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.
|
|
|
// Get new list.
|
|
|
struct dirent **entries;
|
|
|
struct dirent **entries;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (nEntries--) {
|
|
|
while (nEntries--) {
|
|
|
std::string tempName;
|
|
|
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)) {
|
|
|
if ( (0 == filter) || (*filter)(entries[nEntries]->d_name)) {
|
|
|
emplace_back(tempName);
|
|
|
emplace_back(tempName);
|
|
|
}
|
|
|
}
|
|
|
free(entries[nEntries]);
|
|
|
free(entries[nEntries]);
|
|
|
}
|
|
|
}
|
|
|
free(entries);
|
|
|
free(entries);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|