LCOV - code coverage report
Current view: top level - unotools/source/config - bootstrap.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 151 276 54.7 %
Date: 2012-08-25 Functions: 27 40 67.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 82 231 35.5 %

           Branch data     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                 :            : 
      21                 :            : #include <stdio.h>
      22                 :            : 
      23                 :            : #include "unotools/bootstrap.hxx"
      24                 :            : 
      25                 :            : // ---------------------------------------------------------------------------------------
      26                 :            : #include <rtl/ustring.hxx>
      27                 :            : #include <rtl/ustrbuf.hxx>
      28                 :            : #include <osl/file.hxx>
      29                 :            : #include <osl/mutex.hxx>
      30                 :            : #include <osl/diagnose.h>
      31                 :            : // ---------------------------------------------------------------------------------------
      32                 :            : #include <rtl/bootstrap.hxx>
      33                 :            : #include <rtl/instance.hxx>
      34                 :            : #include <osl/process.h> // for osl_getExecutableFile
      35                 :            : #include "tools/getprocessworkingdir.hxx"
      36                 :            : 
      37                 :            : // ---------------------------------------------------------------------------------------
      38                 :            : // #define this to a non-zero value, if remembering defaults is not supported properly
      39                 :            : #define RTL_BOOTSTRAP_DEFAULTS_BROKEN 1
      40                 :            : 
      41                 :            : // ---------------------------------------------------------------------------------------
      42                 :            : #define BOOTSTRAP_DATA_NAME                 SAL_CONFIGFILE("bootstrap")
      43                 :            : 
      44                 :            : #define BOOTSTRAP_ITEM_PRODUCT_KEY          "ProductKey"
      45                 :            : #define BOOTSTRAP_ITEM_PRODUCT_SOURCE       "ProductSource"
      46                 :            : #define BOOTSTRAP_ITEM_VERSIONFILE          "Location"
      47                 :            : #define BOOTSTRAP_ITEM_BUILDID              "buildid"
      48                 :            : #define BOOTSTRAP_ITEM_BUILDVERSION         "BuildVersion"
      49                 :            : 
      50                 :            : #define BOOTSTRAP_ITEM_BASEINSTALLATION     "BRAND_BASE_DIR"
      51                 :            : #define BOOTSTRAP_ITEM_USERINSTALLATION     "UserInstallation"
      52                 :            : 
      53                 :            : #define BOOTSTRAP_ITEM_USERDIR              "UserDataDir"
      54                 :            : 
      55                 :            : #define BOOTSTRAP_DEFAULT_BASEINSTALL       "$SYSBINDIR/.."
      56                 :            : 
      57                 :            : #define BOOTSTRAP_DIRNAME_USERDIR           "user"
      58                 :            : 
      59                 :            : // ---------------------------------------------------------------------------------------
      60                 :            : typedef char const * AsciiString;
      61                 :            : // ---------------------------------------------------------------------------------------
      62                 :            : 
      63                 :            : namespace utl
      64                 :            : {
      65                 :            : // ---------------------------------------------------------------------------------------
      66                 :            :     using ::rtl::OUString;
      67                 :            :     using ::rtl::OUStringBuffer;
      68                 :            :     using ::rtl::OString;
      69                 :            : 
      70                 :            : // ---------------------------------------------------------------------------------------
      71                 :            : // Implementation class: Bootstrap::Impl
      72                 :            : // ---------------------------------------------------------------------------------------
      73                 :            : 
      74                 :            :     namespace
      75                 :            :     {
      76                 :        267 :         rtl::OUString makeImplName()
      77                 :            :         {
      78                 :        267 :             rtl::OUString uri;
      79                 :            :             rtl::Bootstrap::get(
      80                 :            :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BRAND_BASE_DIR")),
      81         [ +  - ]:        267 :                 uri);
      82         [ +  - ]:        267 :             return uri + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/program/" BOOTSTRAP_DATA_NAME));
      83                 :            :         }
      84                 :            :     }
      85                 :            : 
      86 [ +  - ][ +  - ]:        267 :     class Bootstrap::Impl
         [ +  - ][ +  - ]
      87                 :            :     {
      88                 :            :         const OUString m_aImplName;
      89                 :            :     public: // struct to cache the result of a path lookup
      90                 :       1068 :         struct PathData
      91                 :            :         {
      92                 :            :             OUString     path;
      93                 :            :             PathStatus   status;
      94                 :            : 
      95                 :       1068 :             PathData()
      96                 :            :             : path()
      97                 :       1068 :             , status(DATA_UNKNOWN)
      98                 :       1068 :             {}
      99                 :            :         };
     100                 :            :     public: // data members
     101                 :            :         // base install data
     102                 :            :         PathData aBaseInstall_;
     103                 :            : 
     104                 :            :         // user install data
     105                 :            :         PathData aUserInstall_;
     106                 :            : 
     107                 :            :         // INI files
     108                 :            :         PathData aBootstrapINI_;
     109                 :            :         PathData aVersionINI_;
     110                 :            : 
     111                 :            :         // overall status
     112                 :            :         Status status_;
     113                 :            : 
     114                 :            :     public: // construction and initialization
     115                 :        267 :         Impl() : m_aImplName(makeImplName())
     116                 :            :         {
     117         [ +  - ]:        267 :             initialize();
     118                 :        267 :         }
     119                 :            : 
     120                 :            :         void initialize();
     121                 :            : 
     122                 :            :         // access helper
     123                 :            :         OUString getBootstrapValue(OUString const& _sName, OUString const& _sDefault) const;
     124                 :            :         sal_Bool getVersionValue(OUString const& _sName, OUString& _rValue, OUString const& _sDefault) const;
     125                 :            : 
     126                 :        425 :         OUString getImplName() const { return m_aImplName; }
     127                 :            : 
     128                 :            :     private: // implementation
     129                 :            :         bool initBaseInstallationData(rtl::Bootstrap& _rData);
     130                 :            :         bool initUserInstallationData(rtl::Bootstrap& _rData);
     131                 :            :     };
     132                 :            : 
     133                 :            :     namespace
     134                 :            :     {
     135                 :            :         class theImpl : public rtl::Static<Bootstrap::Impl, theImpl> {};
     136                 :            :     }
     137                 :            : 
     138                 :       4019 :     const Bootstrap::Impl& Bootstrap::data()
     139                 :            :     {
     140                 :       4019 :         return theImpl::get();
     141                 :            :     }
     142                 :            : 
     143                 :        158 :     void Bootstrap::reloadData()
     144                 :            :     {
     145                 :        158 :         theImpl::get().initialize();
     146                 :        158 :     }
     147                 :            : 
     148                 :            : // ---------------------------------------------------------------------------------------
     149                 :            : // helper
     150                 :            : // ---------------------------------------------------------------------------------------
     151                 :            : 
     152                 :            : typedef Bootstrap::PathStatus PathStatus;
     153                 :            : 
     154                 :            : sal_Unicode const cURLSeparator = '/';
     155                 :            : 
     156                 :            : // ---------------------------------------------------------------------------------------
     157                 :            : // path status utility function
     158                 :            : static
     159                 :       1695 : PathStatus implCheckStatusOfURL(OUString const& _sURL, osl::DirectoryItem& aDirItem)
     160                 :            : {
     161                 :            :     using namespace osl;
     162                 :            : 
     163                 :       1695 :     PathStatus eStatus = Bootstrap::DATA_UNKNOWN;
     164                 :            : 
     165         [ +  - ]:       1695 :     if (!_sURL.isEmpty())
     166                 :            :     {
     167   [ +  +  -  - ]:       1695 :         switch( DirectoryItem::get(_sURL, aDirItem) )
     168                 :            :         {
     169                 :            :         case DirectoryItem::E_None:         // Success
     170                 :       1581 :             eStatus = Bootstrap::PATH_EXISTS;
     171                 :       1581 :             break;
     172                 :            : 
     173                 :            :         case DirectoryItem::E_NOENT:        // No such file or directory<br>
     174                 :        114 :             eStatus = Bootstrap::PATH_VALID;
     175                 :        114 :             break;
     176                 :            : 
     177                 :            :         case DirectoryItem::E_INVAL:        // the format of the parameters was not valid<br>
     178                 :            :         case DirectoryItem::E_NAMETOOLONG:  // File name too long<br>
     179                 :            :         case DirectoryItem::E_NOTDIR:       // A component of the path prefix of path is not a directory<p>
     180                 :          0 :             eStatus = Bootstrap::DATA_INVALID;
     181                 :          0 :             break;
     182                 :            : 
     183                 :            :         // how to handle these ?
     184                 :            :         case DirectoryItem::E_LOOP:         // Too many symbolic links encountered<br>
     185                 :            :         case DirectoryItem::E_ACCES:        // permission denied<br>
     186                 :            :         // any other error - what to do ?
     187                 :            :         default:
     188                 :          0 :             eStatus = Bootstrap::DATA_UNKNOWN;
     189                 :       1695 :             break;
     190                 :            :         }
     191                 :            :     }
     192                 :            :     else
     193                 :          0 :         eStatus = Bootstrap::DATA_MISSING;
     194                 :            : 
     195                 :       1695 :     return eStatus;
     196                 :            : }
     197                 :            : // ---------------------------------------------------------------------------------------
     198                 :            : 
     199                 :            : static
     200                 :       1581 : bool implNormalizeURL(OUString & _sURL, osl::DirectoryItem& aDirItem)
     201                 :            : {
     202                 :            :     using namespace osl;
     203                 :            : 
     204                 :            :     OSL_PRECOND(aDirItem.is(), "Opened DirItem required");
     205                 :            : 
     206                 :            :     static const sal_uInt32 cosl_FileStatus_Mask = osl_FileStatus_Mask_FileURL;
     207                 :            : 
     208                 :       1581 :     FileStatus aFileStatus(cosl_FileStatus_Mask);
     209                 :            : 
     210 [ -  + ][ +  - ]:       1581 :     if (aDirItem.getFileStatus(aFileStatus) != DirectoryItem::E_None)
     211                 :          0 :         return false;
     212                 :            : 
     213         [ +  - ]:       1581 :     OUString aNormalizedURL = aFileStatus.getFileURL();
     214                 :            : 
     215         [ -  + ]:       1581 :     if (aNormalizedURL.isEmpty())
     216                 :          0 :         return false;
     217                 :            : 
     218                 :            :     // #109863# sal/osl returns final slash for file URLs contradicting
     219                 :            :     // the URL/URI RFCs.
     220         [ +  - ]:       1581 :     if ( aNormalizedURL.getStr()[aNormalizedURL.getLength()-1] != cURLSeparator )
     221                 :       1581 :         _sURL = aNormalizedURL;
     222                 :            :     else
     223                 :          0 :         _sURL = aNormalizedURL.copy( 0, aNormalizedURL.getLength()-1 );
     224                 :            : 
     225                 :       1581 :     return true;
     226                 :            : }
     227                 :            : // ---------------------------------------------------------------------------------------
     228                 :            : static
     229                 :       1695 : bool implEnsureAbsolute(OUString & _rsURL) // also strips embedded dots !!
     230                 :            : {
     231                 :            :     using osl::File;
     232                 :            : 
     233                 :       1695 :     OUString sBasePath;
     234         [ +  - ]:       1695 :     OSL_VERIFY(tools::getProcessWorkingDir(sBasePath));
     235                 :            : 
     236                 :       1695 :     OUString sAbsolute;
     237 [ +  - ][ +  - ]:       1695 :     if ( File::E_None == File::getAbsoluteFileURL(sBasePath, _rsURL, sAbsolute))
     238                 :            :     {
     239                 :       1695 :         _rsURL = sAbsolute;
     240                 :       1695 :         return true;
     241                 :            :     }
     242                 :            :     else
     243                 :            :     {
     244                 :            :         OSL_FAIL("Could not get absolute file URL for URL");
     245                 :          0 :         return false;
     246                 :       1695 :     }
     247                 :            : }
     248                 :            : 
     249                 :            : // ---------------------------------------------------------------------------------------
     250                 :            : 
     251                 :            : static
     252                 :       1695 : bool implMakeAbsoluteURL(OUString & _rsPathOrURL)
     253                 :            : {
     254                 :            :     using namespace osl;
     255                 :            : 
     256                 :            :     bool bURL;
     257                 :            : 
     258                 :       1695 :     OUString sOther;
     259                 :            :     // check if it already was normalized
     260 [ +  - ][ +  - ]:       1695 :     if ( File::E_None == File::getSystemPathFromFileURL(_rsPathOrURL, sOther) )
     261                 :            :     {
     262                 :       1695 :         bURL = true;
     263                 :            :     }
     264                 :            : 
     265 [ #  # ][ #  # ]:          0 :     else if ( File::E_None == File::getFileURLFromSystemPath(_rsPathOrURL, sOther) )
     266                 :            :     {
     267                 :          0 :         _rsPathOrURL = sOther;
     268                 :          0 :         bURL = true;
     269                 :            :     }
     270                 :            :     else
     271                 :          0 :         bURL = false;
     272                 :            : 
     273 [ +  - ][ +  - ]:       1695 :     return bURL && implEnsureAbsolute(_rsPathOrURL);
                 [ +  - ]
     274                 :            : }
     275                 :            : // ---------------------------------------------------------------------------------------
     276                 :            : #if OSL_DEBUG_LEVEL > 0
     277                 :            : static
     278                 :            : PathStatus dbgCheckStatusOfURL(OUString const& _sURL)
     279                 :            : {
     280                 :            :     using namespace osl;
     281                 :            : 
     282                 :            :     DirectoryItem aDirItem;
     283                 :            : 
     284                 :            :     return implCheckStatusOfURL(_sURL,aDirItem);
     285                 :            : }
     286                 :            : // ---------------------------------------------------------------------------------------
     287                 :            : #endif
     288                 :            : 
     289                 :            : static
     290                 :       2120 : PathStatus checkStatusAndNormalizeURL(OUString & _sURL)
     291                 :            : {
     292                 :            :     using namespace osl;
     293                 :            : 
     294                 :       2120 :     PathStatus eStatus = Bootstrap::DATA_UNKNOWN;
     295                 :            : 
     296         [ +  + ]:       2120 :     if (_sURL.isEmpty())
     297                 :        425 :         eStatus = Bootstrap::DATA_MISSING;
     298                 :            : 
     299         [ -  + ]:       1695 :     else if ( !implMakeAbsoluteURL(_sURL) )
     300                 :          0 :         eStatus = Bootstrap::DATA_INVALID;
     301                 :            : 
     302                 :            :     else
     303                 :            :     {
     304                 :       1695 :         DirectoryItem aDirItem;
     305                 :            : 
     306         [ +  - ]:       1695 :         eStatus = implCheckStatusOfURL(_sURL,aDirItem);
     307                 :            : 
     308         [ +  + ]:       1695 :         if (eStatus == Bootstrap::PATH_EXISTS)
     309                 :            :         {
     310         [ +  - ]:       1581 :             if (!implNormalizeURL(_sURL,aDirItem))
     311                 :            :                 OSL_FAIL("Unexpected failure getting actual URL for existing object");
     312         [ +  - ]:       1695 :         }
     313                 :            :     }
     314                 :       2120 :     return eStatus;
     315                 :            : }
     316                 :            : 
     317                 :            : 
     318                 :            : // ----------------------------------------------------------------------------------
     319                 :            : // helpers to build and check a nested URL
     320                 :            : static
     321                 :        430 : PathStatus getDerivedPath(
     322                 :            :               OUString& _rURL,
     323                 :            :               OUString const& _aBaseURL, PathStatus _aBaseStatus,
     324                 :            :               OUString const& _sRelativeURL,
     325                 :            :               rtl::Bootstrap& _rData, OUString const& _sBootstrapParameter
     326                 :            :           )
     327                 :            : {
     328                 :        430 :     OUString sDerivedURL;
     329                 :            :     OSL_PRECOND(!_rData.getFrom(_sBootstrapParameter,sDerivedURL),"Setting for derived path is already defined");
     330                 :            :     OSL_PRECOND(!_sRelativeURL.isEmpty() && _sRelativeURL[0] != cURLSeparator,"Invalid Relative URL");
     331                 :            : 
     332                 :        430 :     PathStatus aStatus = _aBaseStatus;
     333                 :            : 
     334                 :            :     // do we have a base path ?
     335         [ +  + ]:        430 :     if (!_aBaseURL.isEmpty())
     336                 :            :     {
     337                 :            :         OSL_PRECOND(_aBaseURL[_aBaseURL.getLength()-1] != cURLSeparator,"Unexpected: base URL ends in slash");
     338                 :            : 
     339 [ +  - ][ +  - ]:        425 :         sDerivedURL = rtl::OUStringBuffer(_aBaseURL).append(cURLSeparator).append(_sRelativeURL).makeStringAndClear();
         [ +  - ][ +  - ]
     340                 :            : 
     341                 :            :         // a derived (nested) URL can only exist or have a lesser status, if the parent exists
     342         [ +  - ]:        425 :         if (aStatus == Bootstrap::PATH_EXISTS)
     343         [ +  - ]:        425 :             aStatus = checkStatusAndNormalizeURL(sDerivedURL);
     344                 :            : 
     345                 :            :         else // the relative appendix must be valid
     346                 :            :             OSL_ASSERT(aStatus != Bootstrap::PATH_VALID || dbgCheckStatusOfURL(sDerivedURL) == Bootstrap::PATH_VALID);
     347                 :            : 
     348                 :        425 :         _rData.getFrom(_sBootstrapParameter, _rURL, sDerivedURL);
     349                 :            : 
     350                 :            :         OSL_ENSURE(sDerivedURL == _rURL,"Could not set derived URL via Bootstrap default parameter");
     351                 :            :         OSL_POSTCOND(RTL_BOOTSTRAP_DEFAULTS_BROKEN ||
     352                 :            :                     (_rData.getFrom(_sBootstrapParameter,sDerivedURL) && sDerivedURL==_rURL),"Use of default did not affect bootstrap value");
     353                 :            :     }
     354                 :            :     else
     355                 :            :     {
     356                 :            :         // clear the result
     357                 :          5 :         _rURL = _aBaseURL;
     358                 :            : 
     359                 :            :         // if we have no data it can't be a valid path
     360                 :            :         OSL_ASSERT( aStatus > Bootstrap::PATH_VALID );
     361                 :            :     }
     362                 :            : 
     363                 :            : 
     364                 :        430 :     return aStatus;
     365                 :            : }
     366                 :            : 
     367                 :            : // ----------------------------------------------------------------------------------
     368                 :            : static
     369                 :            : inline
     370                 :        430 : PathStatus getDerivedPath(
     371                 :            :               OUString& _rURL,
     372                 :            :               Bootstrap::Impl::PathData const& _aBaseData,
     373                 :            :               OUString const& _sRelativeURL,
     374                 :            :               rtl::Bootstrap& _rData, OUString const& _sBootstrapParameter
     375                 :            :           )
     376                 :            : {
     377                 :        430 :     return getDerivedPath(_rURL,_aBaseData.path,_aBaseData.status,_sRelativeURL,_rData,_sBootstrapParameter);
     378                 :            : }
     379                 :            : 
     380                 :            : // ---------------------------------------------------------------------------------------
     381                 :            : 
     382                 :            : static
     383                 :          0 : OUString getExecutableBaseName()
     384                 :            : {
     385                 :          0 :     OUString sExecutable;
     386                 :            : 
     387 [ #  # ][ #  # ]:          0 :     if (osl_Process_E_None == osl_getExecutableFile(&sExecutable.pData))
     388                 :            :     {
     389                 :            :         // split the executable name
     390                 :          0 :         sal_Int32 nSepIndex = sExecutable.lastIndexOf(cURLSeparator);
     391                 :            : 
     392                 :          0 :         sExecutable = sExecutable.copy(nSepIndex + 1);
     393                 :            : 
     394                 :            :         // ... and get the basename (strip the extension)
     395                 :          0 :         sal_Unicode const cExtensionSep = '.';
     396                 :            : 
     397                 :          0 :         sal_Int32 const nExtIndex =     sExecutable.lastIndexOf(cExtensionSep);
     398                 :          0 :         sal_Int32 const nExtLength =    sExecutable.getLength() - nExtIndex - 1;
     399 [ #  # ][ #  # ]:          0 :         if (0 < nExtIndex && nExtLength < 4)
     400                 :          0 :            sExecutable  = sExecutable.copy(0,nExtIndex);
     401                 :            :     }
     402                 :            :     else
     403                 :            :         OSL_TRACE("Cannot get executable name: osl_getExecutableFile failed");
     404                 :            : 
     405                 :          0 :     return sExecutable;
     406                 :            : }
     407                 :            : 
     408                 :            : // ----------------------------------------------------------------------------------
     409                 :            : 
     410                 :            : static
     411                 :            : inline
     412                 :       1695 : Bootstrap::PathStatus updateStatus(Bootstrap::Impl::PathData & _rResult)
     413                 :            : {
     414                 :       1695 :     return _rResult.status = checkStatusAndNormalizeURL(_rResult.path);
     415                 :            : }
     416                 :            : // ---------------------------------------------------------------------------------------
     417                 :            : 
     418                 :            : static
     419                 :        425 : Bootstrap::PathStatus implGetBootstrapFile(rtl::Bootstrap& _rData, Bootstrap::Impl::PathData & _rBootstrapFile)
     420                 :            : {
     421                 :        425 :     _rData.getIniName(_rBootstrapFile.path);
     422                 :            : 
     423                 :        425 :     return updateStatus(_rBootstrapFile);
     424                 :            : }
     425                 :            : // ---------------------------------------------------------------------------------------
     426                 :            : 
     427                 :            : static
     428                 :        425 : Bootstrap::PathStatus implGetVersionFile(rtl::Bootstrap& _rData, Bootstrap::Impl::PathData & _rVersionFile)
     429                 :            : {
     430         [ +  - ]:        425 :     OUString const csVersionFileItem(RTL_CONSTASCII_USTRINGPARAM(BOOTSTRAP_ITEM_VERSIONFILE));
     431                 :            : 
     432                 :        425 :     _rData.getFrom(csVersionFileItem,_rVersionFile.path);
     433                 :            : 
     434         [ +  - ]:        425 :     return updateStatus(_rVersionFile);
     435                 :            : }
     436                 :            : // ---------------------------------------------------------------------------------------
     437                 :            : // Error reporting
     438                 :            : 
     439                 :            : static char const IS_MISSING[] = "is missing";
     440                 :            : static char const IS_INVALID[] = "is corrupt";
     441                 :            : static char const PERIOD[] = ". ";
     442                 :            : 
     443                 :            : // ---------------------------------------------------------------------------------------
     444                 :          0 : static void addFileError(OUStringBuffer& _rBuf, OUString const& _aPath, AsciiString _sWhat)
     445                 :            : {
     446                 :          0 :     OUString sSimpleFileName = _aPath.copy(1 +_aPath.lastIndexOf(cURLSeparator));
     447                 :            : 
     448         [ #  # ]:          0 :     _rBuf.appendAscii("The configuration file");
     449 [ #  # ][ #  # ]:          0 :     _rBuf.appendAscii(" '").append(sSimpleFileName).appendAscii("' ");
                 [ #  # ]
     450 [ #  # ][ #  # ]:          0 :     _rBuf.appendAscii(_sWhat).appendAscii(PERIOD);
     451                 :          0 : }
     452                 :            : // ---------------------------------------------------------------------------------------
     453                 :            : 
     454                 :          0 : static void addMissingDirectoryError(OUStringBuffer& _rBuf, OUString const& _aPath)
     455                 :            : {
     456                 :          0 :     _rBuf.appendAscii("The configuration directory");
     457                 :          0 :     _rBuf.appendAscii(" '").append(_aPath).appendAscii("' ");
     458                 :          0 :     _rBuf.appendAscii(IS_MISSING).appendAscii(PERIOD);
     459                 :          0 : }
     460                 :            : // ---------------------------------------------------------------------------------------
     461                 :            : 
     462                 :          0 : static void addUnexpectedError(OUStringBuffer& _rBuf, AsciiString _sExtraInfo = NULL)
     463                 :            : {
     464         [ #  # ]:          0 :     if (NULL == _sExtraInfo)
     465                 :          0 :         _sExtraInfo = "An internal failure occurred";
     466                 :            : 
     467                 :          0 :     _rBuf.appendAscii(_sExtraInfo).appendAscii(PERIOD);
     468                 :          0 : }
     469                 :            : // ---------------------------------------------------------------------------------------
     470                 :            : 
     471                 :          0 : static Bootstrap::FailureCode describeError(OUStringBuffer& _rBuf, Bootstrap::Impl const& _rData)
     472                 :            : {
     473                 :          0 :     Bootstrap::FailureCode eErrCode = Bootstrap::INVALID_BOOTSTRAP_DATA;
     474                 :            : 
     475                 :          0 :     _rBuf.appendAscii("The program cannot be started. ");
     476                 :            : 
     477   [ #  #  #  #  :          0 :     switch (_rData.aUserInstall_.status)
                      # ]
     478                 :            :     {
     479                 :            :     case Bootstrap::PATH_EXISTS:
     480   [ #  #  #  #  :          0 :         switch (_rData.aBaseInstall_.status)
                      # ]
     481                 :            :         {
     482                 :            :         case Bootstrap::PATH_VALID:
     483                 :          0 :             addMissingDirectoryError(_rBuf, _rData.aBaseInstall_.path);
     484                 :          0 :             eErrCode = Bootstrap::MISSING_INSTALL_DIRECTORY;
     485                 :          0 :             break;
     486                 :            : 
     487                 :            :         case Bootstrap::DATA_INVALID:
     488                 :          0 :             addUnexpectedError(_rBuf,"The installation path is invalid");
     489                 :          0 :             break;
     490                 :            : 
     491                 :            :         case Bootstrap::DATA_MISSING:
     492                 :          0 :             addUnexpectedError(_rBuf,"The installation path is not available");
     493                 :          0 :             break;
     494                 :            : 
     495                 :            :         case Bootstrap::PATH_EXISTS: // seems to be all fine (?)
     496                 :          0 :             addUnexpectedError(_rBuf,"");
     497                 :          0 :             break;
     498                 :            : 
     499                 :            :         default: OSL_ASSERT(false);
     500                 :          0 :             addUnexpectedError(_rBuf);
     501                 :          0 :             break;
     502                 :            :         }
     503                 :          0 :         break;
     504                 :            : 
     505                 :            :     case Bootstrap::PATH_VALID:
     506                 :          0 :         addMissingDirectoryError(_rBuf, _rData.aUserInstall_.path);
     507                 :          0 :         eErrCode = Bootstrap::MISSING_USER_DIRECTORY;
     508                 :          0 :         break;
     509                 :            : 
     510                 :            :         // else fall through
     511                 :            :     case Bootstrap::DATA_INVALID:
     512         [ #  # ]:          0 :         if (_rData.aVersionINI_.status == Bootstrap::PATH_EXISTS)
     513                 :            :         {
     514                 :          0 :             addFileError(_rBuf, _rData.aVersionINI_.path, IS_INVALID);
     515                 :          0 :             eErrCode = Bootstrap::INVALID_VERSION_FILE_ENTRY;
     516                 :          0 :             break;
     517                 :            :         }
     518                 :            :         // else fall through
     519                 :            : 
     520                 :            :     case Bootstrap::DATA_MISSING:
     521      [ #  #  # ]:          0 :         switch (_rData.aVersionINI_.status)
     522                 :            :         {
     523                 :            :         case Bootstrap::PATH_EXISTS:
     524                 :          0 :             addFileError(_rBuf, _rData.aVersionINI_.path, "does not support the current version");
     525                 :          0 :             eErrCode = Bootstrap::MISSING_VERSION_FILE_ENTRY;
     526                 :          0 :             break;
     527                 :            : 
     528                 :            :         case Bootstrap::PATH_VALID:
     529                 :          0 :             addFileError(_rBuf, _rData.aVersionINI_.path, IS_MISSING);
     530                 :          0 :             eErrCode = Bootstrap::MISSING_VERSION_FILE;
     531                 :          0 :             break;
     532                 :            : 
     533                 :            :         default:
     534      [ #  #  # ]:          0 :             switch (_rData.aBootstrapINI_.status)
     535                 :            :             {
     536                 :            :             case Bootstrap::PATH_EXISTS:
     537                 :          0 :                 addFileError(_rBuf, _rData.aBootstrapINI_.path, IS_INVALID);
     538                 :            : 
     539         [ #  # ]:          0 :                 if (_rData.aVersionINI_.status == Bootstrap::DATA_MISSING)
     540                 :          0 :                     eErrCode = Bootstrap::MISSING_BOOTSTRAP_FILE_ENTRY;
     541                 :            :                 else
     542                 :          0 :                     eErrCode = Bootstrap::INVALID_BOOTSTRAP_FILE_ENTRY;
     543                 :          0 :                 break;
     544                 :            : 
     545                 :            :             case Bootstrap::DATA_INVALID: OSL_ASSERT(false);
     546                 :            :             case Bootstrap::PATH_VALID:
     547                 :          0 :                 addFileError(_rBuf, _rData.aBootstrapINI_.path, IS_MISSING);
     548                 :          0 :                 eErrCode = Bootstrap::MISSING_BOOTSTRAP_FILE;
     549                 :          0 :                 break;
     550                 :            : 
     551                 :            :             default:
     552                 :          0 :                 addUnexpectedError(_rBuf);
     553                 :          0 :                 break;
     554                 :            :             }
     555                 :          0 :             break;
     556                 :            :         }
     557                 :          0 :         break;
     558                 :            : 
     559                 :            :     default: OSL_ASSERT(false);
     560                 :          0 :         addUnexpectedError(_rBuf);
     561                 :          0 :         break;
     562                 :            :     }
     563                 :            : 
     564                 :          0 :     return eErrCode;
     565                 :            : }
     566                 :            : // ---------------------------------------------------------------------------------------
     567                 :            : // ---------------------------------------------------------------------------------------
     568                 :            : // class Bootstrap
     569                 :            : // ---------------------------------------------------------------------------------------
     570                 :            : 
     571                 :          0 : OUString Bootstrap::getProductKey()
     572                 :            : {
     573         [ #  # ]:          0 :     OUString const csProductKeyItem(RTL_CONSTASCII_USTRINGPARAM(BOOTSTRAP_ITEM_PRODUCT_KEY));
     574                 :            : 
     575         [ #  # ]:          0 :     OUString const sDefaultProductKey = getExecutableBaseName();
     576                 :            : 
     577 [ #  # ][ #  # ]:          0 :     return data().getBootstrapValue( csProductKeyItem, sDefaultProductKey );
     578                 :            : }
     579                 :            : // ---------------------------------------------------------------------------------------
     580                 :            : 
     581                 :          0 : OUString Bootstrap::getProductKey(OUString const& _sDefault)
     582                 :            : {
     583         [ #  # ]:          0 :     OUString const csProductKeyItem(RTL_CONSTASCII_USTRINGPARAM(BOOTSTRAP_ITEM_PRODUCT_KEY));
     584                 :            : 
     585 [ #  # ][ #  # ]:          0 :     return data().getBootstrapValue( csProductKeyItem, _sDefault );
     586                 :            : }
     587                 :            : // ---------------------------------------------------------------------------------------
     588                 :            : 
     589                 :          0 : OUString Bootstrap::getProductSource(OUString const& _sDefault)
     590                 :            : {
     591         [ #  # ]:          0 :     OUString const csProductSourceItem(RTL_CONSTASCII_USTRINGPARAM(BOOTSTRAP_ITEM_PRODUCT_SOURCE));
     592                 :            : 
     593                 :          0 :     OUString sProductSource;
     594                 :            :     // read ProductSource from version.ini (versionrc)
     595 [ #  # ][ #  # ]:          0 :     data().getVersionValue( csProductSourceItem, sProductSource, _sDefault );
     596                 :          0 :     return sProductSource;
     597                 :            : }
     598                 :            : // ---------------------------------------------------------------------------------------
     599                 :            : 
     600                 :          0 : OUString Bootstrap::getBuildVersion(OUString const& _sDefault)
     601                 :            : {
     602                 :          0 :     OUString const csBuildVersionItem(BOOTSTRAP_ITEM_BUILDVERSION);
     603                 :            : 
     604                 :          0 :     OUString sBuildVersion;
     605                 :            :     // read ProductSource from version.ini (versionrc)
     606 [ #  # ][ #  # ]:          0 :     data().getVersionValue( csBuildVersionItem, sBuildVersion, _sDefault );
     607                 :          0 :     return sBuildVersion;
     608                 :            : }
     609                 :            : // ---------------------------------------------------------------------------------------
     610                 :            : 
     611                 :       1174 : OUString Bootstrap::getBuildIdData(OUString const& _sDefault)
     612                 :            : {
     613         [ +  - ]:       1174 :     OUString const csBuildIdItem(RTL_CONSTASCII_USTRINGPARAM(BOOTSTRAP_ITEM_BUILDID));
     614                 :            : 
     615                 :       1174 :     OUString sBuildId;
     616                 :            :     // read buildid from version.ini (versionrc), if it doesn't exist or buildid is empty
     617         [ +  - ]:       1241 :     if ( data().getVersionValue( csBuildIdItem, sBuildId, _sDefault ) != sal_True ||
           [ +  +  -  + ]
         [ +  + ][ +  - ]
     618                 :         67 :          sBuildId.isEmpty() )
     619                 :            :          // read buildid from bootstrap.ini (bootstraprc)
     620 [ +  - ][ +  - ]:       1107 :         sBuildId = data().getBootstrapValue( csBuildIdItem, _sDefault );
     621                 :       1174 :     return sBuildId;
     622                 :            : }
     623                 :            : 
     624                 :            : // ---------------------------------------------------------------------------------------
     625                 :            : 
     626                 :        220 : Bootstrap::PathStatus Bootstrap::locateBaseInstallation(OUString& _rURL)
     627                 :            : {
     628                 :        220 :     Impl::PathData const& aPathData = data().aBaseInstall_;
     629                 :            : 
     630                 :        220 :     _rURL = aPathData.path;
     631                 :        220 :     return aPathData.status;
     632                 :            : }
     633                 :            : // ---------------------------------------------------------------------------------------
     634                 :            : 
     635                 :        668 : PathStatus Bootstrap::locateUserInstallation(OUString& _rURL)
     636                 :            : {
     637                 :        668 :     Impl::PathData const& aPathData = data().aUserInstall_;
     638                 :            : 
     639                 :        668 :     _rURL = aPathData.path;
     640                 :        668 :     return aPathData.status;
     641                 :            : }
     642                 :            : 
     643                 :            : // ---------------------------------------------------------------------------------------
     644                 :            : 
     645                 :        425 : PathStatus Bootstrap::locateUserData(OUString& _rURL)
     646                 :            : {
     647         [ +  - ]:        425 :     OUString const csUserDirItem(RTL_CONSTASCII_USTRINGPARAM(BOOTSTRAP_ITEM_USERDIR));
     648                 :            : 
     649         [ +  - ]:        425 :     rtl::Bootstrap aData( data().getImplName() );
     650                 :            : 
     651         [ -  + ]:        425 :     if ( aData.getFrom(csUserDirItem, _rURL) )
     652                 :            :     {
     653         [ #  # ]:          0 :         return checkStatusAndNormalizeURL(_rURL);
     654                 :            :     }
     655                 :            :     else
     656                 :            :     {
     657         [ +  - ]:        425 :         OUString const csUserDir(RTL_CONSTASCII_USTRINGPARAM(BOOTSTRAP_DIRNAME_USERDIR));
     658 [ +  - ][ +  - ]:        425 :         return getDerivedPath(_rURL, data().aUserInstall_ ,csUserDir, aData, csUserDirItem);
     659                 :        425 :     }
     660                 :            : }
     661                 :            : // ---------------------------------------------------------------------------------------
     662                 :            : 
     663                 :          0 : PathStatus Bootstrap::locateBootstrapFile(OUString& _rURL)
     664                 :            : {
     665                 :          0 :     Impl::PathData const& aPathData = data().aBootstrapINI_;
     666                 :            : 
     667                 :          0 :     _rURL = aPathData.path;
     668                 :          0 :     return aPathData.status;
     669                 :            : }
     670                 :            : // ---------------------------------------------------------------------------------------
     671                 :            : 
     672                 :          0 : PathStatus Bootstrap::locateVersionFile(OUString& _rURL)
     673                 :            : {
     674                 :          0 :     Impl::PathData const& aPathData = data().aVersionINI_;
     675                 :            : 
     676                 :          0 :     _rURL = aPathData.path;
     677                 :          0 :     return aPathData.status;
     678                 :            : }
     679                 :            : // ---------------------------------------------------------------------------------------
     680                 :            : 
     681                 :          0 : Bootstrap::Status Bootstrap::checkBootstrapStatus(rtl::OUString& _rDiagnosticMessage, FailureCode& _rErrCode)
     682                 :            : {
     683         [ #  # ]:          0 :     Impl const& aData = data();
     684                 :            : 
     685                 :          0 :     Status result = aData.status_;
     686                 :            : 
     687                 :            :     // maybe do further checks here
     688                 :            : 
     689                 :          0 :     OUStringBuffer sErrorBuffer;
     690         [ #  # ]:          0 :     if (result != DATA_OK)
     691         [ #  # ]:          0 :         _rErrCode = describeError(sErrorBuffer,aData);
     692                 :            : 
     693                 :            :     else
     694                 :          0 :         _rErrCode = NO_FAILURE;
     695                 :            : 
     696         [ #  # ]:          0 :     _rDiagnosticMessage = sErrorBuffer.makeStringAndClear();
     697                 :            : 
     698                 :          0 :     return result;
     699                 :            : }
     700                 :            : 
     701                 :            : // ---------------------------------------------------------------------------------------
     702                 :            : // class Bootstrap::Impl
     703                 :            : // ---------------------------------------------------------------------------------------
     704                 :            : 
     705                 :        425 : bool Bootstrap::Impl::initBaseInstallationData(rtl::Bootstrap& _rData)
     706                 :            : {
     707         [ +  - ]:        425 :     OUString const csBaseInstallItem( RTL_CONSTASCII_USTRINGPARAM(BOOTSTRAP_ITEM_BASEINSTALLATION) );
     708         [ +  - ]:        425 :     OUString const csBaseInstallDefault( RTL_CONSTASCII_USTRINGPARAM(BOOTSTRAP_DEFAULT_BASEINSTALL) );
     709                 :            : 
     710                 :        425 :     _rData.getFrom(csBaseInstallItem, aBaseInstall_.path, csBaseInstallDefault);
     711                 :            : 
     712         [ +  - ]:        425 :     bool bResult = (PATH_EXISTS == updateStatus(aBaseInstall_));
     713                 :            : 
     714         [ +  - ]:        425 :     implGetBootstrapFile(_rData, aBootstrapINI_);
     715                 :            : 
     716                 :        425 :     return bResult;
     717                 :            : }
     718                 :            : // ---------------------------------------------------------------------------------------
     719                 :            : 
     720                 :        425 : bool Bootstrap::Impl::initUserInstallationData(rtl::Bootstrap& _rData)
     721                 :            : {
     722         [ +  - ]:        425 :     OUString const csUserInstallItem( RTL_CONSTASCII_USTRINGPARAM(BOOTSTRAP_ITEM_USERINSTALLATION) );
     723                 :            : 
     724         [ +  + ]:        425 :     if (_rData.getFrom(csUserInstallItem, aUserInstall_.path))
     725                 :            :     {
     726         [ +  - ]:        420 :         updateStatus(aUserInstall_);
     727                 :            :     }
     728                 :            :     else
     729                 :            :     {
     730                 :            :         // should we do just this
     731                 :          5 :         aUserInstall_.status = DATA_MISSING;
     732                 :            : 
     733                 :            :         // .. or this - look for a single-user user directory ?
     734         [ +  - ]:          5 :         OUString const csUserDirItem(RTL_CONSTASCII_USTRINGPARAM(BOOTSTRAP_ITEM_USERDIR));
     735                 :          5 :         OUString sDummy;
     736                 :            :         // look for $BASEINSTALLATION/user only if default UserDir setting is used
     737         [ +  - ]:          5 :         if (! _rData.getFrom(csUserDirItem, sDummy))
     738                 :            :         {
     739         [ +  - ]:          5 :             OUString const csUserDir(RTL_CONSTASCII_USTRINGPARAM(BOOTSTRAP_DIRNAME_USERDIR));
     740                 :            : 
     741 [ +  - ][ -  + ]:          5 :             if ( PATH_EXISTS == getDerivedPath(sDummy, aBaseInstall_, csUserDir, _rData, csUserDirItem) )
     742         [ #  # ]:          5 :                 aUserInstall_ = aBaseInstall_;
     743                 :          5 :         }
     744                 :            :     }
     745                 :            : 
     746                 :        425 :     bool bResult = (PATH_EXISTS == aUserInstall_.status);
     747                 :            : 
     748         [ +  - ]:        425 :     implGetVersionFile(_rData, aVersionINI_);
     749                 :            : 
     750                 :        425 :     return bResult;
     751                 :            : }
     752                 :            : // ---------------------------------------------------------------------------------------
     753                 :            : 
     754                 :        425 : void Bootstrap::Impl::initialize()
     755                 :            : {
     756                 :        425 :     rtl::Bootstrap aData( m_aImplName );
     757                 :            : 
     758 [ -  + ][ +  - ]:        425 :     if (!initBaseInstallationData(aData))
     759                 :            :     {
     760                 :          0 :         status_ = INVALID_BASE_INSTALL;
     761                 :            :     }
     762 [ +  - ][ +  + ]:        425 :     else if (!initUserInstallationData(aData))
     763                 :            :     {
     764                 :          5 :         status_ = INVALID_USER_INSTALL;
     765                 :            : 
     766         [ +  - ]:          5 :         if (aUserInstall_.status >= DATA_MISSING)
     767                 :            :         {
     768      [ -  +  - ]:          5 :             switch (aVersionINI_.status)
     769                 :            :             {
     770                 :            :             case PATH_EXISTS:
     771                 :            :             case PATH_VALID:
     772                 :          0 :                 status_ = MISSING_USER_INSTALL;
     773                 :          0 :                 break;
     774                 :            : 
     775                 :            :             case DATA_INVALID:
     776                 :            :             case DATA_MISSING:
     777                 :          5 :                 status_ = INVALID_BASE_INSTALL;
     778                 :          5 :                 break;
     779                 :            :             default:
     780                 :          5 :                 break;
     781                 :            :             }
     782                 :            :         }
     783                 :            :     }
     784                 :            :     else
     785                 :            :     {
     786                 :        420 :         status_ = DATA_OK;
     787                 :        425 :     }
     788                 :        425 : }
     789                 :            : // ---------------------------------------------------------------------------------------
     790                 :            : 
     791                 :       1107 : OUString Bootstrap::Impl::getBootstrapValue(OUString const& _sName, OUString const& _sDefault) const
     792                 :            : {
     793                 :       1107 :     rtl::Bootstrap aData( m_aImplName );
     794                 :            : 
     795                 :       1107 :     OUString sResult;
     796                 :       1107 :     aData.getFrom(_sName,sResult,_sDefault);
     797                 :       1107 :     return sResult;
     798                 :            : }
     799                 :            : // ---------------------------------------------------------------------------------------
     800                 :            : 
     801                 :       1174 : sal_Bool Bootstrap::Impl::getVersionValue(OUString const& _sName, OUString& _rValue, OUString const& _sDefault) const
     802                 :            : {
     803                 :            :     // try to open version.ini (versionrc)
     804                 :       1174 :     rtl::OUString uri;
     805                 :            :     rtl::Bootstrap::get(
     806         [ +  - ]:       1174 :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BRAND_BASE_DIR")), uri);
     807                 :            :     rtl::Bootstrap aData( uri +
     808         [ +  - ]:       1174 :                           OUString(RTL_CONSTASCII_USTRINGPARAM("/program/" SAL_CONFIGFILE("version"))) );
     809         [ +  + ]:       1174 :     if ( aData.getHandle() == NULL )
     810                 :            :         // version.ini (versionrc) doesn't exist
     811                 :       1107 :         return sal_False;
     812                 :            : 
     813                 :            :     // read value
     814                 :         67 :     aData.getFrom(_sName,_rValue,_sDefault);
     815                 :       1174 :     return sal_True;
     816                 :            : }
     817                 :            : // ---------------------------------------------------------------------------------------
     818                 :            : 
     819                 :            : } // namespace utl
     820                 :            : 
     821                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10