123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- #ifndef BASE_WIN_REGISTRY_H_
- #define BASE_WIN_REGISTRY_H_
- #include <stdint.h>
- #include <memory>
- #include <string>
- #include <vector>
- #include "base/base_export.h"
- #include "base/callback.h"
- #include "base/macros.h"
- #include "base/win/object_watcher.h"
- #include "base/win/scoped_handle.h"
- #include "base/win/windows_types.h"
- namespace base {
- namespace win {
- class BASE_EXPORT RegKey {
- public:
-
- using ChangeCallback = OnceCallback<void()>;
- RegKey();
- explicit RegKey(HKEY key);
- RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access);
- RegKey(RegKey&& other) noexcept;
- RegKey& operator=(RegKey&& other);
- ~RegKey();
- LONG Create(HKEY rootkey, const wchar_t* subkey, REGSAM access);
- LONG CreateWithDisposition(HKEY rootkey,
- const wchar_t* subkey,
- DWORD* disposition,
- REGSAM access);
-
- LONG CreateKey(const wchar_t* name, REGSAM access);
-
- LONG Open(HKEY rootkey, const wchar_t* subkey, REGSAM access);
-
- LONG OpenKey(const wchar_t* relative_key_name, REGSAM access);
-
- void Close();
-
- void Set(HKEY key);
-
- HKEY Take();
-
-
- bool HasValue(const wchar_t* value_name) const;
-
-
- DWORD GetValueCount() const;
-
- LONG GetValueNameAt(int index, std::wstring* name) const;
-
- bool Valid() const { return key_ != nullptr; }
-
-
- LONG DeleteKey(const wchar_t* name);
-
-
- LONG DeleteEmptyKey(const wchar_t* name);
-
- LONG DeleteValue(const wchar_t* name);
-
-
-
- LONG ReadValueDW(const wchar_t* name, DWORD* out_value) const;
-
-
- LONG ReadInt64(const wchar_t* name, int64_t* out_value) const;
-
-
- LONG ReadValue(const wchar_t* name, std::wstring* out_value) const;
-
-
-
- LONG ReadValues(const wchar_t* name, std::vector<std::wstring>* values);
-
-
- LONG ReadValue(const wchar_t* name,
- void* data,
- DWORD* dsize,
- DWORD* dtype) const;
-
-
- LONG WriteValue(const wchar_t* name, DWORD in_value);
-
- LONG WriteValue(const wchar_t* name, const wchar_t* in_value);
-
- LONG WriteValue(const wchar_t* name,
- const void* data,
- DWORD dsize,
- DWORD dtype);
-
-
-
-
-
- bool StartWatching(ChangeCallback callback);
- HKEY Handle() const { return key_; }
- private:
- class Watcher;
-
- static LONG RegDelRecurse(HKEY root_key, const wchar_t* name, REGSAM access);
- HKEY key_ = nullptr;
- REGSAM wow64access_ = 0;
- std::unique_ptr<Watcher> key_watcher_;
- DISALLOW_COPY_AND_ASSIGN(RegKey);
- };
- class BASE_EXPORT RegistryValueIterator {
- public:
-
- RegistryValueIterator(HKEY root_key, const wchar_t* folder_key);
-
-
-
-
-
- RegistryValueIterator(HKEY root_key,
- const wchar_t* folder_key,
- REGSAM wow64access);
- ~RegistryValueIterator();
- DWORD ValueCount() const;
-
- bool Valid() const;
-
- void operator++();
- const wchar_t* Name() const { return name_.c_str(); }
- const wchar_t* Value() const { return value_.data(); }
-
- DWORD ValueSize() const { return value_size_; }
- DWORD Type() const { return type_; }
- int Index() const { return index_; }
- private:
-
- bool Read();
- void Initialize(HKEY root_key, const wchar_t* folder_key, REGSAM wow64access);
-
- HKEY key_;
-
- int index_;
-
- std::wstring name_;
- std::vector<wchar_t> value_;
- DWORD value_size_;
- DWORD type_;
- DISALLOW_COPY_AND_ASSIGN(RegistryValueIterator);
- };
- class BASE_EXPORT RegistryKeyIterator {
- public:
-
- RegistryKeyIterator(HKEY root_key, const wchar_t* folder_key);
-
-
-
-
-
- RegistryKeyIterator(HKEY root_key,
- const wchar_t* folder_key,
- REGSAM wow64access);
- ~RegistryKeyIterator();
- DWORD SubkeyCount() const;
-
- bool Valid() const;
-
- void operator++();
- const wchar_t* Name() const { return name_; }
- int Index() const { return index_; }
- private:
-
- bool Read();
- void Initialize(HKEY root_key, const wchar_t* folder_key, REGSAM wow64access);
-
- HKEY key_;
-
- int index_;
- wchar_t name_[MAX_PATH];
- DISALLOW_COPY_AND_ASSIGN(RegistryKeyIterator);
- };
- }
- }
- #endif
|