#ifndef _COMMON_PROFILE_HPP_
#define _COMMON_PROFILE_HPP_
#include <stdio.h>
#include <direct.h>
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif
#ifndef _COMMON_ARRAY_HPP_
#include <common/array.hpp>
#endif
#ifndef _COMMON_BLOCK_HPP_
#include <common/block.hpp>
#endif
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif
#ifndef _COMMON_DISKINFO_HPP_
#include <common/diskinfo.hpp>
#endif

class Profile
{
public:
	enum Statement{Pure,NoAssign};
	Profile(void);
	Profile(String iniFileName,String unsetString);
	virtual ~Profile(void);
	WORD setIniFile(String iniFileName);
	WORD isOkay(void)const;
	BOOL readSectionNames(Block<String> &sectionNames);
	WORD readProfileString(const String &sectionString,const String &itemString,String &returnString)const;
	WORD readProfileBlock(const String &sectionString,Block<String> &sectionBlock,Statement=Pure);
	WORD writeProfileString(const String &sectionString,const String &itemString,const String &textString);
	WORD writeProfileBlock(const String &sectionString,Block<String> &itemStrings,Block<String> &textStrings);
	WORD makeFileName(String &pathFileName);
	WORD verifyDirectory(String &pathDirectoryName);
	void makePathFileName(String &fileNameString);
  WORD getCurrentDirectory(String &currentDirectory)const;
	void drivePathName(String &currentDriveString,int appendDirConst=TRUE);
  static bool makeDirectoryName(String &directoryName);
  static String removeExtension(String strPathFileName);
  static String getExtension(String strPathFileName);
  static bool makeFileName(const String &strPathFileName,String &strFileName);
	static bool verifyPathFileName(const String &somePathFileName);
private:
  enum{MaxProfileLength=4096};
  WORD verifyInitializationFile(String iniFileName);
	void expandEmbeddedMacro(String &someString)const;

	String mStringUnset;
	String mIniPathFileName;
  WORD mIsOkay;
};

inline
WORD Profile::isOkay(void)const
{
  return mIsOkay;
}

inline
void Profile::drivePathName(String &currentDriveString,int appendDirConst)
{
	DiskInfo diskInfo;

	diskInfo.getCurrentDirectory(currentDriveString);
	if(appendDirConst)currentDriveString+="\\";
}

#if defined(__FLAT__)
inline
WORD Profile::getCurrentDirectory(String &currentDirectory)const
{
	currentDirectory.reserve(String::MaxString+1);
  return (WORD)::GetCurrentDirectory(String::MaxString,currentDirectory);
}
#else
inline
WORD Profile::getCurrentDirectory(String &currentDirectory)const
{
	currentDirectory.reserve(String::MaxString+1);
  return (::getcwd(currentDirectory,String::MaxString)?TRUE:FALSE);
}
#endif
#endif                     
