LibreOffice Module comphelper (master)  1
backupfilehelper.hxx
Go to the documentation of this file.
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 
10 #ifndef INCLUDED_COMPHELPER_BACKUPFILEHELPER_HXX
11 #define INCLUDED_COMPHELPER_BACKUPFILEHELPER_HXX
12 
13 #include <sal/config.h>
14 
16 #include <rtl/ustring.hxx>
17 #include <set>
18 #include <string_view>
19 #include <vector>
20 
21 namespace comphelper
22 {
60  {
61  private:
62  // internal data
63  std::set< OUString > maDirs;
64  std::set< std::pair< OUString, OUString > > maFiles;
65 
66  sal_uInt16 mnNumBackups;
67  sal_uInt16 mnMode;
68 
69  bool mbActive;
71  bool mbCompress;
72 
73  // internal flag if _exit() was called already - a hint to evtl.
74  // not create copies of potentially not well-defined data. This
75  // may be used in destructors of static instances - which unfortunately
76  // get called on WNT but not on linux. Thus I thought about encapsulating
77  // in some '#ifdefs', but it's just more safe to always do it and
78  // allows to add a SAL_WARN when one of these destructors is called
79  // after _exit()
80  static bool mbExitWasCalled;
81 
82  // internal detector if SafeModeName dir exists
83  static bool mbSafeModeDirExists;
84 
85  // internal upper limit (max) of allowed backups
86  static sal_uInt16 mnMaxAllowedBackups;
87 
88  // path to User's configuration directory and derived strings
89  static OUString maInitialBaseURL;
90  static OUString maUserConfigBaseURL;
91  static OUString maUserConfigWorkURL;
92  static OUString maRegModName;
93  static OUString maExt;
94 
95  // get path to User's configuration directory (created on-demand)
96  static const OUString& getInitialBaseURL();
97 
98  // the name of the SafeMode directory for temporary processing
99  static const OUString& getSafeModeName();
100 
101  public:
107 
108  // allow to set static global flag when app had to call _exit()
109  static void setExitWasCalled();
110  static bool getExitWasCalled();
111 
112  // This call initializes the state of the UserDirectory as needed, it may
113  // initialize to SafeMode configuration or return from it by moving files
114  // in that directory
115  static void reactOnSafeMode(bool bSafeMode);
116 
125  void tryPush();
126  void tryPushExtensionInfo();
127 
135  bool isPopPossible();
136  bool isPopPossibleExtensionInfo() const;
137 
145  void tryPop();
146  void tryPopExtensionInfo();
147 
150  static bool isTryDisableAllExtensionsPossible();
151  static void tryDisableAllExtensions();
152 
155  static bool isTryDeinstallUserExtensionsPossible();
156  static void tryDeinstallUserExtensions();
157 
160  static bool isTryResetSharedExtensionsPossible();
161  static void tryResetSharedExtensions();
162 
165  static bool isTryResetBundledExtensionsPossible();
166  static void tryResetBundledExtensions();
167 
169  static void tryDisableHWAcceleration();
170 
173  static bool isTryResetCustomizationsPossible();
174  static void tryResetCustomizations();
175 
178  static void tryResetUserProfile();
179 
181  static const OUString& getUserProfileURL();
182 
184  static const OUString& getUserProfileWorkURL();
185 
186  private:
187  // internal helper methods
188  static OUString getPackURL();
189  static const std::vector< OUString >& getCustomizationDirNames();
190  static const std::vector< OUString >& getCustomizationFileNames();
191 
192  // file push helpers
193  bool tryPush_Files(const std::set< OUString >& rDirs, const std::set< std::pair< OUString, OUString > >& rFiles, std::u16string_view rSourceURL, const OUString& rTargetURL);
194  bool tryPush_file(std::u16string_view rSourceURL, std::u16string_view rTargetURL, std::u16string_view rName, std::u16string_view rExt);
195 
196  // file pop possibilities helper
197  bool isPopPossible_files(const std::set< OUString >& rDirs, const std::set< std::pair< OUString, OUString > >& rFiles, std::u16string_view rSourceURL, std::u16string_view rTargetURL);
198  static bool isPopPossible_file(std::u16string_view rSourceURL, std::u16string_view rTargetURL, std::u16string_view rName, std::u16string_view rExt);
199 
200  // file pop helpers
201  bool tryPop_files(const std::set< OUString >& rDirs, const std::set< std::pair< OUString, OUString > >& rFiles, std::u16string_view rSourceURL, const OUString& rTargetURL);
202  bool tryPop_file(std::u16string_view rSourceURL, std::u16string_view rTargetURL, std::u16string_view rName, std::u16string_view rExt);
203 
204  // ExtensionInfo helpers
205  bool tryPush_extensionInfo(std::u16string_view rTargetURL);
206  static bool isPopPossible_extensionInfo(std::u16string_view rTargetURL);
207  bool tryPop_extensionInfo(std::u16string_view rTargetURL);
208 
209  // FileDirInfo helpers
210  void fillDirFileInfo();
211  };
212 }
213 
214 #endif
215 
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::set< std::pair< OUString, OUString > > maFiles
Helper class to backup/restore a single file.
static sal_uInt16 mnMaxAllowedBackups
#define COMPHELPER_DLLPUBLIC