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