27#if !defined WIN32_LEAN_AND_MEAN
28# define WIN32_LEAN_AND_MEAN
35#include <osl/security.hxx>
36#include <osl/file.hxx>
37#include <osl/thread.h>
39using namespace ::com::sun::star::mozilla;
44 OUString lcl_getUserDataDirectory()
46 ::osl::Security aSecurity;
49 #if defined(_WIN32) || defined(MACOSX)
50 aSecurity.getConfigDir( aConfigPath );
55 aSecurity.getHomeDir( aConfigPath );
58 return aConfigPath +
"/";
62 const size_t NB_PRODUCTS = 3;
63 const size_t NB_CANDIDATES = 4;
69 const char* DefaultProductDir[NB_PRODUCTS][NB_CANDIDATES] =
72 {
"Mozilla/SeaMonkey/",
nullptr,
nullptr,
nullptr },
73 {
"Mozilla/Firefox/",
nullptr,
nullptr,
nullptr },
74 {
"Thunderbird/",
"Mozilla/Thunderbird/",
nullptr,
nullptr }
76 {
"../Mozilla/SeaMonkey/",
nullptr,
nullptr,
nullptr },
77 {
"Firefox/",
nullptr,
nullptr,
nullptr },
78 {
"../Thunderbird/",
nullptr,
nullptr,
nullptr }
80 {
".mozilla/seamonkey/",
nullptr,
nullptr,
nullptr },
81 {
".mozilla/firefox/",
nullptr,
nullptr,
nullptr },
82 {
".thunderbird/",
".mozilla-thunderbird/",
".mozilla/thunderbird/",
".icedove/" }
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;
105 const char* pProfileByEnv = getenv( ProductRootEnvironmentVariable[ productIndex ] );
108 sProductPath = OUString( pProfileByEnv, rtl_str_getLength( pProfileByEnv ), osl_getThreadTextEncoding() );
113 OUString sProductDirCandidate;
114 const char pProfileRegistry[] =
"profiles.ini";
117 for (
size_t i=0;
i<NB_CANDIDATES; ++
i )
119 if (
nullptr == DefaultProductDir[ productIndex ][ i ] )
122 sProductDirCandidate = lcl_getUserDataDirectory() +
123 OUString::createFromAscii( DefaultProductDir[ productIndex ][ i ] );
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 )
140 ::osl::FileBase::getSystemPathFromFileURL( sProductDirCandidate, sProductPath );
143 s_productDirectories[ productIndex ] = sProductPath;
146 return s_productDirectories[ productIndex ];
153 if (product == MozillaProductType_Default)
156 return lcl_guessProfileRoot( product );
OUString getRegistryDir(MozillaProductType product)