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