1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MNSFolders.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include <MNSFolders.hxx>
36 #include <sys/types.h>
42 #include "pre_include_windows.h"
47 #include "post_include_windows.h"
49 #include <osl/security.hxx>
50 #include <osl/file.hxx>
51 #include <osl/thread.h>
53 using namespace ::com::sun::star::mozilla
;
57 #if defined(XP_MAC) || defined(XP_MACOSX) || defined(MACOSX)
58 #define APP_REGISTRY_NAME "Application Registry"
59 #elif defined(XP_WIN) || defined(XP_OS2)
60 #define APP_REGISTRY_NAME "registry.dat"
62 #define APP_REGISTRY_NAME "appreg"
65 // -------------------------------------------------------------------
66 static ::rtl::OUString
lcl_getUserDataDirectory()
68 ::osl::Security aSecurity
;
69 ::rtl::OUString aConfigPath
;
71 aSecurity
.getConfigDir( aConfigPath
);
72 return aConfigPath
+ ::rtl::OUString::createFromAscii( "/" );
75 // -------------------------------------------------------------------
76 static const char* DefaultProductDir
[3][3] =
79 { "Mozilla/", NULL
, NULL
},
80 { "Mozilla/Firefox/", NULL
, NULL
},
81 { "Thunderbird/", "Mozilla/Thunderbird/", NULL
}
83 { "../Mozilla/", NULL
, NULL
},
84 { "Firefox/", NULL
, NULL
},
85 { "../Thunderbird/", NULL
, NULL
}
87 { ".mozilla/", NULL
, NULL
},
88 { ".mozilla/firefox/", NULL
, NULL
},
89 { ".thunderbird/", ".mozilla-thunderbird/", ".mozilla/thunderbird/" }
93 static const char* ProductRootEnvironmentVariable
[3] =
95 "MOZILLA_PROFILE_ROOT",
96 "MOZILLA_FIREFOX_PROFILE_ROOT",
97 "MOZILLA_THUNDERBIRD_PROFILE_ROOT",
100 // -------------------------------------------------------------------
101 static ::rtl::OUString
lcl_guessProfileRoot( MozillaProductType _product
)
103 size_t productIndex
= _product
- 1;
105 static ::rtl::OUString s_productDirectories
[3];
107 if ( !s_productDirectories
[ productIndex
].getLength() )
109 ::rtl::OUString sProductPath
;
111 // check whether we have an anevironment variable which helps us
112 const char* pProfileByEnv
= getenv( ProductRootEnvironmentVariable
[ productIndex
] );
115 sProductPath
= ::rtl::OUString( pProfileByEnv
, rtl_str_getLength( pProfileByEnv
), osl_getThreadTextEncoding() );
116 // asume that this is fine, no further checks
120 ::rtl::OUString sProductDirCandidate
;
121 const char* pProfileRegistry
= ( _product
== MozillaProductType_Mozilla
) ? APP_REGISTRY_NAME
: "profiles.ini";
123 // check all possible candidates
124 for ( size_t i
=0; i
<3; ++i
)
126 if ( NULL
== DefaultProductDir
[ productIndex
][ i
] )
129 sProductDirCandidate
= lcl_getUserDataDirectory() +
130 ::rtl::OUString::createFromAscii( DefaultProductDir
[ productIndex
][ i
] );
133 ::osl::DirectoryItem aRegistryItem
;
134 ::osl::FileBase::RC result
= ::osl::DirectoryItem::get( sProductDirCandidate
+ ::rtl::OUString::createFromAscii( pProfileRegistry
), aRegistryItem
);
135 if ( result
== ::osl::FileBase::E_None
)
137 ::osl::FileStatus
aStatus( FileStatusMask_Validate
);
138 result
= aRegistryItem
.getFileStatus( aStatus
);
139 if ( result
== ::osl::FileBase::E_None
)
141 // the registry file exists
147 ::osl::FileBase::getSystemPathFromFileURL( sProductDirCandidate
, sProductPath
);
150 s_productDirectories
[ productIndex
] = sProductPath
;
153 return s_productDirectories
[ productIndex
];
157 // -----------------------------------------------------------------------
158 ::rtl::OUString
getRegistryDir(MozillaProductType product
)
160 if (product
== MozillaProductType_Default
)
161 return ::rtl::OUString();
163 return lcl_guessProfileRoot( product
);
165 #ifndef MINIMAL_PROFILEDISCOVER
166 // -----------------------------------------------------------------------
167 ::rtl::OUString
getRegistryFileName(MozillaProductType product
)
169 if (product
== MozillaProductType_Default
)
170 return ::rtl::OUString();
172 return getRegistryDir(product
) + ::rtl::OUString::createFromAscii(APP_REGISTRY_NAME
);