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 class csWin32RegistryIterator;
00034 
00043 class CS_CRYSTALSPACE_EXPORT csWin32RegistryConfig : 
00044   public scfImplementation1<csWin32RegistryConfig, iConfigFile>
00045 {
00046 private:
00047   friend class csWin32RegistryIterator;
00048 
00049   HKEY hKey;
00050   HKEY hKeyParent;
00051   char* Prefix;
00052   // whether this key is opened w/ write access.
00053   bool writeAccess;
00054   char* Key;
00055 
00056   typedef struct 
00057   {
00058     csStringHash strings;
00059   } rcStatus;
00060   mutable rcStatus status;
00061 
00062   csArray<csWin32RegistryIterator*> iters;
00063 
00064   // convert CS "x.y.z" keys to registry "x\y\z"
00065   void ReplaceSeparators (char* key) const;
00066 
00067   bool TryOpen (HKEY parent, HKEY& regKey, DWORD access, const char* keyName, 
00068     bool create);
00069 
00070   // convenience class, used to delete[] a buffer on function return
00071   struct Block_O_Mem
00072   {
00073     BYTE* data;
00074     size_t size;
00075     Block_O_Mem () : data(0), size(0) { }
00076     void Clear() { delete[] data; }
00077     void SetSize (size_t sz) { Clear(); size = sz; data = new BYTE[sz]; }
00078     ~Block_O_Mem() { Clear(); }
00079   };
00080   // To shorten calls to RegSetValueEx()
00081   bool InternalSetValue (const char* Key,
00082     DWORD type, const void* data, size_t datasize);
00083   // To shorten calls to RegQueryValueEx()
00084   bool InternalGetValue (const char* Key,
00085     DWORD& type, Block_O_Mem& data) const;
00086 
00087   /*
00088     Helper functions to convert the data from the registry to the 
00089     requested format
00090   */
00091   int RegToInt (DWORD type, Block_O_Mem& data, int Def) const;
00092   float RegToFloat (DWORD type, Block_O_Mem& data, float Def) const;
00093   const char* RegToStr (DWORD type, Block_O_Mem& data, const char* Def) const;
00094   bool RegToBool (DWORD type, Block_O_Mem& data, bool Def) const;
00095 
00096   // Check whether we have registry write access.
00097   bool WriteAccess();
00098 public:
00099 
00100   csWin32RegistryConfig ();
00101   virtual ~csWin32RegistryConfig();
00102 
00110   bool Open (const char* Key, HKEY parent = HKEY_CURRENT_USER);
00117   void Close ();
00118 
00119   virtual const char* GetFileName () const;
00120   virtual iVFS* GetVFS () const;
00121   virtual void SetFileName (const char*, iVFS*);
00122   virtual bool Load (const char* iFileName, iVFS* = 0, bool Merge = false,
00123     bool NewWins = true);
00124   virtual bool Save ();
00125   virtual bool Save (const char *iFileName, iVFS* = 0);
00126   
00127   virtual void Clear ();
00128   
00129   virtual csPtr<iConfigIterator> Enumerate (const char *Subsection = 0);
00130   virtual bool KeyExists (const char *Key) const;
00131   virtual bool SubsectionExists (const char *Subsection) const;
00132   
00133   virtual int GetInt (const char *Key, int Def = 0) const;
00134   virtual float GetFloat (const char *Key, float Def = 0.0) const;
00135   virtual const char *GetStr (const char *Key, const char *Def = "") const;
00136   virtual bool GetBool (const char *Key, bool Def = false) const;
00137   virtual const char *GetComment (const char *Key) const;
00138 
00139   virtual void SetStr (const char *Key, const char *Val);
00140   virtual void SetInt (const char *Key, int Value);
00141   virtual void SetFloat (const char *Key, float Value);
00142   virtual void SetBool (const char *Key, bool Value);
00143   virtual bool SetComment (const char *Key, const char *Text);
00144   virtual void DeleteKey (const char *Key);
00145   virtual const char *GetEOFComment () const;
00146   virtual void SetEOFComment (const char *Text);
00147 };
00148 
00149 #endif
00150 

Generated for Crystal Space 1.2.1 by doxygen 1.5.3