diff options
author | Marc Laukien <marc@zeroc.com> | 2004-11-30 01:13:26 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2004-11-30 01:13:26 +0000 |
commit | 7d8c814c5f73b6b93ec4806c69faf2a44ae1ca8b (patch) | |
tree | d4d83e8c9c27e499548ddbce267eb1a2f5a1c328 /cpp | |
parent | IcePatch2 for WIN32 (diff) | |
download | ice-7d8c814c5f73b6b93ec4806c69faf2a44ae1ca8b.tar.bz2 ice-7d8c814c5f73b6b93ec4806c69faf2a44ae1ca8b.tar.xz ice-7d8c814c5f73b6b93ec4806c69faf2a44ae1ca8b.zip |
IcePatch2 for WIN32
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/IcePatch2/Util.h | 2 | ||||
-rw-r--r-- | cpp/src/IcePatch2/Calc.cpp | 2 | ||||
-rw-r--r-- | cpp/src/IcePatch2/Client.cpp | 2 | ||||
-rwxr-xr-x | cpp/src/IcePatch2/ClientUtil.cpp | 8 | ||||
-rw-r--r-- | cpp/src/IcePatch2/Server.cpp | 4 | ||||
-rw-r--r-- | cpp/src/IcePatch2/Util.cpp | 87 |
6 files changed, 72 insertions, 33 deletions
diff --git a/cpp/include/IcePatch2/Util.h b/cpp/include/IcePatch2/Util.h index ea2cc2468e2..6a2c0c5d4fb 100644 --- a/cpp/include/IcePatch2/Util.h +++ b/cpp/include/IcePatch2/Util.h @@ -16,6 +16,8 @@ namespace IcePatch2 { +ICE_PATCH2_API std::string lastError(); + ICE_PATCH2_API std::string bytesToString(const Ice::ByteSeq&); ICE_PATCH2_API Ice::ByteSeq stringToBytes(const std::string&); diff --git a/cpp/src/IcePatch2/Calc.cpp b/cpp/src/IcePatch2/Calc.cpp index e4b2fdb2c6e..c0564f69dcd 100644 --- a/cpp/src/IcePatch2/Calc.cpp +++ b/cpp/src/IcePatch2/Calc.cpp @@ -96,7 +96,7 @@ main(int argc, char* argv[]) if(getcwd(cwd, PATH_MAX) == NULL) #endif { - throw string("cannot get the current directory: ") + strerror(errno); + throw "cannot get the current directory: " + lastError(); } dataDir = normalize(string(cwd) + '/' + dataDir); diff --git a/cpp/src/IcePatch2/Client.cpp b/cpp/src/IcePatch2/Client.cpp index e1fc67d76b1..f5948a63b95 100644 --- a/cpp/src/IcePatch2/Client.cpp +++ b/cpp/src/IcePatch2/Client.cpp @@ -232,7 +232,7 @@ IcePatch2::Client::run(int argc, char* argv[]) { PatcherFeedbackPtr feedback = new TextPatcherFeedback; PatcherPtr patcher = new Patcher(communicator(), feedback); - patcher->patch(); + patchComplete = patcher->patch(); } catch(const string& ex) { diff --git a/cpp/src/IcePatch2/ClientUtil.cpp b/cpp/src/IcePatch2/ClientUtil.cpp index c9ae0035e12..25297001d5f 100755 --- a/cpp/src/IcePatch2/ClientUtil.cpp +++ b/cpp/src/IcePatch2/ClientUtil.cpp @@ -45,7 +45,7 @@ IcePatch2::Patcher::Patcher(const CommunicatorPtr& communicator, const PatcherFe if(getcwd(cwd, PATH_MAX) == NULL) #endif { - throw string("cannot get the current directory: ") + strerror(errno); + throw "cannot get the current directory: " + lastError(); } const_cast<string&>(_dataDir) = normalize(string(cwd) + '/' + _dataDir); @@ -198,7 +198,7 @@ IcePatch2::Patcher::patch() _fileLog.open(pathLog.c_str()); if(!_fileLog) { - throw "cannot open `" + pathLog + "' for writing: " + strerror(errno); + throw "cannot open `" + pathLog + "' for writing: " + lastError(); } { @@ -356,7 +356,7 @@ IcePatch2::Patcher::updateFiles(const FileInfoSeq& files) fileBZ2.open(pathBZ2.c_str(), ios::binary); if(!fileBZ2) { - throw "cannot open `" + pathBZ2 + "' for writing: " + strerror(errno); + throw "cannot open `" + pathBZ2 + "' for writing: " + lastError(); } } @@ -387,7 +387,7 @@ IcePatch2::Patcher::updateFiles(const FileInfoSeq& files) if(!fileBZ2) { - throw ": cannot write `" + pathBZ2 + "': " + strerror(errno); + throw ": cannot write `" + pathBZ2 + "': " + lastError(); } } diff --git a/cpp/src/IcePatch2/Server.cpp b/cpp/src/IcePatch2/Server.cpp index 9d7af28c3f7..61b5d375720 100644 --- a/cpp/src/IcePatch2/Server.cpp +++ b/cpp/src/IcePatch2/Server.cpp @@ -124,11 +124,11 @@ IcePatch2::PatcherService::start(int argc, char* argv[]) char cwd[_MAX_PATH]; if(_getcwd(cwd, _MAX_PATH) == NULL) #else - char cwd[PATH_MAX]; + char cwd[PATH_MAX]; if(getcwd(cwd, PATH_MAX) == NULL) #endif { - throw string("cannot get the current directory: ") + strerror(errno); + throw "cannot get the current directory: " + lastError(); } dataDir = normalize(string(cwd) + '/' + dataDir); diff --git a/cpp/src/IcePatch2/Util.cpp b/cpp/src/IcePatch2/Util.cpp index 71d7ca22281..d21b9cf587b 100644 --- a/cpp/src/IcePatch2/Util.cpp +++ b/cpp/src/IcePatch2/Util.cpp @@ -101,6 +101,43 @@ using namespace Ice; using namespace IcePatch2; string +IcePatch2::lastError() +{ +#ifdef WIN32 + LPVOID lpMsgBuf = 0; + DWORD ok = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR)&lpMsgBuf, + 0, + NULL); + if(ok) + { + LPCTSTR msg = (LPCTSTR)lpMsgBuf; + assert(msg && strlen((const char*)msg) > 0); + string result = (const char*)msg; + LocalFree(lpMsgBuf); + + while(result.size() >= 1 && (result[result.size() - 1] == '\n' || result[result.size() - 1] == '\r')) + { + result.erase(result.size() - 1); + } + + return result; + } + else + { + return "unknown error"; + } +#else + return strerror(errno); +#endif +} + +string IcePatch2::bytesToString(const ByteSeq& bytes) { ostringstream s; @@ -257,7 +294,7 @@ IcePatch2::remove(const string& pa) if(::remove(path.c_str()) == -1) { - throw "cannot remove file `" + path + "': " + strerror(errno); + throw "cannot remove file `" + path + "': " + lastError(); } } @@ -269,7 +306,7 @@ IcePatch2::removeRecursive(const string& pa) struct stat buf; if(stat(path.c_str(), &buf) == -1) { - throw "cannot stat `" + path + "': " + strerror(errno); + throw "cannot stat `" + path + "': " + lastError(); } if(S_ISDIR(buf.st_mode)) @@ -286,7 +323,7 @@ IcePatch2::removeRecursive(const string& pa) if(rmdir(path.c_str()) == -1) #endif { - throw "cannot remove directory `" + path + "': " + strerror(errno); + throw "cannot remove directory `" + path + "': " + lastError(); } } else @@ -306,7 +343,7 @@ IcePatch2::readDirectory(const string& pa) long h = _findfirst((path + "/*").c_str(), &data); if(h == -1) { - throw "cannot read directory `" + path + "': " + strerror(errno); + throw "cannot read directory `" + path + "': " + lastError(); } StringSeq result; @@ -328,7 +365,7 @@ IcePatch2::readDirectory(const string& pa) break; } - string ex = "cannot read directory `" + path + "': " + strerror(errno); + string ex = "cannot read directory `" + path + "': " + lastError(); _findclose(h); throw ex; } @@ -346,7 +383,7 @@ IcePatch2::readDirectory(const string& pa) int n = scandir(path.c_str(), &namelist, 0, alphasort); if(n < 0) { - throw "cannot read directory `" + path + "': " + strerror(errno); + throw "cannot read directory `" + path + "': " + lastError(); } StringSeq result; @@ -390,7 +427,7 @@ IcePatch2::createDirectoryRecursive(const string& pa) { if(errno != EEXIST) { - throw "cannot create directory `" + path + "': " + strerror(errno); + throw "cannot create directory `" + path + "': " + lastError(); } } } @@ -403,7 +440,7 @@ IcePatch2::compressBytesToFile(const string& pa, const ByteSeq& bytes, Int pos) FILE* stdioFile = fopen(path.c_str(), "wb"); if(!stdioFile) { - throw "cannot open `" + path + "' for writing: " + strerror(errno); + throw "cannot open `" + path + "' for writing: " + lastError(); } int bzError; @@ -413,7 +450,7 @@ IcePatch2::compressBytesToFile(const string& pa, const ByteSeq& bytes, Int pos) string ex = "BZ2_bzWriteOpen failed"; if(bzError == BZ_IO_ERROR) { - ex += string(": ") + strerror(errno); + ex += string(": ") + lastError(); } fclose(stdioFile); throw ex; @@ -425,7 +462,7 @@ IcePatch2::compressBytesToFile(const string& pa, const ByteSeq& bytes, Int pos) string ex = "BZ2_bzWrite failed"; if(bzError == BZ_IO_ERROR) { - ex += string(": ") + strerror(errno); + ex += string(": ") + lastError(); } BZ2_bzWriteClose(&bzError, bzFile, 0, 0, 0); fclose(stdioFile); @@ -438,7 +475,7 @@ IcePatch2::compressBytesToFile(const string& pa, const ByteSeq& bytes, Int pos) string ex = "BZ2_bzWriteClose failed"; if(bzError == BZ_IO_ERROR) { - ex += string(": ") + strerror(errno); + ex += string(": ") + lastError(); } fclose(stdioFile); throw ex; @@ -456,13 +493,13 @@ IcePatch2::decompressFile(const string& pa) ofstream file(path.c_str(), ios::binary); if(!file) { - throw "cannot open `" + path + "' for writing: " + strerror(errno); + throw "cannot open `" + path + "' for writing: " + lastError(); } FILE* stdioFileBZ2 = fopen(pathBZ2.c_str(), "rb"); if(!stdioFileBZ2) { - throw "cannot open `" + pathBZ2 + "' for reading: " + strerror(errno); + throw "cannot open `" + pathBZ2 + "' for reading: " + lastError(); } int bzError; @@ -472,7 +509,7 @@ IcePatch2::decompressFile(const string& pa) string ex = "BZ2_bzReadOpen failed"; if(bzError == BZ_IO_ERROR) { - ex += string(": ") + strerror(errno); + ex += string(": ") + lastError(); } fclose(stdioFileBZ2); throw ex; @@ -489,7 +526,7 @@ IcePatch2::decompressFile(const string& pa) string ex = "BZ2_bzRead failed"; if(bzError == BZ_IO_ERROR) { - ex += string(": ") + strerror(errno); + ex += string(": ") + lastError(); } BZ2_bzReadClose(&bzError, bzFile); fclose(stdioFileBZ2); @@ -503,7 +540,7 @@ IcePatch2::decompressFile(const string& pa) { BZ2_bzReadClose(&bzError, bzFile); fclose(stdioFileBZ2); - throw "cannot get read position for `" + pathBZ2 + "': " + strerror(errno); + throw "cannot get read position for `" + pathBZ2 + "': " + lastError(); } file.write(reinterpret_cast<char*>(bytesBZ2), sz); @@ -511,7 +548,7 @@ IcePatch2::decompressFile(const string& pa) { BZ2_bzReadClose(&bzError, bzFile); fclose(stdioFileBZ2); - throw "cannot write `" + path + "': " + strerror(errno); + throw "cannot write `" + path + "': " + lastError(); } } } @@ -522,7 +559,7 @@ IcePatch2::decompressFile(const string& pa) string ex = "BZ2_bzReadClose failed"; if(bzError == BZ_IO_ERROR) { - ex += string(": ") + strerror(errno); + ex += string(": ") + lastError(); } fclose(stdioFileBZ2); throw ex; @@ -566,7 +603,7 @@ getFileInfoSeqInternal(const string& basePath, const string& relativePath, FileI } else { - throw "cannot stat `" + path + "': " + strerror(errno); + throw "cannot stat `" + path + "': " + lastError(); } } else if(buf.st_size == 0) @@ -585,7 +622,7 @@ getFileInfoSeqInternal(const string& basePath, const string& relativePath, FileI struct stat buf; if(stat(path.c_str(), &buf) == -1) { - throw "cannot stat `" + path + "': " + strerror(errno); + throw "cannot stat `" + path + "': " + lastError(); } if(S_ISDIR(buf.st_mode)) @@ -640,13 +677,13 @@ getFileInfoSeqInternal(const string& basePath, const string& relativePath, FileI #endif if(fd == -1) { - throw "cannot open `" + path + "' for reading: " + strerror(errno); + throw "cannot open `" + path + "' for reading: " + lastError(); } if(read(fd, &bytes[relativePath.size()], buf.st_size) == -1) { close(fd); - throw "cannot read `" + path + "': " + strerror(errno); + throw "cannot read `" + path + "': " + lastError(); } close(fd); @@ -664,7 +701,7 @@ getFileInfoSeqInternal(const string& basePath, const string& relativePath, FileI struct stat bufBZ2; if(stat(pathBZ2.c_str(), &bufBZ2) == -1) { - throw "cannot stat `" + pathBZ2 + "': " + strerror(errno); + throw "cannot stat `" + pathBZ2 + "': " + lastError(); } info.size = bufBZ2.st_size; @@ -714,7 +751,7 @@ IcePatch2::saveFileInfoSeq(const string& pa, const FileInfoSeq& infoSeq) ofstream os(path.c_str()); if(!os) { - throw "cannot open `" + path + "' for writing: " + strerror(errno); + throw "cannot open `" + path + "' for writing: " + lastError(); } for(FileInfoSeq::const_iterator p = infoSeq.begin(); p != infoSeq.end(); ++p) @@ -745,7 +782,7 @@ IcePatch2::loadFileInfoSeq(const string& pa, FileInfoSeq& infoSeq) ifstream is(path.c_str()); if(!is) { - throw "cannot open `" + path + "' for reading: " + strerror(errno); + throw "cannot open `" + path + "' for reading: " + lastError(); } while(is.good()) |