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