Changed: #1023 Use a standard application path for writing files
This commit is contained in:
parent
aa88a7fb49
commit
c426347080
4 changed files with 68 additions and 26 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue