bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / mozab / bootstrap / MNSFolders.cxx
blob71c70c641b30e5355dbb57d5475f04ab698924c5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "MNSFolders.hxx"
22 #ifdef UNIX
23 #include <string.h>
24 #endif // End UNIX
26 #ifdef _WIN32
27 #if !defined WIN32_LEAN_AND_MEAN
28 # define WIN32_LEAN_AND_MEAN
29 #endif
30 #include <windows.h>
31 #include <stdlib.h>
32 #include <shlobj.h>
33 #include <objidl.h>
34 #endif // End _WIN32
35 #include <osl/security.hxx>
36 #include <osl/file.hxx>
37 #include <osl/thread.h>
39 using namespace ::com::sun::star::mozilla;
41 namespace
44 OUString lcl_getUserDataDirectory()
46 ::osl::Security aSecurity;
47 OUString aConfigPath;
49 #if defined(_WIN32) || defined(MACOSX)
50 aSecurity.getConfigDir( aConfigPath );
51 #else
52 //This is to find the dir under which .mozilla/.thunderbird is created.
53 //mozilla doesn't honour XDG_CONFIG_HOME, so raw home dir required here
54 //not xdg-config dir
55 aSecurity.getHomeDir( aConfigPath );
56 #endif
58 return aConfigPath + "/";
62 const size_t NB_PRODUCTS = 3;
63 const size_t NB_CANDIDATES = 4;
65 // The order (index) of entries in DefaultProductDir and
66 // ProductRootEnvironmentVariable *must* match the constants
67 // (minus 1) in offapi/com/sun/star/mozilla/MozillaProductType.idl
68 // DO NOT CHANGE THE ORDER; ADD ONLY TO THE END
69 const char* DefaultProductDir[NB_PRODUCTS][NB_CANDIDATES] =
71 #if defined(_WIN32)
72 { "Mozilla/SeaMonkey/", nullptr, nullptr, nullptr },
73 { "Mozilla/Firefox/", nullptr, nullptr, nullptr },
74 { "Thunderbird/", "Mozilla/Thunderbird/", nullptr, nullptr }
75 #elif defined(MACOSX)
76 { "../Mozilla/SeaMonkey/", nullptr, nullptr, nullptr },
77 { "Firefox/", nullptr, nullptr, nullptr },
78 { "../Thunderbird/", nullptr, nullptr, nullptr }
79 #else
80 { ".mozilla/seamonkey/", nullptr, nullptr, nullptr },
81 { ".mozilla/firefox/", nullptr, nullptr, nullptr },
82 { ".thunderbird/", ".mozilla-thunderbird/", ".mozilla/thunderbird/", ".icedove/" }
83 #endif
86 const char* ProductRootEnvironmentVariable[NB_PRODUCTS] =
88 "MOZILLA_PROFILE_ROOT",
89 "MOZILLA_FIREFOX_PROFILE_ROOT",
90 "MOZILLA_THUNDERBIRD_PROFILE_ROOT",
94 OUString const & lcl_guessProfileRoot( MozillaProductType _product )
96 size_t productIndex = static_cast<int>(_product) - 1;
98 static OUString s_productDirectories[NB_PRODUCTS];
100 if ( s_productDirectories[ productIndex ].isEmpty() )
102 OUString sProductPath;
104 // check whether we have an environment variable which help us
105 const char* pProfileByEnv = getenv( ProductRootEnvironmentVariable[ productIndex ] );
106 if ( pProfileByEnv )
108 sProductPath = OUString( pProfileByEnv, rtl_str_getLength( pProfileByEnv ), osl_getThreadTextEncoding() );
109 // assume that this is fine, no further checks
111 else
113 OUString sProductDirCandidate;
114 const char pProfileRegistry[] = "profiles.ini";
116 // check all possible candidates
117 for ( size_t i=0; i<NB_CANDIDATES; ++i )
119 if ( nullptr == DefaultProductDir[ productIndex ][ i ] )
120 break;
122 sProductDirCandidate = lcl_getUserDataDirectory() +
123 OUString::createFromAscii( DefaultProductDir[ productIndex ][ i ] );
125 // check existence
126 ::osl::DirectoryItem aRegistryItem;
127 ::osl::FileBase::RC result = ::osl::DirectoryItem::get( sProductDirCandidate + pProfileRegistry, aRegistryItem );
128 if ( result == ::osl::FileBase::E_None )
130 ::osl::FileStatus aStatus( osl_FileStatus_Mask_Validate );
131 result = aRegistryItem.getFileStatus( aStatus );
132 if ( result == ::osl::FileBase::E_None )
134 // the registry file exists
135 break;
140 ::osl::FileBase::getSystemPathFromFileURL( sProductDirCandidate, sProductPath );
143 s_productDirectories[ productIndex ] = sProductPath;
146 return s_productDirectories[ productIndex ];
151 OUString getRegistryDir(MozillaProductType product)
153 if (product == MozillaProductType_Default)
154 return OUString();
156 return lcl_guessProfileRoot( product );
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */