update credits
[LibreOffice.git] / cppuhelper / source / paths.cxx
blob5f60ab8060286a559bdd7a0634e9a9f2812254f0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "sal/config.h"
22 #include <cassert>
24 #include "com/sun/star/uno/DeploymentException.hpp"
25 #include "com/sun/star/uno/Reference.hxx"
26 #include "com/sun/star/uno/XInterface.hpp"
27 #include "osl/file.hxx"
28 #include "osl/module.hxx"
29 #include "osl/mutex.hxx"
30 #include "rtl/ustring.hxx"
31 #include "sal/types.h"
33 #include "paths.hxx"
35 namespace {
37 rtl::OUString get_this_libpath() {
38 static rtl::OUString s_uri;
39 if (s_uri.isEmpty()) {
40 rtl::OUString uri;
41 osl::Module::getUrlFromAddress(
42 reinterpret_cast< oslGenericFunction >(get_this_libpath), uri);
43 sal_Int32 i = uri.lastIndexOf('/');
44 if (i == -1) {
45 throw css::uno::DeploymentException(
46 "URI " + uri + " is expected to contain a slash",
47 css::uno::Reference< css::uno::XInterface >());
49 uri = uri.copy(0, i);
50 osl::MutexGuard guard(osl::Mutex::getGlobalMutex());
51 if (s_uri.isEmpty()) {
52 s_uri = uri;
55 return s_uri;
60 rtl::OUString cppu::getUnoIniUri() {
61 #if defined ANDROID
62 // Wouldn't it be lovely to avoid this fugly hard-coding.
63 // The problem is that the 'create_bootstrap_macro_expander_factory()'
64 // required for bootstrapping services, calls cppu::get_unorc directly
65 // instead of re-using the BoostrapHandle from:
66 // defaultBootstrap_InitialComponentContext
67 // and since rtlBootstrapHandle is not ref-counted doing anything
68 // clean here is hardish.
69 rtl::OUString uri("file:///assets/program");
70 #else
71 rtl::OUString uri(get_this_libpath());
72 #endif
73 return uri + "/" SAL_CONFIGFILE("uno");
76 bool cppu::nextDirectoryItem(osl::Directory & directory, rtl::OUString * url) {
77 assert(url != 0);
78 for (;;) {
79 osl::DirectoryItem i;
80 switch (directory.getNextItem(i, SAL_MAX_UINT32)) {
81 case osl::FileBase::E_None:
82 break;
83 case osl::FileBase::E_NOENT:
84 return false;
85 default:
86 throw css::uno::DeploymentException(
87 "Cannot iterate directory",
88 css::uno::Reference< css::uno::XInterface >());
90 osl::FileStatus stat(
91 osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName |
92 osl_FileStatus_Mask_FileURL);
93 if (i.getFileStatus(stat) != osl::FileBase::E_None) {
94 throw css::uno::DeploymentException(
95 "Cannot stat in directory",
96 css::uno::Reference< css::uno::XInterface >());
98 if (stat.getFileType() != osl::FileStatus::Directory) { //TODO: symlinks
99 // Ignore backup files:
100 rtl::OUString name(stat.getFileName());
101 if (!(name.match(".") || name.endsWith("~"))) {
102 *url = stat.getFileURL();
103 return true;
109 void cppu::decodeRdbUri(rtl::OUString * uri, bool * optional, bool * directory)
111 assert(uri != 0 && optional != 0 && directory != 0);
112 *optional = (*uri)[0] == '?';
113 if (*optional) {
114 *uri = uri->copy(1);
116 *directory = uri->getLength() >= 3 && (*uri)[0] == '<'
117 && (*uri)[uri->getLength() - 2] == '>'
118 && (*uri)[uri->getLength() - 1] == '*';
119 if (*directory) {
120 *uri = uri->copy(1, uri->getLength() - 3);
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */