File: registry_key_backup.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (48 lines) | stat: -rw-r--r-- 1,801 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_INSTALLER_UTIL_REGISTRY_KEY_BACKUP_H_
#define CHROME_INSTALLER_UTIL_REGISTRY_KEY_BACKUP_H_

#include <windows.h>

#include <memory>

// A container for a registry key, its values, and its subkeys.  We don't use
// more obvious methods for various reasons:
// - RegCopyTree isn't supported pre-Vista, so we'd have to do something
//   different for XP anyway.
// - SHCopyKey can't copy subkeys into a volatile destination, so we'd have to
//   worry about polluting the registry.
// We don't persist security attributes since we only delete keys that we own,
// and we don't set custom attributes on them anyway.
class RegistryKeyBackup {
 public:
  RegistryKeyBackup();

  RegistryKeyBackup(const RegistryKeyBackup&) = delete;
  RegistryKeyBackup& operator=(const RegistryKeyBackup&) = delete;

  ~RegistryKeyBackup();

  // Recursively reads |key_path| into this instance.  Backing up a non-existent
  // key is valid.  Returns true if the backup was successful; false otherwise,
  // in which case the state of this instance is not modified.
  bool Initialize(HKEY root, const wchar_t* key_path, REGSAM wow64_acccess);

  // Writes the contents of this instance into |key|.  The contents of
  // |key_path| are not modified If this instance is uninitialized or was
  // initialized from a non-existent key.
  bool WriteTo(HKEY root, const wchar_t* key_path, REGSAM wow64_acccess) const;

  void swap(RegistryKeyBackup& other) { key_data_.swap(other.key_data_); }

 private:
  class KeyData;

  // The values and subkeys of the backed-up key.
  std::unique_ptr<KeyData> key_data_;
};

#endif  // CHROME_INSTALLER_UTIL_REGISTRY_KEY_BACKUP_H_