24#include <config_folders.h>
28#include <rtl/ustring.hxx>
29#include <rtl/ustrbuf.hxx>
31#include <osl/file.hxx>
32#include <osl/diagnose.h>
34#include <rtl/bootstrap.hxx>
35#include <osl/process.h>
38#define RTL_BOOTSTRAP_DEFAULTS_BROKEN true
103 OUString
getBootstrapValue(OUString
const& _sName, OUString
const& _sDefault)
const;
129 OUString s(
"$OOO_CWD");
130 rtl::Bootstrap::expandMacros(s);
133 if (osl_getProcessWorkingDir(&rUrl.pData) == osl_Process_E_None)
136 else if (s[0] ==
'1')
141 else if (s[0] ==
'2' &&
142 (osl::FileBase::getFileURLFromSystemPath(s.copy(1), rUrl) ==
143 osl::FileBase::E_None))
152 theImpl().initialize();
168 if (!_sURL.isEmpty())
172 case DirectoryItem::E_None:
176 case DirectoryItem::E_NOENT:
180 case DirectoryItem::E_INVAL:
181 case DirectoryItem::E_NAMETOOLONG:
182 case DirectoryItem::E_NOTDIR:
187 case DirectoryItem::E_LOOP:
188 case DirectoryItem::E_ACCES:
207 OSL_PRECOND(aDirItem.is(),
"Opened DirItem required");
209 static const sal_uInt32 cosl_FileStatus_Mask = osl_FileStatus_Mask_FileURL;
213 if (aDirItem.getFileStatus(aFileStatus) != DirectoryItem::E_None)
216 OUString aNormalizedURL = aFileStatus.getFileURL();
218 if (aNormalizedURL.isEmpty())
224 _sURL = aNormalizedURL;
226 _sURL = aNormalizedURL.copy( 0, aNormalizedURL.getLength()-1 );
239 if ( File::E_None == File::getAbsoluteFileURL(sBasePath, _rsURL, sAbsolute))
246 OSL_FAIL(
"Could not get absolute file URL for URL");
259 if ( File::E_None == File::getSystemPathFromFileURL(_rsPathOrURL, sOther) )
264 else if ( File::E_None == File::getFileURLFromSystemPath(_rsPathOrURL, sOther) )
266 _rsPathOrURL = sOther;
279 DirectoryItem aDirItem;
298 DirectoryItem aDirItem;
303 OSL_FAIL(
"Unexpected failure getting actual URL for existing object");
311 OUString
const& _aBaseURL,
PathStatus _aBaseStatus,
312 std::u16string_view _sRelativeURL,
313 rtl::Bootstrap
const & _rData, OUString
const& _sBootstrapParameter
316 OUString sDerivedURL;
317 OSL_PRECOND(!_rData.getFrom(_sBootstrapParameter,sDerivedURL),
"Setting for derived path is already defined");
318 OSL_PRECOND(!_sRelativeURL.empty() && _sRelativeURL[0] !=
cURLSeparator,
"Invalid Relative URL");
323 if (!_aBaseURL.isEmpty())
325 OSL_PRECOND(!_aBaseURL.endsWith(OUStringChar(
cURLSeparator)),
"Unexpected: base URL ends in slash");
327 sDerivedURL = _aBaseURL + OUStringChar(
cURLSeparator) + _sRelativeURL;
336 _rData.getFrom(_sBootstrapParameter, _rURL, sDerivedURL);
338 OSL_ENSURE(sDerivedURL == _rURL,
"Could not set derived URL via Bootstrap default parameter");
341 "Use of default did not affect bootstrap value");
358 std::u16string_view _sRelativeURL,
359 rtl::Bootstrap
const & _rData, OUString
const& _sBootstrapParameter
367 OUString sExecutable;
369 if (osl_Process_E_None == osl_getExecutableFile(&sExecutable.pData))
372 sal_Int32 nSepIndex = sExecutable.lastIndexOf(
cURLSeparator);
374 sExecutable = sExecutable.copy(nSepIndex + 1);
379 sal_Int32
const nExtIndex = sExecutable.lastIndexOf(cExtensionSep);
380 sal_Int32
const nExtLength = sExecutable.getLength() - nExtIndex - 1;
381 if (0 < nExtIndex && nExtLength < 4)
382 sExecutable = sExecutable.copy(0,nExtIndex);
385 SAL_WARN(
"unotools.config",
"Cannot get executable name: osl_getExecutableFile failed");
398 _rData.getIniName(_rBootstrapFile.
path);
418 std::u16string_view sSimpleFileName = _aPath.substr(1 +_aPath.rfind(
cURLSeparator));
420 _rBuf.append(
"The configuration file");
421 _rBuf.append(OUString::Concat(
" '") + sSimpleFileName +
"' ");
422 _rBuf.appendAscii(_sWhat).append(
PERIOD);
427 _rBuf.append(OUString::Concat(
"The configuration directory '") + _aPath +
"' " +
433 if (
nullptr == _sExtraInfo)
434 _sExtraInfo =
"An internal failure occurred";
436 _rBuf.appendAscii(_sExtraInfo).append(
PERIOD);
443 _rBuf.append(
"The program cannot be started. ");
467 default: OSL_ASSERT(
false);
527 default: OSL_ASSERT(
false);
554 if (
aData.getHandle() ==
nullptr )
568 _rURL = aPathData.
path;
576 _rURL = aPathData.
path;
584 rtl::Bootstrap
aData(
data().getImplName() );
586 if (
aData.getFrom(csUserDirItem, _rURL) )
600 _rURL = aPathData.
path;
608 _rURL = aPathData.
path;
620 OUStringBuffer sErrorBuffer;
627 _rDiagnosticMessage = sErrorBuffer.makeStringAndClear();
659 if (! _rData.getFrom(csUserDirItem, sDummy))
662 aUserInstall_ = aBaseInstall_;
666 bool bResult = (
PATH_EXISTS == aUserInstall_.status);
675 rtl::Bootstrap
aData( m_aImplName );
677 if (!initBaseInstallationData(
aData))
681 else if (!initUserInstallationData(
aData))
687 switch (aVersionINI_.status)
711 rtl::Bootstrap
aData( m_aImplName );
714 aData.getFrom(_sName,sResult,_sDefault);
constexpr OUStringLiteral BOOTSTRAP_DIRNAME_USERDIR
constexpr OUStringLiteral BOOTSTRAP_ITEM_USERDIR
#define RTL_BOOTSTRAP_DEFAULTS_BROKEN
constexpr OUStringLiteral BOOTSTRAP_DEFAULT_BASEINSTALL
constexpr OUStringLiteral BOOTSTRAP_ITEM_BASEINSTALLATION
constexpr OUStringLiteral BOOTSTRAP_ITEM_BUILDID
constexpr OUStringLiteral BOOTSTRAP_ITEM_PRODUCT_KEY
constexpr OUStringLiteral BOOTSTRAP_ITEM_VERSIONFILE
constexpr OUStringLiteral BOOTSTRAP_ITEM_USERINSTALLATION
bool initBaseInstallationData(rtl::Bootstrap const &_rData)
const OUString & getImplName() const
bool initUserInstallationData(rtl::Bootstrap const &_rData)
OUString getBootstrapValue(OUString const &_sName, OUString const &_sDefault) const
const OUString m_aImplName
static PathStatus locateVersionFile(OUString &_rURL)
get a file URL to the version locator INI file used [e.g. ${SYSUSERCONFIG}/sversion....
static PathStatus locateUserInstallation(OUString &_rURL)
get a file URL to the user installation [${userurl}]
static Status checkBootstrapStatus(OUString &_rDiagnosticMessage, FailureCode &_rErrCode)
Evaluates the status of the installation and returns a diagnostic message and error code correspondin...
static PathStatus locateUserData(OUString &_rURL)
get a file URL to the user data directory [default is ${userurl}/user]
static PathStatus locateBaseInstallation(OUString &_rURL)
get a file URL to the common base installation [${insturl}]
static OUString getProductKey()
retrieve the product key; defaults to executable name (without extension)
FailureCode
error code for detailed diagnostics of bootstrap failures
@ MISSING_BOOTSTRAP_FILE
the shared installation directory could not be located
@ MISSING_VERSION_FILE_ENTRY
the version locator INI file could not be found or read
@ INVALID_BOOTSTRAP_FILE_ENTRY
the bootstrap INI is missing a required entry
@ MISSING_USER_DIRECTORY
the version locator INI entry is not a valid directory URL
@ INVALID_VERSION_FILE_ENTRY
the version locator INI has no entry for this version
@ MISSING_BOOTSTRAP_FILE_ENTRY
the bootstrap INI file could not be found or read
@ MISSING_VERSION_FILE
the bootstrap INI contains invalid data
@ INVALID_BOOTSTRAP_DATA
the user installation directory does not exist
@ MISSING_INSTALL_DIRECTORY
bootstrap was successful
static OUString getBuildIdData(OUString const &_sDefault)
retrieve the BUILDID information item; uses the given default, if not found
static const Impl & data()
static void reloadData()
reload cached data
Status
high-level status of bootstrap success
@ INVALID_BASE_INSTALL
can locate ${userurl}, but user-dir is missing
@ INVALID_USER_INSTALL
${userurl} does not exist; or version-file cannot be found or is invalid
@ MISSING_USER_INSTALL
user-dir and share-dir do exist, product key found or can be defaulted to exe-name
static PathStatus locateBootstrapFile(OUString &_rURL)
get a file URL to the bootstrap INI file used [e.g. ${insturl}/program/bootraprc]
static bool getProcessWorkingDir(OUString &rUrl)
get the working directory of the process
#define SAL_CONFIGFILE(name)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
constexpr OUStringLiteral aData
OUString get(TranslateId sContextAndId, const std::locale &loc)
static PathStatus dbgCheckStatusOfURL(OUString const &_sURL)
static Bootstrap::FailureCode describeError(OUStringBuffer &_rBuf, Bootstrap::Impl const &_rData)
static PathStatus getDerivedPath(OUString &_rURL, OUString const &_aBaseURL, PathStatus _aBaseStatus, std::u16string_view _sRelativeURL, rtl::Bootstrap const &_rData, OUString const &_sBootstrapParameter)
static void addMissingDirectoryError(OUStringBuffer &_rBuf, std::u16string_view _aPath)
static OUString makeImplName()
static void addFileError(OUStringBuffer &_rBuf, std::u16string_view _aPath, AsciiString _sWhat)
static bool implNormalizeURL(OUString &_sURL, osl::DirectoryItem &aDirItem)
static bool implEnsureAbsolute(OUString &_rsURL)
Bootstrap::PathStatus PathStatus
static Bootstrap::PathStatus implGetVersionFile(rtl::Bootstrap const &_rData, Bootstrap::Impl::PathData &_rVersionFile)
static bool implMakeAbsoluteURL(OUString &_rsPathOrURL)
static Bootstrap::PathStatus implGetBootstrapFile(rtl::Bootstrap const &_rData, Bootstrap::Impl::PathData &_rBootstrapFile)
static PathStatus checkStatusAndNormalizeURL(OUString &_sURL)
static void addUnexpectedError(OUStringBuffer &_rBuf, AsciiString _sExtraInfo=nullptr)
static Bootstrap::PathStatus updateStatus(Bootstrap::Impl::PathData &_rResult)
static PathStatus implCheckStatusOfURL(OUString const &_sURL, osl::DirectoryItem &aDirItem)
static OUString getExecutableBaseName()
sal_Unicode const cURLSeparator