Tag: cws_src680_dba205b
User: fs      
Date: 2006/08/04 04:29:28

Modified:
   dba/connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx

Log:
 #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.6&r2=1.6.38.1
Delta lines:  +119 -43
----------------------
--- MNSFolders.cxx      20 Jun 2006 01:46:46 -0000      1.6
+++ MNSFolders.cxx      4 Aug 2006 11:29:25 -0000       1.6.38.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: MNSFolders.cxx,v $
  *
- *  $Revision: 1.6 $
+ *  $Revision: 1.6.38.1 $
  *
- *  last change: $Author: hr $ $Date: 2006/06/20 01:46:46 $
+ *  last change: $Author: fs $ $Date: 2006/08/04 11:29:25 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -50,56 +50,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]

Reply via email to