Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
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 #include "sanity.inc" 00035 00036 class csWin32RegistryIterator; 00037 00046 class CS_CSUTIL_EXPORT csWin32RegistryConfig : public iConfigFile 00047 { 00048 private: 00049 friend class csWin32RegistryIterator; 00050 00051 HKEY hKey; 00052 HKEY hKeyParent; 00053 char* Prefix; 00054 // whether this key is opened w/ write access. 00055 bool writeAccess; 00056 char* Key; 00057 00058 typedef struct 00059 { 00060 csStringHash strings; 00061 } rcStatus; 00062 rcStatus* status; 00063 00064 csArray<csWin32RegistryIterator*> iters; 00065 00066 // convert CS "x.y.z" keys to registry "x\y\z" 00067 void ReplaceSeparators (char* key) const; 00068 00069 bool TryOpen (HKEY parent, HKEY& regKey, DWORD access, const char* keyName, 00070 bool create); 00071 00072 // convenience class, used to delete[] a buffer on function return 00073 struct Block_O_Mem 00074 { 00075 BYTE* data; 00076 size_t size; 00077 Block_O_Mem () : data(0), size(0) { } 00078 void Clear() { delete[] data; } 00079 void SetSize (size_t sz) { Clear(); size = sz; data = new BYTE[sz]; } 00080 ~Block_O_Mem() { Clear(); } 00081 }; 00082 // To shorten calls to RegSetValueEx() 00083 bool InternalSetValue (const char* Key, 00084 DWORD type, const void* data, size_t datasize); 00085 // To shorten calls to RegQueryValueEx() 00086 bool InternalGetValue (const char* Key, 00087 DWORD& type, Block_O_Mem& data) const; 00088 00089 /* 00090 Helper functions to convert the data from the registry to the 00091 requested format 00092 */ 00093 int RegToInt (DWORD type, Block_O_Mem& data, int Def) const; 00094 float RegToFloat (DWORD type, Block_O_Mem& data, float Def) const; 00095 const char* RegToStr (DWORD type, Block_O_Mem& data, const char* Def) const; 00096 bool RegToBool (DWORD type, Block_O_Mem& data, bool Def) const; 00097 00098 // Check whether we have registry write access. 00099 bool WriteAccess(); 00100 public: 00101 SCF_DECLARE_IBASE; 00102 00103 csWin32RegistryConfig (); 00104 virtual ~csWin32RegistryConfig(); 00105 00113 bool Open (const char* Key, HKEY parent = HKEY_CURRENT_USER); 00120 void Close (); 00121 00122 virtual const char* GetFileName () const; 00123 virtual iVFS* GetVFS () const; 00124 virtual void SetFileName (const char*, iVFS*); 00125 virtual bool Load (const char* iFileName, iVFS* = 0, bool Merge = false, 00126 bool NewWins = true); 00127 virtual bool Save (); 00128 virtual bool Save (const char *iFileName, iVFS* = 0); 00129 00130 virtual void Clear (); 00131 00132 virtual csPtr<iConfigIterator> Enumerate (const char *Subsection = 0); 00133 virtual bool KeyExists (const char *Key) const; 00134 virtual bool SubsectionExists (const char *Subsection) const; 00135 00136 virtual int GetInt (const char *Key, int Def = 0) const; 00137 virtual float GetFloat (const char *Key, float Def = 0.0) const; 00138 virtual const char *GetStr (const char *Key, const char *Def = "") const; 00139 virtual bool GetBool (const char *Key, bool Def = false) const; 00140 virtual const char *GetComment (const char *Key) const; 00141 00142 virtual void SetStr (const char *Key, const char *Val); 00143 virtual void SetInt (const char *Key, int Value); 00144 virtual void SetFloat (const char *Key, float Value); 00145 virtual void SetBool (const char *Key, bool Value); 00146 virtual bool SetComment (const char *Key, const char *Text); 00147 virtual void DeleteKey (const char *Key); 00148 virtual const char *GetEOFComment () const; 00149 virtual void SetEOFComment (const char *Text); 00150 }; 00151 00160 class CS_CSUTIL_EXPORT csWin32RegistryIterator : public iConfigIterator 00161 { 00162 csRef<csWin32RegistryConfig> owner; 00163 00164 typedef struct 00165 { 00166 csStringHash strings; 00167 } riStatus; 00168 riStatus* status; 00169 00170 DWORD EnumIndex; 00171 00172 char* SubsectionName; 00173 00174 // shortcut to RegEnumValue/RegQueryValueEx 00175 bool GetCurrentData (DWORD& type, 00176 csWin32RegistryConfig::Block_O_Mem& data) const; 00177 public: 00178 SCF_DECLARE_IBASE; 00179 00180 csWin32RegistryIterator (csWin32RegistryConfig* Owner, 00181 const char* Subsection); 00182 virtual ~csWin32RegistryIterator(); 00183 00184 virtual iConfigFile *GetConfigFile () const; 00185 virtual const char *GetSubsection () const; 00186 00187 virtual void Rewind (); 00188 virtual bool Next(); 00189 00190 virtual const char *GetKey (bool Local = false) const; 00191 virtual int GetInt () const; 00192 virtual float GetFloat () const; 00193 virtual const char *GetStr () const; 00194 virtual bool GetBool () const; 00195 virtual const char *GetComment () const; 00196 }; 00197 00198 #endif 00199
Generated for Crystal Space by doxygen 1.3.9.1