Files
Work/m68hc11/backup/M68REG.CPP
2024-08-07 09:16:27 -04:00

220 lines
5.2 KiB
C++

#include <m68hc11/m68reg.hpp>
#include <m68hc11/commctrl.hpp>
M68Reg::M68Reg(void)
: mM68KeyName(STRING_M68KEYNAME),
mHistoryKeyName(STRING_HISTORYKEYNAME),
mSettingsKeyName(STRING_SETTINGSKEYNAME),
mSerialKeyName(STRING_SERIALKEYNAME),
mHistoryKeyShortName(STRING_HISTORYKEYSHORTNAME),
mSettingsEMAIL(STRING_SETTINGSEMAIL),
mSerialPort(STRING_SERIALPORT),
mSerialBaud(STRING_SERIALBAUD),
mSerialData(STRING_SERIALDATA),
mSerialParity(STRING_SERIALPARITY),
mSerialStop(STRING_SERIALSTOP),
mRegKeySettings(RegKey::CurrentUser),
mRegKeyHistory(RegKey::CurrentUser),
mRegKeySerial(RegKey::CurrentUser)
{
guarantee();
getCacheNames();
}
M68Reg::M68Reg(const M68Reg &someM68Reg)
: mM68KeyName(STRING_M68KEYNAME),
mHistoryKeyName(STRING_HISTORYKEYNAME),
mSettingsKeyName(STRING_SETTINGSKEYNAME),
mSerialKeyName(STRING_SERIALKEYNAME),
mHistoryKeyShortName(STRING_HISTORYKEYSHORTNAME),
mSettingsEMAIL(STRING_SETTINGSEMAIL),
mSerialPort(STRING_SERIALPORT),
mSerialBaud(STRING_SERIALBAUD),
mSerialData(STRING_SERIALDATA),
mSerialParity(STRING_SERIALPARITY),
mSerialStop(STRING_SERIALSTOP),
mRegKeySettings(RegKey::CurrentUser),
mRegKeyHistory(RegKey::CurrentUser),
mRegKeySerial(RegKey::CurrentUser)
{
*this=someM68Reg;
}
M68Reg::~M68Reg()
{
}
M68Reg &M68Reg::operator=(const M68Reg &/*someM68Reg*/)
{
return *this;
}
void M68Reg::getCacheNames(void)
{
int itemIndex(0);
String entryName;
DWORD status;
mCachedNames.remove();
while(mRegKeyHistory.enumValue(itemIndex++,entryName,status))mCachedNames.insert(&entryName);
}
String M68Reg::email(void)
{
String strEMAIL;
mRegKeySettings.queryValue(mSettingsEMAIL,strEMAIL);
return strEMAIL;
}
void M68Reg::email(const String &email)
{
mRegKeySettings.setValue(mSettingsEMAIL,email);
}
bool M68Reg::setBaud(const String &strBaud)
{
return mRegKeySerial.setValue(mSerialBaud,strBaud);
}
String M68Reg::getBaud(void)
{
String strBaud;
mRegKeySerial.queryValue(mSerialBaud,strBaud);
return strBaud;
}
bool M68Reg::setParity(const String &strParity)
{
return mRegKeySerial.setValue(mSerialParity,strParity);
}
String M68Reg::getParity(void)
{
String strParity;
mRegKeySerial.queryValue(mSerialParity,strParity);
return strParity;
}
bool M68Reg::setDataBits(const String &strDataBits)
{
return mRegKeySerial.setValue(mSerialData,strDataBits);
}
String M68Reg::getDataBits(void)
{
String strData;
mRegKeySerial.queryValue(mSerialData,strData);
return strData;
}
bool M68Reg::setStopBits(const String &stopBits)
{
return mRegKeySerial.setValue(mSerialStop,stopBits);
}
String M68Reg::getStopBits(void)
{
String strStop;
mRegKeySerial.queryValue(mSerialStop,strStop);
return strStop;
}
bool M68Reg::setPort(const String &strPort)
{
return mRegKeySerial.setValue(mSerialPort,strPort);
}
String M68Reg::getPort(void)
{
String strPort;
mRegKeySerial.queryValue(mSerialPort,strPort);
return strPort;
}
String M68Reg::getSerialSettings(void)
{
String serialSettings;
serialSettings+="baud=";
serialSettings+=getBaud();
serialSettings+=" ";
serialSettings+="parity=";
serialSettings+=getParity();
serialSettings+=" ";
serialSettings+="data=";
serialSettings+=getDataBits();
serialSettings+=" ";
serialSettings+="stop=";
serialSettings+=getStopBits();
return serialSettings;
}
void M68Reg::guarantee(void)
{
if(!mRegKeySettings.openKey(mSettingsKeyName))
{
mRegKeySettings.createKey(mSettingsKeyName,"");
mRegKeySettings.openKey(mSettingsKeyName);
}
if(!mRegKeyHistory.openKey(mHistoryKeyName))
{
mRegKeyHistory.createKey(mHistoryKeyName,"");
mRegKeyHistory.openKey(mHistoryKeyName);
}
if(!mRegKeySerial.openKey(mSerialKeyName))
{
CommControl commControl;
Block<String> deviceList;
commControl.enumerateDevices(deviceList);
mRegKeySerial.createKey(mSerialKeyName,"");
mRegKeySerial.openKey(mSerialKeyName);
setBaud("1200");
setParity("N");
setDataBits("8");
setStopBits("1");
setPort(deviceList.size()?deviceList[0]:"COM1");
}
}
BOOL M68Reg::isOkay(void)const
{
return mRegKeySettings.isOkay()&&mRegKeyHistory.isOkay()&&mRegKeySerial.isOkay();
}
BOOL M68Reg::getHistory(Block<String> &nameList)
{
nameList=mCachedNames;
return nameList.size()?TRUE:FALSE;
}
BOOL M68Reg::setHistory(Block<String> &nameList)
{
RegKey regKey(RegKey::CurrentUser);
mRegKeyHistory.closeKey();
regKey.openKey(mM68KeyName);
regKey.deleteKey(mHistoryKeyShortName);
regKey.closeKey();
mRegKeyHistory.createKey(mHistoryKeyName,"");
mRegKeyHistory.openKey(mHistoryKeyName);
for(int itemIndex=0;itemIndex<nameList.size();itemIndex++)mRegKeyHistory.setValue(nameList[itemIndex],0);
return nameList.size()?TRUE:FALSE;
}
BOOL M68Reg::insertHistory(const String &strName)
{
for(int itemIndex=0;itemIndex<mCachedNames.size();itemIndex++)if(mCachedNames[itemIndex]==strName)return FALSE;
mCachedNames.insert(&strName);
if(mCachedNames.size()>MaxCachedNames)
{
Block<String> mruCachedNames;
for(int itemIndex=0;itemIndex<MaxCachedNames;itemIndex++)mruCachedNames.insert(&String());
for(itemIndex=0;itemIndex<MaxCachedNames;itemIndex++)mruCachedNames[mruCachedNames.size()-itemIndex-1]=mCachedNames[mCachedNames.size()-itemIndex-1];
mCachedNames=mruCachedNames;
setHistory(mCachedNames);
}
else mRegKeyHistory.setValue(strName,0);
return TRUE;
}