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, const OUString &rSourceURL, const OUString &rTargetURL)
 
bool tryPush_file (const OUString &rSourceURL, const OUString &rTargetURL, const OUString &rName, const OUString &rExt)
 
bool isPopPossible_files (const std::set< OUString > &rDirs, const std::set< std::pair< OUString, OUString > > &rFiles, const OUString &rSourceURL, const OUString &rTargetURL)
 
bool tryPop_files (const std::set< OUString > &rDirs, const std::set< std::pair< OUString, OUString > > &rFiles, const OUString &rSourceURL, const OUString &rTargetURL)
 
bool tryPop_file (const OUString &rSourceURL, const OUString &rTargetURL, const OUString &rName, const OUString &rExt)
 
bool tryPush_extensionInfo (const OUString &rTargetURL)
 
bool tryPop_extensionInfo (const OUString &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 (const OUString &rSourceURL, const OUString &rTargetURL, const OUString &rName, const OUString &rExt)
 
static bool isPopPossible_extensionInfo (const OUString &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 58 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 1729 of file backupfilehelper.cxx.

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

Member Function Documentation

void comphelper::BackupFileHelper::fillDirFileInfo ( )
private

Definition at line 2615 of file backupfilehelper.cxx.

References maDirs, maExt, maFiles, maRegModName, maUserConfigWorkURL, and mnMode.

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

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

Definition at line 1787 of file backupfilehelper.cxx.

References mbExitWasCalled.

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

Definition at line 1672 of file backupfilehelper.cxx.

References void().

Referenced by BackupFileHelper(), and reactOnSafeMode().

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

Definition at line 1722 of file backupfilehelper.cxx.

Referenced by reactOnSafeMode().

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

Return the profile url.

Definition at line 2194 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 2199 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 1877 of file backupfilehelper.cxx.

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

bool comphelper::BackupFileHelper::isPopPossible_extensionInfo ( const OUString &  rTargetURL)
staticprivate

Definition at line 2495 of file backupfilehelper.cxx.

Referenced by isPopPossibleExtensionInfo().

bool comphelper::BackupFileHelper::isPopPossible_file ( const OUString &  rSourceURL,
const OUString &  rTargetURL,
const OUString &  rName,
const OUString &  rExt 
)
staticprivate

Definition at line 2340 of file backupfilehelper.cxx.

References fileExists().

Referenced by isPopPossible_files().

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

Definition at line 2295 of file backupfilehelper.cxx.

References isPopPossible_file().

Referenced by isPopPossible().

bool comphelper::BackupFileHelper::isPopPossibleExtensionInfo ( ) const
bool comphelper::BackupFileHelper::isTryDeinstallUserExtensionsPossible ( )
static

Deinstall all User Extensions (installed for User only)

Definition at line 1997 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 1961 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

bool comphelper::BackupFileHelper::isTryResetBundledExtensionsPossible ( )
static

Reset bundled Extensions.

Definition at line 2029 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

bool comphelper::BackupFileHelper::isTryResetCustomizationsPossible ( )
static

resets User-Customizations like Settings and UserInterface modifications

Definition at line 2144 of file backupfilehelper.cxx.

References fileExists(), getCustomizationDirNames(), getCustomizationFileNames(), and maUserConfigWorkURL.

bool comphelper::BackupFileHelper::isTryResetSharedExtensionsPossible ( )
static

Reset shared Extensions.

Definition at line 2013 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

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

Definition at line 1782 of file backupfilehelper.cxx.

References mbExitWasCalled.

void comphelper::BackupFileHelper::tryDeinstallUserExtensions ( )
static

Definition at line 2007 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

void comphelper::BackupFileHelper::tryDisableAllExtensions ( )
static

Definition at line 1973 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 1902 of file backupfilehelper.cxx.

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

bool comphelper::BackupFileHelper::tryPop_extensionInfo ( const OUString &  rTargetURL)
private
bool comphelper::BackupFileHelper::tryPop_file ( const OUString &  rSourceURL,
const OUString &  rTargetURL,
const OUString &  rName,
const OUString &  rExt 
)
private

Definition at line 2413 of file backupfilehelper.cxx.

References fileExists(), mnNumBackups, and comphelper::string::remove().

Referenced by tryPop_files().

bool comphelper::BackupFileHelper::tryPop_files ( const std::set< OUString > &  rDirs,
const std::set< std::pair< OUString, OUString > > &  rFiles,
const OUString &  rSourceURL,
const OUString &  rTargetURL 
)
private

Definition at line 2362 of file backupfilehelper.cxx.

References comphelper::string::remove(), and tryPop_file().

Referenced by tryPop().

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

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

bool comphelper::BackupFileHelper::tryPush_extensionInfo ( const OUString &  rTargetURL)
private

Definition at line 2466 of file backupfilehelper.cxx.

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

Referenced by tryPushExtensionInfo().

bool comphelper::BackupFileHelper::tryPush_file ( const OUString &  rSourceURL,
const OUString &  rTargetURL,
const OUString &  rName,
const OUString &  rExt 
)
private

Definition at line 2265 of file backupfilehelper.cxx.

References 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,
const OUString &  rSourceURL,
const OUString &  rTargetURL 
)
private

Definition at line 2213 of file backupfilehelper.cxx.

References comphelper::string::remove(), and tryPush_file().

Referenced by tryPush().

void comphelper::BackupFileHelper::tryPushExtensionInfo ( )
void comphelper::BackupFileHelper::tryResetBundledExtensions ( )
static

Definition at line 2039 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

void comphelper::BackupFileHelper::tryResetCustomizations ( )
static
void comphelper::BackupFileHelper::tryResetSharedExtensions ( )
static

Definition at line 2023 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

void comphelper::BackupFileHelper::tryResetUserProfile ( )
static

resets the whole UserProfile

Definition at line 2188 of file backupfilehelper.cxx.

References maUserConfigWorkURL.

Member Data Documentation

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

Definition at line 62 of file backupfilehelper.hxx.

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

OUString comphelper::BackupFileHelper::maExt
staticprivate

Definition at line 92 of file backupfilehelper.hxx.

Referenced by fillDirFileInfo().

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

Definition at line 63 of file backupfilehelper.hxx.

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

OUString comphelper::BackupFileHelper::maInitialBaseURL
staticprivate

Definition at line 88 of file backupfilehelper.hxx.

Referenced by BackupFileHelper().

OUString comphelper::BackupFileHelper::maRegModName
staticprivate

Definition at line 91 of file backupfilehelper.hxx.

Referenced by BackupFileHelper(), and fillDirFileInfo().

OUString comphelper::BackupFileHelper::maUserConfigBaseURL
staticprivate

Definition at line 89 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 70 of file backupfilehelper.hxx.

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

bool comphelper::BackupFileHelper::mbExitWasCalled = false
staticprivate

Definition at line 79 of file backupfilehelper.hxx.

Referenced by getExitWasCalled(), and setExitWasCalled().

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

Definition at line 82 of file backupfilehelper.hxx.

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

sal_uInt16 comphelper::BackupFileHelper::mnMaxAllowedBackups = 10
staticprivate

Definition at line 85 of file backupfilehelper.hxx.

Referenced by BackupFileHelper().

sal_uInt16 comphelper::BackupFileHelper::mnMode
private

Definition at line 66 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: