Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / unotools / source / config / pathoptions.cxx
blobb6e5006ce39cde6ea2d85c7386ff5e47148ba89e
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 <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"
44 #include <set>
45 #include <unordered_map>
46 #include <vector>
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 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
74 private:
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 const m_aEmptyString;
85 mutable ::osl::Mutex m_aMutex;
87 public:
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 ); }
120 // set the paths
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;
154 // functions -------------------------------------------------------------
155 struct PropertyStruct
157 const char* pPropName; // The ascii name of the Office path
158 SvtPathOptions::Paths const ePath; // The enum value used by SvtPathOptions
161 struct VarNameAttribute
163 const char* pVarName; // The name of the path variable
166 static const PropertyStruct aPropNames[] =
168 { "Addin", SvtPathOptions::PATH_ADDIN },
169 { "AutoCorrect", SvtPathOptions::PATH_AUTOCORRECT },
170 { "AutoText", SvtPathOptions::PATH_AUTOTEXT },
171 { "Backup", SvtPathOptions::PATH_BACKUP },
172 { "Basic", SvtPathOptions::PATH_BASIC },
173 { "Bitmap", SvtPathOptions::PATH_BITMAP },
174 { "Config", SvtPathOptions::PATH_CONFIG },
175 { "Dictionary", SvtPathOptions::PATH_DICTIONARY },
176 { "Favorite", SvtPathOptions::PATH_FAVORITES },
177 { "Filter", SvtPathOptions::PATH_FILTER },
178 { "Gallery", SvtPathOptions::PATH_GALLERY },
179 { "Graphic", SvtPathOptions::PATH_GRAPHIC },
180 { "Help", SvtPathOptions::PATH_HELP },
181 { "Iconset", SvtPathOptions::PATH_ICONSET },
182 { "Linguistic", SvtPathOptions::PATH_LINGUISTIC },
183 { "Module", SvtPathOptions::PATH_MODULE },
184 { "Palette", SvtPathOptions::PATH_PALETTE },
185 { "Plugin", SvtPathOptions::PATH_PLUGIN },
186 { "Storage", SvtPathOptions::PATH_STORAGE },
187 { "Temp", SvtPathOptions::PATH_TEMP },
188 { "Template", SvtPathOptions::PATH_TEMPLATE },
189 { "UserConfig", SvtPathOptions::PATH_USERCONFIG },
190 { "Work", SvtPathOptions::PATH_WORK },
191 { "UIConfig", SvtPathOptions::PATH_UICONFIG },
192 { "Fingerprint", SvtPathOptions::PATH_FINGERPRINT },
193 { "Numbertext", SvtPathOptions::PATH_NUMBERTEXT },
194 { "Classification", SvtPathOptions::PATH_CLASSIFICATION }
197 static const VarNameAttribute aVarNameAttribute[] =
199 { SUBSTITUTE_INSTPATH }, // $(instpath)
200 { SUBSTITUTE_PROGPATH }, // $(progpath)
201 { SUBSTITUTE_USERPATH }, // $(userpath)
202 { SUBSTITUTE_PATH }, // $(path)
205 // class SvtPathOptions_Impl ---------------------------------------------
207 const OUString& SvtPathOptions_Impl::GetPath( SvtPathOptions::Paths ePath )
209 if ( ePath >= SvtPathOptions::PATH_COUNT )
210 return m_aEmptyString;
212 ::osl::MutexGuard aGuard( m_aMutex );
216 OUString aPathValue;
217 OUString aResult;
218 sal_Int32 nHandle = m_aMapEnumToPropHandle[ static_cast<sal_Int32>(ePath) ];
220 // Substitution is done by the service itself using the substitution service
221 Any a = m_xPathSettings->getFastPropertyValue( nHandle );
222 a >>= aPathValue;
223 if( ePath == SvtPathOptions::PATH_ADDIN ||
224 ePath == SvtPathOptions::PATH_FILTER ||
225 ePath == SvtPathOptions::PATH_HELP ||
226 ePath == SvtPathOptions::PATH_MODULE ||
227 ePath == SvtPathOptions::PATH_PLUGIN ||
228 ePath == SvtPathOptions::PATH_STORAGE
231 // These office paths have to be converted to system pates
232 osl::FileBase::getSystemPathFromFileURL( aPathValue, aResult );
233 aPathValue = aResult;
235 else if (ePath == SvtPathOptions::PATH_PALETTE ||
236 ePath == SvtPathOptions::PATH_ICONSET)
238 auto ctx = comphelper::getProcessComponentContext();
239 OUStringBuffer buf(aPathValue.getLength()*2);
240 for (sal_Int32 i = 0;;)
242 buf.append(
243 comphelper::getExpandedUri(
244 ctx, aPathValue.getToken(0, ';', i)));
245 if (i == -1) {
246 break;
248 buf.append(';');
250 aPathValue = buf.makeStringAndClear();
253 m_aPathArray[ ePath ] = aPathValue;
254 return m_aPathArray[ ePath ];
256 catch (UnknownPropertyException &)
260 return m_aEmptyString;
263 void SvtPathOptions_Impl::SetPath( SvtPathOptions::Paths ePath, const OUString& rNewPath )
265 ::osl::MutexGuard aGuard( m_aMutex );
267 if ( ePath < SvtPathOptions::PATH_COUNT )
269 OUString aResult;
270 OUString aNewValue;
271 Any a;
273 switch ( ePath )
275 case SvtPathOptions::PATH_ADDIN:
276 case SvtPathOptions::PATH_FILTER:
277 case SvtPathOptions::PATH_HELP:
278 case SvtPathOptions::PATH_MODULE:
279 case SvtPathOptions::PATH_PLUGIN:
280 case SvtPathOptions::PATH_STORAGE:
282 // These office paths have to be convert back to UCB-URL's
283 osl::FileBase::getFileURLFromSystemPath( rNewPath, aResult );
284 aNewValue = aResult;
286 break;
288 default:
289 aNewValue = rNewPath;
292 // Resubstitution is done by the service itself using the substitution service
293 a <<= aNewValue;
296 m_xPathSettings->setFastPropertyValue( m_aMapEnumToPropHandle[ static_cast<sal_Int32>(ePath)], a );
298 catch (const Exception&)
300 TOOLS_WARN_EXCEPTION("unotools.config", "SetPath");
305 OUString SvtPathOptions_Impl::ExpandMacros( const OUString& rPath ) const
307 OUString sExpanded( rPath );
309 const INetURLObject aParser( rPath );
310 if ( aParser.GetProtocol() == INetProtocol::VndSunStarExpand )
311 sExpanded = m_xMacroExpander->expandMacros( aParser.GetURLPath( INetURLObject::DecodeMechanism::WithCharset ) );
313 return sExpanded;
316 OUString SvtPathOptions_Impl::UsePathVariables( const OUString& rPath ) const
318 return m_xSubstVariables->reSubstituteVariables( rPath );
321 OUString SvtPathOptions_Impl::SubstVar( const OUString& rVar ) const
323 // Don't work at parameter-string directly. Copy it.
324 OUString aWorkText = rVar;
326 // Convert the returned path to system path!
327 bool bConvertLocal = false;
329 // Search for first occurrence of "$(...".
330 sal_Int32 nPosition = aWorkText.indexOf( SIGN_STARTVARIABLE ); // = first position of "$(" in string
331 sal_Int32 nLength = 0; // = count of letters from "$(" to ")" in string
333 // Have we found any variable like "$(...)"?
334 if ( nPosition != STRPOS_NOTFOUND )
336 // Yes; Get length of found variable.
337 // If no ")" was found - nLength is set to 0 by default! see before.
338 sal_Int32 nEndPosition = aWorkText.indexOf( SIGN_ENDVARIABLE, nPosition );
339 if ( nEndPosition != STRPOS_NOTFOUND )
340 nLength = nEndPosition - nPosition + 1;
343 // Is there another path variable?
344 while ( ( nPosition != STRPOS_NOTFOUND ) && ( nLength > 0 ) )
346 // YES; Get the next variable for replace.
347 OUString aSubString = aWorkText.copy( nPosition, nLength );
348 aSubString = aSubString.toAsciiLowerCase();
350 // Look for special variable that needs a system path.
351 VarNameSet::const_iterator pIter = m_aSystemPathVarNames.find( aSubString );
352 if ( pIter != m_aSystemPathVarNames.end() )
353 bConvertLocal = true;
355 nPosition += nLength;
357 // We must control index in string before call something at OUString!
358 // The OUString-implementation don't do it for us :-( but the result is not defined otherwise.
359 if ( nPosition + 1 > aWorkText.getLength() )
361 // Position is out of range. Break loop!
362 nPosition = STRPOS_NOTFOUND;
363 nLength = 0;
365 else
367 // Else; Position is valid. Search for next variable.
368 nPosition = aWorkText.indexOf( SIGN_STARTVARIABLE, nPosition );
369 // Have we found any variable like "$(...)"?
370 if ( nPosition != STRPOS_NOTFOUND )
372 // Yes; Get length of found variable. If no ")" was found - nLength must set to 0!
373 nLength = 0;
374 sal_Int32 nEndPosition = aWorkText.indexOf( SIGN_ENDVARIABLE, nPosition );
375 if ( nEndPosition != STRPOS_NOTFOUND )
376 nLength = nEndPosition - nPosition + 1;
381 aWorkText = m_xSubstVariables->substituteVariables( rVar, false );
383 if ( bConvertLocal )
385 // Convert the URL to a system path for special path variables
386 OUString aReturn;
387 osl::FileBase::getSystemPathFromFileURL( aWorkText, aReturn );
388 return aReturn;
391 return aWorkText;
394 SvtPathOptions_Impl::SvtPathOptions_Impl() :
395 m_aPathArray( sal_Int32(SvtPathOptions::PATH_COUNT) )
397 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
399 // Create necessary services
400 Reference< XPathSettings > xPathSettings = thePathSettings::get(xContext);
401 m_xPathSettings.set( xPathSettings, UNO_QUERY_THROW );
402 m_xSubstVariables.set( PathSubstitution::create(xContext) );
403 m_xMacroExpander = theMacroExpander::get(xContext);
405 // Create temporary hash map to have a mapping between property names and property handles
406 Reference< XPropertySetInfo > xPropSetInfo = xPathSettings->getPropertySetInfo();
407 const Sequence< Property > aPathPropSeq = xPropSetInfo->getProperties();
409 NameToHandleMap aTempHashMap;
410 for ( const css::beans::Property& aProperty : aPathPropSeq )
412 aTempHashMap.emplace(aProperty.Name, aProperty.Handle);
415 // Create mapping between internal enum (SvtPathOptions::Paths) and property handle
416 for ( auto const & p : aPropNames )
418 NameToHandleMap::const_iterator pIter =
419 aTempHashMap.find( OUString::createFromAscii( p.pPropName ));
421 if ( pIter != aTempHashMap.end() )
423 sal_Int32 nHandle = pIter->second;
424 sal_Int32 nEnum = p.ePath;
425 m_aMapEnumToPropHandle.emplace( nEnum, nHandle );
429 // Create hash map for path variables that need a system path as a return value!
430 for ( auto const & i : aVarNameAttribute )
432 m_aSystemPathVarNames.insert( OUString::createFromAscii( i.pVarName ) );
436 // class SvtPathOptions --------------------------------------------------
438 namespace { struct lclMutex : public rtl::Static< ::osl::Mutex, lclMutex > {}; }
440 SvtPathOptions::SvtPathOptions()
442 // Global access, must be guarded (multithreading)
443 ::osl::MutexGuard aGuard( lclMutex::get() );
444 pImpl = g_pOptions.lock();
445 if ( !pImpl )
447 pImpl = std::make_shared<SvtPathOptions_Impl>();
448 g_pOptions = pImpl;
449 ItemHolder1::holdConfigItem(EItem::PathOptions);
453 SvtPathOptions::~SvtPathOptions()
455 // Global access, must be guarded (multithreading)
456 ::osl::MutexGuard aGuard( lclMutex::get() );
458 pImpl.reset();
461 const OUString& SvtPathOptions::GetAddinPath() const
463 return pImpl->GetAddinPath();
466 const OUString& SvtPathOptions::GetAutoCorrectPath() const
468 return pImpl->GetAutoCorrectPath();
471 const OUString& SvtPathOptions::GetAutoTextPath() const
473 return pImpl->GetAutoTextPath();
476 const OUString& SvtPathOptions::GetBackupPath() const
478 return pImpl->GetBackupPath();
481 const OUString& SvtPathOptions::GetBasicPath() const
483 return pImpl->GetBasicPath();
486 const OUString& SvtPathOptions::GetBitmapPath() const
488 return pImpl->GetBitmapPath();
491 const OUString& SvtPathOptions::GetConfigPath() const
493 return pImpl->GetConfigPath();
496 const OUString& SvtPathOptions::GetDictionaryPath() const
498 return pImpl->GetDictionaryPath();
501 const OUString& SvtPathOptions::GetFavoritesPath() const
503 return pImpl->GetFavoritesPath();
506 const OUString& SvtPathOptions::GetFilterPath() const
508 return pImpl->GetFilterPath();
511 const OUString& SvtPathOptions::GetGalleryPath() const
513 return pImpl->GetGalleryPath();
516 const OUString& SvtPathOptions::GetGraphicPath() const
518 return pImpl->GetGraphicPath();
521 const OUString& SvtPathOptions::GetHelpPath() const
523 return pImpl->GetHelpPath();
526 const OUString& SvtPathOptions::GetLinguisticPath() const
528 return pImpl->GetLinguisticPath();
531 const OUString& SvtPathOptions::GetFingerprintPath() const
533 return pImpl->GetFingerprintPath();
536 const OUString& SvtPathOptions::GetNumbertextPath() const
538 return pImpl->GetNumbertextPath();
541 const OUString& SvtPathOptions::GetModulePath() const
543 return pImpl->GetModulePath();
546 const OUString& SvtPathOptions::GetPalettePath() const
548 return pImpl->GetPalettePath();
551 const OUString& SvtPathOptions::GetIconsetPath() const
553 return pImpl->GetIconsetPath();
556 const OUString& SvtPathOptions::GetPluginPath() const
558 return pImpl->GetPluginPath();
561 const OUString& SvtPathOptions::GetStoragePath() const
563 return pImpl->GetStoragePath();
566 const OUString& SvtPathOptions::GetTempPath() const
568 return pImpl->GetTempPath();
571 const OUString& SvtPathOptions::GetTemplatePath() const
573 return pImpl->GetTemplatePath();
576 const OUString& SvtPathOptions::GetUserConfigPath() const
578 return pImpl->GetUserConfigPath();
581 const OUString& SvtPathOptions::GetWorkPath() const
583 return pImpl->GetWorkPath();
586 const OUString& SvtPathOptions::GetClassificationPath() const
588 return pImpl->GetClassificationPath();
591 void SvtPathOptions::SetAddinPath( const OUString& rPath )
593 pImpl->SetAddinPath( rPath );
596 void SvtPathOptions::SetAutoCorrectPath( const OUString& rPath )
598 pImpl->SetAutoCorrectPath( rPath );
601 void SvtPathOptions::SetAutoTextPath( const OUString& rPath )
603 pImpl->SetAutoTextPath( rPath );
606 void SvtPathOptions::SetBackupPath( const OUString& rPath )
608 pImpl->SetBackupPath( rPath );
611 void SvtPathOptions::SetBasicPath( const OUString& rPath )
613 pImpl->SetBasicPath( rPath );
616 void SvtPathOptions::SetBitmapPath( const OUString& rPath )
618 pImpl->SetBitmapPath( rPath );
621 void SvtPathOptions::SetConfigPath( const OUString& rPath )
623 pImpl->SetConfigPath( rPath );
626 void SvtPathOptions::SetDictionaryPath( const OUString& rPath )
628 pImpl->SetDictionaryPath( rPath );
631 void SvtPathOptions::SetFavoritesPath( const OUString& rPath )
633 pImpl->SetFavoritesPath( rPath );
636 void SvtPathOptions::SetFilterPath( const OUString& rPath )
638 pImpl->SetFilterPath( rPath );
641 void SvtPathOptions::SetGalleryPath( const OUString& rPath )
643 pImpl->SetGalleryPath( rPath );
646 void SvtPathOptions::SetGraphicPath( const OUString& rPath )
648 pImpl->SetGraphicPath( rPath );
651 void SvtPathOptions::SetHelpPath( const OUString& rPath )
653 pImpl->SetHelpPath( rPath );
656 void SvtPathOptions::SetLinguisticPath( const OUString& rPath )
658 pImpl->SetLinguisticPath( rPath );
661 void SvtPathOptions::SetModulePath( const OUString& rPath )
663 pImpl->SetModulePath( rPath );
666 void SvtPathOptions::SetPalettePath( const OUString& rPath )
668 pImpl->SetPalettePath( rPath );
671 void SvtPathOptions::SetPluginPath( const OUString& rPath )
673 pImpl->SetPluginPath( rPath );
676 void SvtPathOptions::SetStoragePath( const OUString& rPath )
678 pImpl->SetStoragePath( rPath );
681 void SvtPathOptions::SetTempPath( const OUString& rPath )
683 pImpl->SetTempPath( rPath );
686 void SvtPathOptions::SetTemplatePath( const OUString& rPath )
688 pImpl->SetTemplatePath( rPath );
691 void SvtPathOptions::SetUserConfigPath( const OUString& rPath )
693 pImpl->SetUserConfigPath( rPath );
696 void SvtPathOptions::SetWorkPath( const OUString& rPath )
698 pImpl->SetWorkPath( rPath );
701 OUString SvtPathOptions::SubstituteVariable( const OUString& rVar ) const
703 return pImpl->SubstVar( rVar );
706 OUString SvtPathOptions::ExpandMacros( const OUString& rPath ) const
708 return pImpl->ExpandMacros( rPath );
711 OUString SvtPathOptions::UseVariable( const OUString& rPath ) const
713 return pImpl->UsePathVariables( rPath );
716 bool SvtPathOptions::SearchFile( OUString& rIniFile, Paths ePath )
718 // check parameter: empty inifile name?
719 if ( rIniFile.isEmpty() )
721 SAL_WARN( "unotools.config", "SvtPathOptions::SearchFile(): invalid parameter" );
722 return false;
725 OUString aIniFile = pImpl->SubstVar( rIniFile );
726 bool bRet = false;
728 switch ( ePath )
730 case PATH_USERCONFIG:
732 // path is a URL
733 bRet = true;
734 INetURLObject aObj( GetUserConfigPath() );
736 sal_Int32 nIniIndex = 0;
739 OUString aToken = aIniFile.getToken( 0, '/', nIniIndex );
740 aObj.insertName(aToken);
742 while ( nIniIndex >= 0 );
744 if ( !::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ) ) )
746 aObj.SetSmartURL( GetConfigPath() );
747 aObj.insertName( aIniFile );
748 bRet = ::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
751 if ( bRet )
752 rIniFile = aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
754 break;
757 default:
759 OUString aPath;
760 switch ( ePath )
762 case PATH_ADDIN: aPath = GetAddinPath(); break;
763 case PATH_AUTOCORRECT: aPath = GetAutoCorrectPath(); break;
764 case PATH_AUTOTEXT: aPath = GetAutoTextPath(); break;
765 case PATH_BACKUP: aPath = GetBackupPath(); break;
766 case PATH_BASIC: aPath = GetBasicPath(); break;
767 case PATH_BITMAP: aPath = GetBitmapPath(); break;
768 case PATH_CONFIG: aPath = GetConfigPath(); break;
769 case PATH_DICTIONARY: aPath = GetDictionaryPath(); break;
770 case PATH_FAVORITES: aPath = GetFavoritesPath(); break;
771 case PATH_FILTER: aPath = GetFilterPath(); break;
772 case PATH_GALLERY: aPath = GetGalleryPath(); break;
773 case PATH_GRAPHIC: aPath = GetGraphicPath(); break;
774 case PATH_HELP: aPath = GetHelpPath(); break;
775 case PATH_LINGUISTIC: aPath = GetLinguisticPath(); break;
776 case PATH_MODULE: aPath = GetModulePath(); break;
777 case PATH_PALETTE: aPath = GetPalettePath(); break;
778 case PATH_ICONSET: aPath = GetIconsetPath(); break;
779 case PATH_PLUGIN: aPath = GetPluginPath(); break;
780 case PATH_STORAGE: aPath = GetStoragePath(); break;
781 case PATH_TEMP: aPath = GetTempPath(); break;
782 case PATH_TEMPLATE: aPath = GetTemplatePath(); break;
783 case PATH_WORK: aPath = GetWorkPath(); break;
784 case PATH_UICONFIG: aPath = pImpl->GetUIConfigPath(); break;
785 case PATH_FINGERPRINT: aPath = GetFingerprintPath(); break;
786 case PATH_NUMBERTEXT: aPath = GetNumbertextPath(); break;
787 case PATH_CLASSIFICATION: aPath = GetClassificationPath(); break;
788 // coverity[dead_error_begin] - following conditions exist to avoid compiler warning
789 case PATH_USERCONFIG:
790 case PATH_COUNT:
791 break;
794 sal_Int32 nPathIndex = 0;
797 bool bIsURL = true;
798 OUString aPathToken = aPath.getToken( 0, SEARCHPATH_DELIMITER, nPathIndex );
799 INetURLObject aObj( aPathToken );
800 if ( aObj.HasError() )
802 bIsURL = false;
803 OUString aURL;
804 if ( osl::FileBase::getFileURLFromSystemPath( aPathToken, aURL )
805 == osl::FileBase::E_None )
806 aObj.SetURL( aURL );
808 if ( aObj.GetProtocol() == INetProtocol::VndSunStarExpand )
810 Reference< XMacroExpander > xMacroExpander = theMacroExpander::get( ::comphelper::getProcessComponentContext() );
811 const OUString sExpandedPath = xMacroExpander->expandMacros( aObj.GetURLPath( INetURLObject::DecodeMechanism::WithCharset ) );
812 aObj.SetURL( sExpandedPath );
815 sal_Int32 nIniIndex = 0;
818 OUString aToken = aIniFile.getToken( 0, '/', nIniIndex );
819 aObj.insertName(aToken);
821 while ( nIniIndex >= 0 );
823 bRet = ::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
825 if ( bRet )
827 if ( !bIsURL )
829 OUString sTmp;
830 osl::FileBase::getSystemPathFromFileURL(
831 aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ), sTmp );
832 rIniFile = sTmp;
834 else
835 rIniFile = aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
836 break;
839 while ( nPathIndex >= 0 );
843 return bRet;
846 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */