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 <tools/diagnose_ex.h>
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 <rtl/instance.hxx>
42 #include "itemholder1.hxx"
45 #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 std::vector
< OUString
> m_aPathArray
;
77 Reference
< XFastPropertySet
> m_xPathSettings
;
78 Reference
< XStringSubstitution
> m_xSubstVariables
;
79 Reference
< XMacroExpander
> m_xMacroExpander
;
80 mutable std::unordered_map
<sal_Int32
, sal_Int32
>
81 m_aMapEnumToPropHandle
;
82 VarNameSet m_aSystemPathVarNames
;
84 OUString m_aEmptyString
;
85 mutable ::osl::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::PATH_ADDIN
); }
93 const OUString
& GetAutoCorrectPath() { return GetPath( SvtPathOptions::PATH_AUTOCORRECT
); }
94 const OUString
& GetAutoTextPath() { return GetPath( SvtPathOptions::PATH_AUTOTEXT
); }
95 const OUString
& GetBackupPath() { return GetPath( SvtPathOptions::PATH_BACKUP
); }
96 const OUString
& GetBasicPath() { return GetPath( SvtPathOptions::PATH_BASIC
); }
97 const OUString
& GetBitmapPath() { return GetPath( SvtPathOptions::PATH_BITMAP
); }
98 const OUString
& GetConfigPath() { return GetPath( SvtPathOptions::PATH_CONFIG
); }
99 const OUString
& GetDictionaryPath() { return GetPath( SvtPathOptions::PATH_DICTIONARY
); }
100 const OUString
& GetFavoritesPath() { return GetPath( SvtPathOptions::PATH_FAVORITES
); }
101 const OUString
& GetFilterPath() { return GetPath( SvtPathOptions::PATH_FILTER
); }
102 const OUString
& GetGalleryPath() { return GetPath( SvtPathOptions::PATH_GALLERY
); }
103 const OUString
& GetGraphicPath() { return GetPath( SvtPathOptions::PATH_GRAPHIC
); }
104 const OUString
& GetHelpPath() { return GetPath( SvtPathOptions::PATH_HELP
); }
105 const OUString
& GetLinguisticPath() { return GetPath( SvtPathOptions::PATH_LINGUISTIC
); }
106 const OUString
& GetModulePath() { return GetPath( SvtPathOptions::PATH_MODULE
); }
107 const OUString
& GetPalettePath() { return GetPath( SvtPathOptions::PATH_PALETTE
); }
108 const OUString
& GetIconsetPath() { return GetPath( SvtPathOptions::PATH_ICONSET
); }
109 const OUString
& GetPluginPath() { return GetPath( SvtPathOptions::PATH_PLUGIN
); }
110 const OUString
& GetStoragePath() { return GetPath( SvtPathOptions::PATH_STORAGE
); }
111 const OUString
& GetTempPath() { return GetPath( SvtPathOptions::PATH_TEMP
); }
112 const OUString
& GetTemplatePath() { return GetPath( SvtPathOptions::PATH_TEMPLATE
); }
113 const OUString
& GetUserConfigPath() { return GetPath( SvtPathOptions::PATH_USERCONFIG
); }
114 const OUString
& GetWorkPath() { return GetPath( SvtPathOptions::PATH_WORK
); }
115 const OUString
& GetUIConfigPath() { return GetPath( SvtPathOptions::PATH_UICONFIG
); }
116 const OUString
& GetFingerprintPath() { return GetPath( SvtPathOptions::PATH_FINGERPRINT
); }
117 const OUString
& GetNumbertextPath() { return GetPath( SvtPathOptions::PATH_NUMBERTEXT
); }
118 const OUString
& GetClassificationPath() { return GetPath( SvtPathOptions::PATH_CLASSIFICATION
); }
121 void SetPath( SvtPathOptions::Paths
, const OUString
& rNewPath
);
122 void SetAddinPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_ADDIN
, rPath
); }
123 void SetAutoCorrectPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_AUTOCORRECT
, rPath
); }
124 void SetAutoTextPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_AUTOTEXT
, rPath
); }
125 void SetBackupPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_BACKUP
, rPath
); }
126 void SetBasicPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_BASIC
, rPath
); }
127 void SetBitmapPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_BITMAP
, rPath
); }
128 void SetConfigPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_CONFIG
, rPath
); }
129 void SetDictionaryPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_DICTIONARY
, rPath
); }
130 void SetFavoritesPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_FAVORITES
, rPath
); }
131 void SetFilterPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_FILTER
, rPath
); }
132 void SetGalleryPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_GALLERY
, rPath
); }
133 void SetGraphicPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_GRAPHIC
, rPath
); }
134 void SetHelpPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_HELP
, rPath
); }
135 void SetLinguisticPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_LINGUISTIC
, rPath
); }
136 void SetModulePath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_MODULE
, rPath
); }
137 void SetPalettePath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_PALETTE
, rPath
); }
138 void SetPluginPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_PLUGIN
, rPath
); }
139 void SetStoragePath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_STORAGE
, rPath
); }
140 void SetTempPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_TEMP
, rPath
); }
141 void SetTemplatePath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_TEMPLATE
, rPath
); }
142 void SetUserConfigPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_USERCONFIG
, rPath
); }
143 void SetWorkPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_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::PATH_ADDIN
},
173 { "AutoCorrect", SvtPathOptions::PATH_AUTOCORRECT
},
174 { "AutoText", SvtPathOptions::PATH_AUTOTEXT
},
175 { "Backup", SvtPathOptions::PATH_BACKUP
},
176 { "Basic", SvtPathOptions::PATH_BASIC
},
177 { "Bitmap", SvtPathOptions::PATH_BITMAP
},
178 { "Config", SvtPathOptions::PATH_CONFIG
},
179 { "Dictionary", SvtPathOptions::PATH_DICTIONARY
},
180 { "Favorite", SvtPathOptions::PATH_FAVORITES
},
181 { "Filter", SvtPathOptions::PATH_FILTER
},
182 { "Gallery", SvtPathOptions::PATH_GALLERY
},
183 { "Graphic", SvtPathOptions::PATH_GRAPHIC
},
184 { "Help", SvtPathOptions::PATH_HELP
},
185 { "Iconset", SvtPathOptions::PATH_ICONSET
},
186 { "Linguistic", SvtPathOptions::PATH_LINGUISTIC
},
187 { "Module", SvtPathOptions::PATH_MODULE
},
188 { "Palette", SvtPathOptions::PATH_PALETTE
},
189 { "Plugin", SvtPathOptions::PATH_PLUGIN
},
190 { "Storage", SvtPathOptions::PATH_STORAGE
},
191 { "Temp", SvtPathOptions::PATH_TEMP
},
192 { "Template", SvtPathOptions::PATH_TEMPLATE
},
193 { "UserConfig", SvtPathOptions::PATH_USERCONFIG
},
194 { "Work", SvtPathOptions::PATH_WORK
},
195 { "UIConfig", SvtPathOptions::PATH_UICONFIG
},
196 { "Fingerprint", SvtPathOptions::PATH_FINGERPRINT
},
197 { "Numbertext", SvtPathOptions::PATH_NUMBERTEXT
},
198 { "Classification", SvtPathOptions::PATH_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 if ( ePath
>= SvtPathOptions::PATH_COUNT
)
214 return m_aEmptyString
;
216 ::osl::MutexGuard
aGuard( m_aMutex
);
221 sal_Int32 nHandle
= m_aMapEnumToPropHandle
[ static_cast<sal_Int32
>(ePath
) ];
223 // Substitution is done by the service itself using the substitution service
224 Any a
= m_xPathSettings
->getFastPropertyValue( nHandle
);
226 if( ePath
== SvtPathOptions::PATH_ADDIN
||
227 ePath
== SvtPathOptions::PATH_FILTER
||
228 ePath
== SvtPathOptions::PATH_HELP
||
229 ePath
== SvtPathOptions::PATH_MODULE
||
230 ePath
== SvtPathOptions::PATH_PLUGIN
||
231 ePath
== SvtPathOptions::PATH_STORAGE
234 // These office paths have to be converted to system pates
236 osl::FileBase::getSystemPathFromFileURL( aPathValue
, aResult
);
237 aPathValue
= aResult
;
239 else if (ePath
== SvtPathOptions::PATH_PALETTE
||
240 ePath
== SvtPathOptions::PATH_ICONSET
)
242 auto ctx
= comphelper::getProcessComponentContext();
243 OUStringBuffer
buf(aPathValue
.getLength()*2);
244 for (sal_Int32 i
= 0;;)
247 comphelper::getExpandedUri(
248 ctx
, aPathValue
.getToken(0, ';', i
)));
254 aPathValue
= buf
.makeStringAndClear();
257 m_aPathArray
[ ePath
] = aPathValue
;
258 return m_aPathArray
[ ePath
];
260 catch (UnknownPropertyException
&)
264 return m_aEmptyString
;
267 void SvtPathOptions_Impl::SetPath( SvtPathOptions::Paths ePath
, const OUString
& rNewPath
)
269 ::osl::MutexGuard
aGuard( m_aMutex
);
271 if ( ePath
>= SvtPathOptions::PATH_COUNT
)
280 case SvtPathOptions::PATH_ADDIN
:
281 case SvtPathOptions::PATH_FILTER
:
282 case SvtPathOptions::PATH_HELP
:
283 case SvtPathOptions::PATH_MODULE
:
284 case SvtPathOptions::PATH_PLUGIN
:
285 case SvtPathOptions::PATH_STORAGE
:
287 // These office paths have to be convert back to UCB-URL's
288 osl::FileBase::getFileURLFromSystemPath( rNewPath
, aResult
);
294 aNewValue
= rNewPath
;
297 // Resubstitution is done by the service itself using the substitution service
301 m_xPathSettings
->setFastPropertyValue( m_aMapEnumToPropHandle
[ static_cast<sal_Int32
>(ePath
)], a
);
303 catch (const Exception
&)
305 TOOLS_WARN_EXCEPTION("unotools.config", "SetPath");
309 OUString
SvtPathOptions_Impl::ExpandMacros( const OUString
& rPath
) const
311 OUString
sExpanded( rPath
);
313 const INetURLObject
aParser( rPath
);
314 if ( aParser
.GetProtocol() == INetProtocol::VndSunStarExpand
)
315 sExpanded
= m_xMacroExpander
->expandMacros( aParser
.GetURLPath( INetURLObject::DecodeMechanism::WithCharset
) );
320 OUString
SvtPathOptions_Impl::UsePathVariables( const OUString
& rPath
) const
322 return m_xSubstVariables
->reSubstituteVariables( rPath
);
325 OUString
SvtPathOptions_Impl::SubstVar( const OUString
& rVar
) const
327 // Don't work at parameter-string directly. Copy it.
328 OUString aWorkText
= rVar
;
330 // Convert the returned path to system path!
331 bool bConvertLocal
= false;
333 // Search for first occurrence of "$(...".
334 sal_Int32 nPosition
= aWorkText
.indexOf( SIGN_STARTVARIABLE
); // = first position of "$(" in string
335 sal_Int32 nLength
= 0; // = count of letters from "$(" to ")" in string
337 // Have we found any variable like "$(...)"?
338 if ( nPosition
!= STRPOS_NOTFOUND
)
340 // Yes; Get length of found variable.
341 // If no ")" was found - nLength is set to 0 by default! see before.
342 sal_Int32 nEndPosition
= aWorkText
.indexOf( SIGN_ENDVARIABLE
, nPosition
);
343 if ( nEndPosition
!= STRPOS_NOTFOUND
)
344 nLength
= nEndPosition
- nPosition
+ 1;
347 // Is there another path variable?
348 while ( ( nPosition
!= STRPOS_NOTFOUND
) && ( nLength
> 0 ) )
350 // YES; Get the next variable for replace.
351 OUString aSubString
= aWorkText
.copy( nPosition
, nLength
);
352 aSubString
= aSubString
.toAsciiLowerCase();
354 // Look for special variable that needs a system path.
355 VarNameSet::const_iterator pIter
= m_aSystemPathVarNames
.find( aSubString
);
356 if ( pIter
!= m_aSystemPathVarNames
.end() )
357 bConvertLocal
= true;
359 nPosition
+= nLength
;
361 // We must control index in string before call something at OUString!
362 // The OUString-implementation don't do it for us :-( but the result is not defined otherwise.
363 if ( nPosition
+ 1 > aWorkText
.getLength() )
365 // Position is out of range. Break loop!
366 nPosition
= STRPOS_NOTFOUND
;
371 // Else; Position is valid. Search for next variable.
372 nPosition
= aWorkText
.indexOf( SIGN_STARTVARIABLE
, nPosition
);
373 // Have we found any variable like "$(...)"?
374 if ( nPosition
!= STRPOS_NOTFOUND
)
376 // Yes; Get length of found variable. If no ")" was found - nLength must set to 0!
378 sal_Int32 nEndPosition
= aWorkText
.indexOf( SIGN_ENDVARIABLE
, nPosition
);
379 if ( nEndPosition
!= STRPOS_NOTFOUND
)
380 nLength
= nEndPosition
- nPosition
+ 1;
385 aWorkText
= m_xSubstVariables
->substituteVariables( rVar
, false );
389 // Convert the URL to a system path for special path variables
391 osl::FileBase::getSystemPathFromFileURL( aWorkText
, aReturn
);
398 SvtPathOptions_Impl::SvtPathOptions_Impl() :
399 m_aPathArray( sal_Int32(SvtPathOptions::PATH_COUNT
) )
401 Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
403 // Create necessary services
404 Reference
< XPathSettings
> xPathSettings
= thePathSettings::get(xContext
);
405 m_xPathSettings
.set( xPathSettings
, UNO_QUERY_THROW
);
406 m_xSubstVariables
.set( PathSubstitution::create(xContext
) );
407 m_xMacroExpander
= theMacroExpander::get(xContext
);
409 // Create temporary hash map to have a mapping between property names and property handles
410 Reference
< XPropertySetInfo
> xPropSetInfo
= xPathSettings
->getPropertySetInfo();
411 const Sequence
< Property
> aPathPropSeq
= xPropSetInfo
->getProperties();
413 NameToHandleMap aTempHashMap
;
414 for ( const css::beans::Property
& aProperty
: aPathPropSeq
)
416 aTempHashMap
.emplace(aProperty
.Name
, aProperty
.Handle
);
419 // Create mapping between internal enum (SvtPathOptions::Paths) and property handle
420 for ( auto const & p
: aPropNames
)
422 NameToHandleMap::const_iterator pIter
=
423 aTempHashMap
.find( OUString::createFromAscii( p
.pPropName
));
425 if ( pIter
!= aTempHashMap
.end() )
427 sal_Int32 nHandle
= pIter
->second
;
428 sal_Int32 nEnum
= p
.ePath
;
429 m_aMapEnumToPropHandle
.emplace( nEnum
, nHandle
);
433 // Create hash map for path variables that need a system path as a return value!
434 for ( auto const & i
: aVarNameAttribute
)
436 m_aSystemPathVarNames
.insert( OUString::createFromAscii( i
.pVarName
) );
440 // class SvtPathOptions --------------------------------------------------
442 namespace { struct lclMutex
: public rtl::Static
< ::osl::Mutex
, lclMutex
> {}; }
444 SvtPathOptions::SvtPathOptions()
446 // Global access, must be guarded (multithreading)
447 ::osl::MutexGuard
aGuard( lclMutex::get() );
448 pImpl
= g_pOptions
.lock();
451 pImpl
= std::make_shared
<SvtPathOptions_Impl
>();
453 ItemHolder1::holdConfigItem(EItem::PathOptions
);
457 SvtPathOptions::~SvtPathOptions()
459 // Global access, must be guarded (multithreading)
460 ::osl::MutexGuard
aGuard( lclMutex::get() );
465 const OUString
& SvtPathOptions::GetAddinPath() const
467 return pImpl
->GetAddinPath();
470 const OUString
& SvtPathOptions::GetAutoCorrectPath() const
472 return pImpl
->GetAutoCorrectPath();
475 const OUString
& SvtPathOptions::GetAutoTextPath() const
477 return pImpl
->GetAutoTextPath();
480 const OUString
& SvtPathOptions::GetBackupPath() const
482 return pImpl
->GetBackupPath();
485 const OUString
& SvtPathOptions::GetBasicPath() const
487 return pImpl
->GetBasicPath();
490 const OUString
& SvtPathOptions::GetBitmapPath() const
492 return pImpl
->GetBitmapPath();
495 const OUString
& SvtPathOptions::GetConfigPath() const
497 return pImpl
->GetConfigPath();
500 const OUString
& SvtPathOptions::GetDictionaryPath() const
502 return pImpl
->GetDictionaryPath();
505 const OUString
& SvtPathOptions::GetFavoritesPath() const
507 return pImpl
->GetFavoritesPath();
510 const OUString
& SvtPathOptions::GetFilterPath() const
512 return pImpl
->GetFilterPath();
515 const OUString
& SvtPathOptions::GetGalleryPath() const
517 return pImpl
->GetGalleryPath();
520 const OUString
& SvtPathOptions::GetGraphicPath() const
522 return pImpl
->GetGraphicPath();
525 const OUString
& SvtPathOptions::GetHelpPath() const
527 return pImpl
->GetHelpPath();
530 const OUString
& SvtPathOptions::GetLinguisticPath() const
532 return pImpl
->GetLinguisticPath();
535 const OUString
& SvtPathOptions::GetFingerprintPath() const
537 return pImpl
->GetFingerprintPath();
540 const OUString
& SvtPathOptions::GetNumbertextPath() const
542 return pImpl
->GetNumbertextPath();
545 const OUString
& SvtPathOptions::GetModulePath() const
547 return pImpl
->GetModulePath();
550 const OUString
& SvtPathOptions::GetPalettePath() const
552 return pImpl
->GetPalettePath();
555 const OUString
& SvtPathOptions::GetIconsetPath() const
557 return pImpl
->GetIconsetPath();
560 const OUString
& SvtPathOptions::GetPluginPath() const
562 return pImpl
->GetPluginPath();
565 const OUString
& SvtPathOptions::GetStoragePath() const
567 return pImpl
->GetStoragePath();
570 const OUString
& SvtPathOptions::GetTempPath() const
572 return pImpl
->GetTempPath();
575 const OUString
& SvtPathOptions::GetTemplatePath() const
577 return pImpl
->GetTemplatePath();
580 const OUString
& SvtPathOptions::GetUserConfigPath() const
582 return pImpl
->GetUserConfigPath();
585 const OUString
& SvtPathOptions::GetWorkPath() const
587 return pImpl
->GetWorkPath();
590 const OUString
& SvtPathOptions::GetClassificationPath() const
592 return pImpl
->GetClassificationPath();
595 void SvtPathOptions::SetAddinPath( const OUString
& rPath
)
597 pImpl
->SetAddinPath( rPath
);
600 void SvtPathOptions::SetAutoCorrectPath( const OUString
& rPath
)
602 pImpl
->SetAutoCorrectPath( rPath
);
605 void SvtPathOptions::SetAutoTextPath( const OUString
& rPath
)
607 pImpl
->SetAutoTextPath( rPath
);
610 void SvtPathOptions::SetBackupPath( const OUString
& rPath
)
612 pImpl
->SetBackupPath( rPath
);
615 void SvtPathOptions::SetBasicPath( const OUString
& rPath
)
617 pImpl
->SetBasicPath( rPath
);
620 void SvtPathOptions::SetBitmapPath( const OUString
& rPath
)
622 pImpl
->SetBitmapPath( rPath
);
625 void SvtPathOptions::SetConfigPath( const OUString
& rPath
)
627 pImpl
->SetConfigPath( rPath
);
630 void SvtPathOptions::SetDictionaryPath( const OUString
& rPath
)
632 pImpl
->SetDictionaryPath( rPath
);
635 void SvtPathOptions::SetFavoritesPath( const OUString
& rPath
)
637 pImpl
->SetFavoritesPath( rPath
);
640 void SvtPathOptions::SetFilterPath( const OUString
& rPath
)
642 pImpl
->SetFilterPath( rPath
);
645 void SvtPathOptions::SetGalleryPath( const OUString
& rPath
)
647 pImpl
->SetGalleryPath( rPath
);
650 void SvtPathOptions::SetGraphicPath( const OUString
& rPath
)
652 pImpl
->SetGraphicPath( rPath
);
655 void SvtPathOptions::SetHelpPath( const OUString
& rPath
)
657 pImpl
->SetHelpPath( rPath
);
660 void SvtPathOptions::SetLinguisticPath( const OUString
& rPath
)
662 pImpl
->SetLinguisticPath( rPath
);
665 void SvtPathOptions::SetModulePath( const OUString
& rPath
)
667 pImpl
->SetModulePath( rPath
);
670 void SvtPathOptions::SetPalettePath( const OUString
& rPath
)
672 pImpl
->SetPalettePath( rPath
);
675 void SvtPathOptions::SetPluginPath( const OUString
& rPath
)
677 pImpl
->SetPluginPath( rPath
);
680 void SvtPathOptions::SetStoragePath( const OUString
& rPath
)
682 pImpl
->SetStoragePath( rPath
);
685 void SvtPathOptions::SetTempPath( const OUString
& rPath
)
687 pImpl
->SetTempPath( rPath
);
690 void SvtPathOptions::SetTemplatePath( const OUString
& rPath
)
692 pImpl
->SetTemplatePath( rPath
);
695 void SvtPathOptions::SetUserConfigPath( const OUString
& rPath
)
697 pImpl
->SetUserConfigPath( rPath
);
700 void SvtPathOptions::SetWorkPath( const OUString
& rPath
)
702 pImpl
->SetWorkPath( rPath
);
705 OUString
SvtPathOptions::SubstituteVariable( const OUString
& rVar
) const
707 return pImpl
->SubstVar( rVar
);
710 OUString
SvtPathOptions::ExpandMacros( const OUString
& rPath
) const
712 return pImpl
->ExpandMacros( rPath
);
715 OUString
SvtPathOptions::UseVariable( const OUString
& rPath
) const
717 return pImpl
->UsePathVariables( rPath
);
720 bool SvtPathOptions::SearchFile( OUString
& rIniFile
, Paths ePath
)
722 // check parameter: empty inifile name?
723 if ( rIniFile
.isEmpty() )
725 SAL_WARN( "unotools.config", "SvtPathOptions::SearchFile(): invalid parameter" );
729 OUString aIniFile
= pImpl
->SubstVar( rIniFile
);
734 case PATH_USERCONFIG
:
738 INetURLObject
aObj( GetUserConfigPath() );
740 sal_Int32 nIniIndex
= 0;
743 OUString aToken
= aIniFile
.getToken( 0, '/', nIniIndex
);
744 aObj
.insertName(aToken
);
746 while ( nIniIndex
>= 0 );
748 if ( !::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) ) )
750 aObj
.SetSmartURL( GetConfigPath() );
751 aObj
.insertName( aIniFile
);
752 bRet
= ::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
756 rIniFile
= aObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
);
766 case PATH_ADDIN
: aPath
= GetAddinPath(); break;
767 case PATH_AUTOCORRECT
: aPath
= GetAutoCorrectPath(); break;
768 case PATH_AUTOTEXT
: aPath
= GetAutoTextPath(); break;
769 case PATH_BACKUP
: aPath
= GetBackupPath(); break;
770 case PATH_BASIC
: aPath
= GetBasicPath(); break;
771 case PATH_BITMAP
: aPath
= GetBitmapPath(); break;
772 case PATH_CONFIG
: aPath
= GetConfigPath(); break;
773 case PATH_DICTIONARY
: aPath
= GetDictionaryPath(); break;
774 case PATH_FAVORITES
: aPath
= GetFavoritesPath(); break;
775 case PATH_FILTER
: aPath
= GetFilterPath(); break;
776 case PATH_GALLERY
: aPath
= GetGalleryPath(); break;
777 case PATH_GRAPHIC
: aPath
= GetGraphicPath(); break;
778 case PATH_HELP
: aPath
= GetHelpPath(); break;
779 case PATH_LINGUISTIC
: aPath
= GetLinguisticPath(); break;
780 case PATH_MODULE
: aPath
= GetModulePath(); break;
781 case PATH_PALETTE
: aPath
= GetPalettePath(); break;
782 case PATH_ICONSET
: aPath
= GetIconsetPath(); break;
783 case PATH_PLUGIN
: aPath
= GetPluginPath(); break;
784 case PATH_STORAGE
: aPath
= GetStoragePath(); break;
785 case PATH_TEMP
: aPath
= GetTempPath(); break;
786 case PATH_TEMPLATE
: aPath
= GetTemplatePath(); break;
787 case PATH_WORK
: aPath
= GetWorkPath(); break;
788 case PATH_UICONFIG
: aPath
= pImpl
->GetUIConfigPath(); break;
789 case PATH_FINGERPRINT
: aPath
= GetFingerprintPath(); break;
790 case PATH_NUMBERTEXT
: aPath
= GetNumbertextPath(); break;
791 case PATH_CLASSIFICATION
: aPath
= GetClassificationPath(); break;
792 // coverity[dead_error_begin] - following conditions exist to avoid compiler warning
793 case PATH_USERCONFIG
:
798 sal_Int32 nPathIndex
= 0;
802 OUString aPathToken
= aPath
.getToken( 0, SEARCHPATH_DELIMITER
, nPathIndex
);
803 INetURLObject
aObj( aPathToken
);
804 if ( aObj
.HasError() )
808 if ( osl::FileBase::getFileURLFromSystemPath( aPathToken
, aURL
)
809 == osl::FileBase::E_None
)
812 if ( aObj
.GetProtocol() == INetProtocol::VndSunStarExpand
)
814 Reference
< XMacroExpander
> xMacroExpander
= theMacroExpander::get( ::comphelper::getProcessComponentContext() );
815 const OUString sExpandedPath
= xMacroExpander
->expandMacros( aObj
.GetURLPath( INetURLObject::DecodeMechanism::WithCharset
) );
816 aObj
.SetURL( sExpandedPath
);
819 sal_Int32 nIniIndex
= 0;
822 OUString aToken
= aIniFile
.getToken( 0, '/', nIniIndex
);
823 aObj
.insertName(aToken
);
825 while ( nIniIndex
>= 0 );
827 bRet
= ::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
834 osl::FileBase::getSystemPathFromFileURL(
835 aObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
), sTmp
);
839 rIniFile
= aObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
);
843 while ( nPathIndex
>= 0 );
850 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */