Merge branch 'main' of feistymeow.org:feisty_meow
[feisty_meow.git] / nucleus / library / application / registry_config.h
1 #ifndef REGISTRY_CONFIGURATOR_CLASS
2 #define REGISTRY_CONFIGURATOR_CLASS
3
4 /*
5 *  Name   : registry_configurator                                             *
6 *  Author : Chris Koeritz                                                     *
7 **
8 * Copyright (c) 2004-$now By Author.  This program is free software; you can  *
9 * redistribute it and/or modify it under the terms of the GNU General Public  *
10 * License as published by the Free Software Foundation; either version 2 of   *
11 * the License or (at your option) any later version.  This is online at:      *
12 *     http://www.fsf.org/copyleft/gpl.html                                    *
13 * Please send any updates to: fred@gruntose.com                               *
14 */
15
16 #include <basis/contracts.h>
17 #include <configuration/configurator.h>
18 #include <filesystem/byte_filer.h>
19 #include <filesystem/filename.h>
20
21 namespace configuration {
22
23 //! Supports the configurator class interface on the windows registry.
24
25 class registry_configurator : public configurator
26 {
27 public:
28   //! the hives are major partitions of the registry.
29   enum registry_hives {
30     hkey_classes_root,
31     hkey_current_user,
32     hkey_local_machine,
33     hkey_users,
34     hkey_current_config,
35     // abbreviations for the above sections...
36     HKCR = hkey_classes_root,
37     HKCU = hkey_current_user,
38     HKLM = hkey_local_machine,
39     HKU = hkey_users,
40     HKCC = hkey_current_config
41   };
42
43   registry_configurator(registry_hives hive, treatment_of_defaults behavior);
44     //!< creates a registry_configurator that stores entries into the "hive".
45     /*!< applies the "behavior" to items that are not found. */
46
47   virtual ~registry_configurator();
48
49   DEFINE_CLASS_NAME("registry_configurator");
50
51   virtual bool get(const basis::astring &section, const basis::astring &entry,
52           basis::astring &found);
53     //!< implements the configurator retrieval function.
54     /*!< note that for registry based retrieval, an empty "entry" is allowed,
55     and that specifies the default item in the "section". */
56
57   virtual bool section_exists(const basis::astring &section);
58     //!< returns true if the "section" was found in the file.
59
60   virtual bool put(const basis::astring &section, const basis::astring &entry,
61           const basis::astring &to_store);
62     //!< implements the configurator storage function.
63     /*!< put interprets an empty string for "entry" as pointing at the
64     default item in the "section". */
65
66   virtual bool delete_section(const basis::astring &section);
67     //!< removes the entire "section" specified.
68
69   virtual bool delete_entry(const basis::astring &section, const basis::astring &entry);
70     //!< removes the entry specified by the "section" and "entry" name.
71
72   virtual bool get_section(const basis::astring &section, structures::string_table &info);
73     //!< reads the entire "section" into a table called "info".
74     /*!< on win-9x, this will fail if the section's data exceeds 32K. */
75
76   virtual bool put_section(const basis::astring &section, const structures::string_table &info);
77     //!< writes a table called "info" into the "section" in the INI file.
78     /*!< any existing data for that section is wiped out.  on win-9x, this will
79     fail if the section's data exceeds 32K. */
80
81   void *translate_hive(registry_hives hive);
82     //!< translates from our enum to the windows specific type for hives.
83
84   basis::astring fix_section(const basis::astring &section);
85     //!< repairs malformed section names.
86     /*!< translates a section name that might use forward slashes into the
87     form required for windows that uses backslashes. */
88
89 private:
90   registry_hives _hive;  //!< which hive our entries are stored in.
91
92   // not to be called.
93   registry_configurator(const registry_configurator &);
94   registry_configurator &operator =(const registry_configurator &);
95
96   static const basis::astring &reg_str_fake_default();
97 };
98
99 }
100
101 #endif
102