diff --git a/VERSION.txt b/VERSION.txt index 51e8fdc..6bf5ecb 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.2.18 +0.2.19 diff --git a/src/combine/util.cpp b/src/combine/util.cpp index 778a8c5..5fbd0ca 100644 --- a/src/combine/util.cpp +++ b/src/combine/util.cpp @@ -13,6 +13,21 @@ LIBCOMBINE_CPP_NAMESPACE_USE +std::string Util::mDefaultTempDir = "."; + +std::string +Util::getDefaultTempDir() +{ + return mDefaultTempDir; +} + +void +Util::setDefaultTempDir(const std::string& defaultDir) +{ + mDefaultTempDir = defaultDir; +} + + std::string Util::getTempPath() { @@ -20,7 +35,7 @@ Util::getTempPath() if (tmpDir != NULL) return tmpDir; tmpDir = getenv("TEMP"); if (tmpDir != NULL) return tmpDir; - return "."; + return mDefaultTempDir; } std::string diff --git a/src/combine/util.h b/src/combine/util.h index 26b5292..78a21d9 100644 --- a/src/combine/util.h +++ b/src/combine/util.h @@ -105,6 +105,19 @@ class LIBCOMBINE_EXTERN Util */ static bool removeFileOrFolder(const std::string& path); + /** + * @brief Get the Default Temp Dir object + * + * @return std::string of the default directory + */ + static std::string getDefaultTempDir(); + + /** + * @brief Set the Default Temp Dir object + * + * @param defaultDir the default directory + */ + static void setDefaultTempDir(const std::string& defaultDir); private: @@ -118,7 +131,10 @@ class LIBCOMBINE_EXTERN Util */ static size_t getExtensionIndex(const char *fileName); - + /** + * the default temp dir (defaults to ".") + */ + static std::string mDefaultTempDir; }; LIBCOMBINE_CPP_NAMESPACE_END diff --git a/src/test/util_test.cpp b/src/test/util_test.cpp index 8c78a43..7aab67c 100644 --- a/src/test/util_test.cpp +++ b/src/test/util_test.cpp @@ -29,4 +29,13 @@ SCENARIO("utility methods", "[combine][util]") REQUIRE(KnownFormats::isFormat("sbml", KnownFormats::guessFormat(getTestFile("test-data/BorisEJB.xml")))); } + + GIVEN("The default dir is changed") + { + std::string defaultDir = Util::getDefaultTempDir(); + REQUIRE(defaultDir.empty() == false); + Util::setDefaultTempDir("/tmp/"); + REQUIRE(Util::getDefaultTempDir() == "/tmp/"); + Util::setDefaultTempDir(defaultDir); + } }