diff --git a/code/nel/include/nel/misc/path.h b/code/nel/include/nel/misc/path.h index 98896a216..f19050c90 100644 --- a/code/nel/include/nel/misc/path.h +++ b/code/nel/include/nel/misc/path.h @@ -224,6 +224,16 @@ public: */ std::string getWindowsDirectory(); + /** Get application directory. + * \return directory where applications should write files. + */ + std::string getApplicationDirectory(const std::string &appName = ""); + + /** Get a temporary directory. + * \return temporary directory where applications should write files. + */ + std::string getTemporaryDirectory(); + private: // All path in this vector must have a terminated '/' @@ -506,6 +516,16 @@ public: */ static std::string getWindowsDirectory(); + /** Get application directory. + * \return directory where applications should write files. + */ + static std::string getApplicationDirectory(const std::string &appName = ""); + + /** Get a temporary directory. + * \return temporary directory where applications should write files. + */ + static std::string getTemporaryDirectory(); + // release singleton static void releaseInstance(); @@ -700,11 +720,6 @@ struct CFile * Call this method to get a temporary output filename. If you have successfully saved your data, delete the old filename and move the new one. */ static void getTemporaryOutputFilename (const std::string &originalFilename, std::string &tempFilename); - - /** Get application directory. - * \return directory where applications should write files. - */ - static std::string getApplicationDirectory(const std::string &appName = ""); }; } // NLMISC diff --git a/code/nel/src/misc/path.cpp b/code/nel/src/misc/path.cpp index 308b78af4..80911027b 100644 --- a/code/nel/src/misc/path.cpp +++ b/code/nel/src/misc/path.cpp @@ -1686,6 +1686,66 @@ std::string CFileContainer::getWindowsDirectory() #endif } +std::string CPath::getApplicationDirectory(const std::string &appName) +{ + return getInstance()->_FileContainer.getApplicationDirectory(appName); +} + +std::string CFileContainer::getApplicationDirectory(const std::string &appName) +{ + static std::string appPath; + if (appPath.empty()) + { +#ifdef NL_OS_WINDOWS + wchar_t buffer[MAX_PATH]; + SHGetSpecialFolderPathW(NULL, buffer, CSIDL_APPDATA, TRUE); + appPath = CPath::standardizePath(ucstring((ucchar*)buffer).toUtf8()); +#else + appPath = CPath::standardizePath(getenv("HOME")); +#endif + } + + std::string path = appPath; +#ifdef NL_OS_WINDOWS + if (!appName.empty()) + path = CPath::standardizePath(path + appName); +#else + if (!appName.empty()) + path = CPath::standardizePath(path + "." + toLower(appName)); +#endif + + return path; +} + +std::string CPath::getTemporaryDirectory() +{ + return getInstance()->_FileContainer.getTemporaryDirectory(); +} + +std::string CFileContainer::getTemporaryDirectory() +{ + static std::string path; + if (path.empty()) + { + char *tempDir = getenv("TEMP"); + + if (tempDir == NULL) + tempDir = getenv("TMP"); + +#ifdef NL_OS_UNIX + if (tempDir == NULL) + tempDir = "/tmp"; +#else + if (tempDir == NULL) + tempDir = "."; +#endif + + path = CPath::standardizePath(tempDir); + } + + return path; +} + ////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2470,30 +2530,4 @@ void CFile::getTemporaryOutputFilename (const std::string &originalFilename, std while (CFile::isExists(tempFilename)); } -std::string CFile::getApplicationDirectory(const std::string &appName) -{ - static std::string appPath; - if (appPath.empty()) - { -#ifdef NL_OS_WINDOWS - wchar_t buffer[MAX_PATH]; - SHGetSpecialFolderPathW(NULL, buffer, CSIDL_APPDATA, TRUE); - appPath = CPath::standardizePath(ucstring((ucchar*)buffer).toUtf8()); -#else - appPath = CPath::standardizePath(getenv("HOME")); -#endif - } - - std::string path = appPath; -#ifdef NL_OS_WINDOWS - if (!appName.empty()) - path = CPath::standardizePath(path + appName); -#else - if (!appName.empty()) - path = CPath::standardizePath(path + "." + toLower(appName)); -#endif - - return path; -} - } // NLMISC diff --git a/code/ryzom/client/src/client.cpp b/code/ryzom/client/src/client.cpp index 1c31a2e7b..7d5ddeb34 100644 --- a/code/ryzom/client/src/client.cpp +++ b/code/ryzom/client/src/client.cpp @@ -361,7 +361,7 @@ int main(int argc, char **argv) // if client_default.cfg is not in current directory, use application default directory if (!CFile::isExists("client_default.cfg")) { - std::string currentPath = CFile::getApplicationDirectory("Ryzom"); + std::string currentPath = CPath::getApplicationDirectory("Ryzom"); if (!CFile::isExists(currentPath)) CFile::createDirectory(currentPath); diff --git a/code/ryzom/tools/client/client_patcher/main.cpp b/code/ryzom/tools/client/client_patcher/main.cpp index 1c0affb9c..824ce093b 100644 --- a/code/ryzom/tools/client/client_patcher/main.cpp +++ b/code/ryzom/tools/client/client_patcher/main.cpp @@ -121,7 +121,7 @@ void printDownload(const std::string &str) // add padding with spaces memset(spaces, ' ', maxLength); spaces[maxLength - length] = '\0'; - + // display download in purple if (useEsc) { @@ -150,8 +150,8 @@ int main(int argc, char *argv[]) // init the Nel context CApplicationContext appContext; - // create logs in TEMP directory - createDebug(getenv("TEMP"), true, true); + // create logs in temporary directory + createDebug(CPath::getTemporaryDirectory(), true, true); // disable log display on stdout INelContext::getInstance().getDebugLog()->removeDisplayer("DEFAULT_SD"); @@ -198,7 +198,7 @@ int main(int argc, char *argv[]) } #endif - // create or load client.cfg + // load client.cfg or client_default.cfg ClientCfg.init(config); // check if PatchServer is defined