CrystalSpace

Public API Reference

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_implementation.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_CRYSTALSPACE_EXPORT csWin32RegistryConfig : 
00047   public scfImplementation1<csWin32RegistryConfig, iConfigFile>
00048 {
00049 private:
00050   friend class csWin32RegistryIterator;
00051 
00052   HKEY hKey;
00053   HKEY hKeyParent;
00054   char* Prefix;
00055   // whether this key is opened w/ write access.
00056   bool writeAccess;
00057   char* Key;
00058 
00059   typedef struct 
00060   {
00061     csStringHash strings;
00062   } rcStatus;
00063   mutable rcStatus status;
00064 
00065   csArray<csWin32RegistryIterator*> iters;
00066 
00067   // convert CS "x.y.z" keys to registry "x\y\z"
00068   void ReplaceSeparators (char* key) const;
00069 
00070   bool TryOpen (HKEY parent, HKEY& regKey, DWORD access, const char* keyName, 
00071     bool create);
00072 
00073   // convenience class, used to delete[] a buffer on function return
00074   struct Block_O_Mem
00075   {
00076     BYTE* data;
00077     size_t size;
00078     Block_O_Mem () : data(0), size(0) { }
00079     void Clear() { delete[] data; }
00080     void SetSize (size_t sz) { Clear(); size = sz; data = new BYTE[sz]; }
00081     ~Block_O_Mem() { Clear(); }
00082   };
00083   // To shorten calls to RegSetValueEx()
00084   bool InternalSetValue (const char* Key,
00085     DWORD type, const void* data, size_t datasize);
00086   // To shorten calls to RegQueryValueEx()
00087   bool InternalGetValue (const char* Key,
00088     DWORD& type, Block_O_Mem& data) const;
00089 
00090   /*
00091     Helper functions to convert the data from the registry to the 
00092     requested format
00093   */
00094   int RegToInt (DWORD type, Block_O_Mem& data, int Def) const;
00095   float RegToFloat (DWORD type, Block_O_Mem& data, float Def) const;
00096   const char* RegToStr (DWORD type, Block_O_Mem& data, const char* Def) const;
00097   bool RegToBool (DWORD type, Block_O_Mem& data, bool Def) const;
00098 
00099   // Check whether we have registry write access.
00100   bool WriteAccess();
00101 public:
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 
00152 #endif
00153 

Generated for Crystal Space by doxygen 1.4.7