diff --git a/code/nel/include/nel/misc/path.h b/code/nel/include/nel/misc/path.h index 52088d67b..98896a216 100644 --- a/code/nel/include/nel/misc/path.h +++ b/code/nel/include/nel/misc/path.h @@ -700,6 +700,11 @@ 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 e30982056..7ba510aa4 100644 --- a/code/nel/src/misc/path.cpp +++ b/code/nel/src/misc/path.cpp @@ -2435,4 +2435,30 @@ 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 93a243949..cf0c621b3 100644 --- a/code/ryzom/client/src/client.cpp +++ b/code/ryzom/client/src/client.cpp @@ -345,6 +345,14 @@ int main(int argc, char **argv) // init the Nel context CApplicationContext *appContext = new CApplicationContext; +#ifdef CHANGE_CURRENT_PATH + std::string currentPath = CFile::getApplicationDirectory("Ryzom"); + + if (!CFile::isExists(currentPath)) CFile::createDirectory(currentPath); + + CPath::setCurrentPath(currentPath); +#endif // CHANGE_CURRENT_PATH + // temporary buffer to store Ryzom full path char filename[1024]; @@ -437,31 +445,6 @@ int main(int argc, char **argv) GetModuleFileName(GetModuleHandle(NULL), filename, 1024); -#else - - // TODO for Linux : splashscreen - - if (argc >= 3) - { - LoginLogin = argv[1]; - LoginPassword = argv[2]; - if (!fromString(argv[3], LoginShardId)) LoginShardId = -1; - } - else if (argc >= 2) - { - LoginLogin = argv[1]; - LoginPassword = argv[2]; - LoginShardId = -1; - } - - strcpy(filename, argv[0]); - -#endif - - // initialize patch manager and set the ryzom full path, before it's used - CPatchManager *pPM = CPatchManager::getInstance(); - pPM->setRyzomFilename(NLMISC::CFile::getFilename(filename)); - // Delete the .bat file because it s not useful anymore if (NLMISC::CFile::fileExists("updt_nl.bat")) NLMISC::CFile::deleteFile("updt_nl.bat"); @@ -488,6 +471,31 @@ int main(int argc, char **argv) } } +#else + + // TODO for Linux : splashscreen + + if (argc >= 3) + { + LoginLogin = argv[1]; + LoginPassword = argv[2]; + if (!fromString(argv[3], LoginShardId)) LoginShardId = -1; + } + else if (argc >= 2) + { + LoginLogin = argv[1]; + LoginPassword = argv[2]; + LoginShardId = -1; + } + + strcpy(filename, argv[0]); + +#endif + + // initialize patch manager and set the ryzom full path, before it's used + CPatchManager *pPM = CPatchManager::getInstance(); + pPM->setRyzomFilename(NLMISC::CFile::getFilename(filename)); + ///////////////////////////////// // Initialize the application. // #ifndef TEST_CRASH_COUNTER diff --git a/code/ryzom/client/src/init.cpp b/code/ryzom/client/src/init.cpp index 9f19b4844..ca2dcd9fe 100644 --- a/code/ryzom/client/src/init.cpp +++ b/code/ryzom/client/src/init.cpp @@ -728,7 +728,10 @@ void prelogInit() setDefaultEmailParams ("smtp.nevrax.com", "", "ryzombug@nevrax.com"); // create the save dir. - CFile::createDirectory("save"); + if (!CFile::isExists("data")) CFile::createDirectory("data"); + + // create the save dir. + if (!CFile::isExists("save")) CFile::createDirectory("save"); #if !FINAL_VERSION // if we're not in final version then start the file access logger to keep track of the files that we read as we play