OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
StdRegistry.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Some wrappers for easier access to the Windows registry */
19 
20 #ifndef INC_STDREGISTRY
21 #define INC_STDREGISTRY
22 
23 #ifdef _WIN32
24 #include "lib/StdCompiler.h"
26 
27 StdCopyStrBuf GetRegistryString(const char *szSubKey, const char *szValueName);
28 bool SetRegistryString(const char *szSubKey, const char *szValueName, const char *szValue);
29 
30 bool SetRegShell(const wchar_t *szClassName,
31  const wchar_t *szShellName,
32  const wchar_t *szShellCaption,
33  const wchar_t *szCommand,
34  bool fMakeDefault = false);
35 
36 bool RemoveRegShell(const char *szClassName,
37  const char *szShellName);
38 
39 bool StoreWindowPosition(HWND hwnd,
40  const char *szWindowName,
41  const char *szSubKey,
42  bool fStoreSize = true);
43 
44 bool RestoreWindowPosition(HWND hwnd,
45  const char *szWindowName,
46  const char *szSubKey,
47  bool fHidden = false);
48 
49 // config writer
50 class StdCompilerConfigWrite : public StdCompiler
51 {
52 public:
53 
54  // Construct with root key
55  StdCompilerConfigWrite(HKEY hRoot, const char *szPath);
56  ~StdCompilerConfigWrite();
57 
58  // Properties
59  virtual bool hasNaming() override { return true; }
60  virtual bool isRegistry() override { return true; }
61 
62  // Naming
63  virtual bool Name(const char *szName) override;
64  virtual void NameEnd(bool fBreak = false) override;
65  virtual bool FollowName(const char *szName) override;
66  virtual bool Default(const char *szName) override;
67 
68  // Separators
69  virtual bool Separator(Sep eSep) override;
70 
71  // Data writers
72  virtual void DWord(int32_t &rInt) override;
73  virtual void DWord(uint32_t &rInt) override;
74  virtual void Word(int16_t &rShort) override;
75  virtual void Word(uint16_t &rShort) override;
76  virtual void Byte(int8_t &rByte) override;
77  virtual void Byte(uint8_t &rByte) override;
78  virtual void Boolean(bool &rBool) override;
79  virtual void Character(char &rChar) override;
80  virtual void String(char *szString, size_t iMaxLength, RawCompileType eType = RCT_Escaped) override;
81  virtual void String(char **pszString, RawCompileType eType = RCT_Escaped) override;
82  virtual void String(std::string &str, RawCompileType type = RCT_Escaped) override;
83  virtual void Raw(void *pData, size_t iSize, RawCompileType eType = RCT_Escaped) override;
84 
85  // Passes
86  virtual void Begin() override;
87  virtual void End() override;
88 
89 private:
90 
91  // Key stack
92  int iDepth;
93  struct Key
94  {
95  StdCopyStrBuf Name;
96  StdCopyStrBuf LastChildName; // last occuring child name to increase subindex if needed
97  int32_t subindex; // incremented when multiple keys of the same name are encountered
98  HKEY Handle;
99  Key *Parent;
100  } *pKey;
101 
102  // Current string for writing with separators
103  std::string last_written_string;
104 
105  // Writing
106  void CreateKey(HKEY hParent = 0);
107  void WriteDWord(uint32_t iVal);
108  void WriteString(const char *szStr);
109 
110 };
111 
112 // config reader
113 class StdCompilerConfigRead : public StdCompiler
114 {
115 public:
116 
117  // Construct with root key
118  StdCompilerConfigRead(HKEY hRoot, const char *szPath);
119  ~StdCompilerConfigRead();
120 
121  // Properties
122  virtual bool isDeserializer() override { return true; }
123  virtual bool hasNaming() override { return true; }
124  virtual bool isRegistry() override { return true; }
125 
126  // Naming
127  virtual bool Name(const char *szName) override;
128  virtual void NameEnd(bool fBreak = false) override;
129  virtual bool FollowName(const char *szName) override;
130 
131  // Separators
132  virtual bool Separator(Sep eSep) override;
133 
134  // Data writers
135  virtual void DWord(int32_t &rInt) override;
136  virtual void DWord(uint32_t &rInt) override;
137  virtual void Word(int16_t &rShort) override;
138  virtual void Word(uint16_t &rShort) override;
139  virtual void Byte(int8_t &rByte) override;
140  virtual void Byte(uint8_t &rByte) override;
141  virtual void Boolean(bool &rBool) override;
142  virtual void Character(char &rChar) override;
143  virtual void String(char *szString, size_t iMaxLength, RawCompileType eType = RCT_Escaped) override;
144  virtual void String(char **pszString, RawCompileType eType = RCT_Escaped) override;
145  virtual void String(std::string &str, RawCompileType type = RCT_Escaped) override;
146  virtual void Raw(void *pData, size_t iSize, RawCompileType eType = RCT_Escaped) override;
147 
148  // Passes
149  virtual void Begin() override;
150  virtual void End() override;
151 
152 private:
153 
154  // Key stack
155  int iDepth;
156  struct Key
157  {
158  StdCopyStrBuf Name;
159  StdCopyStrBuf LastChildName; // last occuring child name to increase subindex if needed
160  int32_t subindex; // incremented when multiple keys of the same name are encountered
161  HKEY Handle; // for keys only
162  Key *Parent;
163  bool Virtual;
164  DWORD Type; // for values only
165  } *pKey;
166 
167  // Current string for reading with separators
168  std::string last_read_string;
169  bool has_read_string = false;
170  bool has_separator_mismatch = false;
171 
172  // Reading
173  uint32_t ReadDWord();
174  void ReadString();
175  void ResetLastString();
176 
177 };
178 
179 #endif
180 
181 #endif // INC_STDREGISTRY
virtual void End()
Definition: StdCompiler.h:166
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:129
virtual bool hasNaming()
Definition: StdCompiler.h:68
virtual void Boolean(bool &rBool)=0
virtual bool Name(const char *szName)
Definition: StdCompiler.h:87
virtual void Raw(void *pData, size_t iSize, RawCompileType eType=RCT_Escaped)=0
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped)=0
virtual void DWord(int32_t &rInt)=0
virtual bool isDeserializer()
Definition: StdCompiler.h:63
virtual void Character(char &rChar)=0
virtual void Begin()
Definition: StdCompiler.h:164
virtual bool Default(const char *szName)
Definition: StdCompiler.h:98
virtual void Word(int16_t &rShort)=0
virtual bool FollowName(const char *szName)
Definition: StdCompiler.h:94
uint32_t DWORD
virtual void NameEnd(bool fBreak=false)
Definition: StdCompiler.h:88
virtual void Byte(int8_t &rByte)=0
int iSize
Definition: TstC4NetIO.cpp:35
virtual bool isRegistry()
Definition: StdCompiler.h:75