diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:09:45 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:09:45 +0200 |
commit | 88c8801298cbf6fec9cdce254c7b3cb9e066a421 (patch) | |
tree | 35a35acf48eb227bac30abc8f87ea9b1c3c57b68 /shared/privilege.h | |
parent | 3.12 (diff) | |
download | FreeFileSync-88c8801298cbf6fec9cdce254c7b3cb9e066a421.tar.gz FreeFileSync-88c8801298cbf6fec9cdce254c7b3cb9e066a421.tar.bz2 FreeFileSync-88c8801298cbf6fec9cdce254c7b3cb9e066a421.zip |
3.13
Diffstat (limited to 'shared/privilege.h')
-rw-r--r-- | shared/privilege.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/shared/privilege.h b/shared/privilege.h new file mode 100644 index 00000000..c5ec99c7 --- /dev/null +++ b/shared/privilege.h @@ -0,0 +1,59 @@ +#ifndef PRIVILEGE_H_INCLUDED +#define PRIVILEGE_H_INCLUDED + +#include <map> +#include "zstring.h" +#include "file_error.h" +#include <wx/msw/wrapwin.h> //includes "windows.h" + + +namespace ffs3 +{ +#ifdef FFS_WIN +class Privileges +{ +public: + static Privileges& getInstance(); + + void ensureActive(LPCTSTR privilege) //throw FileError() + { + if (activePrivileges.find(privilege) != activePrivileges.end()) + return; //privilege already active + + if (privilegeIsActive(privilege)) //privilege was already active before starting this tool + activePrivileges.insert(std::make_pair(privilege, false)); + else + { + setPrivilege(privilege, true); + activePrivileges.insert(std::make_pair(privilege, true)); + } + } + +private: + Privileges() {} + Privileges(Privileges&); + void operator=(Privileges&); + + ~Privileges() //clean up: deactivate all privileges that have been activated by this application + { + for (PrivBuffType::const_iterator i = activePrivileges.begin(); i != activePrivileges.end(); ++i) + try + { + if (i->second) + Privileges::setPrivilege(i->first, false); + } + catch(...) {} + } + + static bool privilegeIsActive(LPCTSTR privilege); //throw FileError() + static void setPrivilege(LPCTSTR privilege, bool enable); //throw FileError() + + typedef std::map<Zstring, bool> PrivBuffType; //bool: enabled by this application + + PrivBuffType activePrivileges; +}; +#endif +} + + +#endif // PRIVILEGE_H_INCLUDED |