diff options
author | Oz Linden <oz@lindenlab.com> | 2018-01-17 12:43:28 -0500 |
---|---|---|
committer | Oz Linden <oz@lindenlab.com> | 2018-01-17 12:43:28 -0500 |
commit | d7c8678c3aa46aed09dce6c1edfc196e72d4b428 (patch) | |
tree | 538a1ef15c2e28676f6a7618bc1e0b5749e2bcea /indra/llvfs/lldir_win32.cpp | |
parent | 9e4b977b2fbb565cef88f3d72e07dbdf8cb2cd69 (diff) | |
parent | 7acbd8ed8d73c507675d45360df07d232c431a8b (diff) |
merge 5.1.0-release
Diffstat (limited to 'indra/llvfs/lldir_win32.cpp')
-rw-r--r-- | indra/llvfs/lldir_win32.cpp | 109 |
1 files changed, 66 insertions, 43 deletions
diff --git a/indra/llvfs/lldir_win32.cpp b/indra/llvfs/lldir_win32.cpp index 46f946d08a..c4a4c74d1e 100644 --- a/indra/llvfs/lldir_win32.cpp +++ b/indra/llvfs/lldir_win32.cpp @@ -31,7 +31,8 @@ #include "lldir_win32.h" #include "llerror.h" #include "llrand.h" // for gLindenLabRandomNumber -#include "shlobj.h" +#include <shlobj.h> +#include <fstream> #include <direct.h> #include <errno.h> @@ -44,28 +45,25 @@ DWORD GetDllVersion(LPCTSTR lpszDllName); LLDir_Win32::LLDir_Win32() { + // set this first: used by append() and add() methods mDirDelimiter = "\\"; - WCHAR w_str[MAX_PATH]; - - // Application Data is where user settings go - SHGetSpecialFolderPath(NULL, w_str, CSIDL_APPDATA, TRUE); - - mOSUserDir = utf16str_to_utf8str(llutf16string(w_str)); + // Application Data is where user settings go. We rely on $APPDATA being + // correct; in fact the VMP makes a point of setting it properly, since + // Windows itself botches the job for non-ASCII usernames (MAINT-8087). + mOSUserDir = ll_safe_string(getenv("APPDATA")); // We want cache files to go on the local disk, even if the // user is on a network with a "roaming profile". // - // On XP this is: - // C:\Docments and Settings\James\Local Settings\Application Data // On Vista this is: // C:\Users\James\AppData\Local // // We used to store the cache in AppData\Roaming, and the installer // cleans up that version on upgrade. JC - SHGetSpecialFolderPath(NULL, w_str, CSIDL_LOCAL_APPDATA, TRUE); - mOSCacheDir = utf16str_to_utf8str(llutf16string(w_str)); + mOSCacheDir = ll_safe_string(getenv("LOCALAPPDATA")); + WCHAR w_str[MAX_PATH]; if (GetTempPath(MAX_PATH, w_str)) { if (wcslen(w_str)) /* Flawfinder: ignore */ @@ -73,12 +71,54 @@ LLDir_Win32::LLDir_Win32() w_str[wcslen(w_str)-1] = '\0'; /* Flawfinder: ignore */ // remove trailing slash } mTempDir = utf16str_to_utf8str(llutf16string(w_str)); + + if (mOSUserDir.empty()) + { + mOSUserDir = mTempDir; + } + + if (mOSCacheDir.empty()) + { + mOSCacheDir = mTempDir; + } } else { mTempDir = mOSUserDir; } +/*==========================================================================*| + // Now that we've got mOSUserDir, one way or another, let's see how we did + // with our environment variables. + { + auto report = [this](std::ostream& out){ + out << "mOSUserDir = '" << mOSUserDir << "'\n" + << "mOSCacheDir = '" << mOSCacheDir << "'\n" + << "mTempDir = '" << mTempDir << "'" << std::endl; + }; + int res = LLFile::mkdir(mOSUserDir); + if (res == -1) + { + // If we couldn't even create the directory, just blurt to stderr + report(std::cerr); + } + else + { + // successfully created logdir, plunk a log file there + std::string logfilename(add(mOSUserDir, "lldir.log")); + std::ofstream logfile(logfilename.c_str()); + if (! logfile.is_open()) + { + report(std::cerr); + } + else + { + report(logfile); + } + } + } +|*==========================================================================*/ + // fprintf(stderr, "mTempDir = <%s>",mTempDir); // Set working directory, for LLDir::getWorkingDir() @@ -124,7 +164,7 @@ LLDir_Win32::LLDir_Win32() // 'llplugin' need to go somewhere else. // alas... this also gets called during static initialization // time due to the construction of gDirUtil in lldir.cpp. - if(! LLFile::isdir(mAppRODataDir + mDirDelimiter + "skins")) + if(! LLFile::isdir(add(mAppRODataDir, "skins"))) { // What? No skins in the working dir? // Try the executable's directory. @@ -133,7 +173,7 @@ LLDir_Win32::LLDir_Win32() // LL_INFOS() << "mAppRODataDir = " << mAppRODataDir << LL_ENDL; - mSkinBaseDir = mAppRODataDir + mDirDelimiter + "skins"; + mSkinBaseDir = add(mAppRODataDir, "skins"); // Build the default cache directory mDefaultCacheDir = buildSLOSCacheDir(); @@ -142,13 +182,10 @@ LLDir_Win32::LLDir_Win32() int res = LLFile::mkdir(mDefaultCacheDir); if (res == -1) { - if (errno != EEXIST) - { - LL_WARNS() << "Couldn't create LL_PATH_CACHE dir " << mDefaultCacheDir << LL_ENDL; - } + LL_WARNS() << "Couldn't create LL_PATH_CACHE dir " << mDefaultCacheDir << LL_ENDL; } - mLLPluginDir = mExecutableDir + mDirDelimiter + "llplugin"; + mLLPluginDir = add(mExecutableDir, "llplugin"); } LLDir_Win32::~LLDir_Win32() @@ -164,52 +201,38 @@ void LLDir_Win32::initAppDirs(const std::string &app_name, if (!app_read_only_data_dir.empty()) { mAppRODataDir = app_read_only_data_dir; - mSkinBaseDir = mAppRODataDir + mDirDelimiter + "skins"; + mSkinBaseDir = add(mAppRODataDir, "skins"); } mAppName = app_name; - mOSUserAppDir = mOSUserDir; - mOSUserAppDir += "\\"; - mOSUserAppDir += app_name; + mOSUserAppDir = add(mOSUserDir, app_name); int res = LLFile::mkdir(mOSUserAppDir); if (res == -1) { - if (errno != EEXIST) - { - LL_WARNS() << "Couldn't create app user dir " << mOSUserAppDir << LL_ENDL; - LL_WARNS() << "Default to base dir" << mOSUserDir << LL_ENDL; - mOSUserAppDir = mOSUserDir; - } + LL_WARNS() << "Couldn't create app user dir " << mOSUserAppDir << LL_ENDL; + LL_WARNS() << "Default to base dir" << mOSUserDir << LL_ENDL; + mOSUserAppDir = mOSUserDir; } //dumpCurrentDirectories(); res = LLFile::mkdir(getExpandedFilename(LL_PATH_LOGS,"")); if (res == -1) { - if (errno != EEXIST) - { - LL_WARNS() << "Couldn't create LL_PATH_LOGS dir " << getExpandedFilename(LL_PATH_LOGS,"") << LL_ENDL; - } + LL_WARNS() << "Couldn't create LL_PATH_LOGS dir " << getExpandedFilename(LL_PATH_LOGS,"") << LL_ENDL; } - + res = LLFile::mkdir(getExpandedFilename(LL_PATH_USER_SETTINGS,"")); if (res == -1) { - if (errno != EEXIST) - { - LL_WARNS() << "Couldn't create LL_PATH_USER_SETTINGS dir " << getExpandedFilename(LL_PATH_USER_SETTINGS,"") << LL_ENDL; - } + LL_WARNS() << "Couldn't create LL_PATH_USER_SETTINGS dir " << getExpandedFilename(LL_PATH_USER_SETTINGS,"") << LL_ENDL; } - + res = LLFile::mkdir(getExpandedFilename(LL_PATH_CACHE,"")); if (res == -1) { - if (errno != EEXIST) - { - LL_WARNS() << "Couldn't create LL_PATH_CACHE dir " << getExpandedFilename(LL_PATH_CACHE,"") << LL_ENDL; - } + LL_WARNS() << "Couldn't create LL_PATH_CACHE dir " << getExpandedFilename(LL_PATH_CACHE,"") << LL_ENDL; } - + mCAFile = getExpandedFilename(LL_PATH_APP_SETTINGS, "ca-bundle.crt"); } |