csutil/win32/registrycfg.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2003 by Jorrit Tyberghein 00003 (C) 2003 by Frank Richter 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_CSSYS_WIN32_REGISTRYCFG_H__ 00021 #define __CS_CSSYS_WIN32_REGISTRYCFG_H__ 00022 00027 #include "csextern.h" 00028 #include "iutil/cfgfile.h" 00029 #include "csutil/scf.h" 00030 #include "csutil/strhash.h" 00031 #include "csutil/array.h" 00032 00033 #include <windows.h> 00034 00035 class csWin32RegistryIterator; 00036 00045 class CS_CSUTIL_EXPORT csWin32RegistryConfig : public iConfigFile 00046 { 00047 private: 00048 friend class csWin32RegistryIterator; 00049 00050 HKEY hKey; 00051 HKEY hKeyParent; 00052 char* Prefix; 00053 // whether this key is opened w/ write access. 00054 bool writeAccess; 00055 char* Key; 00056 00057 typedef struct 00058 { 00059 csStringHash strings; 00060 } rcStatus; 00061 rcStatus* status; 00062 00063 csArray<csWin32RegistryIterator*> iters; 00064 00065 // convert CS "x.y.z" keys to registry "x\y\z" 00066 void ReplaceSeparators (char* key) const; 00067 00068 bool TryOpen (HKEY parent, HKEY& regKey, DWORD access, const char* keyName, 00069 bool create); 00070 00071 // convenience class, used to delete[] a buffer on function return 00072 struct Block_O_Mem 00073 { 00074 BYTE* data; 00075 size_t size; 00076 Block_O_Mem () : data(0), size(0) { } 00077 void Clear() { delete[] data; } 00078 void SetSize (size_t sz) { Clear(); size = sz; data = new BYTE[sz]; } 00079 ~Block_O_Mem() { Clear(); } 00080 }; 00081 // To shorten calls to RegSetValueEx() 00082 bool InternalSetValue (const char* Key, 00083 DWORD type, const void* data, size_t datasize); 00084 // To shorten calls to RegQueryValueEx() 00085 bool InternalGetValue (const char* Key, 00086 DWORD& type, Block_O_Mem& data) const; 00087 00088 /* 00089 Helper functions to convert the data from the registry to the 00090 requested format 00091 */ 00092 int RegToInt (DWORD type, Block_O_Mem& data, int Def) const; 00093 float RegToFloat (DWORD type, Block_O_Mem& data, float Def) const; 00094 const char* RegToStr (DWORD type, Block_O_Mem& data, const char* Def) const; 00095 bool RegToBool (DWORD type, Block_O_Mem& data, bool Def) const; 00096 00097 // Check whether we have registry write access. 00098 bool WriteAccess(); 00099 public: 00100 SCF_DECLARE_IBASE; 00101 00102 csWin32RegistryConfig (); 00103 virtual ~csWin32RegistryConfig(); 00104 00112 bool Open (const char* Key, HKEY parent = HKEY_CURRENT_USER); 00119 void Close (); 00120 00121 virtual const char* GetFileName () const; 00122 virtual iVFS* GetVFS () const; 00123 virtual void SetFileName (const char*, iVFS*); 00124 virtual bool Load (const char* iFileName, iVFS* = 0, bool Merge = false, 00125 bool NewWins = true); 00126 virtual bool Save (); 00127 virtual bool Save (const char *iFileName, iVFS* = 0); 00128 00129 virtual void Clear (); 00130 00131 virtual csPtr<iConfigIterator> Enumerate (const char *Subsection = 0); 00132 virtual bool KeyExists (const char *Key) const; 00133 virtual bool SubsectionExists (const char *Subsection) const; 00134 00135 virtual int GetInt (const char *Key, int Def = 0) const; 00136 virtual float GetFloat (const char *Key, float Def = 0.0) const; 00137 virtual const char *GetStr (const char *Key, const char *Def = "") const; 00138 virtual bool GetBool (const char *Key, bool Def = false) const; 00139 virtual const char *GetComment (const char *Key) const; 00140 00141 virtual void SetStr (const char *Key, const char *Val); 00142 virtual void SetInt (const char *Key, int Value); 00143 virtual void SetFloat (const char *Key, float Value); 00144 virtual void SetBool (const char *Key, bool Value); 00145 virtual bool SetComment (const char *Key, const char *Text); 00146 virtual void DeleteKey (const char *Key); 00147 virtual const char *GetEOFComment () const; 00148 virtual void SetEOFComment (const char *Text); 00149 }; 00150 00159 class CS_CSUTIL_EXPORT csWin32RegistryIterator : public iConfigIterator 00160 { 00161 csRef<csWin32RegistryConfig> owner; 00162 00163 typedef struct 00164 { 00165 csStringHash strings; 00166 } riStatus; 00167 riStatus* status; 00168 00169 DWORD EnumIndex; 00170 00171 char* SubsectionName; 00172 00173 // shortcut to RegEnumValue/RegQueryValueEx 00174 bool GetCurrentData (DWORD& type, 00175 csWin32RegistryConfig::Block_O_Mem& data) const; 00176 public: 00177 SCF_DECLARE_IBASE; 00178 00179 csWin32RegistryIterator (csWin32RegistryConfig* Owner, 00180 const char* Subsection); 00181 virtual ~csWin32RegistryIterator(); 00182 00183 virtual iConfigFile *GetConfigFile () const; 00184 virtual const char *GetSubsection () const; 00185 00186 virtual void Rewind (); 00187 virtual bool Next(); 00188 00189 virtual const char *GetKey (bool Local = false) const; 00190 virtual int GetInt () const; 00191 virtual float GetFloat () const; 00192 virtual const char *GetStr () const; 00193 virtual bool GetBool () const; 00194 virtual const char *GetComment () const; 00195 }; 00196 00197 #endif 00198
Generated for Crystal Space by doxygen 1.2.18