summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2005-01-27 22:37:17 +0000
committerMarc Laukien <marc@zeroc.com>2005-01-27 22:37:17 +0000
commit5b5b9d594d4f465103f6b72acfd4194a00a78541 (patch)
treef5726ff5065de40ff34494199fdbdfcc9e0260b8 /cpp/src
parentservice cleanup (diff)
downloadice-5b5b9d594d4f465103f6b72acfd4194a00a78541.tar.bz2
ice-5b5b9d594d4f465103f6b72acfd4194a00a78541.tar.xz
ice-5b5b9d594d4f465103f6b72acfd4194a00a78541.zip
more fixes
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IcePatch2/Calc.cpp23
-rw-r--r--cpp/src/IcePatch2/Client.cpp26
-rwxr-xr-xcpp/src/IcePatch2/ClientUtil.cpp13
-rw-r--r--cpp/src/IcePatch2/Server.cpp23
-rw-r--r--cpp/src/IcePatch2/Util.cpp12
5 files changed, 51 insertions, 46 deletions
diff --git a/cpp/src/IcePatch2/Calc.cpp b/cpp/src/IcePatch2/Calc.cpp
index 358794c146d..7846de7c0f0 100644
--- a/cpp/src/IcePatch2/Calc.cpp
+++ b/cpp/src/IcePatch2/Calc.cpp
@@ -192,39 +192,26 @@ main(int argc, char* argv[])
{
throw "cannot get the current directory:\n" + lastError();
}
-
- if(absDataDir[0] != '/' && !(absDataDir.size() > 1 && isalpha(absDataDir[0]) && absDataDir[1] == ':'))
- {
- absDataDir = string(cwd) + '/' + absDataDir;
- }
-
- for(p = fileSeq.begin(); p != fileSeq.end(); ++p)
- {
- if((*p)[0] != '/' && !(p->size() > 1 && isalpha((*p)[0]) && (*p)[1] == ':'))
- {
- *p = string(cwd) + '/' + *p;
- }
- }
#else
char cwd[PATH_MAX];
if(getcwd(cwd, PATH_MAX) == NULL)
{
throw "cannot get the current directory:\n" + lastError();
}
-
- if(absDataDir[0] != '/')
+#endif
+
+ if(!isAbsolute(absDataDir))
{
- absDataDir = string(cwd) + '/' + absDataDir;
+ absDataDir = simplify(string(cwd) + '/' + absDataDir);
}
for(p = fileSeq.begin(); p != fileSeq.end(); ++p)
{
- if((*p)[0] != '/')
+ if(!isAbsolute(*p))
{
*p = string(cwd) + '/' + *p;
}
}
-#endif
string absDataDirWithSlash = absDataDir + '/';
diff --git a/cpp/src/IcePatch2/Client.cpp b/cpp/src/IcePatch2/Client.cpp
index 8c9581061f2..55236f9f251 100644
--- a/cpp/src/IcePatch2/Client.cpp
+++ b/cpp/src/IcePatch2/Client.cpp
@@ -27,7 +27,8 @@ class TextPatcherFeedback : public PatcherFeedback
{
public:
- TextPatcherFeedback()
+ TextPatcherFeedback() :
+ _pressAnyKeyMessage(false)
{
#ifndef _WIN32
tcgetattr(0, &_savedTerm);
@@ -66,6 +67,12 @@ public:
virtual bool
checksumStart()
{
+ if(!_pressAnyKeyMessage)
+ {
+ cout << "[Press any key to abort]" << endl;
+ _pressAnyKeyMessage = true;
+ }
+
return !keyPressed();
}
@@ -85,6 +92,12 @@ public:
virtual bool
fileListStart()
{
+ if(!_pressAnyKeyMessage)
+ {
+ cout << "[Press any key to abort]" << endl;
+ _pressAnyKeyMessage = true;
+ }
+
_lastProgress = "0%";
cout << "Getting list of files to patch: " << _lastProgress << flush;
return !keyPressed();
@@ -114,6 +127,12 @@ public:
virtual bool
patchStart(const string& path, Long size, Long totalProgress, Long totalSize)
{
+ if(!_pressAnyKeyMessage)
+ {
+ cout << "[Press any key to abort]" << endl;
+ _pressAnyKeyMessage = true;
+ }
+
ostringstream s;
s << "0/" << size << " (" << totalProgress << '/' << totalSize << ')';
_lastProgress = s.str();
@@ -177,8 +196,6 @@ private:
fcntl(0, F_SETFL, flags);
_block = false;
-
- cout << "[Press any key to abort]" << endl;
}
bool pressed = false;
@@ -197,6 +214,7 @@ private:
#endif
string _lastProgress;
+ bool _pressAnyKeyMessage;
};
class Client : public Application
@@ -255,7 +273,7 @@ Client::run(int argc, char* argv[])
}
if(args.size() == 1)
{
- properties->setProperty("IcePatch2.Directory", args[0]);
+ properties->setProperty("IcePatch2.Directory", simplify(args[0]));
}
bool aborted = false;
diff --git a/cpp/src/IcePatch2/ClientUtil.cpp b/cpp/src/IcePatch2/ClientUtil.cpp
index a8d86f9e006..d9603a3e373 100755
--- a/cpp/src/IcePatch2/ClientUtil.cpp
+++ b/cpp/src/IcePatch2/ClientUtil.cpp
@@ -142,7 +142,7 @@ private:
IcePatch2::Patcher::Patcher(const CommunicatorPtr& communicator, const PatcherFeedbackPtr& feedback) :
_feedback(feedback),
- _dataDir(simplify(communicator->getProperties()->getProperty("IcePatch2.Directory"))),
+ _dataDir(simplify(communicator->getProperties()->getPropertyWithDefault("IcePatch2.Directory", "."))),
_thorough(communicator->getProperties()->getPropertyAsInt("IcePatch2.Thorough") > 0),
_chunkSize(communicator->getProperties()->getPropertyAsIntWithDefault("IcePatch2.ChunkSize", 100000)),
_remove(communicator->getProperties()->getPropertyAsIntWithDefault("IcePatch2.Remove", 1))
@@ -157,29 +157,24 @@ IcePatch2::Patcher::Patcher(const CommunicatorPtr& communicator, const PatcherFe
const_cast<Int&>(_chunkSize) = 1;
}
-#ifdef _WIN32
- if(_dataDir[0] != '/' && !(_dataDir.size() > 1 && isalpha(_dataDir[0]) && _dataDir[1] == ':'))
+ if(!isAbsolute(_dataDir))
{
+#ifdef _WIN32
char cwd[_MAX_PATH];
if(_getcwd(cwd, _MAX_PATH) == NULL)
{
throw "cannot get the current directory:\n" + lastError();
}
-
- const_cast<string&>(_dataDir) = string(cwd) + '/' + _dataDir;
- }
#else
- if(_dataDir[0] != '/')
- {
char cwd[PATH_MAX];
if(getcwd(cwd, PATH_MAX) == NULL)
{
throw "cannot get the current directory:\n" + lastError();
}
+#endif
const_cast<string&>(_dataDir) = string(cwd) + '/' + _dataDir;
}
-#endif
PropertiesPtr properties = communicator->getProperties();
diff --git a/cpp/src/IcePatch2/Server.cpp b/cpp/src/IcePatch2/Server.cpp
index 7abed80da46..468e52a6598 100644
--- a/cpp/src/IcePatch2/Server.cpp
+++ b/cpp/src/IcePatch2/Server.cpp
@@ -69,7 +69,7 @@ IcePatch2::PatcherService::PatcherService()
bool
IcePatch2::PatcherService::start(int argc, char* argv[])
{
- string dataDir;
+ PropertiesPtr properties = communicator()->getProperties();
IceUtil::Options opts;
opts.addOpt("h", "help");
@@ -106,34 +106,27 @@ IcePatch2::PatcherService::start(int argc, char* argv[])
}
if(args.size() == 1)
{
- dataDir = args[0];
+ properties->setProperty("IcePatch2.Directory", simplify(args[0]));
}
- PropertiesPtr properties = communicator()->getProperties();
-
+ string dataDir = properties->getPropertyWithDefault("IcePatch2.Directory", ".");
if(dataDir.empty())
{
- dataDir = properties->getProperty("IcePatch2.Directory");
- if(dataDir.empty())
- {
- error("no data directory specified");
- usage(argv[0]);
- return false;
- }
+ error("no data directory specified");
+ usage(argv[0]);
+ return false;
}
FileInfoSeq infoSeq;
try
{
-#ifdef _WIN32
- if(dataDir[0] != '/' && !(dataDir.size() > 1 && isalpha(dataDir[0]) && dataDir[1] == ':'))
+ if(!isAbsolute(dataDir))
{
+#ifdef _WIN32
char cwd[_MAX_PATH];
if(_getcwd(cwd, _MAX_PATH) == NULL)
#else
- if(dataDir[0] != '/')
- {
char cwd[PATH_MAX];
if(getcwd(cwd, PATH_MAX) == NULL)
#endif
diff --git a/cpp/src/IcePatch2/Util.cpp b/cpp/src/IcePatch2/Util.cpp
index 0a71e26b11f..34b92d7df5d 100644
--- a/cpp/src/IcePatch2/Util.cpp
+++ b/cpp/src/IcePatch2/Util.cpp
@@ -260,6 +260,18 @@ IcePatch2::simplify(const string& path)
return result;
}
+bool
+IcePatch2::isAbsolute(const string& pa)
+{
+ const string path = simplify(pa);
+
+#ifdef _WIN32
+ return path[0] == '/' || path.size() > 1 && isalpha(path[0]) && path[1] == ':';
+#else
+ return path[0] == '/';
+#endif
+}
+
string
IcePatch2::getSuffix(const string& pa)
{