Changed: #1023 Use a standard application path for writing files
This commit is contained in:
parent
f5657002bf
commit
10522eae91
4 changed files with 85 additions and 36 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue