From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- .../source/drivers/mozab/bootstrap/MNSFolders.cxx | 159 +++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx (limited to 'connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx') diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx b/connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx new file mode 100644 index 000000000..71c70c641 --- /dev/null +++ b/connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx @@ -0,0 +1,159 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "MNSFolders.hxx" + +#ifdef UNIX +#include +#endif // End UNIX + +#ifdef _WIN32 +#if !defined WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif +#include +#include +#include +#include +#endif // End _WIN32 +#include +#include +#include + +using namespace ::com::sun::star::mozilla; + +namespace +{ + + OUString lcl_getUserDataDirectory() + { + ::osl::Security aSecurity; + OUString aConfigPath; + + #if defined(_WIN32) || defined(MACOSX) + aSecurity.getConfigDir( aConfigPath ); + #else + //This is to find the dir under which .mozilla/.thunderbird is created. + //mozilla doesn't honour XDG_CONFIG_HOME, so raw home dir required here + //not xdg-config dir + aSecurity.getHomeDir( aConfigPath ); + #endif + + return aConfigPath + "/"; + } + + + const size_t NB_PRODUCTS = 3; + const size_t NB_CANDIDATES = 4; + + // The order (index) of entries in DefaultProductDir and + // ProductRootEnvironmentVariable *must* match the constants + // (minus 1) in offapi/com/sun/star/mozilla/MozillaProductType.idl + // DO NOT CHANGE THE ORDER; ADD ONLY TO THE END + const char* DefaultProductDir[NB_PRODUCTS][NB_CANDIDATES] = + { + #if defined(_WIN32) + { "Mozilla/SeaMonkey/", nullptr, nullptr, nullptr }, + { "Mozilla/Firefox/", nullptr, nullptr, nullptr }, + { "Thunderbird/", "Mozilla/Thunderbird/", nullptr, nullptr } + #elif defined(MACOSX) + { "../Mozilla/SeaMonkey/", nullptr, nullptr, nullptr }, + { "Firefox/", nullptr, nullptr, nullptr }, + { "../Thunderbird/", nullptr, nullptr, nullptr } + #else + { ".mozilla/seamonkey/", nullptr, nullptr, nullptr }, + { ".mozilla/firefox/", nullptr, nullptr, nullptr }, + { ".thunderbird/", ".mozilla-thunderbird/", ".mozilla/thunderbird/", ".icedove/" } + #endif + }; + + const char* ProductRootEnvironmentVariable[NB_PRODUCTS] = + { + "MOZILLA_PROFILE_ROOT", + "MOZILLA_FIREFOX_PROFILE_ROOT", + "MOZILLA_THUNDERBIRD_PROFILE_ROOT", + }; + + + OUString const & lcl_guessProfileRoot( MozillaProductType _product ) + { + size_t productIndex = static_cast(_product) - 1; + + static OUString s_productDirectories[NB_PRODUCTS]; + + if ( s_productDirectories[ productIndex ].isEmpty() ) + { + OUString sProductPath; + + // check whether we have an environment variable which help us + const char* pProfileByEnv = getenv( ProductRootEnvironmentVariable[ productIndex ] ); + if ( pProfileByEnv ) + { + sProductPath = OUString( pProfileByEnv, rtl_str_getLength( pProfileByEnv ), osl_getThreadTextEncoding() ); + // assume that this is fine, no further checks + } + else + { + OUString sProductDirCandidate; + const char pProfileRegistry[] = "profiles.ini"; + + // check all possible candidates + for ( size_t i=0; i