linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #01075
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2140: move the impl of FileFindIter
------------------------------------------------------------
revno: 2140
committer: poy <poy@xxxxxxxxxx>
branch nick: repo
timestamp: Mon 2010-05-10 18:07:57 +0200
message:
move the impl of FileFindIter
modified:
dcpp/File.cpp
dcpp/File.h
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dcpp/File.cpp'
--- dcpp/File.cpp 2010-04-18 04:32:43 +0000
+++ dcpp/File.cpp 2010-05-10 16:07:57 +0000
@@ -454,4 +454,138 @@
return ret;
}
+#ifdef _WIN32
+
+FileFindIter::FileFindIter() : handle(INVALID_HANDLE_VALUE) { }
+
+FileFindIter::FileFindIter(const string& path) : handle(INVALID_HANDLE_VALUE) {
+ handle = ::FindFirstFile(Text::toT(path).c_str(), &data);
+}
+
+FileFindIter::~FileFindIter() {
+ if(handle != INVALID_HANDLE_VALUE) {
+ ::FindClose(handle);
+ }
+}
+
+FileFindIter& FileFindIter::operator++() {
+ if(!::FindNextFile(handle, &data)) {
+ ::FindClose(handle);
+ handle = INVALID_HANDLE_VALUE;
+ }
+ return *this;
+}
+
+bool FileFindIter::operator!=(const FileFindIter& rhs) const { return handle != rhs.handle; }
+
+FileFindIter::DirData::DirData() { }
+
+string FileFindIter::DirData::getFileName() {
+ return Text::fromT(cFileName);
+}
+
+bool FileFindIter::DirData::isDirectory() {
+ return (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) > 0;
+}
+
+bool FileFindIter::DirData::isHidden() {
+ return ((dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) || (cFileName[0] == L'.'));
+}
+
+bool FileFindIter::DirData::isLink() {
+ return false;
+}
+
+int64_t FileFindIter::DirData::getSize() {
+ return (int64_t)nFileSizeLow | ((int64_t)nFileSizeHigh)<<32;
+}
+
+uint32_t FileFindIter::DirData::getLastWriteTime() {
+ return File::convertTime(&ftLastWriteTime);
+}
+
+#else // _WIN32
+
+FileFindIter::FileFindIter() {
+ dir = NULL;
+ data.ent = NULL;
+}
+
+FileFindIter::FileFindIter(const string& path) {
+ string filename = Text::fromUtf8(path);
+ dir = opendir(filename.c_str());
+ if (!dir)
+ return;
+ data.base = filename;
+ data.ent = readdir(dir);
+ if (!data.ent) {
+ closedir(dir);
+ dir = NULL;
+ }
+}
+
+FileFindIter::~FileFindIter() {
+ if (dir) closedir(dir);
+}
+
+FileFindIter& FileFindIter::operator++() {
+ if (!dir)
+ return *this;
+ data.ent = readdir(dir);
+ if (!data.ent) {
+ closedir(dir);
+ dir = NULL;
+ }
+ return *this;
+}
+
+bool operator FileFindIter::!=(const FileFindIter& rhs) const {
+ // good enough to to say if it's null
+ return dir != rhs.dir;
+}
+
+FileFindIter::DirData::DirData() : ent(NULL) {}
+
+string FileFindIter::DirData::getFileName() {
+ if (!ent) return Util::emptyString;
+ return Text::toUtf8(ent->d_name);
+}
+
+bool FileFindIter::DirData::isDirectory() {
+ struct stat inode;
+ if (!ent) return false;
+ if (stat((base + PATH_SEPARATOR + ent->d_name).c_str(), &inode) == -1) return false;
+ return S_ISDIR(inode.st_mode);
+}
+
+bool FileFindIter::DirData::isHidden() {
+ if (!ent) return false;
+ // Check if the parent directory is hidden for '.'
+ if (strcmp(ent->d_name, ".") == 0 && base[0] == '.') return true;
+ return ent->d_name[0] == '.' && strlen(ent->d_name) > 1;
+}
+
+bool FileFindIter::DirData::isLink() {
+ struct stat inode;
+ if (!ent) return false;
+ if (lstat((base + PATH_SEPARATOR + ent->d_name).c_str(), &inode) == -1) return false;
+ return S_ISLNK(inode.st_mode);
+}
+
+int64_t FileFindIter::DirData::getSize() {
+ struct stat inode;
+ if (!ent) return false;
+ if (stat((base + PATH_SEPARATOR + ent->d_name).c_str(), &inode) == -1) return 0;
+ return inode.st_size;
+}
+
+uint32_t FileFindIter::DirData::getLastWriteTime() {
+ struct stat inode;
+ if (!ent) return false;
+ if (stat((base + PATH_SEPARATOR + ent->d_name).c_str(), &inode) == -1) return 0;
+ return inode.st_mtime;
+}
+
+#endif // _WIN32
+
} // namespace dcpp
=== modified file 'dcpp/File.h'
--- dcpp/File.h 2010-03-30 01:32:40 +0000
+++ dcpp/File.h 2010-05-10 16:07:57 +0000
@@ -120,148 +120,42 @@
};
class FileFindIter {
-#ifdef _WIN32
public:
/** End iterator constructor */
- FileFindIter() : handle(INVALID_HANDLE_VALUE) { }
+ FileFindIter();
/** Begin iterator constructor, path in utf-8 */
- FileFindIter(const string& path) : handle(INVALID_HANDLE_VALUE) {
- handle = ::FindFirstFile(Text::toT(path).c_str(), &data);
- }
-
- ~FileFindIter() {
- if(handle != INVALID_HANDLE_VALUE) {
- ::FindClose(handle);
- }
- }
-
- FileFindIter& operator++() {
- if(!::FindNextFile(handle, &data)) {
- ::FindClose(handle);
- handle = INVALID_HANDLE_VALUE;
- }
- return *this;
- }
- bool operator!=(const FileFindIter& rhs) const { return handle != rhs.handle; }
-
- struct DirData : public WIN32_FIND_DATA {
- string getFileName() {
- return Text::fromT(cFileName);
- }
-
- bool isDirectory() {
- return (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) > 0;
- }
-
- bool isHidden() {
- return ((dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) || (cFileName[0] == L'.'));
- }
-
- bool isLink() {
- return false;
- }
-
- int64_t getSize() {
- return (int64_t)nFileSizeLow | ((int64_t)nFileSizeHigh)<<32;
- }
-
- uint32_t getLastWriteTime() {
- return File::convertTime(&ftLastWriteTime);
- }
+ FileFindIter(const string& path);
+
+ ~FileFindIter();
+
+ FileFindIter& operator++();
+ bool operator!=(const FileFindIter& rhs) const;
+
+ struct DirData
+#ifdef _WIN32
+ : public WIN32_FIND_DATA
+#endif
+ {
+ DirData();
+
+ string getFileName();
+ bool isDirectory();
+ bool isHidden();
+ bool isLink();
+ int64_t getSize();
+ uint32_t getLastWriteTime();
};
+ DirData& operator*() { return data; }
+ DirData* operator->() { return &data; }
private:
+#ifdef _WIN32
HANDLE handle;
#else
-public:
- FileFindIter() {
- dir = NULL;
- data.ent = NULL;
- }
-
- ~FileFindIter() {
- if (dir) closedir(dir);
- }
-
- FileFindIter(const string& name) {
- string filename = Text::fromUtf8(name);
- dir = opendir(filename.c_str());
- if (!dir)
- return;
- data.base = filename;
- data.ent = readdir(dir);
- if (!data.ent) {
- closedir(dir);
- dir = NULL;
- }
- }
-
- FileFindIter& operator++() {
- if (!dir)
- return *this;
- data.ent = readdir(dir);
- if (!data.ent) {
- closedir(dir);
- dir = NULL;
- }
- return *this;
- }
-
- // good enough to to say if it's null
- bool operator !=(const FileFindIter& rhs) const {
- return dir != rhs.dir;
- }
-
- struct DirData {
- DirData() : ent(NULL) {}
- string getFileName() {
- if (!ent) return Util::emptyString;
- return Text::toUtf8(ent->d_name);
- }
- bool isDirectory() {
- struct stat inode;
- if (!ent) return false;
- if (stat((base + PATH_SEPARATOR + ent->d_name).c_str(), &inode) == -1) return false;
- return S_ISDIR(inode.st_mode);
- }
- bool isHidden() {
- if (!ent) return false;
- // Check if the parent directory is hidden for '.'
- if (strcmp(ent->d_name, ".") == 0 && base[0] == '.') return true;
- return ent->d_name[0] == '.' && strlen(ent->d_name) > 1;
- }
- bool isLink() {
- struct stat inode;
- if (!ent) return false;
- if (lstat((base + PATH_SEPARATOR + ent->d_name).c_str(), &inode) == -1) return false;
- return S_ISLNK(inode.st_mode);
- }
- int64_t getSize() {
- struct stat inode;
- if (!ent) return false;
- if (stat((base + PATH_SEPARATOR + ent->d_name).c_str(), &inode) == -1) return 0;
- return inode.st_size;
- }
- uint32_t getLastWriteTime() {
- struct stat inode;
- if (!ent) return false;
- if (stat((base + PATH_SEPARATOR + ent->d_name).c_str(), &inode) == -1) return 0;
- return inode.st_mtime;
- }
- struct dirent* ent;
- string base;
- };
-private:
DIR* dir;
#endif
-public:
-
- DirData& operator*() { return data; }
- DirData* operator->() { return &data; }
-
-private:
DirData data;
};