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

◆ BackupFileHelper()

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.

Member Function Documentation

◆ fillDirFileInfo()

void comphelper::BackupFileHelper::fillDirFileInfo ( )
private

◆ getCustomizationDirNames()

const std::vector< OUString > & comphelper::BackupFileHelper::getCustomizationDirNames ( )
staticprivate

◆ getCustomizationFileNames()

const std::vector< OUString > & comphelper::BackupFileHelper::getCustomizationFileNames ( )
staticprivate

◆ getExitWasCalled()

bool comphelper::BackupFileHelper::getExitWasCalled ( )
static

Definition at line 1576 of file backupfilehelper.cxx.

References mbExitWasCalled.

◆ getInitialBaseURL()

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

◆ getPackURL()

OUString comphelper::BackupFileHelper::getPackURL ( )
staticprivate

◆ getSafeModeName()

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

Definition at line 1513 of file backupfilehelper.cxx.

Referenced by getInitialBaseURL(), and reactOnSafeMode().

◆ getUserProfileURL()

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

Return the profile url.

Definition at line 1989 of file backupfilehelper.cxx.

References maUserConfigBaseURL.

◆ getUserProfileWorkURL()

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

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

Definition at line 1994 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

◆ isPopPossible()

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

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

◆ isPopPossible_extensionInfo()

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

Definition at line 2288 of file backupfilehelper.cxx.

References u.

Referenced by isPopPossibleExtensionInfo().

◆ isPopPossible_file()

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

References comphelper::DirectoryHelper::fileExists().

Referenced by isPopPossible_files().

◆ 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

◆ isPopPossibleExtensionInfo()

bool comphelper::BackupFileHelper::isPopPossibleExtensionInfo ( ) const

◆ isTryDeinstallUserExtensionsPossible()

bool comphelper::BackupFileHelper::isTryDeinstallUserExtensionsPossible ( )
static

Deinstall all User Extensions (installed for User only)

Definition at line 1786 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

◆ isTryDisableAllExtensionsPossible()

bool comphelper::BackupFileHelper::isTryDisableAllExtensionsPossible ( )
static

tries to iterate the extensions and to disable all of them

Definition at line 1750 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

◆ isTryResetBundledExtensionsPossible()

bool comphelper::BackupFileHelper::isTryResetBundledExtensionsPossible ( )
static

Reset bundled Extensions.

Definition at line 1818 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

◆ isTryResetCustomizationsPossible()

bool comphelper::BackupFileHelper::isTryResetCustomizationsPossible ( )
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.

◆ isTryResetSharedExtensionsPossible()

bool comphelper::BackupFileHelper::isTryResetSharedExtensionsPossible ( )
static

Reset shared Extensions.

Definition at line 1802 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

◆ reactOnSafeMode()

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

◆ setExitWasCalled()

void comphelper::BackupFileHelper::setExitWasCalled ( )
static

Definition at line 1571 of file backupfilehelper.cxx.

References mbExitWasCalled.

◆ tryDeinstallUserExtensions()

void comphelper::BackupFileHelper::tryDeinstallUserExtensions ( )
static

◆ tryDisableAllExtensions()

void comphelper::BackupFileHelper::tryDisableAllExtensions ( )
static

Definition at line 1762 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

◆ tryDisableHWAcceleration()

void comphelper::BackupFileHelper::tryDisableHWAcceleration ( )
static

◆ tryPop()

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().

◆ tryPop_extensionInfo()

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

Definition at line 2299 of file backupfilehelper.cxx.

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

Referenced by tryPopExtensionInfo().

◆ tryPop_file()

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

◆ tryPop_files()

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

◆ tryPopExtensionInfo()

void comphelper::BackupFileHelper::tryPopExtensionInfo ( )

◆ tryPush()

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().

◆ tryPush_extensionInfo()

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

Definition at line 2259 of file backupfilehelper.cxx.

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

Referenced by tryPushExtensionInfo().

◆ tryPush_file()

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

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

Referenced by tryPush_Files().

◆ 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

◆ tryPushExtensionInfo()

void comphelper::BackupFileHelper::tryPushExtensionInfo ( )

◆ tryResetBundledExtensions()

void comphelper::BackupFileHelper::tryResetBundledExtensions ( )
static

◆ tryResetCustomizations()

void comphelper::BackupFileHelper::tryResetCustomizations ( )
static

◆ tryResetSharedExtensions()

void comphelper::BackupFileHelper::tryResetSharedExtensions ( )
static

◆ tryResetUserProfile()

void comphelper::BackupFileHelper::tryResetUserProfile ( )
static

resets the whole UserProfile

Definition at line 1983 of file backupfilehelper.cxx.

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

Member Data Documentation

◆ maDirs

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

Definition at line 63 of file backupfilehelper.hxx.

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

◆ maExt

OUString comphelper::BackupFileHelper::maExt
staticprivate

Definition at line 93 of file backupfilehelper.hxx.

Referenced by fillDirFileInfo(), and getInitialBaseURL().

◆ maFiles

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().

◆ maInitialBaseURL

OUString comphelper::BackupFileHelper::maInitialBaseURL
staticprivate

Definition at line 89 of file backupfilehelper.hxx.

Referenced by BackupFileHelper(), and getInitialBaseURL().

◆ maRegModName

OUString comphelper::BackupFileHelper::maRegModName
staticprivate

Definition at line 92 of file backupfilehelper.hxx.

Referenced by BackupFileHelper(), fillDirFileInfo(), and getInitialBaseURL().

◆ maUserConfigBaseURL

OUString comphelper::BackupFileHelper::maUserConfigBaseURL
staticprivate

◆ maUserConfigWorkURL

OUString comphelper::BackupFileHelper::maUserConfigWorkURL
staticprivate

◆ mbActive

bool comphelper::BackupFileHelper::mbActive
private

◆ mbCompress

bool comphelper::BackupFileHelper::mbCompress
private

Definition at line 71 of file backupfilehelper.hxx.

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

◆ mbExitWasCalled

bool comphelper::BackupFileHelper::mbExitWasCalled = false
staticprivate

Definition at line 80 of file backupfilehelper.hxx.

Referenced by getExitWasCalled(), and setExitWasCalled().

◆ mbExtensions

bool comphelper::BackupFileHelper::mbExtensions
private

◆ mbSafeModeDirExists

bool comphelper::BackupFileHelper::mbSafeModeDirExists = false
staticprivate

◆ mnMaxAllowedBackups

sal_uInt16 comphelper::BackupFileHelper::mnMaxAllowedBackups = 10
staticprivate

Definition at line 86 of file backupfilehelper.hxx.

Referenced by BackupFileHelper().

◆ mnMode

sal_uInt16 comphelper::BackupFileHelper::mnMode
private

Definition at line 67 of file backupfilehelper.hxx.

Referenced by BackupFileHelper(), and fillDirFileInfo().

◆ mnNumBackups

sal_uInt16 comphelper::BackupFileHelper::mnNumBackups
private

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