finished building out module/user based registry system (round 1)

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@299 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
imaginos
2005-05-15 03:49:11 +00:00
parent 8a1b797187
commit 1f4f4aab64
4 changed files with 85 additions and 1 deletions

View File

@@ -38,12 +38,54 @@ CModule::CModule(void* pDLL, CUser* pUser, const CString& sModName) {
m_pManager = pUser->GetManager();
m_pUser = pUser;
m_sModName = sModName;
LoadRegistry();
}
CModule::~CModule() {
while (m_vTimers.size()) {
RemTimer(m_vTimers[0]->GetName());
}
SaveRegistry();
}
bool CModule::LoadRegistry()
{
CString sRegistryDir = m_pUser->GetDataPath() + "/" + m_sModName;
CUtils::MakeDir( sRegistryDir );
return( ( m_mssRegistry.ReadFromDisk( sRegistryDir + "/" + m_pUser->GetUserName() + "-registry.txt", 0600 ) == MCString::MCS_SUCCESS ) );
}
bool CModule::SaveRegistry()
{
CString sRegistryDir = m_pUser->GetDataPath() + "/" + m_sModName;
CUtils::MakeDir( sRegistryDir );
return( ( m_mssRegistry.WriteToDisk( sRegistryDir + "/" + m_pUser->GetUserName() + "-registry.txt", 0600 ) == MCString::MCS_SUCCESS ) );
}
bool CModule::SetNV( const CString & sName, const CString & sValue, bool bWriteToDisk )
{
m_mssRegistry[sName] = sValue;
if ( bWriteToDisk )
return( SaveRegistry() );
return( true );
}
CString CModule::GetNV( const CString & sName )
{
return( m_mssRegistry[sName] );
}
bool CModule::DelNV( const CString & sName, bool bWriteToDisk )
{
MCString::iterator it = m_mssRegistry.find( sName );
if ( it != m_mssRegistry.end() )
m_mssRegistry.erase( it );
if ( bWriteToDisk )
return( SaveRegistry() );
return( true );
}
bool CModule::AddTimer(CTimer* pTimer) {
@@ -57,6 +99,14 @@ bool CModule::AddTimer(CTimer* pTimer) {
return true;
}
bool CModule::AddTimer(FPTimer_t pFBCallback, const CString& sLabel, u_int uInterval,
u_int uCycles, const CString& sDescription )
{
CFPTimer *pTimer = new CFPTimer( this, uInterval, uCycles, sLabel, sDescription );
pTimer->SetFPCallback( pFBCallback );
return( AddTimer( pTimer ) );
}
bool CModule::RemTimer(const CString& sLabel) {
for (unsigned int a = 0; a < m_vTimers.size(); a++) {
CTimer* pTimer = m_vTimers[a];