Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/unotools/source/config/pathoptions.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#include <sal/config.h>
21
22
#include <sal/log.hxx>
23
#include <unotools/pathoptions.hxx>
24
#include <comphelper/diagnose_ex.hxx>
25
#include <tools/urlobj.hxx>
26
#include <com/sun/star/uno/Any.hxx>
27
#include <com/sun/star/uno/Sequence.hxx>
28
#include <osl/mutex.hxx>
29
#include <osl/file.hxx>
30
31
#include <unotools/ucbhelper.hxx>
32
#include <comphelper/getexpandeduri.hxx>
33
#include <comphelper/processfactory.hxx>
34
#include <com/sun/star/beans/XFastPropertySet.hpp>
35
#include <com/sun/star/beans/XPropertySetInfo.hpp>
36
#include <com/sun/star/util/thePathSettings.hpp>
37
#include <com/sun/star/util/PathSubstitution.hpp>
38
#include <com/sun/star/util/XStringSubstitution.hpp>
39
#include <com/sun/star/util/theMacroExpander.hpp>
40
#include <o3tl/enumarray.hxx>
41
#include <o3tl/string_view.hxx>
42
43
#include "itemholder1.hxx"
44
45
#include <set>
46
#include <unordered_map>
47
48
using namespace osl;
49
using namespace utl;
50
using namespace com::sun::star::uno;
51
using namespace com::sun::star::beans;
52
using namespace com::sun::star::util;
53
54
0
#define SEARCHPATH_DELIMITER  ';'
55
0
#define SIGN_STARTVARIABLE    "$("
56
0
#define SIGN_ENDVARIABLE      ")"
57
58
0
#define STRPOS_NOTFOUND       -1
59
60
typedef std::unordered_map<OUString, sal_Int32> NameToHandleMap;
61
62
typedef std::set<OUString> VarNameSet;
63
64
// class SvtPathOptions_Impl ---------------------------------------------
65
class SvtPathOptions_Impl
66
{
67
    private:
68
        // Local variables to return const references
69
        o3tl::enumarray< SvtPathOptions::Paths, OUString > m_aPathArray;
70
        Reference< XFastPropertySet >       m_xPathSettings;
71
        Reference< XStringSubstitution >    m_xSubstVariables;
72
        Reference< XMacroExpander >         m_xMacroExpander;
73
        mutable std::unordered_map<SvtPathOptions::Paths, sal_Int32>
74
                                            m_aMapEnumToPropHandle;
75
        VarNameSet                          m_aSystemPathVarNames;
76
77
        OUString                            m_aEmptyString;
78
        mutable std::mutex                  m_aMutex;
79
80
    public:
81
                        SvtPathOptions_Impl();
82
83
        // get the paths, not const because of using a mutex
84
        const OUString& GetPath( SvtPathOptions::Paths );
85
0
        const OUString& GetAddinPath() { return GetPath( SvtPathOptions::Paths::AddIn ); }
86
0
        const OUString& GetAutoCorrectPath() { return GetPath( SvtPathOptions::Paths::AutoCorrect ); }
87
0
        const OUString& GetAutoTextPath() { return GetPath( SvtPathOptions::Paths::AutoText ); }
88
0
        const OUString& GetBackupPath() { return GetPath( SvtPathOptions::Paths::Backup ); }
89
0
        const OUString& GetBasicPath() { return GetPath( SvtPathOptions::Paths::Basic ); }
90
0
        const OUString& GetBitmapPath() { return GetPath( SvtPathOptions::Paths::Bitmap ); }
91
0
        const OUString& GetConfigPath() { return GetPath( SvtPathOptions::Paths::Config ); }
92
0
        const OUString& GetDictionaryPath() { return GetPath( SvtPathOptions::Paths::Dictionary ); }
93
0
        const OUString& GetFavoritesPath() { return GetPath( SvtPathOptions::Paths::Favorites ); }
94
0
        const OUString& GetFilterPath() { return GetPath( SvtPathOptions::Paths::Filter ); }
95
0
        const OUString& GetGalleryPath() { return GetPath( SvtPathOptions::Paths::Gallery ); }
96
0
        const OUString& GetGraphicPath() { return GetPath( SvtPathOptions::Paths::Graphic ); }
97
0
        const OUString& GetHelpPath() { return GetPath( SvtPathOptions::Paths::Help ); }
98
0
        const OUString& GetLinguisticPath() { return GetPath( SvtPathOptions::Paths::Linguistic ); }
99
0
        const OUString& GetModulePath() { return GetPath( SvtPathOptions::Paths::Module ); }
100
0
        const OUString& GetPalettePath() { return GetPath( SvtPathOptions::Paths::Palette ); }
101
0
        const OUString& GetIconsetPath() { return GetPath( SvtPathOptions::Paths::IconSet); }
102
0
        const OUString& GetPluginPath() { return GetPath( SvtPathOptions::Paths::Plugin ); }
103
0
        const OUString& GetStoragePath() { return GetPath( SvtPathOptions::Paths::Storage ); }
104
0
        const OUString& GetTempPath() { return GetPath( SvtPathOptions::Paths::Temp ); }
105
0
        const OUString& GetTemplatePath() { return GetPath( SvtPathOptions::Paths::Template ); }
106
0
        const OUString& GetUserConfigPath() { return GetPath( SvtPathOptions::Paths::UserConfig ); }
107
0
        const OUString& GetWorkPath() { return GetPath( SvtPathOptions::Paths::Work ); }
108
0
        const OUString& GetUIConfigPath() { return GetPath( SvtPathOptions::Paths::UIConfig ); }
109
0
        const OUString& GetFingerprintPath() { return GetPath( SvtPathOptions::Paths::Fingerprint ); }
110
0
        const OUString& GetNumbertextPath() { return GetPath( SvtPathOptions::Paths::NumberText ); }
111
0
        const OUString& GetClassificationPath() { return GetPath( SvtPathOptions::Paths::Classification ); }
112
0
        const OUString& GetDocumentThemePath() { return GetPath( SvtPathOptions::Paths::DocumentTheme ); }
113
114
        // set the paths
115
        void            SetPath( SvtPathOptions::Paths, const OUString& rNewPath );
116
0
        void            SetAutoTextPath( const OUString& rPath ) { SetPath( SvtPathOptions::Paths::AutoText, rPath ); }
117
0
        void            SetBasicPath( const OUString& rPath ) { SetPath( SvtPathOptions::Paths::Basic, rPath ); }
118
0
        void            SetTempPath( const OUString& rPath ) { SetPath( SvtPathOptions::Paths::Temp, rPath ); }
119
0
        void            SetWorkPath( const OUString& rPath ) { SetPath( SvtPathOptions::Paths::Work, rPath ); }
120
121
        OUString   SubstVar( const OUString& rVar ) const;
122
        OUString   ExpandMacros( const OUString& rPath ) const;
123
        OUString   UsePathVariables( const OUString& rPath ) const;
124
};
125
126
// global ----------------------------------------------------------------
127
128
static std::weak_ptr<SvtPathOptions_Impl> g_pOptions;
129
130
namespace {
131
132
// functions -------------------------------------------------------------
133
struct PropertyStruct
134
{
135
    OUString                aPropName;  // The ascii name of the Office path
136
    SvtPathOptions::Paths   ePath;      // The enum value used by SvtPathOptions
137
};
138
139
struct VarNameAttribute
140
{
141
    OUString aVarName;       // The name of the path variable
142
};
143
144
}
145
146
constexpr PropertyStruct aPropNames[] =
147
{
148
    { u"Addin"_ustr,          SvtPathOptions::Paths::AddIn          },
149
    { u"AutoCorrect"_ustr,    SvtPathOptions::Paths::AutoCorrect    },
150
    { u"AutoText"_ustr,       SvtPathOptions::Paths::AutoText       },
151
    { u"Backup"_ustr,         SvtPathOptions::Paths::Backup         },
152
    { u"Basic"_ustr,          SvtPathOptions::Paths::Basic          },
153
    { u"Bitmap"_ustr,         SvtPathOptions::Paths::Bitmap         },
154
    { u"Config"_ustr,         SvtPathOptions::Paths::Config         },
155
    { u"Dictionary"_ustr,     SvtPathOptions::Paths::Dictionary     },
156
    { u"Favorite"_ustr,       SvtPathOptions::Paths::Favorites      },
157
    { u"Filter"_ustr,         SvtPathOptions::Paths::Filter         },
158
    { u"Gallery"_ustr,        SvtPathOptions::Paths::Gallery        },
159
    { u"Graphic"_ustr,        SvtPathOptions::Paths::Graphic        },
160
    { u"Help"_ustr,           SvtPathOptions::Paths::Help           },
161
    { u"Iconset"_ustr,        SvtPathOptions::Paths::IconSet        },
162
    { u"Linguistic"_ustr,     SvtPathOptions::Paths::Linguistic     },
163
    { u"Module"_ustr,         SvtPathOptions::Paths::Module         },
164
    { u"Palette"_ustr,        SvtPathOptions::Paths::Palette        },
165
    { u"Plugin"_ustr,         SvtPathOptions::Paths::Plugin         },
166
    { u"Storage"_ustr,        SvtPathOptions::Paths::Storage        },
167
    { u"Temp"_ustr,           SvtPathOptions::Paths::Temp           },
168
    { u"Template"_ustr,       SvtPathOptions::Paths::Template       },
169
    { u"UserConfig"_ustr,     SvtPathOptions::Paths::UserConfig     },
170
    { u"Work"_ustr,           SvtPathOptions::Paths::Work           },
171
    { u"UIConfig"_ustr,       SvtPathOptions::Paths::UIConfig       },
172
    { u"Fingerprint"_ustr,    SvtPathOptions::Paths::Fingerprint    },
173
    { u"Numbertext"_ustr,     SvtPathOptions::Paths::NumberText     },
174
    { u"Classification"_ustr, SvtPathOptions::Paths::Classification },
175
    { u"DocumentTheme"_ustr, SvtPathOptions::Paths::DocumentTheme },
176
};
177
178
// Supported variables by the old SvtPathOptions implementation
179
constexpr VarNameAttribute aVarNameAttribute[] =
180
{
181
    { u"$(instpath)"_ustr },    // $(instpath)
182
    { u"$(progpath)"_ustr },    // $(progpath)
183
    { u"$(userpath)"_ustr },    // $(userpath)
184
    { u"$(path)"_ustr },    // $(path)
185
};
186
187
// class SvtPathOptions_Impl ---------------------------------------------
188
189
const OUString& SvtPathOptions_Impl::GetPath( SvtPathOptions::Paths ePath )
190
0
{
191
0
    std::unique_lock aGuard( m_aMutex );
192
193
0
    try
194
0
    {
195
0
        OUString    aPathValue;
196
0
        sal_Int32   nHandle = m_aMapEnumToPropHandle[ePath];
197
198
        // Substitution is done by the service itself using the substitution service
199
0
        Any         a = m_xPathSettings->getFastPropertyValue( nHandle );
200
0
        a >>= aPathValue;
201
0
        if( ePath == SvtPathOptions::Paths::AddIn     ||
202
0
            ePath == SvtPathOptions::Paths::Filter    ||
203
0
            ePath == SvtPathOptions::Paths::Help      ||
204
0
            ePath == SvtPathOptions::Paths::Module    ||
205
0
            ePath == SvtPathOptions::Paths::Plugin    ||
206
0
            ePath == SvtPathOptions::Paths::Storage
207
0
          )
208
0
        {
209
            // These office paths have to be converted to system paths
210
0
            OUString    aResult;
211
0
            osl::FileBase::getSystemPathFromFileURL( aPathValue, aResult );
212
0
            aPathValue = aResult;
213
0
        }
214
0
        else if (ePath == SvtPathOptions::Paths::Palette ||
215
0
                 ePath == SvtPathOptions::Paths::IconSet)
216
0
        {
217
0
            const auto& ctx = comphelper::getProcessComponentContext();
218
0
            OUStringBuffer buf(aPathValue.getLength()*2);
219
0
            for (sal_Int32 i = 0;;)
220
0
            {
221
0
                buf.append(
222
0
                    comphelper::getExpandedUri(
223
0
                        ctx, aPathValue.getToken(0, ';', i)));
224
0
                if (i == -1) {
225
0
                    break;
226
0
                }
227
0
                buf.append(';');
228
0
            }
229
0
            aPathValue = buf.makeStringAndClear();
230
0
        }
231
232
0
        m_aPathArray[ ePath ] = aPathValue;
233
0
        return m_aPathArray[ ePath ];
234
0
    }
235
0
    catch (UnknownPropertyException &)
236
0
    {
237
0
    }
238
239
0
    return m_aEmptyString;
240
0
}
241
242
void SvtPathOptions_Impl::SetPath( SvtPathOptions::Paths ePath, const OUString& rNewPath )
243
0
{
244
0
    std::unique_lock aGuard( m_aMutex );
245
246
0
    OUString    aResult;
247
0
    OUString    aNewValue;
248
0
    Any         a;
249
250
0
    switch ( ePath )
251
0
    {
252
0
        case SvtPathOptions::Paths::AddIn:
253
0
        case SvtPathOptions::Paths::Filter:
254
0
        case SvtPathOptions::Paths::Help:
255
0
        case SvtPathOptions::Paths::Module:
256
0
        case SvtPathOptions::Paths::Plugin:
257
0
        case SvtPathOptions::Paths::Storage:
258
0
        {
259
            // These office paths have to be convert back to UCB-URL's
260
0
            osl::FileBase::getFileURLFromSystemPath( rNewPath, aResult );
261
0
            aNewValue = aResult;
262
0
        }
263
0
        break;
264
265
0
        default:
266
0
            aNewValue = rNewPath;
267
0
    }
268
269
    // Resubstitution is done by the service itself using the substitution service
270
0
    a <<= aNewValue;
271
0
    try
272
0
    {
273
0
        m_xPathSettings->setFastPropertyValue( m_aMapEnumToPropHandle[ePath], a );
274
0
    }
275
0
    catch (const Exception&)
276
0
    {
277
0
        TOOLS_WARN_EXCEPTION("unotools.config", "SetPath");
278
0
    }
279
0
}
280
281
OUString SvtPathOptions_Impl::ExpandMacros( const OUString& rPath ) const
282
0
{
283
0
    OUString sExpanded( rPath );
284
285
0
    const INetURLObject aParser( rPath );
286
0
    if ( aParser.GetProtocol() == INetProtocol::VndSunStarExpand )
287
0
        sExpanded = m_xMacroExpander->expandMacros( aParser.GetURLPath( INetURLObject::DecodeMechanism::WithCharset ) );
288
289
0
    return sExpanded;
290
0
}
291
292
OUString SvtPathOptions_Impl::UsePathVariables( const OUString& rPath ) const
293
0
{
294
0
    return m_xSubstVariables->reSubstituteVariables( rPath );
295
0
}
296
297
OUString SvtPathOptions_Impl::SubstVar( const OUString& rVar ) const
298
0
{
299
    // Don't work at parameter-string directly. Copy it.
300
0
    OUString aWorkText = rVar;
301
302
    // Convert the returned path to system path!
303
0
    bool bConvertLocal = false;
304
305
    // Search for first occurrence of "$(...".
306
0
    sal_Int32 nPosition = aWorkText.indexOf( SIGN_STARTVARIABLE );  // = first position of "$(" in string
307
0
    sal_Int32 nLength   = 0;                                        // = count of letters from "$(" to ")" in string
308
309
    // Have we found any variable like "$(...)"?
310
0
    if ( nPosition != STRPOS_NOTFOUND )
311
0
    {
312
        // Yes; Get length of found variable.
313
        // If no ")" was found - nLength is set to 0 by default! see before.
314
0
        sal_Int32 nEndPosition = aWorkText.indexOf( SIGN_ENDVARIABLE, nPosition );
315
0
        if ( nEndPosition != STRPOS_NOTFOUND )
316
0
            nLength = nEndPosition - nPosition + 1;
317
0
    }
318
319
    // Is there another path variable?
320
0
    while ( ( nPosition != STRPOS_NOTFOUND ) && ( nLength > 0 ) )
321
0
    {
322
        // YES; Get the next variable for replace.
323
0
        OUString aSubString = aWorkText.copy( nPosition, nLength );
324
0
        aSubString = aSubString.toAsciiLowerCase();
325
326
        // Look for special variable that needs a system path.
327
0
        VarNameSet::const_iterator pIter = m_aSystemPathVarNames.find( aSubString );
328
0
        if ( pIter != m_aSystemPathVarNames.end() )
329
0
            bConvertLocal = true;
330
331
0
        nPosition += nLength;
332
333
        // We must control index in string before call something at OUString!
334
        // The OUString-implementation don't do it for us :-( but the result is not defined otherwise.
335
0
        if ( nPosition + 1 > aWorkText.getLength() )
336
0
        {
337
            // Position is out of range. Break loop!
338
0
            nPosition = STRPOS_NOTFOUND;
339
0
            nLength = 0;
340
0
        }
341
0
        else
342
0
        {
343
            // Else; Position is valid. Search for next variable.
344
0
            nPosition = aWorkText.indexOf( SIGN_STARTVARIABLE, nPosition );
345
            // Have we found any variable like "$(...)"?
346
0
            if ( nPosition != STRPOS_NOTFOUND )
347
0
            {
348
                // Yes; Get length of found variable. If no ")" was found - nLength must set to 0!
349
0
                nLength = 0;
350
0
                sal_Int32 nEndPosition = aWorkText.indexOf( SIGN_ENDVARIABLE, nPosition );
351
0
                if ( nEndPosition != STRPOS_NOTFOUND )
352
0
                    nLength = nEndPosition - nPosition + 1;
353
0
            }
354
0
        }
355
0
    }
356
357
0
    aWorkText = m_xSubstVariables->substituteVariables( rVar, false );
358
359
0
    if ( bConvertLocal )
360
0
    {
361
        // Convert the URL to a system path for special path variables
362
0
        OUString aReturn;
363
0
        osl::FileBase::getSystemPathFromFileURL( aWorkText, aReturn );
364
0
        return aReturn;
365
0
    }
366
367
0
    return aWorkText;
368
0
}
369
370
SvtPathOptions_Impl::SvtPathOptions_Impl()
371
6
{
372
6
    const Reference< XComponentContext >& xContext = comphelper::getProcessComponentContext();
373
374
    // Create necessary services
375
6
    Reference< XPathSettings > xPathSettings = thePathSettings::get(xContext);
376
6
    m_xPathSettings.set( xPathSettings, UNO_QUERY_THROW );
377
6
    m_xSubstVariables.set( PathSubstitution::create(xContext) );
378
6
    m_xMacroExpander = theMacroExpander::get(xContext);
379
380
    // Create temporary hash map to have a mapping between property names and property handles
381
6
    Reference< XPropertySetInfo > xPropSetInfo = xPathSettings->getPropertySetInfo();
382
6
    const Sequence< Property > aPathPropSeq = xPropSetInfo->getProperties();
383
384
6
    NameToHandleMap aTempHashMap;
385
6
    for ( const css::beans::Property& aProperty : aPathPropSeq )
386
0
    {
387
0
        aTempHashMap.emplace(aProperty.Name, aProperty.Handle);
388
0
    }
389
390
    // Create mapping between internal enum (SvtPathOptions::Paths) and property handle
391
6
    for ( auto const & p : aPropNames )
392
0
    {
393
0
        NameToHandleMap::const_iterator pIter = aTempHashMap.find( p.aPropName );
394
395
0
        if ( pIter != aTempHashMap.end() )
396
0
        {
397
0
            sal_Int32 nHandle   = pIter->second;
398
0
            SvtPathOptions::Paths nEnum       = p.ePath;
399
0
            m_aMapEnumToPropHandle.emplace( nEnum, nHandle );
400
0
        }
401
0
    }
402
403
    // Create hash map for path variables that need a system path as a return value!
404
6
    for ( auto const & i : aVarNameAttribute )
405
0
    {
406
0
        m_aSystemPathVarNames.insert( i.aVarName );
407
0
    }
408
6
}
409
410
// class SvtPathOptions --------------------------------------------------
411
412
namespace
413
{
414
    std::mutex& lclMutex()
415
6
    {
416
6
        static std::mutex SINGLETON;
417
6
        return SINGLETON;
418
6
    }
419
}
420
421
SvtPathOptions::SvtPathOptions()
422
6
{
423
    // Global access, must be guarded (multithreading)
424
6
    std::unique_lock aGuard( lclMutex() );
425
6
    pImpl = g_pOptions.lock();
426
6
    if ( !pImpl )
427
6
    {
428
6
        pImpl = std::make_shared<SvtPathOptions_Impl>();
429
6
        g_pOptions = pImpl;
430
6
        aGuard.unlock(); // because holdConfigItem will call this constructor
431
6
        ItemHolder1::holdConfigItem(EItem::PathOptions);
432
6
    }
433
6
}
434
435
SvtPathOptions::~SvtPathOptions()
436
0
{
437
    // Global access, must be guarded (multithreading)
438
0
    std::unique_lock aGuard( lclMutex() );
439
440
0
    pImpl.reset();
441
0
}
442
443
const OUString& SvtPathOptions::GetAddinPath() const
444
0
{
445
0
    return pImpl->GetAddinPath();
446
0
}
447
448
const OUString& SvtPathOptions::GetAutoCorrectPath() const
449
0
{
450
0
    return pImpl->GetAutoCorrectPath();
451
0
}
452
453
const OUString& SvtPathOptions::GetAutoTextPath() const
454
0
{
455
0
    return pImpl->GetAutoTextPath();
456
0
}
457
458
const OUString& SvtPathOptions::GetBackupPath() const
459
0
{
460
0
    return pImpl->GetBackupPath();
461
0
}
462
463
const OUString& SvtPathOptions::GetBasicPath() const
464
0
{
465
0
    return pImpl->GetBasicPath();
466
0
}
467
468
const OUString& SvtPathOptions::GetBitmapPath() const
469
0
{
470
0
    return pImpl->GetBitmapPath();
471
0
}
472
473
const OUString& SvtPathOptions::GetConfigPath() const
474
0
{
475
0
    return pImpl->GetConfigPath();
476
0
}
477
478
const OUString& SvtPathOptions::GetDictionaryPath() const
479
0
{
480
0
    return pImpl->GetDictionaryPath();
481
0
}
482
483
const OUString& SvtPathOptions::GetFavoritesPath() const
484
0
{
485
0
    return pImpl->GetFavoritesPath();
486
0
}
487
488
const OUString& SvtPathOptions::GetFilterPath() const
489
0
{
490
0
    return pImpl->GetFilterPath();
491
0
}
492
493
const OUString& SvtPathOptions::GetGalleryPath() const
494
0
{
495
0
    return pImpl->GetGalleryPath();
496
0
}
497
498
const OUString& SvtPathOptions::GetGraphicPath() const
499
0
{
500
0
    return pImpl->GetGraphicPath();
501
0
}
502
503
const OUString& SvtPathOptions::GetHelpPath() const
504
0
{
505
0
    return pImpl->GetHelpPath();
506
0
}
507
508
const OUString& SvtPathOptions::GetLinguisticPath() const
509
0
{
510
0
    return pImpl->GetLinguisticPath();
511
0
}
512
513
const OUString& SvtPathOptions::GetFingerprintPath() const
514
0
{
515
0
    return pImpl->GetFingerprintPath();
516
0
}
517
518
const OUString& SvtPathOptions::GetNumbertextPath() const
519
0
{
520
0
    return pImpl->GetNumbertextPath();
521
0
}
522
523
const OUString& SvtPathOptions::GetModulePath() const
524
0
{
525
0
    return pImpl->GetModulePath();
526
0
}
527
528
const OUString& SvtPathOptions::GetPalettePath() const
529
0
{
530
0
    return pImpl->GetPalettePath();
531
0
}
532
533
const OUString& SvtPathOptions::GetIconsetPath() const
534
0
{
535
0
    return pImpl->GetIconsetPath();
536
0
}
537
538
const OUString& SvtPathOptions::GetPluginPath() const
539
0
{
540
0
    return pImpl->GetPluginPath();
541
0
}
542
543
const OUString& SvtPathOptions::GetStoragePath() const
544
0
{
545
0
    return pImpl->GetStoragePath();
546
0
}
547
548
const OUString& SvtPathOptions::GetTempPath() const
549
0
{
550
0
    return pImpl->GetTempPath();
551
0
}
552
553
const OUString& SvtPathOptions::GetTemplatePath() const
554
0
{
555
0
    return pImpl->GetTemplatePath();
556
0
}
557
558
const OUString& SvtPathOptions::GetUserConfigPath() const
559
0
{
560
0
    return pImpl->GetUserConfigPath();
561
0
}
562
563
const OUString& SvtPathOptions::GetWorkPath() const
564
0
{
565
0
    return pImpl->GetWorkPath();
566
0
}
567
568
const OUString& SvtPathOptions::GetClassificationPath() const
569
0
{
570
0
    return pImpl->GetClassificationPath();
571
0
}
572
573
const OUString& SvtPathOptions::GetDocumentThemePath() const
574
0
{
575
0
    return pImpl->GetDocumentThemePath();
576
0
}
577
578
void SvtPathOptions::SetAutoTextPath( const OUString& rPath )
579
0
{
580
0
    pImpl->SetAutoTextPath( rPath );
581
0
}
582
583
void SvtPathOptions::SetBasicPath( const OUString& rPath )
584
0
{
585
0
    pImpl->SetBasicPath( rPath );
586
0
}
587
588
void SvtPathOptions::SetTempPath( const OUString& rPath )
589
0
{
590
0
    pImpl->SetTempPath( rPath );
591
0
}
592
593
void SvtPathOptions::SetWorkPath( const OUString& rPath )
594
0
{
595
0
    pImpl->SetWorkPath( rPath );
596
0
}
597
598
OUString SvtPathOptions::SubstituteVariable( const OUString& rVar ) const
599
0
{
600
0
    return pImpl->SubstVar( rVar );
601
0
}
602
603
OUString SvtPathOptions::ExpandMacros( const OUString& rPath ) const
604
0
{
605
0
    return pImpl->ExpandMacros( rPath );
606
0
}
607
608
OUString SvtPathOptions::UseVariable( const OUString& rPath ) const
609
0
{
610
0
    return pImpl->UsePathVariables( rPath );
611
0
}
612
613
bool SvtPathOptions::SearchFile( OUString& rIniFile, SvtPathOptions::Paths ePath )
614
0
{
615
    // check parameter: empty inifile name?
616
0
    if ( rIniFile.isEmpty() )
617
0
    {
618
0
        SAL_WARN( "unotools.config", "SvtPathOptions::SearchFile(): invalid parameter" );
619
0
        return false;
620
0
    }
621
622
0
    OUString aIniFile = pImpl->SubstVar( rIniFile );
623
0
    bool bRet = false;
624
625
0
    switch ( ePath )
626
0
    {
627
0
        case SvtPathOptions::Paths::UserConfig:
628
0
        {
629
            // path is a URL
630
0
            bRet = true;
631
0
            INetURLObject aObj( GetUserConfigPath() );
632
633
0
            sal_Int32 nIniIndex = 0;
634
0
            do
635
0
            {
636
0
                std::u16string_view aToken = o3tl::getToken(aIniFile, 0, '/', nIniIndex );
637
0
                aObj.insertName(aToken);
638
0
            }
639
0
            while ( nIniIndex >= 0 );
640
641
0
            if ( !::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ) ) )
642
0
            {
643
0
                aObj.SetSmartURL( GetConfigPath() );
644
0
                aObj.insertName( aIniFile );
645
0
                bRet = ::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
646
0
            }
647
648
0
            if ( bRet )
649
0
                rIniFile = aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
650
651
0
            break;
652
0
        }
653
654
0
        default:
655
0
        {
656
0
            OUString aPath;
657
0
            switch ( ePath )
658
0
            {
659
0
                case SvtPathOptions::Paths::AddIn:        aPath = GetAddinPath();         break;
660
0
                case SvtPathOptions::Paths::AutoCorrect:  aPath = GetAutoCorrectPath();   break;
661
0
                case SvtPathOptions::Paths::AutoText:     aPath = GetAutoTextPath();      break;
662
0
                case SvtPathOptions::Paths::Backup:       aPath = GetBackupPath();        break;
663
0
                case SvtPathOptions::Paths::Basic:        aPath = GetBasicPath();         break;
664
0
                case SvtPathOptions::Paths::Bitmap:       aPath = GetBitmapPath();        break;
665
0
                case SvtPathOptions::Paths::Config:       aPath = GetConfigPath();        break;
666
0
                case SvtPathOptions::Paths::Dictionary:   aPath = GetDictionaryPath();    break;
667
0
                case SvtPathOptions::Paths::Favorites:    aPath = GetFavoritesPath();     break;
668
0
                case SvtPathOptions::Paths::Filter:       aPath = GetFilterPath();        break;
669
0
                case SvtPathOptions::Paths::Gallery:      aPath = GetGalleryPath();       break;
670
0
                case SvtPathOptions::Paths::Graphic:      aPath = GetGraphicPath();       break;
671
0
                case SvtPathOptions::Paths::Help:         aPath = GetHelpPath();          break;
672
0
                case SvtPathOptions::Paths::Linguistic:   aPath = GetLinguisticPath();    break;
673
0
                case SvtPathOptions::Paths::Module:       aPath = GetModulePath();        break;
674
0
                case SvtPathOptions::Paths::Palette:      aPath = GetPalettePath();       break;
675
0
                case SvtPathOptions::Paths::IconSet:      aPath = GetIconsetPath();       break;
676
0
                case SvtPathOptions::Paths::Plugin:       aPath = GetPluginPath();        break;
677
0
                case SvtPathOptions::Paths::Storage:      aPath = GetStoragePath();       break;
678
0
                case SvtPathOptions::Paths::Temp:         aPath = GetTempPath();          break;
679
0
                case SvtPathOptions::Paths::Template:     aPath = GetTemplatePath();      break;
680
0
                case SvtPathOptions::Paths::Work:         aPath = GetWorkPath();          break;
681
0
                case SvtPathOptions::Paths::UIConfig:     aPath = pImpl->GetUIConfigPath(); break;
682
0
                case SvtPathOptions::Paths::Fingerprint:  aPath = GetFingerprintPath();   break;
683
0
                case SvtPathOptions::Paths::NumberText:   aPath = GetNumbertextPath();    break;
684
0
                case SvtPathOptions::Paths::Classification: aPath = GetClassificationPath(); break;
685
0
                case SvtPathOptions::Paths::DocumentTheme: aPath = GetDocumentThemePath(); break;
686
                // coverity[dead_error_begin] - following conditions exist to avoid compiler warning
687
0
                case SvtPathOptions::Paths::UserConfig:
688
0
                case SvtPathOptions::Paths::LAST:
689
0
                    break;
690
0
            }
691
692
0
            sal_Int32 nPathIndex = 0;
693
0
            do
694
0
            {
695
0
                bool bIsURL = true;
696
0
                OUString aPathToken( aPath.getToken( 0, SEARCHPATH_DELIMITER, nPathIndex ) );
697
0
                INetURLObject aObj( aPathToken );
698
0
                if ( aObj.HasError() )
699
0
                {
700
0
                    bIsURL = false;
701
0
                    OUString aURL;
702
0
                    if ( osl::FileBase::getFileURLFromSystemPath( aPathToken, aURL )
703
0
                         == osl::FileBase::E_None )
704
0
                        aObj.SetURL( aURL );
705
0
                }
706
0
                if ( aObj.GetProtocol() == INetProtocol::VndSunStarExpand )
707
0
                {
708
0
                    Reference< XMacroExpander > xMacroExpander = theMacroExpander::get( ::comphelper::getProcessComponentContext() );
709
0
                    const OUString sExpandedPath = xMacroExpander->expandMacros( aObj.GetURLPath( INetURLObject::DecodeMechanism::WithCharset ) );
710
0
                    aObj.SetURL( sExpandedPath );
711
0
                }
712
713
0
                sal_Int32 nIniIndex = 0;
714
0
                do
715
0
                {
716
0
                    std::u16string_view aToken = o3tl::getToken(aIniFile, 0, '/', nIniIndex );
717
0
                    aObj.insertName(aToken);
718
0
                }
719
0
                while ( nIniIndex >= 0 );
720
721
0
                bRet = ::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
722
723
0
                if ( bRet )
724
0
                {
725
0
                    if ( !bIsURL )
726
0
                    {
727
0
                        OUString sTmp;
728
0
                        osl::FileBase::getSystemPathFromFileURL(
729
0
                                            aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ), sTmp );
730
0
                        rIniFile = sTmp;
731
0
                    }
732
0
                    else
733
0
                        rIniFile = aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
734
0
                    break;
735
0
                }
736
0
            }
737
0
            while ( nPathIndex >= 0 );
738
0
        }
739
0
    }
740
741
0
    return bRet;
742
0
}
743
744
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */