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 <sal/config.h>
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>
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>
43 #include "itemholder1.hxx"
46 #include <unordered_map>
50 using namespace com::sun::star::uno
;
51 using namespace com::sun::star::beans
;
52 using namespace com::sun::star::util
;
53 using namespace com::sun::star::lang
;
55 #define SEARCHPATH_DELIMITER ';'
56 #define SIGN_STARTVARIABLE "$("
57 #define SIGN_ENDVARIABLE ")"
59 // Supported variables by the old SvtPathOptions implementation
60 #define SUBSTITUTE_INSTPATH "$(instpath)"
61 #define SUBSTITUTE_PROGPATH "$(progpath)"
62 #define SUBSTITUTE_USERPATH "$(userpath)"
63 #define SUBSTITUTE_PATH "$(path)"
65 #define STRPOS_NOTFOUND -1
67 typedef std::unordered_map
<OUString
, sal_Int32
> NameToHandleMap
;
69 typedef std::set
<OUString
> VarNameSet
;
71 // class SvtPathOptions_Impl ---------------------------------------------
72 class SvtPathOptions_Impl
75 // Local variables to return const references
76 o3tl::enumarray
< SvtPathOptions::Paths
, OUString
> m_aPathArray
;
77 Reference
< XFastPropertySet
> m_xPathSettings
;
78 Reference
< XStringSubstitution
> m_xSubstVariables
;
79 Reference
< XMacroExpander
> m_xMacroExpander
;
80 mutable std::unordered_map
<SvtPathOptions::Paths
, sal_Int32
>
81 m_aMapEnumToPropHandle
;
82 VarNameSet m_aSystemPathVarNames
;
84 OUString m_aEmptyString
;
85 mutable std::mutex m_aMutex
;
88 SvtPathOptions_Impl();
90 // get the paths, not const because of using a mutex
91 const OUString
& GetPath( SvtPathOptions::Paths
);
92 const OUString
& GetAddinPath() { return GetPath( SvtPathOptions::Paths::AddIn
); }
93 const OUString
& GetAutoCorrectPath() { return GetPath( SvtPathOptions::Paths::AutoCorrect
); }
94 const OUString
& GetAutoTextPath() { return GetPath( SvtPathOptions::Paths::AutoText
); }
95 const OUString
& GetBackupPath() { return GetPath( SvtPathOptions::Paths::Backup
); }
96 const OUString
& GetBasicPath() { return GetPath( SvtPathOptions::Paths::Basic
); }
97 const OUString
& GetBitmapPath() { return GetPath( SvtPathOptions::Paths::Bitmap
); }
98 const OUString
& GetConfigPath() { return GetPath( SvtPathOptions::Paths::Config
); }
99 const OUString
& GetDictionaryPath() { return GetPath( SvtPathOptions::Paths::Dictionary
); }
100 const OUString
& GetFavoritesPath() { return GetPath( SvtPathOptions::Paths::Favorites
); }
101 const OUString
& GetFilterPath() { return GetPath( SvtPathOptions::Paths::Filter
); }
102 const OUString
& GetGalleryPath() { return GetPath( SvtPathOptions::Paths::Gallery
); }
103 const OUString
& GetGraphicPath() { return GetPath( SvtPathOptions::Paths::Graphic
); }
104 const OUString
& GetHelpPath() { return GetPath( SvtPathOptions::Paths::Help
); }
105 const OUString
& GetLinguisticPath() { return GetPath( SvtPathOptions::Paths::Linguistic
); }
106 const OUString
& GetModulePath() { return GetPath( SvtPathOptions::Paths::Module
); }
107 const OUString
& GetPalettePath() { return GetPath( SvtPathOptions::Paths::Palette
); }
108 const OUString
& GetIconsetPath() { return GetPath( SvtPathOptions::Paths::IconSet
); }
109 const OUString
& GetPluginPath() { return GetPath( SvtPathOptions::Paths::Plugin
); }
110 const OUString
& GetStoragePath() { return GetPath( SvtPathOptions::Paths::Storage
); }
111 const OUString
& GetTempPath() { return GetPath( SvtPathOptions::Paths::Temp
); }
112 const OUString
& GetTemplatePath() { return GetPath( SvtPathOptions::Paths::Template
); }
113 const OUString
& GetUserConfigPath() { return GetPath( SvtPathOptions::Paths::UserConfig
); }
114 const OUString
& GetWorkPath() { return GetPath( SvtPathOptions::Paths::Work
); }
115 const OUString
& GetUIConfigPath() { return GetPath( SvtPathOptions::Paths::UIConfig
); }
116 const OUString
& GetFingerprintPath() { return GetPath( SvtPathOptions::Paths::Fingerprint
); }
117 const OUString
& GetNumbertextPath() { return GetPath( SvtPathOptions::Paths::NumberText
); }
118 const OUString
& GetClassificationPath() { return GetPath( SvtPathOptions::Paths::Classification
); }
121 void SetPath( SvtPathOptions::Paths
, const OUString
& rNewPath
);
122 void SetAddinPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::AddIn
, rPath
); }
123 void SetAutoCorrectPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::AutoCorrect
, rPath
); }
124 void SetAutoTextPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::AutoText
, rPath
); }
125 void SetBackupPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Backup
, rPath
); }
126 void SetBasicPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Basic
, rPath
); }
127 void SetBitmapPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Bitmap
, rPath
); }
128 void SetConfigPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Config
, rPath
); }
129 void SetDictionaryPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Dictionary
, rPath
); }
130 void SetFavoritesPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Favorites
, rPath
); }
131 void SetFilterPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Filter
, rPath
); }
132 void SetGalleryPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Gallery
, rPath
); }
133 void SetGraphicPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Graphic
, rPath
); }
134 void SetHelpPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Help
, rPath
); }
135 void SetLinguisticPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Linguistic
, rPath
); }
136 void SetModulePath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Module
, rPath
); }
137 void SetPalettePath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Palette
, rPath
); }
138 void SetPluginPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Plugin
, rPath
); }
139 void SetStoragePath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Storage
, rPath
); }
140 void SetTempPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Temp
, rPath
); }
141 void SetTemplatePath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Template
, rPath
); }
142 void SetUserConfigPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::UserConfig
, rPath
); }
143 void SetWorkPath( const OUString
& rPath
) { SetPath( SvtPathOptions::Paths::Work
, rPath
); }
145 OUString
SubstVar( const OUString
& rVar
) const;
146 OUString
ExpandMacros( const OUString
& rPath
) const;
147 OUString
UsePathVariables( const OUString
& rPath
) const;
150 // global ----------------------------------------------------------------
152 static std::weak_ptr
<SvtPathOptions_Impl
> g_pOptions
;
156 // functions -------------------------------------------------------------
157 struct PropertyStruct
159 const char* pPropName
; // The ascii name of the Office path
160 SvtPathOptions::Paths ePath
; // The enum value used by SvtPathOptions
163 struct VarNameAttribute
165 const char* pVarName
; // The name of the path variable
170 const PropertyStruct aPropNames
[] =
172 { "Addin", SvtPathOptions::Paths::AddIn
},
173 { "AutoCorrect", SvtPathOptions::Paths::AutoCorrect
},
174 { "AutoText", SvtPathOptions::Paths::AutoText
},
175 { "Backup", SvtPathOptions::Paths::Backup
},
176 { "Basic", SvtPathOptions::Paths::Basic
},
177 { "Bitmap", SvtPathOptions::Paths::Bitmap
},
178 { "Config", SvtPathOptions::Paths::Config
},
179 { "Dictionary", SvtPathOptions::Paths::Dictionary
},
180 { "Favorite", SvtPathOptions::Paths::Favorites
},
181 { "Filter", SvtPathOptions::Paths::Filter
},
182 { "Gallery", SvtPathOptions::Paths::Gallery
},
183 { "Graphic", SvtPathOptions::Paths::Graphic
},
184 { "Help", SvtPathOptions::Paths::Help
},
185 { "Iconset", SvtPathOptions::Paths::IconSet
},
186 { "Linguistic", SvtPathOptions::Paths::Linguistic
},
187 { "Module", SvtPathOptions::Paths::Module
},
188 { "Palette", SvtPathOptions::Paths::Palette
},
189 { "Plugin", SvtPathOptions::Paths::Plugin
},
190 { "Storage", SvtPathOptions::Paths::Storage
},
191 { "Temp", SvtPathOptions::Paths::Temp
},
192 { "Template", SvtPathOptions::Paths::Template
},
193 { "UserConfig", SvtPathOptions::Paths::UserConfig
},
194 { "Work", SvtPathOptions::Paths::Work
},
195 { "UIConfig", SvtPathOptions::Paths::UIConfig
},
196 { "Fingerprint", SvtPathOptions::Paths::Fingerprint
},
197 { "Numbertext", SvtPathOptions::Paths::NumberText
},
198 { "Classification", SvtPathOptions::Paths::Classification
}
201 const VarNameAttribute aVarNameAttribute
[] =
203 { SUBSTITUTE_INSTPATH
}, // $(instpath)
204 { SUBSTITUTE_PROGPATH
}, // $(progpath)
205 { SUBSTITUTE_USERPATH
}, // $(userpath)
206 { SUBSTITUTE_PATH
}, // $(path)
209 // class SvtPathOptions_Impl ---------------------------------------------
211 const OUString
& SvtPathOptions_Impl::GetPath( SvtPathOptions::Paths ePath
)
213 std::unique_lock
aGuard( m_aMutex
);
218 sal_Int32 nHandle
= m_aMapEnumToPropHandle
[ePath
];
220 // Substitution is done by the service itself using the substitution service
221 Any a
= m_xPathSettings
->getFastPropertyValue( nHandle
);
223 if( ePath
== SvtPathOptions::Paths::AddIn
||
224 ePath
== SvtPathOptions::Paths::Filter
||
225 ePath
== SvtPathOptions::Paths::Help
||
226 ePath
== SvtPathOptions::Paths::Module
||
227 ePath
== SvtPathOptions::Paths::Plugin
||
228 ePath
== SvtPathOptions::Paths::Storage
231 // These office paths have to be converted to system pates
233 osl::FileBase::getSystemPathFromFileURL( aPathValue
, aResult
);
234 aPathValue
= aResult
;
236 else if (ePath
== SvtPathOptions::Paths::Palette
||
237 ePath
== SvtPathOptions::Paths::IconSet
)
239 auto ctx
= comphelper::getProcessComponentContext();
240 OUStringBuffer
buf(aPathValue
.getLength()*2);
241 for (sal_Int32 i
= 0;;)
244 comphelper::getExpandedUri(
245 ctx
, aPathValue
.getToken(0, ';', i
)));
251 aPathValue
= buf
.makeStringAndClear();
254 m_aPathArray
[ ePath
] = aPathValue
;
255 return m_aPathArray
[ ePath
];
257 catch (UnknownPropertyException
&)
261 return m_aEmptyString
;
264 void SvtPathOptions_Impl::SetPath( SvtPathOptions::Paths ePath
, const OUString
& rNewPath
)
266 std::unique_lock
aGuard( m_aMutex
);
274 case SvtPathOptions::Paths::AddIn
:
275 case SvtPathOptions::Paths::Filter
:
276 case SvtPathOptions::Paths::Help
:
277 case SvtPathOptions::Paths::Module
:
278 case SvtPathOptions::Paths::Plugin
:
279 case SvtPathOptions::Paths::Storage
:
281 // These office paths have to be convert back to UCB-URL's
282 osl::FileBase::getFileURLFromSystemPath( rNewPath
, aResult
);
288 aNewValue
= rNewPath
;
291 // Resubstitution is done by the service itself using the substitution service
295 m_xPathSettings
->setFastPropertyValue( m_aMapEnumToPropHandle
[ePath
], a
);
297 catch (const Exception
&)
299 TOOLS_WARN_EXCEPTION("unotools.config", "SetPath");
303 OUString
SvtPathOptions_Impl::ExpandMacros( const OUString
& rPath
) const
305 OUString
sExpanded( rPath
);
307 const INetURLObject
aParser( rPath
);
308 if ( aParser
.GetProtocol() == INetProtocol::VndSunStarExpand
)
309 sExpanded
= m_xMacroExpander
->expandMacros( aParser
.GetURLPath( INetURLObject::DecodeMechanism::WithCharset
) );
314 OUString
SvtPathOptions_Impl::UsePathVariables( const OUString
& rPath
) const
316 return m_xSubstVariables
->reSubstituteVariables( rPath
);
319 OUString
SvtPathOptions_Impl::SubstVar( const OUString
& rVar
) const
321 // Don't work at parameter-string directly. Copy it.
322 OUString aWorkText
= rVar
;
324 // Convert the returned path to system path!
325 bool bConvertLocal
= false;
327 // Search for first occurrence of "$(...".
328 sal_Int32 nPosition
= aWorkText
.indexOf( SIGN_STARTVARIABLE
); // = first position of "$(" in string
329 sal_Int32 nLength
= 0; // = count of letters from "$(" to ")" in string
331 // Have we found any variable like "$(...)"?
332 if ( nPosition
!= STRPOS_NOTFOUND
)
334 // Yes; Get length of found variable.
335 // If no ")" was found - nLength is set to 0 by default! see before.
336 sal_Int32 nEndPosition
= aWorkText
.indexOf( SIGN_ENDVARIABLE
, nPosition
);
337 if ( nEndPosition
!= STRPOS_NOTFOUND
)
338 nLength
= nEndPosition
- nPosition
+ 1;
341 // Is there another path variable?
342 while ( ( nPosition
!= STRPOS_NOTFOUND
) && ( nLength
> 0 ) )
344 // YES; Get the next variable for replace.
345 OUString aSubString
= aWorkText
.copy( nPosition
, nLength
);
346 aSubString
= aSubString
.toAsciiLowerCase();
348 // Look for special variable that needs a system path.
349 VarNameSet::const_iterator pIter
= m_aSystemPathVarNames
.find( aSubString
);
350 if ( pIter
!= m_aSystemPathVarNames
.end() )
351 bConvertLocal
= true;
353 nPosition
+= nLength
;
355 // We must control index in string before call something at OUString!
356 // The OUString-implementation don't do it for us :-( but the result is not defined otherwise.
357 if ( nPosition
+ 1 > aWorkText
.getLength() )
359 // Position is out of range. Break loop!
360 nPosition
= STRPOS_NOTFOUND
;
365 // Else; Position is valid. Search for next variable.
366 nPosition
= aWorkText
.indexOf( SIGN_STARTVARIABLE
, nPosition
);
367 // Have we found any variable like "$(...)"?
368 if ( nPosition
!= STRPOS_NOTFOUND
)
370 // Yes; Get length of found variable. If no ")" was found - nLength must set to 0!
372 sal_Int32 nEndPosition
= aWorkText
.indexOf( SIGN_ENDVARIABLE
, nPosition
);
373 if ( nEndPosition
!= STRPOS_NOTFOUND
)
374 nLength
= nEndPosition
- nPosition
+ 1;
379 aWorkText
= m_xSubstVariables
->substituteVariables( rVar
, false );
383 // Convert the URL to a system path for special path variables
385 osl::FileBase::getSystemPathFromFileURL( aWorkText
, aReturn
);
392 SvtPathOptions_Impl::SvtPathOptions_Impl()
394 Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
396 // Create necessary services
397 Reference
< XPathSettings
> xPathSettings
= thePathSettings::get(xContext
);
398 m_xPathSettings
.set( xPathSettings
, UNO_QUERY_THROW
);
399 m_xSubstVariables
.set( PathSubstitution::create(xContext
) );
400 m_xMacroExpander
= theMacroExpander::get(xContext
);
402 // Create temporary hash map to have a mapping between property names and property handles
403 Reference
< XPropertySetInfo
> xPropSetInfo
= xPathSettings
->getPropertySetInfo();
404 const Sequence
< Property
> aPathPropSeq
= xPropSetInfo
->getProperties();
406 NameToHandleMap aTempHashMap
;
407 for ( const css::beans::Property
& aProperty
: aPathPropSeq
)
409 aTempHashMap
.emplace(aProperty
.Name
, aProperty
.Handle
);
412 // Create mapping between internal enum (SvtPathOptions::Paths) and property handle
413 for ( auto const & p
: aPropNames
)
415 NameToHandleMap::const_iterator pIter
=
416 aTempHashMap
.find( OUString::createFromAscii( p
.pPropName
));
418 if ( pIter
!= aTempHashMap
.end() )
420 sal_Int32 nHandle
= pIter
->second
;
421 SvtPathOptions::Paths nEnum
= p
.ePath
;
422 m_aMapEnumToPropHandle
.emplace( nEnum
, nHandle
);
426 // Create hash map for path variables that need a system path as a return value!
427 for ( auto const & i
: aVarNameAttribute
)
429 m_aSystemPathVarNames
.insert( OUString::createFromAscii( i
.pVarName
) );
433 // class SvtPathOptions --------------------------------------------------
437 std::mutex
& lclMutex()
439 static std::mutex SINGLETON
;
444 SvtPathOptions::SvtPathOptions()
446 // Global access, must be guarded (multithreading)
447 std::unique_lock
aGuard( lclMutex() );
448 pImpl
= g_pOptions
.lock();
451 pImpl
= std::make_shared
<SvtPathOptions_Impl
>();
453 aGuard
.unlock(); // because holdConfigItem will call this constructor
454 ItemHolder1::holdConfigItem(EItem::PathOptions
);
458 SvtPathOptions::~SvtPathOptions()
460 // Global access, must be guarded (multithreading)
461 std::unique_lock
aGuard( lclMutex() );
466 const OUString
& SvtPathOptions::GetAddinPath() const
468 return pImpl
->GetAddinPath();
471 const OUString
& SvtPathOptions::GetAutoCorrectPath() const
473 return pImpl
->GetAutoCorrectPath();
476 const OUString
& SvtPathOptions::GetAutoTextPath() const
478 return pImpl
->GetAutoTextPath();
481 const OUString
& SvtPathOptions::GetBackupPath() const
483 return pImpl
->GetBackupPath();
486 const OUString
& SvtPathOptions::GetBasicPath() const
488 return pImpl
->GetBasicPath();
491 const OUString
& SvtPathOptions::GetBitmapPath() const
493 return pImpl
->GetBitmapPath();
496 const OUString
& SvtPathOptions::GetConfigPath() const
498 return pImpl
->GetConfigPath();
501 const OUString
& SvtPathOptions::GetDictionaryPath() const
503 return pImpl
->GetDictionaryPath();
506 const OUString
& SvtPathOptions::GetFavoritesPath() const
508 return pImpl
->GetFavoritesPath();
511 const OUString
& SvtPathOptions::GetFilterPath() const
513 return pImpl
->GetFilterPath();
516 const OUString
& SvtPathOptions::GetGalleryPath() const
518 return pImpl
->GetGalleryPath();
521 const OUString
& SvtPathOptions::GetGraphicPath() const
523 return pImpl
->GetGraphicPath();
526 const OUString
& SvtPathOptions::GetHelpPath() const
528 return pImpl
->GetHelpPath();
531 const OUString
& SvtPathOptions::GetLinguisticPath() const
533 return pImpl
->GetLinguisticPath();
536 const OUString
& SvtPathOptions::GetFingerprintPath() const
538 return pImpl
->GetFingerprintPath();
541 const OUString
& SvtPathOptions::GetNumbertextPath() const
543 return pImpl
->GetNumbertextPath();
546 const OUString
& SvtPathOptions::GetModulePath() const
548 return pImpl
->GetModulePath();
551 const OUString
& SvtPathOptions::GetPalettePath() const
553 return pImpl
->GetPalettePath();
556 const OUString
& SvtPathOptions::GetIconsetPath() const
558 return pImpl
->GetIconsetPath();
561 const OUString
& SvtPathOptions::GetPluginPath() const
563 return pImpl
->GetPluginPath();
566 const OUString
& SvtPathOptions::GetStoragePath() const
568 return pImpl
->GetStoragePath();
571 const OUString
& SvtPathOptions::GetTempPath() const
573 return pImpl
->GetTempPath();
576 const OUString
& SvtPathOptions::GetTemplatePath() const
578 return pImpl
->GetTemplatePath();
581 const OUString
& SvtPathOptions::GetUserConfigPath() const
583 return pImpl
->GetUserConfigPath();
586 const OUString
& SvtPathOptions::GetWorkPath() const
588 return pImpl
->GetWorkPath();
591 const OUString
& SvtPathOptions::GetClassificationPath() const
593 return pImpl
->GetClassificationPath();
596 void SvtPathOptions::SetAddinPath( const OUString
& rPath
)
598 pImpl
->SetAddinPath( rPath
);
601 void SvtPathOptions::SetAutoCorrectPath( const OUString
& rPath
)
603 pImpl
->SetAutoCorrectPath( rPath
);
606 void SvtPathOptions::SetAutoTextPath( const OUString
& rPath
)
608 pImpl
->SetAutoTextPath( rPath
);
611 void SvtPathOptions::SetBackupPath( const OUString
& rPath
)
613 pImpl
->SetBackupPath( rPath
);
616 void SvtPathOptions::SetBasicPath( const OUString
& rPath
)
618 pImpl
->SetBasicPath( rPath
);
621 void SvtPathOptions::SetBitmapPath( const OUString
& rPath
)
623 pImpl
->SetBitmapPath( rPath
);
626 void SvtPathOptions::SetConfigPath( const OUString
& rPath
)
628 pImpl
->SetConfigPath( rPath
);
631 void SvtPathOptions::SetDictionaryPath( const OUString
& rPath
)
633 pImpl
->SetDictionaryPath( rPath
);
636 void SvtPathOptions::SetFavoritesPath( const OUString
& rPath
)
638 pImpl
->SetFavoritesPath( rPath
);
641 void SvtPathOptions::SetFilterPath( const OUString
& rPath
)
643 pImpl
->SetFilterPath( rPath
);
646 void SvtPathOptions::SetGalleryPath( const OUString
& rPath
)
648 pImpl
->SetGalleryPath( rPath
);
651 void SvtPathOptions::SetGraphicPath( const OUString
& rPath
)
653 pImpl
->SetGraphicPath( rPath
);
656 void SvtPathOptions::SetHelpPath( const OUString
& rPath
)
658 pImpl
->SetHelpPath( rPath
);
661 void SvtPathOptions::SetLinguisticPath( const OUString
& rPath
)
663 pImpl
->SetLinguisticPath( rPath
);
666 void SvtPathOptions::SetModulePath( const OUString
& rPath
)
668 pImpl
->SetModulePath( rPath
);
671 void SvtPathOptions::SetPalettePath( const OUString
& rPath
)
673 pImpl
->SetPalettePath( rPath
);
676 void SvtPathOptions::SetPluginPath( const OUString
& rPath
)
678 pImpl
->SetPluginPath( rPath
);
681 void SvtPathOptions::SetStoragePath( const OUString
& rPath
)
683 pImpl
->SetStoragePath( rPath
);
686 void SvtPathOptions::SetTempPath( const OUString
& rPath
)
688 pImpl
->SetTempPath( rPath
);
691 void SvtPathOptions::SetTemplatePath( const OUString
& rPath
)
693 pImpl
->SetTemplatePath( rPath
);
696 void SvtPathOptions::SetUserConfigPath( const OUString
& rPath
)
698 pImpl
->SetUserConfigPath( rPath
);
701 void SvtPathOptions::SetWorkPath( const OUString
& rPath
)
703 pImpl
->SetWorkPath( rPath
);
706 OUString
SvtPathOptions::SubstituteVariable( const OUString
& rVar
) const
708 return pImpl
->SubstVar( rVar
);
711 OUString
SvtPathOptions::ExpandMacros( const OUString
& rPath
) const
713 return pImpl
->ExpandMacros( rPath
);
716 OUString
SvtPathOptions::UseVariable( const OUString
& rPath
) const
718 return pImpl
->UsePathVariables( rPath
);
721 bool SvtPathOptions::SearchFile( OUString
& rIniFile
, SvtPathOptions::Paths ePath
)
723 // check parameter: empty inifile name?
724 if ( rIniFile
.isEmpty() )
726 SAL_WARN( "unotools.config", "SvtPathOptions::SearchFile(): invalid parameter" );
730 OUString aIniFile
= pImpl
->SubstVar( rIniFile
);
735 case SvtPathOptions::Paths::UserConfig
:
739 INetURLObject
aObj( GetUserConfigPath() );
741 sal_Int32 nIniIndex
= 0;
744 std::u16string_view aToken
= o3tl::getToken(aIniFile
, 0, '/', nIniIndex
);
745 aObj
.insertName(aToken
);
747 while ( nIniIndex
>= 0 );
749 if ( !::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) ) )
751 aObj
.SetSmartURL( GetConfigPath() );
752 aObj
.insertName( aIniFile
);
753 bRet
= ::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
757 rIniFile
= aObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
);
767 case SvtPathOptions::Paths::AddIn
: aPath
= GetAddinPath(); break;
768 case SvtPathOptions::Paths::AutoCorrect
: aPath
= GetAutoCorrectPath(); break;
769 case SvtPathOptions::Paths::AutoText
: aPath
= GetAutoTextPath(); break;
770 case SvtPathOptions::Paths::Backup
: aPath
= GetBackupPath(); break;
771 case SvtPathOptions::Paths::Basic
: aPath
= GetBasicPath(); break;
772 case SvtPathOptions::Paths::Bitmap
: aPath
= GetBitmapPath(); break;
773 case SvtPathOptions::Paths::Config
: aPath
= GetConfigPath(); break;
774 case SvtPathOptions::Paths::Dictionary
: aPath
= GetDictionaryPath(); break;
775 case SvtPathOptions::Paths::Favorites
: aPath
= GetFavoritesPath(); break;
776 case SvtPathOptions::Paths::Filter
: aPath
= GetFilterPath(); break;
777 case SvtPathOptions::Paths::Gallery
: aPath
= GetGalleryPath(); break;
778 case SvtPathOptions::Paths::Graphic
: aPath
= GetGraphicPath(); break;
779 case SvtPathOptions::Paths::Help
: aPath
= GetHelpPath(); break;
780 case SvtPathOptions::Paths::Linguistic
: aPath
= GetLinguisticPath(); break;
781 case SvtPathOptions::Paths::Module
: aPath
= GetModulePath(); break;
782 case SvtPathOptions::Paths::Palette
: aPath
= GetPalettePath(); break;
783 case SvtPathOptions::Paths::IconSet
: aPath
= GetIconsetPath(); break;
784 case SvtPathOptions::Paths::Plugin
: aPath
= GetPluginPath(); break;
785 case SvtPathOptions::Paths::Storage
: aPath
= GetStoragePath(); break;
786 case SvtPathOptions::Paths::Temp
: aPath
= GetTempPath(); break;
787 case SvtPathOptions::Paths::Template
: aPath
= GetTemplatePath(); break;
788 case SvtPathOptions::Paths::Work
: aPath
= GetWorkPath(); break;
789 case SvtPathOptions::Paths::UIConfig
: aPath
= pImpl
->GetUIConfigPath(); break;
790 case SvtPathOptions::Paths::Fingerprint
: aPath
= GetFingerprintPath(); break;
791 case SvtPathOptions::Paths::NumberText
: aPath
= GetNumbertextPath(); break;
792 case SvtPathOptions::Paths::Classification
: aPath
= GetClassificationPath(); break;
793 // coverity[dead_error_begin] - following conditions exist to avoid compiler warning
794 case SvtPathOptions::Paths::UserConfig
:
795 case SvtPathOptions::Paths::LAST
:
799 sal_Int32 nPathIndex
= 0;
803 OUString
aPathToken( aPath
.getToken( 0, SEARCHPATH_DELIMITER
, nPathIndex
) );
804 INetURLObject
aObj( aPathToken
);
805 if ( aObj
.HasError() )
809 if ( osl::FileBase::getFileURLFromSystemPath( aPathToken
, aURL
)
810 == osl::FileBase::E_None
)
813 if ( aObj
.GetProtocol() == INetProtocol::VndSunStarExpand
)
815 Reference
< XMacroExpander
> xMacroExpander
= theMacroExpander::get( ::comphelper::getProcessComponentContext() );
816 const OUString sExpandedPath
= xMacroExpander
->expandMacros( aObj
.GetURLPath( INetURLObject::DecodeMechanism::WithCharset
) );
817 aObj
.SetURL( sExpandedPath
);
820 sal_Int32 nIniIndex
= 0;
823 std::u16string_view aToken
= o3tl::getToken(aIniFile
, 0, '/', nIniIndex
);
824 aObj
.insertName(aToken
);
826 while ( nIniIndex
>= 0 );
828 bRet
= ::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
835 osl::FileBase::getSystemPathFromFileURL(
836 aObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
), sTmp
);
840 rIniFile
= aObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
);
844 while ( nPathIndex
>= 0 );
851 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */