Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <MNSFolders.hxx>
21 :
22 : #ifdef UNIX
23 : #include <sys/types.h>
24 : #include <strings.h>
25 : #include <string.h>
26 : #endif // End UNIX
27 :
28 : #ifdef WNT
29 : #include "pre_include_windows.h"
30 : #include <windows.h>
31 : #include <stdlib.h>
32 : #include <shlobj.h>
33 : #include <objidl.h>
34 : #include "post_include_windows.h"
35 : #endif // End WNT
36 : #include <osl/security.hxx>
37 : #include <osl/file.hxx>
38 : #include <osl/thread.h>
39 :
40 : using namespace ::com::sun::star::mozilla;
41 :
42 : namespace
43 : {
44 : // -------------------------------------------------------------------
45 0 : static ::rtl::OUString lcl_getUserDataDirectory()
46 : {
47 0 : ::osl::Security aSecurity;
48 0 : ::rtl::OUString aConfigPath;
49 :
50 : #if defined(XP_WIN) || defined(MACOSX)
51 : aSecurity.getConfigDir( aConfigPath );
52 : #else
53 : //This is to find the dir under which .mozilla/.thunderbird is created.
54 : //mozilla doesn't honour XDG_CONFIG_HOME, so raw home dir required here
55 : //not xdg-config dir
56 0 : aSecurity.getHomeDir( aConfigPath );
57 : #endif
58 :
59 0 : return aConfigPath + ::rtl::OUString("/");
60 : }
61 :
62 : // -------------------------------------------------------------------
63 : const size_t NB_PRODUCTS = 3;
64 : const size_t NB_CANDIDATES = 4;
65 :
66 : static const char* DefaultProductDir[NB_PRODUCTS][NB_CANDIDATES] =
67 : {
68 : #if defined(XP_WIN)
69 : { "Mozilla/SeaMonkey/", NULL, NULL, NULL },
70 : { "Mozilla/Firefox/", NULL, NULL, NULL },
71 : { "Thunderbird/", "Mozilla/Thunderbird/", NULL, NULL }
72 : #elif(MACOSX)
73 : { "../Mozilla/SeaMonkey/", NULL, NULL, NULL },
74 : { "Firefox/", NULL, NULL, NULL },
75 : { "../Thunderbird/", NULL, NULL, NULL }
76 : #else
77 : { ".mozilla/seamonkey/", NULL, NULL, NULL },
78 : { ".mozilla/firefox/", NULL, NULL, NULL },
79 : { ".thunderbird/", ".mozilla-thunderbird/", ".mozilla/thunderbird/", ".icedove/" }
80 : #endif
81 : };
82 :
83 : static const char* ProductRootEnvironmentVariable[NB_PRODUCTS] =
84 : {
85 : "MOZILLA_PROFILE_ROOT",
86 : "MOZILLA_FIREFOX_PROFILE_ROOT",
87 : "MOZILLA_THUNDERBIRD_PROFILE_ROOT",
88 : };
89 :
90 : // -------------------------------------------------------------------
91 0 : static ::rtl::OUString lcl_guessProfileRoot( MozillaProductType _product )
92 : {
93 0 : size_t productIndex = _product - 1;
94 :
95 0 : static ::rtl::OUString s_productDirectories[NB_PRODUCTS];
96 :
97 0 : if ( s_productDirectories[ productIndex ].isEmpty() )
98 : {
99 0 : ::rtl::OUString sProductPath;
100 :
101 : // check whether we have an anevironment variable which helps us
102 0 : const char* pProfileByEnv = getenv( ProductRootEnvironmentVariable[ productIndex ] );
103 0 : if ( pProfileByEnv )
104 : {
105 0 : sProductPath = ::rtl::OUString( pProfileByEnv, rtl_str_getLength( pProfileByEnv ), osl_getThreadTextEncoding() );
106 : // asume that this is fine, no further checks
107 : }
108 : else
109 : {
110 0 : ::rtl::OUString sProductDirCandidate;
111 0 : const char* pProfileRegistry = "profiles.ini";
112 :
113 : // check all possible candidates
114 0 : for ( size_t i=0; i<NB_CANDIDATES; ++i )
115 : {
116 0 : if ( NULL == DefaultProductDir[ productIndex ][ i ] )
117 : break;
118 :
119 : sProductDirCandidate = lcl_getUserDataDirectory() +
120 0 : ::rtl::OUString::createFromAscii( DefaultProductDir[ productIndex ][ i ] );
121 :
122 : // check existence
123 0 : ::osl::DirectoryItem aRegistryItem;
124 0 : ::osl::FileBase::RC result = ::osl::DirectoryItem::get( sProductDirCandidate + ::rtl::OUString::createFromAscii( pProfileRegistry ), aRegistryItem );
125 0 : if ( result == ::osl::FileBase::E_None )
126 : {
127 0 : ::osl::FileStatus aStatus( osl_FileStatus_Mask_Validate );
128 0 : result = aRegistryItem.getFileStatus( aStatus );
129 0 : if ( result == ::osl::FileBase::E_None )
130 : {
131 : // the registry file exists
132 : break;
133 0 : }
134 : }
135 0 : }
136 :
137 0 : ::osl::FileBase::getSystemPathFromFileURL( sProductDirCandidate, sProductPath );
138 : }
139 :
140 0 : s_productDirectories[ productIndex ] = sProductPath;
141 : }
142 :
143 0 : return s_productDirectories[ productIndex ];
144 : }
145 : }
146 :
147 : // -----------------------------------------------------------------------
148 0 : ::rtl::OUString getRegistryDir(MozillaProductType product)
149 : {
150 0 : if (product == MozillaProductType_Default)
151 0 : return ::rtl::OUString();
152 :
153 0 : return lcl_guessProfileRoot( product );
154 : }
155 :
156 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|