From: <arn...@us...> - 2006-10-04 01:47:41
|
Revision: 662 http://svn.sourceforge.net/dcplusplus/?rev=662&view=rev Author: arnetheduck Date: 2006-09-29 09:24:13 -0700 (Fri, 29 Sep 2006) Log Message: ----------- file patch Modified Paths: -------------- dcplusplus/trunk/changelog.txt dcplusplus/trunk/client/File.cpp dcplusplus/trunk/client/File.h Modified: dcplusplus/trunk/changelog.txt =================================================================== --- dcplusplus/trunk/changelog.txt 2006-09-29 16:05:42 UTC (rev 661) +++ dcplusplus/trunk/changelog.txt 2006-09-29 16:24:13 UTC (rev 662) @@ -1,4 +1,8 @@ -- -- +* [bug 1065] Code cleanup (thanks steven sheehy) + + +-- 0.697 2006-09-29 -- * [ADC] Fixed a few protocol issues * Some code cleanup * Queue frame fixes and memory saves Modified: dcplusplus/trunk/client/File.cpp =================================================================== --- dcplusplus/trunk/client/File.cpp 2006-09-29 16:05:42 UTC (rev 661) +++ dcplusplus/trunk/client/File.cpp 2006-09-29 16:24:13 UTC (rev 662) @@ -66,6 +66,10 @@ return 0; } +bool File::isOpen() throw() { + return h != INVALID_HANDLE_VALUE; +} + void File::close() throw() { if(isOpen()) { CloseHandle(h); @@ -133,7 +137,7 @@ } } -size_t File::flush() throw(Exception) { +size_t File::flush() throw(FileException) { if(isOpen() && !FlushFileBuffers(h)) throw FileException(Util::translateError(GetLastError())); return 0; @@ -153,6 +157,11 @@ } } +void File::deleteFile(const string& aFileName) throw() +{ + ::DeleteFile(Text::toT(aFileName).c_str()); +} + int64_t File::getSize(const string& aFileName) throw() { WIN32_FIND_DATA fd; HANDLE hFind; @@ -185,7 +194,7 @@ return path.size() > 2 && (path[1] == ':' || path[0] == '/' || path[0] == '\\'); } -#else // _WIN32 +#else // !_WIN32 File::File(const string& aFileName, int access, int mode) throw(FileException) { dcassert(access == WRITE || access == READ || access == (READ | WRITE)); @@ -218,6 +227,10 @@ return (u_int32_t)s.st_mtime; } +bool File::isOpen() throw() { + return h != -1; +} + void File::close() throw() { if(h != -1) { ::close(h); @@ -302,7 +315,7 @@ } size_t File::flush() throw(FileException) { - if(h != -1 && fsync(h) == -1) + if(isOpen() && fsync(h) == -1) throw FileException(Util::translateError(errno)); return 0; } @@ -342,6 +355,10 @@ } } +void File::deleteFile(const string& aFileName) throw() { + ::unlink(aFileName.c_str()); +} + int64_t File::getSize(const string& aFileName) throw() { struct stat s; if(stat(aFileName.c_str(), &s) == -1) @@ -363,7 +380,7 @@ return path.size() > 1 && path[0] = '/'; } -#endif // _WIN32 +#endif // !_WIN32 string File::read(size_t len) throw(FileException) { string s(len, 0); Modified: dcplusplus/trunk/client/File.h =================================================================== --- dcplusplus/trunk/client/File.h 2006-09-29 16:05:42 UTC (rev 661) +++ dcplusplus/trunk/client/File.h 2006-09-29 16:24:13 UTC (rev 662) @@ -48,8 +48,33 @@ CREATE = 0x02, TRUNCATE = 0x04 }; + +#ifdef _WIN32 + enum { + READ = GENERIC_READ, + WRITE = GENERIC_WRITE, + RW = READ | WRITE + }; + + static u_int32_t convertTime(FILETIME* f); + +#else // !_WIN32 + + enum { + READ = 0x01, + WRITE = 0x02, + RW = READ | WRITE + }; + + // some ftruncate implementations can't extend files like SetEndOfFile, + // not sure if the client code needs this... + int extendFile(int64_t len) throw(); + +#endif // !_WIN32 + File(const string& aFileName, int access, int mode) throw(FileException); + bool isOpen() throw(); virtual void close() throw(); virtual int64_t getSize() throw(); virtual void setSize(int64_t newSize) throw(FileException); @@ -68,41 +93,13 @@ static void copyFile(const string& src, const string& target) throw(FileException); static void renameFile(const string& source, const string& target) throw(FileException); + static void deleteFile(const string& aFileName) throw(); static int64_t getSize(const string& aFileName) throw(); - static void ensureDirectory(const string& aFile); - static bool isAbsolute(const string& path); + static void ensureDirectory(const string& aFile) throw(); + static bool isAbsolute(const string& path) throw(); -#ifdef _WIN32 - enum { - READ = GENERIC_READ, - WRITE = GENERIC_WRITE, - RW = READ | WRITE - }; - - static u_int32_t convertTime(FILETIME* f); - bool isOpen() { return h != INVALID_HANDLE_VALUE; } - - static void deleteFile(const string& aFileName) throw() { ::DeleteFile(Text::toT(aFileName).c_str()); } - -#else // _WIN32 - - enum { - READ = 0x01, - WRITE = 0x02, - RW = READ | WRITE - }; - - bool isOpen() { return h != -1; } - static void deleteFile(const string& aFileName) throw() { ::unlink(aFileName.c_str()); } - - // some ftruncate implementations can't extend files like SetEndOfFile, - // not sure if the client code needs this... - int extendFile(int64_t len); - -#endif // _WIN32 - virtual ~File() throw() { File::close(); } string read(size_t len) throw(FileException); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |