diff --git a/gazebo/common/CommonIface.hh b/gazebo/common/CommonIface.hh index cc990d8a14..82606a8528 100644 --- a/gazebo/common/CommonIface.hh +++ b/gazebo/common/CommonIface.hh @@ -85,6 +85,12 @@ namespace gazebo GZ_COMMON_VISIBLE const char *getEnv(const char *_name); +#ifdef _WIN32 + #define HOMEDIR "USERPROFILE" +#else + #define HOMEDIR "HOME" +#endif // _WIN32 + /// \brief Get the current working directory /// \return Name of the current directory GZ_COMMON_VISIBLE diff --git a/gazebo/common/Console.cc b/gazebo/common/Console.cc index 5bda931a05..b334978369 100644 --- a/gazebo/common/Console.cc +++ b/gazebo/common/Console.cc @@ -23,6 +23,7 @@ #include "gazebo/common/Exception.hh" #include "gazebo/common/Time.hh" #include "gazebo/common/Console.hh" +#include "gazebo/common/CommonIface.hh" #include "gazebo/gazebo_config.h" @@ -155,7 +156,7 @@ FileLogger::~FileLogger() ///////////////////////////////////////////////// void FileLogger::Init(const std::string &_prefix, const std::string &_filename) { - if (!getenv("HOME")) + if (!getenv(HOMEDIR)) { gzerr << "Missing HOME environment variable." << "No log file will be generated."; @@ -165,7 +166,7 @@ void FileLogger::Init(const std::string &_prefix, const std::string &_filename) FileLogger::Buffer *buf = static_cast( this->rdbuf()); - boost::filesystem::path logPath(getenv("HOME")); + boost::filesystem::path logPath(getenv(HOMEDIR)); // Create a subdirectory for the informational log. The name of the directory // will be . E.g.: server-11346. If the environment diff --git a/gazebo/common/ModelDatabase.cc b/gazebo/common/ModelDatabase.cc index 4e46add362..c434a1cdf3 100644 --- a/gazebo/common/ModelDatabase.cc +++ b/gazebo/common/ModelDatabase.cc @@ -40,6 +40,7 @@ #include "gazebo/common/ModelDatabasePrivate.hh" #include "gazebo/common/ModelDatabase.hh" #include "gazebo/common/SemanticVersion.hh" +#include "gazebo/common/CommonIface.hh" using namespace gazebo; using namespace common; @@ -503,7 +504,7 @@ std::string ModelDatabase::GetModelPath(const std::string &_uri, continue; } - std::string outputPath = getenv("HOME"); + std::string outputPath = getenv(HOMEDIR); outputPath += "/.gazebo/models"; #ifndef _WIN32 diff --git a/gazebo/common/SystemPaths.cc b/gazebo/common/SystemPaths.cc index 08e84f234e..788628eac7 100644 --- a/gazebo/common/SystemPaths.cc +++ b/gazebo/common/SystemPaths.cc @@ -38,6 +38,7 @@ #include "gazebo/common/Exception.hh" #include "gazebo/common/ModelDatabase.hh" #include "gazebo/common/SystemPaths.hh" +#include "gazebo/common/CommonIface.hh" using namespace gazebo; using namespace common; @@ -81,7 +82,7 @@ SystemPaths::SystemPaths() return; } - char *homePath = getenv("HOME"); + char *homePath = getenv(HOMEDIR); std::string home; if (!homePath) home = this->TmpPath() + "/gazebo"; diff --git a/gazebo/gui/DataLogger.cc b/gazebo/gui/DataLogger.cc index e25cb0157c..40f9eb32b9 100644 --- a/gazebo/gui/DataLogger.cc +++ b/gazebo/gui/DataLogger.cc @@ -254,11 +254,7 @@ DataLogger::DataLogger(QWidget *_parent) "~/log/status", &DataLogger::OnStatus, this); // Fill the path with the home folder - duplicated from util/LogRecord -#ifndef _WIN32 - const char *homePath = common::getEnv("HOME"); -#else - const char *homePath = common::getEnv("HOMEPATH"); -#endif + const char *homePath = common::getEnv(HOMEDIR); GZ_ASSERT(homePath, "HOME environment variable is missing"); diff --git a/gazebo/gui/GuiIface.cc b/gazebo/gui/GuiIface.cc index 018e3a6f23..1d6c03ed8a 100644 --- a/gazebo/gui/GuiIface.cc +++ b/gazebo/gui/GuiIface.cc @@ -43,12 +43,6 @@ #include "gazebo/gui/GuiPlugin.hh" #include "gazebo/gui/RenderWidget.hh" -#ifdef WIN32 -# define HOMEDIR "HOMEPATH" -#else -# define HOMEDIR "HOME" -#endif // WIN32 - // These are needed by QT. They need to stay valid during the entire // lifetime of the application, and argc > 0 and argv must contain one valid // character string diff --git a/gazebo/gui/MainWindow.cc b/gazebo/gui/MainWindow.cc index 9cd24dde47..7b04049043 100644 --- a/gazebo/gui/MainWindow.cc +++ b/gazebo/gui/MainWindow.cc @@ -27,6 +27,7 @@ #include "gazebo/common/Console.hh" #include "gazebo/common/Events.hh" #include "gazebo/common/Exception.hh" +#include "gazebo/common/CommonIface.hh" #include "gazebo/msgs/msgs.hh" @@ -463,7 +464,7 @@ void MainWindow::Open() ///////////////////////////////////////////////// void MainWindow::SaveINI() { - char *home = getenv("HOME"); + char *home = getenv(HOMEDIR); if (!home) { gzerr << "HOME environment variable not found. " diff --git a/gazebo/gui/SaveEntityDialog.cc b/gazebo/gui/SaveEntityDialog.cc index 296cf10fb7..66e49262aa 100644 --- a/gazebo/gui/SaveEntityDialog.cc +++ b/gazebo/gui/SaveEntityDialog.cc @@ -19,6 +19,7 @@ #include "gazebo/common/SystemPaths.hh" #include "gazebo/common/Console.hh" +#include "gazebo/common/CommonIface.hh" #include "gazebo/gui/GuiIface.hh" #include "gazebo/gui/SaveEntityDialog.hh" @@ -408,7 +409,7 @@ void SaveEntityDialog::AddDirToModelPaths(const std::string &_path) // Save any changes that were made to the property tree // TODO: check gui.ini env variable - char *home = getenv("HOME"); + char *home = getenv(HOMEDIR); if (home) { boost::filesystem::path guiINIPath = home; diff --git a/gazebo/rendering/Camera.cc b/gazebo/rendering/Camera.cc index 8b6e717e7e..246868298b 100644 --- a/gazebo/rendering/Camera.cc +++ b/gazebo/rendering/Camera.cc @@ -44,6 +44,7 @@ #include "gazebo/common/Console.hh" #include "gazebo/common/Exception.hh" #include "gazebo/common/VideoEncoder.hh" +#include "gazebo/common/CommonIface.hh" #include "gazebo/rendering/ogre_gazebo.h" #include "gazebo/rendering/RTShaderSystem.hh" @@ -101,7 +102,7 @@ Camera::Camera(const std::string &_name, ScenePtr _scene, this->sceneNode = NULL; - this->screenshotPath = getenv("HOME"); + this->screenshotPath = getenv(HOMEDIR); this->screenshotPath += "/.gazebo/pictures"; // Connect to the render signal diff --git a/gazebo/util/Diagnostics.cc b/gazebo/util/Diagnostics.cc index 55626b0fc1..60983bdab6 100644 --- a/gazebo/util/Diagnostics.cc +++ b/gazebo/util/Diagnostics.cc @@ -32,11 +32,7 @@ using namespace gazebo::util; DiagnosticManager::DiagnosticManager() : dataPtr(new DiagnosticManagerPrivate) { -#ifndef _WIN32 - const char *homePath = common::getEnv("HOME"); -#else - const char *homePath = common::getEnv("HOMEPATH"); -#endif + const char *homePath = common::getEnv(HOMEDIR); this->dataPtr->logPath = homePath; // Get the base of the time logging path diff --git a/gazebo/util/LogRecord.cc b/gazebo/util/LogRecord.cc index 19658f54a4..221543655a 100644 --- a/gazebo/util/LogRecord.cc +++ b/gazebo/util/LogRecord.cc @@ -71,11 +71,7 @@ LogRecord::LogRecord() this->dataPtr->readyToStart = false; // Get the user's home directory -#ifndef _WIN32 - const char *homePath = common::getEnv("HOME"); -#else - const char *homePath = common::getEnv("HOMEPATH"); -#endif + const char *homePath = common::getEnv(HOMEDIR); GZ_ASSERT(homePath, "HOME environment variable is missing"); diff --git a/gazebo/util/LogRecord_TEST.cc b/gazebo/util/LogRecord_TEST.cc index 7448c2bfcf..70912ac25f 100644 --- a/gazebo/util/LogRecord_TEST.cc +++ b/gazebo/util/LogRecord_TEST.cc @@ -33,11 +33,7 @@ TEST_F(LogRecord_TEST, Constructor) { gazebo::util::LogRecord *recorder = gazebo::util::LogRecord::Instance(); -#ifndef _WIN32 - const char *homePath = common::getEnv("HOME"); -#else - const char *homePath = common::getEnv("HOMEPATH"); -#endif + const char *homePath = common::getEnv(HOMEDIR); EXPECT_TRUE(homePath != NULL); diff --git a/test/integration/plugin.cc b/test/integration/plugin.cc index 19f605e535..e4240da9a6 100644 --- a/test/integration/plugin.cc +++ b/test/integration/plugin.cc @@ -17,6 +17,7 @@ #include #include "gazebo/test/ServerFixture.hh" +#include "gazebo/common/CommonIface.hh" using namespace gazebo; class PluginTest : public ServerFixture @@ -36,7 +37,7 @@ TEST_F(PluginTest, ModelExceptionConstructor) world->Step(100); - char *home = getenv("HOME"); + char *home = getenv(HOMEDIR); ASSERT_TRUE(home); boost::filesystem::path path(home); @@ -71,7 +72,7 @@ TEST_F(PluginTest, ModelExceptionInit) world->Step(100); - char *home = getenv("HOME"); + char *home = getenv(HOMEDIR); ASSERT_TRUE(home); boost::filesystem::path path(home); @@ -106,7 +107,7 @@ TEST_F(PluginTest, ModelExceptionLoad) world->Step(100); - char *home = getenv("HOME"); + char *home = getenv(HOMEDIR); ASSERT_TRUE(home); boost::filesystem::path path(home); diff --git a/test/integration/sdf_errors.cc b/test/integration/sdf_errors.cc index c1bce2b223..aa4e322e09 100644 --- a/test/integration/sdf_errors.cc +++ b/test/integration/sdf_errors.cc @@ -40,11 +40,7 @@ class SDFLogsTest : public ServerFixture { public: void SetUp() { -#ifndef _WIN32 - const boost::filesystem::path home = common::getEnv("HOME"); -#else - const boost::filesystem::path home = common::getEnv("HOMEPATH"); -#endif + const boost::filesystem::path home = common::getEnv(HOMEDIR); boost::filesystem::path log_path("/.gazebo/server-11345/default.log"); path = home / log_path; }