LibreOffice Module comphelper (master) 1
|
Helper class to backup/restore a single file. More...
#include <backupfilehelper.hxx>
Public Member Functions | |
BackupFileHelper () | |
Constructor to handle Backups of the given file, will internally detect configuration values and URL to initial registrymodifications and thus the User configuration directory. More... | |
void | tryPush () |
tries to create a new backup, if there is none yet, or if the last differs from the base file. More... | |
void | tryPushExtensionInfo () |
bool | isPopPossible () |
finds out if a restore is possible More... | |
bool | isPopPossibleExtensionInfo () const |
void | tryPop () |
tries to execute a restore. More... | |
void | tryPopExtensionInfo () |
Static Public Member Functions | |
static void | setExitWasCalled () |
static bool | getExitWasCalled () |
static void | reactOnSafeMode (bool bSafeMode) |
static bool | isTryDisableAllExtensionsPossible () |
tries to iterate the extensions and to disable all of them More... | |
static void | tryDisableAllExtensions () |
static bool | isTryDeinstallUserExtensionsPossible () |
Deinstall all User Extensions (installed for User only) More... | |
static void | tryDeinstallUserExtensions () |
static bool | isTryResetSharedExtensionsPossible () |
Reset shared Extensions. More... | |
static void | tryResetSharedExtensions () |
static bool | isTryResetBundledExtensionsPossible () |
Reset bundled Extensions. More... | |
static void | tryResetBundledExtensions () |
static void | tryDisableHWAcceleration () |
Disables OpenGL and OpenCL. More... | |
static bool | isTryResetCustomizationsPossible () |
resets User-Customizations like Settings and UserInterface modifications More... | |
static void | tryResetCustomizations () |
static void | tryResetUserProfile () |
resets the whole UserProfile More... | |
static const OUString & | getUserProfileURL () |
Return the profile url. More... | |
static const OUString & | getUserProfileWorkURL () |
Return the url of the backed up profile (when in safe mode) More... | |
Private Member Functions | |
bool | tryPush_Files (const std::set< OUString > &rDirs, const std::set< std::pair< OUString, OUString > > &rFiles, std::u16string_view rSourceURL, const OUString &rTargetURL) |
bool | tryPush_file (std::u16string_view rSourceURL, std::u16string_view rTargetURL, std::u16string_view rName, std::u16string_view rExt) |
bool | isPopPossible_files (const std::set< OUString > &rDirs, const std::set< std::pair< OUString, OUString > > &rFiles, std::u16string_view rSourceURL, std::u16string_view rTargetURL) |
bool | tryPop_files (const std::set< OUString > &rDirs, const std::set< std::pair< OUString, OUString > > &rFiles, std::u16string_view rSourceURL, const OUString &rTargetURL) |
bool | tryPop_file (std::u16string_view rSourceURL, std::u16string_view rTargetURL, std::u16string_view rName, std::u16string_view rExt) |
bool | tryPush_extensionInfo (std::u16string_view rTargetURL) |
bool | tryPop_extensionInfo (std::u16string_view rTargetURL) |
void | fillDirFileInfo () |
Static Private Member Functions | |
static const OUString & | getInitialBaseURL () |
static const OUString & | getSafeModeName () |
static OUString | getPackURL () |
static const std::vector< OUString > & | getCustomizationDirNames () |
static const std::vector< OUString > & | getCustomizationFileNames () |
static bool | isPopPossible_file (std::u16string_view rSourceURL, std::u16string_view rTargetURL, std::u16string_view rName, std::u16string_view rExt) |
static bool | isPopPossible_extensionInfo (std::u16string_view rTargetURL) |
Private Attributes | |
std::set< OUString > | maDirs |
std::set< std::pair< OUString, OUString > > | maFiles |
sal_uInt16 | mnNumBackups |
sal_uInt16 | mnMode |
bool | mbActive |
bool | mbExtensions |
bool | mbCompress |
Static Private Attributes | |
static bool | mbExitWasCalled = false |
static bool | mbSafeModeDirExists = false |
static sal_uInt16 | mnMaxAllowedBackups = 10 |
static OUString | maInitialBaseURL |
static OUString | maUserConfigBaseURL |
static OUString | maUserConfigWorkURL |
static OUString | maRegModName |
static OUString | maExt |
Helper class to backup/restore a single file.
This is a general class to manage backups/restore of the file given by the URL. The container holding the backups is created aside the original file, e.g for 'test.txt' a container called '.test.pack' will be used. If it was not yet backed-up this container file will be created at the 1st backup and deleted when the last gets removed. The container holds a stack with a maximum given number (in the constructor) of copies, these are by default compressed, but don't have to be (see tryPush).
Due to being on a low system level here, no UNO API and not much other tooling can be used, as a consequence for the container a own simple format is used and e.g. the zip lib directly.
You need to hand over the URL of the file to look at and a maximum number of allowed copies. That number is internally limited to an absolute max of 10 (see implementation). The number of allowed copies is limited to [1..max].
Calling tryPush() will check if there is no backup yet or if there is one that the file has changed. If yes, a new copy is created on a kind of 'stack' of copies. The return value can be used to see if a backup was indeed created.
Calling tryPop() will do the opposite: if a backup is available, delete the orig file and re-instantiate the backup. The backup is taken off the 'stack' of copies. The return value can be used to check if this was done.
isPopPossible can be called to see if there is a backup available before calling tryPop().
The 'stack' of copies works by using the same path, filename and extension, but adding a '1' -> '(num_of_copy)' to it.
Definition at line 59 of file backupfilehelper.hxx.
comphelper::BackupFileHelper::BackupFileHelper | ( | ) |
Constructor to handle Backups of the given file, will internally detect configuration values and URL to initial registrymodifications and thus the User configuration directory.
Definition at line 1520 of file backupfilehelper.cxx.
References getInitialBaseURL(), maInitialBaseURL, maRegModName, maUserConfigBaseURL, mbActive, mbActive, mbCompress, mbExtensions, mnMaxAllowedBackups, mnMode, mnMode, and mnNumBackups.
|
private |
Definition at line 2406 of file backupfilehelper.cxx.
References maDirs, maExt, maFiles, maRegModName, maUserConfigWorkURL, mnMode, and comphelper::DirectoryHelper::scanDirsAndFiles().
Referenced by isPopPossible(), tryPop(), and tryPush().
|
staticprivate |
Definition at line 1834 of file backupfilehelper.cxx.
Referenced by isTryResetCustomizationsPossible(), and tryResetCustomizations().
|
staticprivate |
Definition at line 1849 of file backupfilehelper.cxx.
Referenced by isTryResetCustomizationsPossible(), and tryResetCustomizations().
|
static |
Definition at line 1576 of file backupfilehelper.cxx.
References mbExitWasCalled.
|
staticprivate |
Definition at line 1462 of file backupfilehelper.cxx.
References comphelper::DirectoryHelper::dirExists(), getSafeModeName(), maExt, maInitialBaseURL, maRegModName, maUserConfigBaseURL, maUserConfigWorkURL, mbSafeModeDirExists, comphelper::DirectoryHelper::splitAtLastToken(), and u.
Referenced by BackupFileHelper(), and reactOnSafeMode().
|
staticprivate |
Definition at line 2001 of file backupfilehelper.cxx.
References maUserConfigWorkURL.
Referenced by isPopPossible(), isPopPossibleExtensionInfo(), tryPop(), tryPopExtensionInfo(), tryPush(), and tryPushExtensionInfo().
|
staticprivate |
Definition at line 1513 of file backupfilehelper.cxx.
Referenced by getInitialBaseURL(), and reactOnSafeMode().
|
static |
Return the profile url.
Definition at line 1989 of file backupfilehelper.cxx.
References maUserConfigBaseURL.
|
static |
Return the url of the backed up profile (when in safe mode)
Definition at line 1994 of file backupfilehelper.cxx.
References maUserConfigWorkURL.
bool comphelper::BackupFileHelper::isPopPossible | ( | ) |
finds out if a restore is possible
isPopPossibleExtensionInfo is the specialized version for ExtensionInfo
Definition at line 1666 of file backupfilehelper.cxx.
References fillDirFileInfo(), getPackURL(), isPopPossible_files(), maDirs, maFiles, maUserConfigWorkURL, and mbActive.
|
staticprivate |
Definition at line 2288 of file backupfilehelper.cxx.
References u.
Referenced by isPopPossibleExtensionInfo().
|
staticprivate |
Definition at line 2135 of file backupfilehelper.cxx.
References comphelper::DirectoryHelper::fileExists().
Referenced by isPopPossible_files().
|
private |
Definition at line 2090 of file backupfilehelper.cxx.
References isPopPossible_file(), isPopPossible_files(), and comphelper::DirectoryHelper::scanDirsAndFiles().
Referenced by isPopPossible(), and isPopPossible_files().
bool comphelper::BackupFileHelper::isPopPossibleExtensionInfo | ( | ) | const |
Definition at line 1719 of file backupfilehelper.cxx.
References getPackURL(), isPopPossible_extensionInfo(), mbActive, and mbExtensions.
|
static |
Deinstall all User Extensions (installed for User only)
Definition at line 1786 of file backupfilehelper.cxx.
References maUserConfigWorkURL.
|
static |
tries to iterate the extensions and to disable all of them
Definition at line 1750 of file backupfilehelper.cxx.
References maUserConfigWorkURL.
|
static |
Reset bundled Extensions.
Definition at line 1818 of file backupfilehelper.cxx.
References maUserConfigWorkURL.
|
static |
resets User-Customizations like Settings and UserInterface modifications
Definition at line 1939 of file backupfilehelper.cxx.
References a, comphelper::DirectoryHelper::dirExists(), comphelper::DirectoryHelper::fileExists(), getCustomizationDirNames(), getCustomizationFileNames(), and maUserConfigWorkURL.
|
static |
Reset shared Extensions.
Definition at line 1802 of file backupfilehelper.cxx.
References maUserConfigWorkURL.
|
static |
Definition at line 1581 of file backupfilehelper.cxx.
References getInitialBaseURL(), getSafeModeName(), maUserConfigBaseURL, maUserConfigWorkURL, mbSafeModeDirExists, comphelper::DirectoryHelper::moveDirContent(), and comphelper::string::remove().
|
static |
Definition at line 1571 of file backupfilehelper.cxx.
References mbExitWasCalled.
|
static |
Definition at line 1796 of file backupfilehelper.cxx.
References comphelper::DirectoryHelper::deleteDirRecursively(), and maUserConfigWorkURL.
|
static |
Definition at line 1762 of file backupfilehelper.cxx.
References maUserConfigWorkURL.
|
static |
Disables OpenGL and OpenCL.
Definition at line 1881 of file backupfilehelper.cxx.
References comphelper::DirectoryHelper::fileExists(), comphelper::getProcessComponentContext(), maUserConfigWorkURL, comphelper::string::remove(), result, and SAL_WARN_IF.
void comphelper::BackupFileHelper::tryPop | ( | ) |
tries to execute a restore.
Will overwrite the base file in that case and take one version off the 'stack' of copies. Also may cleanup older backups when NumBackups given in the constructor has changed.
tryPopExtensionInfo is the specialized version for ExtensionInfo
Definition at line 1691 of file backupfilehelper.cxx.
References fillDirFileInfo(), getPackURL(), maDirs, maFiles, maUserConfigWorkURL, mbActive, comphelper::string::remove(), and tryPop_files().
|
private |
Definition at line 2299 of file backupfilehelper.cxx.
References maUserConfigWorkURL, mnNumBackups, comphelper::string::remove(), and u.
Referenced by tryPopExtensionInfo().
|
private |
Definition at line 2208 of file backupfilehelper.cxx.
References comphelper::DirectoryHelper::fileExists(), mnNumBackups, and comphelper::string::remove().
Referenced by tryPop_files().
|
private |
Definition at line 2157 of file backupfilehelper.cxx.
References comphelper::string::remove(), comphelper::DirectoryHelper::scanDirsAndFiles(), tryPop_file(), and tryPop_files().
Referenced by tryPop(), and tryPop_files().
void comphelper::BackupFileHelper::tryPopExtensionInfo | ( | ) |
Definition at line 1733 of file backupfilehelper.cxx.
References getPackURL(), mbActive, mbExtensions, comphelper::string::remove(), and tryPop_extensionInfo().
void comphelper::BackupFileHelper::tryPush | ( | ) |
tries to create a new backup, if there is none yet, or if the last differs from the base file.
It will then put a new version on the 'stack' of copies and evtl. delete the oldest backup. Also may cleanup older backups when NumBackups given in the constructor has changed.
tryPushExtensionInfo is the specialized version for ExtensionInfo
Definition at line 1629 of file backupfilehelper.cxx.
References fillDirFileInfo(), getPackURL(), maDirs, maFiles, maUserConfigWorkURL, mbActive, mbSafeModeDirExists, and tryPush_Files().
|
private |
Definition at line 2259 of file backupfilehelper.cxx.
References mbCompress, mnNumBackups, comphelper::string::remove(), and u.
Referenced by tryPushExtensionInfo().
|
private |
Definition at line 2060 of file backupfilehelper.cxx.
References comphelper::DirectoryHelper::fileExists(), mbCompress, and mnNumBackups.
Referenced by tryPush_Files().
|
private |
Definition at line 2008 of file backupfilehelper.cxx.
References comphelper::string::remove(), comphelper::DirectoryHelper::scanDirsAndFiles(), tryPush_file(), and tryPush_Files().
Referenced by tryPush(), and tryPush_Files().
void comphelper::BackupFileHelper::tryPushExtensionInfo | ( | ) |
Definition at line 1653 of file backupfilehelper.cxx.
References getPackURL(), mbActive, mbExtensions, mbSafeModeDirExists, and tryPush_extensionInfo().
|
static |
Definition at line 1828 of file backupfilehelper.cxx.
References comphelper::DirectoryHelper::deleteDirRecursively(), and maUserConfigWorkURL.
|
static |
Definition at line 1965 of file backupfilehelper.cxx.
References a, comphelper::DirectoryHelper::deleteDirRecursively(), getCustomizationDirNames(), getCustomizationFileNames(), maUserConfigWorkURL, and comphelper::string::remove().
|
static |
Definition at line 1812 of file backupfilehelper.cxx.
References comphelper::DirectoryHelper::deleteDirRecursively(), and maUserConfigWorkURL.
|
static |
resets the whole UserProfile
Definition at line 1983 of file backupfilehelper.cxx.
References comphelper::DirectoryHelper::deleteDirRecursively(), and maUserConfigWorkURL.
|
private |
Definition at line 63 of file backupfilehelper.hxx.
Referenced by fillDirFileInfo(), isPopPossible(), tryPop(), and tryPush().
|
staticprivate |
Definition at line 93 of file backupfilehelper.hxx.
Referenced by fillDirFileInfo(), and getInitialBaseURL().
|
private |
Definition at line 64 of file backupfilehelper.hxx.
Referenced by fillDirFileInfo(), isPopPossible(), tryPop(), and tryPush().
|
staticprivate |
Definition at line 89 of file backupfilehelper.hxx.
Referenced by BackupFileHelper(), and getInitialBaseURL().
|
staticprivate |
Definition at line 92 of file backupfilehelper.hxx.
Referenced by BackupFileHelper(), fillDirFileInfo(), and getInitialBaseURL().
|
staticprivate |
Definition at line 90 of file backupfilehelper.hxx.
Referenced by BackupFileHelper(), getInitialBaseURL(), getUserProfileURL(), and reactOnSafeMode().
|
staticprivate |
Definition at line 91 of file backupfilehelper.hxx.
Referenced by fillDirFileInfo(), getInitialBaseURL(), getPackURL(), getUserProfileWorkURL(), isPopPossible(), isTryDeinstallUserExtensionsPossible(), isTryDisableAllExtensionsPossible(), isTryResetBundledExtensionsPossible(), isTryResetCustomizationsPossible(), isTryResetSharedExtensionsPossible(), reactOnSafeMode(), tryDeinstallUserExtensions(), tryDisableAllExtensions(), tryDisableHWAcceleration(), tryPop(), tryPop_extensionInfo(), tryPush(), tryResetBundledExtensions(), tryResetCustomizations(), tryResetSharedExtensions(), and tryResetUserProfile().
|
private |
Definition at line 69 of file backupfilehelper.hxx.
Referenced by BackupFileHelper(), isPopPossible(), isPopPossibleExtensionInfo(), tryPop(), tryPopExtensionInfo(), tryPush(), and tryPushExtensionInfo().
|
private |
Definition at line 71 of file backupfilehelper.hxx.
Referenced by BackupFileHelper(), tryPush_extensionInfo(), and tryPush_file().
|
staticprivate |
Definition at line 80 of file backupfilehelper.hxx.
Referenced by getExitWasCalled(), and setExitWasCalled().
|
private |
Definition at line 70 of file backupfilehelper.hxx.
Referenced by BackupFileHelper(), isPopPossibleExtensionInfo(), tryPopExtensionInfo(), and tryPushExtensionInfo().
|
staticprivate |
Definition at line 83 of file backupfilehelper.hxx.
Referenced by getInitialBaseURL(), reactOnSafeMode(), tryPush(), and tryPushExtensionInfo().
|
staticprivate |
Definition at line 86 of file backupfilehelper.hxx.
Referenced by BackupFileHelper().
|
private |
Definition at line 67 of file backupfilehelper.hxx.
Referenced by BackupFileHelper(), and fillDirFileInfo().
|
private |
Definition at line 66 of file backupfilehelper.hxx.
Referenced by BackupFileHelper(), tryPop_extensionInfo(), tryPop_file(), tryPush_extensionInfo(), and tryPush_file().