summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2014-12-19 17:38:37 -0500
committerBernard Normier <bernard@zeroc.com>2014-12-19 17:38:37 -0500
commitdcc7ad378c043f1c52007db9ef4b879b4c29c00b (patch)
treec9cc999afad4c2a6761e8da804993d78a822abb2 /cpp/src
parentminor edits to CHANGES (diff)
downloadice-dcc7ad378c043f1c52007db9ef4b879b4c29c00b.tar.bz2
ice-dcc7ad378c043f1c52007db9ef4b879b4c29c00b.tar.xz
ice-dcc7ad378c043f1c52007db9ef4b879b4c29c00b.zip
iceserviceinstall cleanup
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/iceserviceinstall/Install.cpp13
-rw-r--r--cpp/src/iceserviceinstall/ServiceInstaller.cpp44
-rw-r--r--cpp/src/iceserviceinstall/ServiceInstaller.h2
3 files changed, 49 insertions, 10 deletions
diff --git a/cpp/src/iceserviceinstall/Install.cpp b/cpp/src/iceserviceinstall/Install.cpp
index facf29d6316..fd3280489d9 100644
--- a/cpp/src/iceserviceinstall/Install.cpp
+++ b/cpp/src/iceserviceinstall/Install.cpp
@@ -184,6 +184,17 @@ Install::pause() const
void
Install::usage() const
{
+ string defaultImagePath = IceServiceInstaller::getServiceInstallerPath();
+ if(defaultImagePath.empty())
+ {
+ defaultImagePath = string("<error: cannot retrieve path of ") + appName() + ">";
+ }
+ defaultImagePath += "\\<service>";
+#ifdef _DEBUG
+ defaultImagePath += 'd';
+#endif
+ defaultImagePath += ".exe";
+
cerr << "Usage: " << appName()
<< " [options] service config-file [property] [property]\n";
cerr <<
@@ -202,7 +213,7 @@ Install::usage() const
"\n"
"Valid properties:\n"
"ImagePath Full path to <service>.exe. The default value is\n"
- " <directory of " << appName() << ">\\<service>.exe\n"
+ " " << defaultImagePath << "\n" <<
"DisplayName Display name of the service.\n"
"Description Description of the service.\n"
"AutoStart If non-zero, the service is started automatically when\n"
diff --git a/cpp/src/iceserviceinstall/ServiceInstaller.cpp b/cpp/src/iceserviceinstall/ServiceInstaller.cpp
index 8766e3fbdbe..fc44c72feec 100644
--- a/cpp/src/iceserviceinstall/ServiceInstaller.cpp
+++ b/cpp/src/iceserviceinstall/ServiceInstaller.cpp
@@ -120,14 +120,17 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
string imagePath = properties->getProperty("ImagePath");
if(imagePath == "")
{
- char buffer[MAX_PATH];
- DWORD size = GetModuleFileName(0, buffer, MAX_PATH);
- if(size == 0)
+ string serviceInstallerPath = getServiceInstallerPath();
+ if(serviceInstallerPath.empty())
{
- throw "Can't get full path to self: " + IceUtilInternal::errorToString(GetLastError());
+ throw "Can't get full path to service installer!";
}
- imagePath = string(buffer, size);
- imagePath.replace(imagePath.rfind('\\'), string::npos, "\\" + serviceTypeToLowerString(_serviceType) + ".exe");
+
+ imagePath = serviceInstallerPath + '\\' + serviceTypeToLowerString(_serviceType);
+#ifdef _DEBUG
+ imagePath += 'd';
+#endif
+ imagePath += ".exe";
}
else
{
@@ -367,7 +370,7 @@ IceServiceInstaller::uninstall()
}
}
-vector<string>
+/*static*/ vector<string>
IceServiceInstaller::getPropertyNames()
{
static const string propertyNames[] = { "ImagePath", "DisplayName", "ObjectName", "Password",
@@ -378,7 +381,7 @@ IceServiceInstaller::getPropertyNames()
return result;
}
-string
+/*static*/ string
IceServiceInstaller::serviceTypeToString(int serviceType)
{
static const string serviceTypeArray[] = { "IceGridRegistry", "IceGridNode", "Glacier2Router" };
@@ -393,7 +396,7 @@ IceServiceInstaller::serviceTypeToString(int serviceType)
}
}
-string
+/*static*/ string
IceServiceInstaller::serviceTypeToLowerString(int serviceType)
{
static const string serviceTypeArray[] = { "icegridregistry", "icegridnode", "glacier2router" };
@@ -408,6 +411,29 @@ IceServiceInstaller::serviceTypeToLowerString(int serviceType)
}
}
+/*static*/ string
+IceServiceInstaller::getServiceInstallerPath()
+{
+ string path;
+
+ char buffer[MAX_PATH];
+ DWORD size = GetModuleFileName(0, buffer, MAX_PATH);
+ if(size > 0)
+ {
+ path = string(buffer, size);
+ size_t p = path.find_last_of("/\\");
+ if(p != string::npos)
+ {
+ path = path.substr(0, p);
+ }
+ else
+ {
+ path = "";
+ }
+ }
+ return path;
+}
+
void
IceServiceInstaller::initializeSid(const string& name)
{
diff --git a/cpp/src/iceserviceinstall/ServiceInstaller.h b/cpp/src/iceserviceinstall/ServiceInstaller.h
index 0d020398829..2a1a9fdd8d2 100644
--- a/cpp/src/iceserviceinstall/ServiceInstaller.h
+++ b/cpp/src/iceserviceinstall/ServiceInstaller.h
@@ -33,6 +33,8 @@ public:
static std::string serviceTypeToString(int);
static std::string serviceTypeToLowerString(int);
+ static std::string getServiceInstallerPath();
+
private:
void initializeSid(const std::string&);