2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Copyright (c) 1998-2000, Matthes Bender
|
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
|
2016-04-03 18:18:29 +00:00
|
|
|
* Copyright (c) 2009-2016, The OpenClonk Team and contributors
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Distributed under the terms of the ISC license; see accompanying file
|
|
|
|
* "COPYING" for details.
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
|
|
|
|
* See accompanying file "TRADEMARK" for details.
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* To redistribute this file separately, substitute the full license texts
|
|
|
|
* for the above references.
|
2009-05-08 13:28:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Some wrappers for easier access to the Windows registry */
|
|
|
|
|
|
|
|
#ifndef INC_STDREGISTRY
|
|
|
|
#define INC_STDREGISTRY
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2016-04-03 18:07:56 +00:00
|
|
|
#include "lib/StdCompiler.h"
|
|
|
|
#include "platform/C4windowswrapper.h"
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2011-07-27 15:30:56 +00:00
|
|
|
StdCopyStrBuf GetRegistryString(const char *szSubKey, const char *szValueName);
|
2009-08-15 18:50:32 +00:00
|
|
|
bool SetRegistryString(const char *szSubKey, const char *szValueName, const char *szValue);
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2011-04-02 16:48:01 +00:00
|
|
|
bool SetRegShell(const wchar_t *szClassName,
|
|
|
|
const wchar_t *szShellName,
|
|
|
|
const wchar_t *szShellCaption,
|
|
|
|
const wchar_t *szCommand,
|
2010-03-28 17:58:21 +00:00
|
|
|
bool fMakeDefault = false);
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool RemoveRegShell(const char *szClassName,
|
2010-03-28 17:58:21 +00:00
|
|
|
const char *szShellName);
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool StoreWindowPosition(HWND hwnd,
|
2010-03-28 17:58:21 +00:00
|
|
|
const char *szWindowName,
|
|
|
|
const char *szSubKey,
|
|
|
|
bool fStoreSize = true);
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool RestoreWindowPosition(HWND hwnd,
|
2010-03-28 17:58:21 +00:00
|
|
|
const char *szWindowName,
|
|
|
|
const char *szSubKey,
|
|
|
|
bool fHidden = false);
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// config writer
|
|
|
|
class StdCompilerConfigWrite : public StdCompiler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Construct with root key
|
|
|
|
StdCompilerConfigWrite(HKEY hRoot, const char *szPath);
|
2017-05-07 11:50:00 +00:00
|
|
|
~StdCompilerConfigWrite() override;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-27 16:05:02 +00:00
|
|
|
// Properties
|
2017-05-07 11:50:00 +00:00
|
|
|
bool hasNaming() override { return true; }
|
|
|
|
bool isRegistry() override { return true; }
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-27 16:05:02 +00:00
|
|
|
// Naming
|
2017-05-07 11:50:00 +00:00
|
|
|
bool Name(const char *szName) override;
|
|
|
|
void NameEnd(bool fBreak = false) override;
|
|
|
|
bool FollowName(const char *szName) override;
|
|
|
|
bool Default(const char *szName) override;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-04-01 21:08:06 +00:00
|
|
|
// Separators
|
2017-05-07 11:50:00 +00:00
|
|
|
bool Separator(Sep eSep) override;
|
2010-03-27 16:05:02 +00:00
|
|
|
|
|
|
|
// Data writers
|
2017-05-07 11:50:00 +00:00
|
|
|
void DWord(int32_t &rInt) override;
|
|
|
|
void DWord(uint32_t &rInt) override;
|
|
|
|
void Word(int16_t &rShort) override;
|
|
|
|
void Word(uint16_t &rShort) override;
|
|
|
|
void Byte(int8_t &rByte) override;
|
|
|
|
void Byte(uint8_t &rByte) override;
|
|
|
|
void Boolean(bool &rBool) override;
|
|
|
|
void Character(char &rChar) override;
|
|
|
|
void String(char *szString, size_t iMaxLength, RawCompileType eType = RCT_Escaped) override;
|
|
|
|
void String(char **pszString, RawCompileType eType = RCT_Escaped) override;
|
|
|
|
void String(std::string &str, RawCompileType type = RCT_Escaped) override;
|
|
|
|
void Raw(void *pData, size_t iSize, RawCompileType eType = RCT_Escaped) override;
|
2010-03-27 16:05:02 +00:00
|
|
|
|
|
|
|
// Passes
|
2017-05-07 11:50:00 +00:00
|
|
|
void Begin() override;
|
|
|
|
void End() override;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// Key stack
|
|
|
|
int iDepth;
|
2010-03-28 17:58:21 +00:00
|
|
|
struct Key
|
|
|
|
{
|
2014-03-19 13:15:27 +00:00
|
|
|
StdCopyStrBuf Name;
|
|
|
|
StdCopyStrBuf LastChildName; // last occuring child name to increase subindex if needed
|
2011-03-30 20:11:47 +00:00
|
|
|
int32_t subindex; // incremented when multiple keys of the same name are encountered
|
2009-05-08 13:28:41 +00:00
|
|
|
HKEY Handle;
|
|
|
|
Key *Parent;
|
|
|
|
} *pKey;
|
|
|
|
|
2017-03-27 00:55:27 +00:00
|
|
|
// Current string for writing with separators
|
|
|
|
std::string last_written_string;
|
|
|
|
|
2009-05-08 13:28:41 +00:00
|
|
|
// Writing
|
2017-05-07 11:50:00 +00:00
|
|
|
void CreateKey(HKEY hParent = nullptr);
|
2009-05-08 13:28:41 +00:00
|
|
|
void WriteDWord(uint32_t iVal);
|
|
|
|
void WriteString(const char *szStr);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// config reader
|
|
|
|
class StdCompilerConfigRead : public StdCompiler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Construct with root key
|
|
|
|
StdCompilerConfigRead(HKEY hRoot, const char *szPath);
|
2017-05-07 11:50:00 +00:00
|
|
|
~StdCompilerConfigRead() override;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-27 16:05:02 +00:00
|
|
|
// Properties
|
2017-05-07 11:50:00 +00:00
|
|
|
bool isDeserializer() override { return true; }
|
|
|
|
bool hasNaming() override { return true; }
|
|
|
|
bool isRegistry() override { return true; }
|
2010-03-27 16:05:02 +00:00
|
|
|
|
|
|
|
// Naming
|
2017-05-07 11:50:00 +00:00
|
|
|
bool Name(const char *szName) override;
|
|
|
|
void NameEnd(bool fBreak = false) override;
|
|
|
|
bool FollowName(const char *szName) override;
|
2010-03-27 16:05:02 +00:00
|
|
|
|
2010-04-01 21:08:06 +00:00
|
|
|
// Separators
|
2017-05-07 11:50:00 +00:00
|
|
|
bool Separator(Sep eSep) override;
|
2018-01-17 23:40:39 +00:00
|
|
|
void NoSeparator() override;
|
2010-03-27 16:05:02 +00:00
|
|
|
|
|
|
|
// Data writers
|
2017-05-07 11:50:00 +00:00
|
|
|
void DWord(int32_t &rInt) override;
|
|
|
|
void DWord(uint32_t &rInt) override;
|
|
|
|
void Word(int16_t &rShort) override;
|
|
|
|
void Word(uint16_t &rShort) override;
|
|
|
|
void Byte(int8_t &rByte) override;
|
|
|
|
void Byte(uint8_t &rByte) override;
|
|
|
|
void Boolean(bool &rBool) override;
|
|
|
|
void Character(char &rChar) override;
|
|
|
|
void String(char *szString, size_t iMaxLength, RawCompileType eType = RCT_Escaped) override;
|
|
|
|
void String(char **pszString, RawCompileType eType = RCT_Escaped) override;
|
|
|
|
void String(std::string &str, RawCompileType type = RCT_Escaped) override;
|
|
|
|
void Raw(void *pData, size_t iSize, RawCompileType eType = RCT_Escaped) override;
|
2010-03-27 16:05:02 +00:00
|
|
|
|
|
|
|
// Passes
|
2017-05-07 11:50:00 +00:00
|
|
|
void Begin() override;
|
|
|
|
void End() override;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// Key stack
|
|
|
|
int iDepth;
|
2010-03-28 17:58:21 +00:00
|
|
|
struct Key
|
|
|
|
{
|
2014-03-19 13:15:27 +00:00
|
|
|
StdCopyStrBuf Name;
|
|
|
|
StdCopyStrBuf LastChildName; // last occuring child name to increase subindex if needed
|
2011-03-30 20:11:47 +00:00
|
|
|
int32_t subindex; // incremented when multiple keys of the same name are encountered
|
2009-05-08 13:28:41 +00:00
|
|
|
HKEY Handle; // for keys only
|
|
|
|
Key *Parent;
|
|
|
|
bool Virtual;
|
|
|
|
DWORD Type; // for values only
|
|
|
|
} *pKey;
|
|
|
|
|
2017-03-27 00:55:27 +00:00
|
|
|
// Current string for reading with separators
|
|
|
|
std::string last_read_string;
|
|
|
|
bool has_read_string = false;
|
|
|
|
bool has_separator_mismatch = false;
|
|
|
|
|
2009-05-08 13:28:41 +00:00
|
|
|
// Reading
|
|
|
|
uint32_t ReadDWord();
|
2017-03-27 00:55:27 +00:00
|
|
|
void ReadString();
|
|
|
|
void ResetLastString();
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // INC_STDREGISTRY
|