LibreOffice Module comphelper (master)  1
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
comphelper::BackupFileHelper Class Reference

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
 

Detailed Description

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.

Constructor & Destructor Documentation

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 1531 of file backupfilehelper.cxx.

References getInitialBaseURL(), maInitialBaseURL, maRegModName, maUserConfigBaseURL, mbActive, mbActive, mbCompress, mbExtensions, mnMaxAllowedBackups, mnMode, mnMode, and mnNumBackups.

Member Function Documentation

void comphelper::BackupFileHelper::fillDirFileInfo ( )
private
const std::vector< OUString > & comphelper::BackupFileHelper::getCustomizationDirNames ( )
staticprivate
const std::vector< OUString > & comphelper::BackupFileHelper::getCustomizationFileNames ( )
staticprivate
bool comphelper::BackupFileHelper::getExitWasCalled ( )
static

Definition at line 1587 of file backupfilehelper.cxx.

References mbExitWasCalled.

const OUString & comphelper::BackupFileHelper::getInitialBaseURL ( )
staticprivate
OUString comphelper::BackupFileHelper::getPackURL ( )
staticprivate
const OUString & comphelper::BackupFileHelper::getSafeModeName ( )
staticprivate

Definition at line 1524 of file backupfilehelper.cxx.

Referenced by reactOnSafeMode().

const OUString & comphelper::BackupFileHelper::getUserProfileURL ( )
static

Return the profile url.

Definition at line 1997 of file backupfilehelper.cxx.

References maUserConfigBaseURL.

const OUString & comphelper::BackupFileHelper::getUserProfileWorkURL ( )
static

Return the url of the backed up profile (when in safe mode)

Definition at line 2002 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

bool comphelper::BackupFileHelper::isPopPossible ( )

finds out if a restore is possible

Returns
bool returns true if a restore to an older backup is possible

isPopPossibleExtensionInfo is the specialized version for ExtensionInfo

Definition at line 1677 of file backupfilehelper.cxx.

References fillDirFileInfo(), getPackURL(), isPopPossible_files(), maDirs, maFiles, maUserConfigWorkURL, and mbActive.

bool comphelper::BackupFileHelper::isPopPossible_extensionInfo ( std::u16string_view  rTargetURL)
staticprivate

Definition at line 2298 of file backupfilehelper.cxx.

References u.

Referenced by isPopPossibleExtensionInfo().

bool comphelper::BackupFileHelper::isPopPossible_file ( std::u16string_view  rSourceURL,
std::u16string_view  rTargetURL,
std::u16string_view  rName,
std::u16string_view  rExt 
)
staticprivate

Definition at line 2143 of file backupfilehelper.cxx.

References comphelper::DirectoryHelper::fileExists().

Referenced by isPopPossible_files().

bool comphelper::BackupFileHelper::isPopPossible_files ( const std::set< OUString > &  rDirs,
const std::set< std::pair< OUString, OUString > > &  rFiles,
std::u16string_view  rSourceURL,
std::u16string_view  rTargetURL 
)
private
bool comphelper::BackupFileHelper::isPopPossibleExtensionInfo ( ) const
bool comphelper::BackupFileHelper::isTryDeinstallUserExtensionsPossible ( )
static

Deinstall all User Extensions (installed for User only)

Definition at line 1797 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

bool comphelper::BackupFileHelper::isTryDisableAllExtensionsPossible ( )
static

tries to iterate the extensions and to disable all of them

Definition at line 1761 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

bool comphelper::BackupFileHelper::isTryResetBundledExtensionsPossible ( )
static

Reset bundled Extensions.

Definition at line 1829 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

bool comphelper::BackupFileHelper::isTryResetCustomizationsPossible ( )
static

resets User-Customizations like Settings and UserInterface modifications

Definition at line 1947 of file backupfilehelper.cxx.

References a, comphelper::DirectoryHelper::dirExists(), comphelper::DirectoryHelper::fileExists(), getCustomizationDirNames(), getCustomizationFileNames(), and maUserConfigWorkURL.

bool comphelper::BackupFileHelper::isTryResetSharedExtensionsPossible ( )
static

Reset shared Extensions.

Definition at line 1813 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

void comphelper::BackupFileHelper::reactOnSafeMode ( bool  bSafeMode)
static
void comphelper::BackupFileHelper::setExitWasCalled ( )
static

Definition at line 1582 of file backupfilehelper.cxx.

References mbExitWasCalled.

void comphelper::BackupFileHelper::tryDeinstallUserExtensions ( )
static
void comphelper::BackupFileHelper::tryDisableAllExtensions ( )
static

Definition at line 1773 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

void comphelper::BackupFileHelper::tryDisableHWAcceleration ( )
static
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 1702 of file backupfilehelper.cxx.

References fillDirFileInfo(), getPackURL(), maDirs, maFiles, maUserConfigWorkURL, mbActive, comphelper::string::remove(), and tryPop_files().

bool comphelper::BackupFileHelper::tryPop_extensionInfo ( std::u16string_view  rTargetURL)
private

Definition at line 2309 of file backupfilehelper.cxx.

References maUserConfigWorkURL, mnNumBackups, comphelper::string::remove(), and u.

Referenced by tryPopExtensionInfo().

bool comphelper::BackupFileHelper::tryPop_file ( std::u16string_view  rSourceURL,
std::u16string_view  rTargetURL,
std::u16string_view  rName,
std::u16string_view  rExt 
)
private
bool comphelper::BackupFileHelper::tryPop_files ( const std::set< OUString > &  rDirs,
const std::set< std::pair< OUString, OUString > > &  rFiles,
std::u16string_view  rSourceURL,
const OUString &  rTargetURL 
)
private
void comphelper::BackupFileHelper::tryPopExtensionInfo ( )
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 1640 of file backupfilehelper.cxx.

References fillDirFileInfo(), getPackURL(), maDirs, maFiles, maUserConfigWorkURL, mbActive, mbSafeModeDirExists, and tryPush_Files().

bool comphelper::BackupFileHelper::tryPush_extensionInfo ( std::u16string_view  rTargetURL)
private

Definition at line 2269 of file backupfilehelper.cxx.

References mbCompress, mnNumBackups, comphelper::string::remove(), and u.

Referenced by tryPushExtensionInfo().

bool comphelper::BackupFileHelper::tryPush_file ( std::u16string_view  rSourceURL,
std::u16string_view  rTargetURL,
std::u16string_view  rName,
std::u16string_view  rExt 
)
private

Definition at line 2068 of file backupfilehelper.cxx.

References comphelper::DirectoryHelper::fileExists(), mbCompress, and mnNumBackups.

Referenced by tryPush_Files().

bool comphelper::BackupFileHelper::tryPush_Files ( const std::set< OUString > &  rDirs,
const std::set< std::pair< OUString, OUString > > &  rFiles,
std::u16string_view  rSourceURL,
const OUString &  rTargetURL 
)
private
void comphelper::BackupFileHelper::tryPushExtensionInfo ( )
void comphelper::BackupFileHelper::tryResetBundledExtensions ( )
static
void comphelper::BackupFileHelper::tryResetCustomizations ( )
static
void comphelper::BackupFileHelper::tryResetSharedExtensions ( )
static
void comphelper::BackupFileHelper::tryResetUserProfile ( )
static

resets the whole UserProfile

Definition at line 1991 of file backupfilehelper.cxx.

References comphelper::DirectoryHelper::deleteDirRecursively(), and maUserConfigWorkURL.

Member Data Documentation

std::set< OUString > comphelper::BackupFileHelper::maDirs
private

Definition at line 63 of file backupfilehelper.hxx.

Referenced by fillDirFileInfo(), isPopPossible(), tryPop(), and tryPush().

OUString comphelper::BackupFileHelper::maExt
staticprivate

Definition at line 93 of file backupfilehelper.hxx.

Referenced by fillDirFileInfo().

std::set< std::pair< OUString, OUString > > comphelper::BackupFileHelper::maFiles
private

Definition at line 64 of file backupfilehelper.hxx.

Referenced by fillDirFileInfo(), isPopPossible(), tryPop(), and tryPush().

OUString comphelper::BackupFileHelper::maInitialBaseURL
staticprivate

Definition at line 89 of file backupfilehelper.hxx.

Referenced by BackupFileHelper().

OUString comphelper::BackupFileHelper::maRegModName
staticprivate

Definition at line 92 of file backupfilehelper.hxx.

Referenced by BackupFileHelper(), and fillDirFileInfo().

OUString comphelper::BackupFileHelper::maUserConfigBaseURL
staticprivate

Definition at line 90 of file backupfilehelper.hxx.

Referenced by BackupFileHelper(), getUserProfileURL(), and reactOnSafeMode().

OUString comphelper::BackupFileHelper::maUserConfigWorkURL
staticprivate
bool comphelper::BackupFileHelper::mbActive
private
bool comphelper::BackupFileHelper::mbCompress
private

Definition at line 71 of file backupfilehelper.hxx.

Referenced by BackupFileHelper(), tryPush_extensionInfo(), and tryPush_file().

bool comphelper::BackupFileHelper::mbExitWasCalled = false
staticprivate

Definition at line 80 of file backupfilehelper.hxx.

Referenced by getExitWasCalled(), and setExitWasCalled().

bool comphelper::BackupFileHelper::mbExtensions
private
bool comphelper::BackupFileHelper::mbSafeModeDirExists = false
staticprivate

Definition at line 83 of file backupfilehelper.hxx.

Referenced by reactOnSafeMode(), tryPush(), and tryPushExtensionInfo().

sal_uInt16 comphelper::BackupFileHelper::mnMaxAllowedBackups = 10
staticprivate

Definition at line 86 of file backupfilehelper.hxx.

Referenced by BackupFileHelper().

sal_uInt16 comphelper::BackupFileHelper::mnMode
private

Definition at line 67 of file backupfilehelper.hxx.

Referenced by BackupFileHelper(), and fillDirFileInfo().

sal_uInt16 comphelper::BackupFileHelper::mnNumBackups
private

The documentation for this class was generated from the following files: