1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_folders.h>
22 #include <sal/config.h>
26 #include <com/sun/star/uno/DeploymentException.hpp>
27 #include <osl/file.hxx>
28 #include <osl/module.hxx>
29 #include <rtl/ustring.hxx>
30 #include <sal/types.h>
31 #include <o3tl/string_view.hxx>
37 #if !(defined ANDROID || defined EMSCRIPTEN)
38 OUString
get_this_libpath() {
39 static OUString s_uri
= []() {
42 if (osl::Module::getUrlFromAddress(reinterpret_cast<oslGenericFunction
>(get_this_libpath
), uri
))
43 i
= uri
.lastIndexOf('/');
45 throw css::uno::DeploymentException("URI " + uri
+ " is expected to contain a slash");
46 return uri
.copy(0, i
);
54 OUString
cppu::getUnoIniUri() {
56 // Wouldn't it be lovely to avoid this ugly hard-coding.
57 // The problem is that the 'create_bootstrap_macro_expander_factory()'
58 // required for bootstrapping services, calls cppu::get_unorc directly
59 // instead of re-using the BootstrapHandle from:
60 // defaultBootstrap_InitialComponentContext
61 // and since rtlBootstrapHandle is not ref-counted doing anything
62 // clean here is hardish.
63 OUString
uri("file:///assets/program");
64 #elif defined(EMSCRIPTEN)
65 OUString
uri("file:///instdir/program");
67 OUString
uri(get_this_libpath());
69 // We keep the URE dylibs directly in "Frameworks" (that is, LIBO_LIB_FOLDER) and unorc in
70 // "Resources/ure/etc" (LIBO_URE_ETC_FOLDER).
71 if (uri
.endsWith( "/" LIBO_LIB_FOLDER
) )
73 uri
= OUString::Concat(uri
.subView( 0, uri
.getLength() - (sizeof(LIBO_LIB_FOLDER
)-1) )) + LIBO_URE_ETC_FOLDER
;
77 return uri
+ "/" SAL_CONFIGFILE("uno");
80 bool cppu::nextDirectoryItem(osl::Directory
& directory
, OUString
* url
) {
81 assert(url
!= nullptr);
84 switch (directory
.getNextItem(i
, SAL_MAX_UINT32
)) {
85 case osl::FileBase::E_None
:
87 case osl::FileBase::E_NOENT
:
90 throw css::uno::DeploymentException(
91 u
"Cannot iterate directory"_ustr
);
94 osl_FileStatus_Mask_Type
| osl_FileStatus_Mask_FileName
|
95 osl_FileStatus_Mask_FileURL
);
96 if (i
.getFileStatus(stat
) != osl::FileBase::E_None
) {
97 throw css::uno::DeploymentException(
98 u
"Cannot stat in directory"_ustr
);
100 if (stat
.getFileType() != osl::FileStatus::Directory
) { //TODO: symlinks
101 // Ignore backup and spurious junk files:
102 OUString
name(stat
.getFileName());
103 if (name
.startsWith(".") || !name
.endsWithIgnoreAsciiCase(u
".rdb")) {
104 SAL_WARN("cppuhelper", "ignoring <" << stat
.getFileURL() << ">");
106 *url
= stat
.getFileURL();
113 void cppu::decodeRdbUri(std::u16string_view
* uri
, bool * optional
, bool * directory
)
115 assert(uri
!= nullptr && optional
!= nullptr && directory
!= nullptr);
118 *optional
= (*uri
)[0] == '?';
120 *uri
= uri
->substr(1);
122 *directory
= o3tl::starts_with(*uri
, u
"<") && o3tl::ends_with(*uri
, u
">*");
124 *uri
= uri
->substr(1, uri
->size() - 3);
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */