1*9874e4f6SJuergen Schmidt /**************************************************************
2*9874e4f6SJuergen Schmidt *
3*9874e4f6SJuergen Schmidt * Licensed to the Apache Software Foundation (ASF) under one
4*9874e4f6SJuergen Schmidt * or more contributor license agreements. See the NOTICE file
5*9874e4f6SJuergen Schmidt * distributed with this work for additional information
6*9874e4f6SJuergen Schmidt * regarding copyright ownership. The ASF licenses this file
7*9874e4f6SJuergen Schmidt * to you under the Apache License, Version 2.0 (the
8*9874e4f6SJuergen Schmidt * "License"); you may not use this file except in compliance
9*9874e4f6SJuergen Schmidt * with the License. You may obtain a copy of the License at
10*9874e4f6SJuergen Schmidt *
11*9874e4f6SJuergen Schmidt * http://www.apache.org/licenses/LICENSE-2.0
12*9874e4f6SJuergen Schmidt *
13*9874e4f6SJuergen Schmidt * Unless required by applicable law or agreed to in writing,
14*9874e4f6SJuergen Schmidt * software distributed under the License is distributed on an
15*9874e4f6SJuergen Schmidt * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9874e4f6SJuergen Schmidt * KIND, either express or implied. See the License for the
17*9874e4f6SJuergen Schmidt * specific language governing permissions and limitations
18*9874e4f6SJuergen Schmidt * under the License.
19*9874e4f6SJuergen Schmidt *
20*9874e4f6SJuergen Schmidt *************************************************************/
21*9874e4f6SJuergen Schmidt
22*9874e4f6SJuergen Schmidt // MARKER(update_precomp.py): autogen include statement, do not remove
23*9874e4f6SJuergen Schmidt #include "precompiled_extensions.hxx"
24*9874e4f6SJuergen Schmidt #include <MNSFolders.hxx>
25*9874e4f6SJuergen Schmidt
26*9874e4f6SJuergen Schmidt #ifdef UNIX
27*9874e4f6SJuergen Schmidt #include <sys/types.h>
28*9874e4f6SJuergen Schmidt #include <strings.h>
29*9874e4f6SJuergen Schmidt #include <string.h>
30*9874e4f6SJuergen Schmidt #endif // End UNIX
31*9874e4f6SJuergen Schmidt
32*9874e4f6SJuergen Schmidt #ifdef WNT
33*9874e4f6SJuergen Schmidt #include "pre_include_windows.h"
34*9874e4f6SJuergen Schmidt #include <windows.h>
35*9874e4f6SJuergen Schmidt #include <stdlib.h>
36*9874e4f6SJuergen Schmidt #include <shlobj.h>
37*9874e4f6SJuergen Schmidt #include <objidl.h>
38*9874e4f6SJuergen Schmidt #include "post_include_windows.h"
39*9874e4f6SJuergen Schmidt #endif // End WNT
40*9874e4f6SJuergen Schmidt #include <osl/security.hxx>
41*9874e4f6SJuergen Schmidt #include <osl/file.hxx>
42*9874e4f6SJuergen Schmidt #include <osl/thread.h>
43*9874e4f6SJuergen Schmidt
44*9874e4f6SJuergen Schmidt using namespace ::com::sun::star::mozilla;
45*9874e4f6SJuergen Schmidt
46*9874e4f6SJuergen Schmidt namespace
47*9874e4f6SJuergen Schmidt {
48*9874e4f6SJuergen Schmidt // -------------------------------------------------------------------
lcl_getUserDataDirectory()49*9874e4f6SJuergen Schmidt static ::rtl::OUString lcl_getUserDataDirectory()
50*9874e4f6SJuergen Schmidt {
51*9874e4f6SJuergen Schmidt ::osl::Security aSecurity;
52*9874e4f6SJuergen Schmidt ::rtl::OUString aConfigPath;
53*9874e4f6SJuergen Schmidt
54*9874e4f6SJuergen Schmidt aSecurity.getConfigDir( aConfigPath );
55*9874e4f6SJuergen Schmidt return aConfigPath + ::rtl::OUString::createFromAscii( "/" );
56*9874e4f6SJuergen Schmidt }
57*9874e4f6SJuergen Schmidt
58*9874e4f6SJuergen Schmidt // -------------------------------------------------------------------
59*9874e4f6SJuergen Schmidt static const char* DefaultProductDir[3][3] =
60*9874e4f6SJuergen Schmidt {
61*9874e4f6SJuergen Schmidt #if defined(XP_WIN)
62*9874e4f6SJuergen Schmidt { "Mozilla/SeaMonkey/", NULL, NULL },
63*9874e4f6SJuergen Schmidt { "Mozilla/Firefox/", NULL, NULL },
64*9874e4f6SJuergen Schmidt { "Thunderbird/", "Mozilla/Thunderbird/", NULL }
65*9874e4f6SJuergen Schmidt #elif(MACOSX)
66*9874e4f6SJuergen Schmidt { "../Mozilla/SeaMonkey/", NULL, NULL },
67*9874e4f6SJuergen Schmidt { "Firefox/", NULL, NULL },
68*9874e4f6SJuergen Schmidt { "../Thunderbird/", NULL, NULL }
69*9874e4f6SJuergen Schmidt #else
70*9874e4f6SJuergen Schmidt { ".mozilla/seamonkey/", NULL, NULL },
71*9874e4f6SJuergen Schmidt { ".mozilla/firefox/", NULL, NULL },
72*9874e4f6SJuergen Schmidt { ".thunderbird/", ".mozilla-thunderbird/", ".mozilla/thunderbird/" }
73*9874e4f6SJuergen Schmidt #endif
74*9874e4f6SJuergen Schmidt };
75*9874e4f6SJuergen Schmidt
76*9874e4f6SJuergen Schmidt static const char* ProductRootEnvironmentVariable[3] =
77*9874e4f6SJuergen Schmidt {
78*9874e4f6SJuergen Schmidt "MOZILLA_PROFILE_ROOT",
79*9874e4f6SJuergen Schmidt "MOZILLA_FIREFOX_PROFILE_ROOT",
80*9874e4f6SJuergen Schmidt "MOZILLA_THUNDERBIRD_PROFILE_ROOT",
81*9874e4f6SJuergen Schmidt };
82*9874e4f6SJuergen Schmidt
83*9874e4f6SJuergen Schmidt // -------------------------------------------------------------------
lcl_guessProfileRoot(MozillaProductType _product)84*9874e4f6SJuergen Schmidt static ::rtl::OUString lcl_guessProfileRoot( MozillaProductType _product )
85*9874e4f6SJuergen Schmidt {
86*9874e4f6SJuergen Schmidt size_t productIndex = _product - 1;
87*9874e4f6SJuergen Schmidt
88*9874e4f6SJuergen Schmidt static ::rtl::OUString s_productDirectories[3];
89*9874e4f6SJuergen Schmidt
90*9874e4f6SJuergen Schmidt if ( !s_productDirectories[ productIndex ].getLength() )
91*9874e4f6SJuergen Schmidt {
92*9874e4f6SJuergen Schmidt ::rtl::OUString sProductPath;
93*9874e4f6SJuergen Schmidt
94*9874e4f6SJuergen Schmidt // check whether we have an anevironment variable which helps us
95*9874e4f6SJuergen Schmidt const char* pProfileByEnv = getenv( ProductRootEnvironmentVariable[ productIndex ] );
96*9874e4f6SJuergen Schmidt if ( pProfileByEnv )
97*9874e4f6SJuergen Schmidt {
98*9874e4f6SJuergen Schmidt sProductPath = ::rtl::OUString( pProfileByEnv, rtl_str_getLength( pProfileByEnv ), osl_getThreadTextEncoding() );
99*9874e4f6SJuergen Schmidt // asume that this is fine, no further checks
100*9874e4f6SJuergen Schmidt }
101*9874e4f6SJuergen Schmidt else
102*9874e4f6SJuergen Schmidt {
103*9874e4f6SJuergen Schmidt ::rtl::OUString sProductDirCandidate;
104*9874e4f6SJuergen Schmidt const char* pProfileRegistry = "profiles.ini";
105*9874e4f6SJuergen Schmidt
106*9874e4f6SJuergen Schmidt // check all possible candidates
107*9874e4f6SJuergen Schmidt for ( size_t i=0; i<3; ++i )
108*9874e4f6SJuergen Schmidt {
109*9874e4f6SJuergen Schmidt if ( NULL == DefaultProductDir[ productIndex ][ i ] )
110*9874e4f6SJuergen Schmidt break;
111*9874e4f6SJuergen Schmidt
112*9874e4f6SJuergen Schmidt sProductDirCandidate = lcl_getUserDataDirectory() +
113*9874e4f6SJuergen Schmidt ::rtl::OUString::createFromAscii( DefaultProductDir[ productIndex ][ i ] );
114*9874e4f6SJuergen Schmidt
115*9874e4f6SJuergen Schmidt // check existence
116*9874e4f6SJuergen Schmidt ::osl::DirectoryItem aRegistryItem;
117*9874e4f6SJuergen Schmidt ::osl::FileBase::RC result = ::osl::DirectoryItem::get( sProductDirCandidate + ::rtl::OUString::createFromAscii( pProfileRegistry ), aRegistryItem );
118*9874e4f6SJuergen Schmidt if ( result == ::osl::FileBase::E_None )
119*9874e4f6SJuergen Schmidt {
120*9874e4f6SJuergen Schmidt ::osl::FileStatus aStatus( FileStatusMask_Validate );
121*9874e4f6SJuergen Schmidt result = aRegistryItem.getFileStatus( aStatus );
122*9874e4f6SJuergen Schmidt if ( result == ::osl::FileBase::E_None )
123*9874e4f6SJuergen Schmidt {
124*9874e4f6SJuergen Schmidt // the registry file exists
125*9874e4f6SJuergen Schmidt break;
126*9874e4f6SJuergen Schmidt }
127*9874e4f6SJuergen Schmidt }
128*9874e4f6SJuergen Schmidt }
129*9874e4f6SJuergen Schmidt
130*9874e4f6SJuergen Schmidt ::osl::FileBase::getSystemPathFromFileURL( sProductDirCandidate, sProductPath );
131*9874e4f6SJuergen Schmidt }
132*9874e4f6SJuergen Schmidt
133*9874e4f6SJuergen Schmidt s_productDirectories[ productIndex ] = sProductPath;
134*9874e4f6SJuergen Schmidt }
135*9874e4f6SJuergen Schmidt
136*9874e4f6SJuergen Schmidt return s_productDirectories[ productIndex ];
137*9874e4f6SJuergen Schmidt }
138*9874e4f6SJuergen Schmidt }
139*9874e4f6SJuergen Schmidt
140*9874e4f6SJuergen Schmidt // -----------------------------------------------------------------------
getRegistryDir(MozillaProductType product)141*9874e4f6SJuergen Schmidt ::rtl::OUString getRegistryDir(MozillaProductType product)
142*9874e4f6SJuergen Schmidt {
143*9874e4f6SJuergen Schmidt if (product == MozillaProductType_Default)
144*9874e4f6SJuergen Schmidt return ::rtl::OUString();
145*9874e4f6SJuergen Schmidt
146*9874e4f6SJuergen Schmidt return lcl_guessProfileRoot( product );
147*9874e4f6SJuergen Schmidt }
148