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  // Writing
103  void CreateKey(HKEY hParent = 0);
104  void WriteDWord(uint32_t iVal);
105  void WriteString(const char *szStr);
106 
107 };
108 
109 // config reader
110 class StdCompilerConfigRead : public StdCompiler
111 {
112 public:
113 
114  // Construct with root key
115  StdCompilerConfigRead(HKEY hRoot, const char *szPath);
116  ~StdCompilerConfigRead();
117 
118  // Properties
119  virtual bool isDeserializer() override { return true; }
120  virtual bool hasNaming() override { return true; }
121  virtual bool isRegistry() override { return true; }
122 
123  // Naming
124  virtual bool Name(const char *szName) override;
125  virtual void NameEnd(bool fBreak = false) override;
126  virtual bool FollowName(const char *szName) override;
127 
128  // Separators
129  virtual bool Separator(Sep eSep) override;
130 
131  // Data writers
132  virtual void DWord(int32_t &rInt) override;
133  virtual void DWord(uint32_t &rInt) override;
134  virtual void Word(int16_t &rShort) override;
135  virtual void Word(uint16_t &rShort) override;
136  virtual void Byte(int8_t &rByte) override;
137  virtual void Byte(uint8_t &rByte) override;
138  virtual void Boolean(bool &rBool) override;
139  virtual void Character(char &rChar) override;
140  virtual void String(char *szString, size_t iMaxLength, RawCompileType eType = RCT_Escaped) override;
141  virtual void String(char **pszString, RawCompileType eType = RCT_Escaped) override;
142  virtual void String(std::string &str, RawCompileType type = RCT_Escaped) override;
143  virtual void Raw(void *pData, size_t iSize, RawCompileType eType = RCT_Escaped) override;
144 
145  // Passes
146  virtual void Begin() override;
147  virtual void End() override;
148 
149 private:
150 
151  // Key stack
152  int iDepth;
153  struct Key
154  {
155  StdCopyStrBuf Name;
156  StdCopyStrBuf LastChildName; // last occuring child name to increase subindex if needed
157  int32_t subindex; // incremented when multiple keys of the same name are encountered
158  HKEY Handle; // for keys only
159  Key *Parent;
160  bool Virtual;
161  DWORD Type; // for values only
162  } *pKey;
163 
164  // Reading
165  uint32_t ReadDWord();
166  StdStrBuf ReadString();
167 
168 };
169 
170 #endif
171 
172 #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