From c4096f670c7b3d43f8a5c1f65ef7e02033b0329d Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 14 Dec 2018 15:38:13 -0500 Subject: SL-10153: Review and rationalize fetching paths from environment. Use LLStringUtil::getenv() or getoptenv() whenever we fetch a string that will be used as a pathname. Use LLFile::tmpdir() instead of getenv("TEMP"). As an added extra-special bonus, finally clean up $TMP/llcontrol-test-zzzzzz directories that have been accumulating every time we run a local build! --- indra/llrender/llfontgl.cpp | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp index cf0a117567..bb56988422 100644 --- a/indra/llrender/llfontgl.cpp +++ b/indra/llrender/llfontgl.cpp @@ -1063,33 +1063,24 @@ LLFontGL* LLFontGL::getFontDefault() // static std::string LLFontGL::getFontPathSystem() { - std::string system_path; - - // Try to figure out where the system's font files are stored. - char *system_root = NULL; -#if LL_WINDOWS - system_root = getenv("SystemRoot"); /* Flawfinder: ignore */ - if (!system_root) - { - LL_WARNS() << "SystemRoot not found, attempting to load fonts from default path." << LL_ENDL; - } +#if LL_DARWIN + // HACK for Mac OS X + return "/System/Library/Fonts/"; + +#elif LL_WINDOWS + wchar_t *pwstr = NULL; + HRESULT okay = SHGetKnownFolderPath(FOLDERID_Fonts, 0, NULL, &pwstr); + if (SUCCEEDED(okay) && pwstr) + { + std::string fontpath(ll_convert_wide_to_string(pwstr)); + // SHGetKnownFolderPath() contract requires us to free pwstr + CoTaskMemFree(pwstr); + return fontpath; + } #endif - if (system_root) - { - system_path = llformat("%s/fonts/", system_root); - } - else - { -#if LL_WINDOWS - // HACK for windows 98/Me - system_path = "/WINDOWS/FONTS/"; -#elif LL_DARWIN - // HACK for Mac OS X - system_path = "/System/Library/Fonts/"; -#endif - } - return system_path; + LL_WARNS() << "Could not determine system fonts path" << LL_ENDL; + return {}; } -- cgit v1.3 From 4a136572857fcf5d5fd21789a777bbde67c1076d Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Sat, 15 Dec 2018 09:13:24 -0500 Subject: SL-10153: auto name{expression} declares an initializer_list instead of a variable of type decltype(expression). Using SHGetKnownFolderPath(FOLDERID_Fonts) in LLFontGL::getFontPathSystem() requires new Windows #include files. A variable with a constructor can't be declared within the braces of a switch statement, even outside any of its case clauses. --- indra/llcommon/llstring.h | 4 ++-- indra/llrender/llfontgl.cpp | 6 ++++++ indra/llvfs/lldir_win32.cpp | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llcommon/llstring.h b/indra/llcommon/llstring.h index 8d2c8d79d7..30bec3a6f8 100644 --- a/indra/llcommon/llstring.h +++ b/indra/llcommon/llstring.h @@ -1755,7 +1755,7 @@ bool LLStringUtilBase::endsWith( template auto LLStringUtilBase::getoptenv(const std::string& key) -> boost::optional { - auto found{llstring_getoptenv(key)}; + auto found(llstring_getoptenv(key)); if (found) { // return populated boost::optional @@ -1772,7 +1772,7 @@ auto LLStringUtilBase::getoptenv(const std::string& key) -> boost::optional auto LLStringUtilBase::getenv(const std::string& key, const string_type& dflt) -> string_type { - auto found{getoptenv(key)}; + auto found(getoptenv(key)); if (found) { return *found; diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp index bb56988422..9b43680949 100644 --- a/indra/llrender/llfontgl.cpp +++ b/indra/llrender/llfontgl.cpp @@ -44,6 +44,12 @@ // Third party library includes #include +#if LL_WINDOWS +#include +#include +#include +#endif // LL_WINDOWS + const S32 BOLD_OFFSET = 1; // static class members diff --git a/indra/llvfs/lldir_win32.cpp b/indra/llvfs/lldir_win32.cpp index acf734f16b..b3b3afb37e 100644 --- a/indra/llvfs/lldir_win32.cpp +++ b/indra/llvfs/lldir_win32.cpp @@ -54,15 +54,15 @@ namespace void prelog(const std::string& message) { + boost::optional prelog_name; + switch (state) { - boost::optional prelog_name; - case prst::INIT: // assume we failed, until we succeed state = prst::SKIP; - prelog_name = LLDirUtil::getoptenv("PRELOG"); + prelog_name = LLStringUtil::getoptenv("PRELOG"); if (! prelog_name) // no PRELOG variable set, carry on return; -- cgit v1.3 From 4b99e6a1f11efe66b3fb0aa3b6fa721afe698446 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 17 Dec 2018 15:23:57 -0500 Subject: SL-10252: On Windows, use $SystemRoot again, not FOLDERID_Fonts. --- indra/llrender/llfontgl.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp index 9b43680949..8cd18c5fa1 100644 --- a/indra/llrender/llfontgl.cpp +++ b/indra/llrender/llfontgl.cpp @@ -40,6 +40,7 @@ #include "v4color.h" #include "lltexture.h" #include "lldir.h" +#include "llstring.h" // Third party library includes #include @@ -1074,6 +1075,14 @@ std::string LLFontGL::getFontPathSystem() return "/System/Library/Fonts/"; #elif LL_WINDOWS + auto system_root = LLStringUtil::getenv("SystemRoot"); + if (! system_root.empty()) + { + std::string fontpath(gDirUtilp->add(system_root, "fonts") + gDirUtilp->getDirDelimiter()); + LL_INFOS() << "from SystemRoot: " << fontpath << LL_ENDL; + return fontpath; + } + wchar_t *pwstr = NULL; HRESULT okay = SHGetKnownFolderPath(FOLDERID_Fonts, 0, NULL, &pwstr); if (SUCCEEDED(okay) && pwstr) @@ -1081,6 +1090,7 @@ std::string LLFontGL::getFontPathSystem() std::string fontpath(ll_convert_wide_to_string(pwstr)); // SHGetKnownFolderPath() contract requires us to free pwstr CoTaskMemFree(pwstr); + LL_INFOS() << "from SHGetKnownFolderPath(): " << fontpath << LL_ENDL; return fontpath; } #endif -- cgit v1.3