/*
Module : HKLM.H
Purpose: Interface for a class to provide simple access to the HKEY_LOCAL_MACHINE\Software\Company\MyApp
				 registry key similiar to the functions MFC provides to access the same settings in HKEY_CURRENT_USER
Created: PJN / 27-07-1998

Copyright (c) 1998 - 2006 by PJ Naughter (Web: www.naughter.com, Email: pjna@naughter.com)

All rights reserved.

Copyright / Usage Details:

You are allowed to include the source code in any product (commercial, shareware, freeware or otherwise) 
when your product is released in binary form. You are allowed to modify the source code in any way you want 
except you cannot modify the copyright details at the top of each module. If you want to distribute source 
code with your application, then you are only allowed to distribute versions released by the author. This is 
to maintain a single distribution point for the source code. 

*/

/////////////////////////////////////// Macros / Defines //////////////////////

#ifndef __HKLM_H__
#define __HKLM_H__

#ifndef HKLM_EXT_CLASS
#define HKLM_EXT_CLASS
#endif


/////////////////////////////////////// Classes ///////////////////////////////

class HKLM_EXT_CLASS CHKLM
{
public:
//Constructors / Destructors
  CHKLM();

  //Perform the same job as the function of the same name
	// in the CWinApp class in MFC
  void SetRegistryKey(LPCTSTR lpszRegistryKey);
  void SetRegistryKey(UINT nIDRegistryKey);

  //Allows you to customize the "Product Name" registry key. If you do not
  //call SetAppRegistryKey, then "AfxGetApp()->m_pszAppName" is
  //used by default
  void SetProductNameRegistryKey(LPCTSTR lpszProductNameRegistryKey);
  void SetProductNameRegistryKey(UINT nIDProductNameRegistryKey);
  CString GetProductNameRegistryKey() const;

	//Allows saving and restoring of a profile settings to the 
	//HKEY_LOCAL_MACHINE\Software\"Company Name"\"Product Name"
	//registry key. These classes are modelled upon the functions
	//of the same name in the CWinApp class in MFC
	BOOL    WriteProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszValue);
	BOOL    WriteProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nValue);
	CString GetProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault = NULL);
	UINT    GetProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault);
	BOOL    GetProfileBinary(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPBYTE* ppData, UINT* pBytes);
	BOOL    WriteProfileBinary(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPBYTE pData, UINT nBytes);
  BOOL    GetProfileStringArray(LPCTSTR lpszSection, LPCTSTR lpszEntry, CStringArray& array);
  BOOL    WriteProfileStringArray(LPCTSTR lpszSection, LPCTSTR lpszEntry, const CStringArray& array);

	//Allows client apps to decide if the above settings should be flushed to the registry
	//or allow them to be written to the registry in a lazy fashion
	void SetProfileWriteFlush(BOOL bFlush) { m_bProfileWriteFlush = bFlush; };
	BOOL GetProfileWriteFlush() const { return m_bProfileWriteFlush; };

protected:
//Misc functions
	HKEY GetAppRegistryKey(BOOL bReadOnly = FALSE);
	HKEY GetSectionKey(LPCTSTR lpszSection, BOOL bReadOnly = FALSE);
  BOOL GetStringArrayFromRegistry(HKEY hKey, LPCTSTR lpszEntry, CStringArray& array);
  BOOL SetStringArrayIntoRegistry(HKEY hKey, LPCTSTR lpszEntry, const CStringArray& array);

//Member variables
	CString m_sRegistryKey;
  CString m_sProductNameRegistryKey;
  BOOL    m_bProfileWriteFlush;      //Should calls to WriteProfile... be synchronous or left to be written by the lazy writer
};

#endif //__HKLM_H__
