diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2020-01-13 02:11:38 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2020-01-13 03:38:20 +0100 |
commit | 628189b73465b811fd7083e1fdc8533443b52588 (patch) | |
tree | bdb5f83ec618b012c99c64986745afea4bcdedbd /vcl/unx/generic/fontmanager | |
parent | bb9c74189c9d8dd3e4de7efe94b9ba8d158a9133 (diff) |
Use static initializer
Change-Id: If46a12403bf941ed8b4b131bfdfa17667d3f1f0d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86650
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'vcl/unx/generic/fontmanager')
-rw-r--r-- | vcl/unx/generic/fontmanager/helper.cxx | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/vcl/unx/generic/fontmanager/helper.cxx b/vcl/unx/generic/fontmanager/helper.cxx index 9c1649d547f3..c586dcce7d7f 100644 --- a/vcl/unx/generic/fontmanager/helper.cxx +++ b/vcl/unx/generic/fontmanager/helper.cxx @@ -21,6 +21,7 @@ #include <sys/stat.h> #include <limits.h> +#include <osl/file.hxx> #include <osl/process.h> #include <osl/thread.h> #include <rtl/bootstrap.hxx> @@ -29,51 +30,47 @@ #include <tools/urlobj.hxx> #include <unx/helper.hxx> +#include <tuple> + using ::rtl::Bootstrap; namespace psp { OUString getOfficePath( whichOfficePath ePath ) { - static OUString aInstallationRootPath; - static OUString aUserPath; - static OUString aConfigPath; - static bool bOnce = false; - - if( ! bOnce ) - { - bOnce = true; - OUString aIni; - Bootstrap::get( "BRAND_BASE_DIR", aInstallationRootPath ); - aIni = aInstallationRootPath + "/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap" ); - Bootstrap aBootstrap( aIni ); - aBootstrap.getFrom( "CustomDataUrl", aConfigPath ); - aBootstrap.getFrom( "UserInstallation", aUserPath ); - OUString aUPath = aUserPath; - - if( aConfigPath.startsWith( "file://" ) ) + static const auto aPaths = [] { + OUString sRoot, sUser, sConfig; + Bootstrap::get("BRAND_BASE_DIR", sRoot); + Bootstrap aBootstrap(sRoot + "/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap")); + aBootstrap.getFrom("UserInstallation", sUser); + aBootstrap.getFrom("CustomDataUrl", sConfig); + OUString aUPath = sUser + "/user/psprint"; + if (sRoot.startsWith("file://")) { OUString aSysPath; - if( osl_getSystemPathFromFileURL( aConfigPath.pData, &aSysPath.pData ) == osl_File_E_None ) - aConfigPath = aSysPath; + if (osl::FileBase::getSystemPathFromFileURL(sRoot, aSysPath) == osl::FileBase::E_None) + sRoot = aSysPath; } - if( aInstallationRootPath.startsWith( "file://" ) ) + if (sUser.startsWith("file://")) { OUString aSysPath; - if( osl_getSystemPathFromFileURL( aInstallationRootPath.pData, &aSysPath.pData ) == osl_File_E_None ) - aInstallationRootPath = aSysPath; + if (osl::FileBase::getSystemPathFromFileURL(sUser, aSysPath) == osl::FileBase::E_None) + sUser = aSysPath; } - if( aUserPath.startsWith( "file://" ) ) + if (sConfig.startsWith("file://")) { OUString aSysPath; - if( osl_getSystemPathFromFileURL( aUserPath.pData, &aSysPath.pData ) == osl_File_E_None ) - aUserPath = aSysPath; + if (osl::FileBase::getSystemPathFromFileURL(sConfig, aSysPath) == osl::FileBase::E_None) + sConfig = aSysPath; } + // ensure user path exists - aUPath += "/user/psprint"; SAL_INFO("vcl.fonts", "Trying to create: " << aUPath); - osl_createDirectoryPath( aUPath.pData, nullptr, nullptr ); - } + osl::Directory::createPath(aUPath); + + return std::make_tuple(sRoot, sUser, sConfig); + }(); + const auto& [aInstallationRootPath, aUserPath, aConfigPath] = aPaths; switch( ePath ) { |