User: ihi Date: 2006/10/18 06:10:12 Modified: dba/connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx
Log: INTEGRATION: CWS dba205b (1.6.38); FILE MERGED 2006/08/04 11:32:18 fs 1.6.38.2: #i10000# 2006/08/04 11:29:25 fs 1.6.38.1: #i62667# some magic in finding the profile directory, so we have a fallback for thunderbird, where the profile root could be .thunderbird, .mozilla-thunderbird (debian-based), or .mozilla/thunderbird (future) File Changes: Directory: /dba/connectivity/source/drivers/mozab/bootstrap/ ============================================================ File [changed]: MNSFolders.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx?r1=1.7&r2=1.8 Delta lines: +117 -40 ---------------------- --- MNSFolders.cxx 17 Sep 2006 02:58:58 -0000 1.7 +++ MNSFolders.cxx 18 Oct 2006 13:10:09 -0000 1.8 @@ -42,6 +42,7 @@ #ifdef UNIX #include <sys/types.h> #include <strings.h> +#include <string.h> #endif // End UNIX #ifdef WNT @@ -53,56 +54,132 @@ #include "post_include_windows.h" #endif // End WNT -static const char * DefaultProductDir[] = -{ -#if defined(XP_WIN) - "Mozilla\\", - "Mozilla\\Firefox\\", - "Thunderbird\\" -#else - ".mozilla/", - ".mozilla/firefox/", - ".thunderbird/" +#ifndef _OSL_SECURITY_HXX_ +#include <osl/security.hxx> #endif -}; -#if defined(XP_MAC) || defined(XP_MACOSX) -#define APP_REGISTRY_NAME "Application Registry" -#elif defined(XP_WIN) || defined(XP_OS2) -#define APP_REGISTRY_NAME "registry.dat" -#else -#define APP_REGISTRY_NAME "appreg" +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> #endif - -::rtl::OString getAppDir() -{ -#if defined(WNT) - char szPath[MAX_PATH]; - if (!SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, 0)) - return ::rtl::OString(); - return ::rtl::OString(szPath) + ::rtl::OString("\\"); -#elif defined(UNIX) - const char* homeDir = getenv("HOME"); - return ::rtl::OString(homeDir) + ::rtl::OString("/"); +#ifndef _OSL_THREAD_H_ +#include <osl/thread.h> #endif -} -::rtl::OString getRegistryDir(::com::sun::star::mozilla::MozillaProductType product) +using namespace ::com::sun::star::mozilla; + +namespace { - if (product == ::com::sun::star::mozilla::MozillaProductType_Default) + #if defined(XP_MAC) || defined(XP_MACOSX) + #define APP_REGISTRY_NAME "Application Registry" + #elif defined(XP_WIN) || defined(XP_OS2) + #define APP_REGISTRY_NAME "registry.dat" + #else + #define APP_REGISTRY_NAME "appreg" + #endif + + // ------------------------------------------------------------------- + static ::rtl::OUString lcl_getUserDataDirectory() { - return ::rtl::OString(); + ::osl::Security aSecurity; + ::rtl::OUString aConfigPath; + + aSecurity.getConfigDir( aConfigPath ); + return aConfigPath + ::rtl::OUString::createFromAscii( "/" ); } - sal_Int32 type = product - 1; - return getAppDir() + ::rtl::OString(DefaultProductDir[type]); -} -::rtl::OString getRegistryFileName(::com::sun::star::mozilla::MozillaProductType product) -{ - if (product == ::com::sun::star::mozilla::MozillaProductType_Default) + // ------------------------------------------------------------------- + static const char* DefaultProductDir[3][3] = + { + #if defined(XP_WIN) + { "Mozilla/", NULL, NULL }, + { "Mozilla/Firefox/", NULL, NULL }, + { "Thunderbird/", "Mozilla/Thunderbird/", NULL } + #else + { ".mozilla/", NULL, NULL }, + { ".mozilla/firefox/", NULL, NULL }, + { ".thunderbird/", ".mozilla-thunderbird/", ".mozilla/thunderbird/" } + #endif + }; + + static const char* ProductRootEnvironmentVariable[3] = + { + "MOZILLA_PROFILE_ROOT", + "MOZILLA_FIREFOX_PROFILE_ROOT", + "MOZILLA_THUNDERBIRD_PROFILE_ROOT", + }; + + // ------------------------------------------------------------------- + static ::rtl::OUString lcl_guessProfileRoot( MozillaProductType _product ) + { + size_t productIndex = _product - 1; + + static ::rtl::OUString s_productDirectories[3]; + + if ( !s_productDirectories[ productIndex ].getLength() ) + { + ::rtl::OUString sProductPath; + + // check whether we have an anevironment variable which helps us + const char* pProfileByEnv = getenv( ProductRootEnvironmentVariable[ productIndex ] ); + if ( pProfileByEnv ) + { + sProductPath = ::rtl::OUString( pProfileByEnv, strlen( pProfileByEnv ), osl_getThreadTextEncoding() ); + // asume that this is fine, no further checks + } + else + { + ::rtl::OUString sProductDirCandidate; + const char* pProfileRegistry = ( _product == MozillaProductType_Mozilla ) ? APP_REGISTRY_NAME : "profiles.ini"; + + // check all possible candidates + for ( size_t i=0; i<3; ++i ) + { + if ( NULL == DefaultProductDir[ productIndex ][ i ] ) + break; + + sProductDirCandidate = lcl_getUserDataDirectory() + + ::rtl::OUString::createFromAscii( DefaultProductDir[ productIndex ][ i ] ); + + // check existence + ::osl::DirectoryItem aRegistryItem; + ::osl::FileBase::RC result = ::osl::DirectoryItem::get( sProductDirCandidate + ::rtl::OUString::createFromAscii( pProfileRegistry ), aRegistryItem ); + if ( result == ::osl::FileBase::E_None ) + { + ::osl::FileStatus aStatus( FileStatusMask_Validate ); + result = aRegistryItem.getFileStatus( aStatus ); + if ( result == ::osl::FileBase::E_None ) { - return ::rtl::OString(); + // the registry file exists + break; + } + } + } + + ::osl::FileBase::getSystemPathFromFileURL( sProductDirCandidate, sProductPath ); + } + + s_productDirectories[ productIndex ] = sProductPath; } - return getRegistryDir(product) + ::rtl::OString(APP_REGISTRY_NAME); + + return s_productDirectories[ productIndex ]; + } +} + +// ----------------------------------------------------------------------- +::rtl::OUString getRegistryDir(MozillaProductType product) +{ + if (product == MozillaProductType_Default) + return ::rtl::OUString(); + + return lcl_guessProfileRoot( product ); +} + +// ----------------------------------------------------------------------- +::rtl::OUString getRegistryFileName(MozillaProductType product) +{ + if (product == MozillaProductType_Default) + return ::rtl::OUString(); + + return getRegistryDir(product) + ::rtl::OUString::createFromAscii(APP_REGISTRY_NAME); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
