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