diff --git a/Modules.cpp b/Modules.cpp index 9416ce98..da927bab 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -279,6 +279,15 @@ bool CModule::DelNV(const CString & sName, bool bWriteToDisk) { return true; } +bool CModule::ClearNV(bool bWriteToDisk) { + m_mssRegistry.clear(); + + if (bWriteToDisk) { + return SaveRegistry(); + } + return true; +} + bool CModule::AddTimer(CTimer* pTimer) { if ((!pTimer) || (FindTimer(pTimer->GetName()))) { delete pTimer; diff --git a/Modules.h b/Modules.h index f2203e7d..bbf7f8b8 100644 --- a/Modules.h +++ b/Modules.h @@ -328,6 +328,7 @@ public: MCString::iterator EndNV() { return m_mssRegistry.end(); } MCString::iterator BeginNV() { return m_mssRegistry.begin(); } void DelNV(MCString::iterator it) { m_mssRegistry.erase(it); } + bool ClearNV(bool bWriteToDisk = true); const CString& GetSavePath() const { if (!CFile::Exists(m_sSavePath)) { CDir::MakeDir(m_sSavePath); } return m_sSavePath; } diff --git a/modules/watch.cpp b/modules/watch.cpp index c5bf78a4..02cc4e81 100644 --- a/modules/watch.cpp +++ b/modules/watch.cpp @@ -154,9 +154,11 @@ class CWatcherMod : public CModule { public: MODCONSTRUCTOR(CWatcherMod) { m_Buffer.SetLineCount(500); + Load(); } virtual ~CWatcherMod() { + Save(); } virtual void OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, const CString& sArgs) { @@ -479,6 +481,55 @@ private: } } + void Save() { + ClearNV(false); + for (list::iterator it = m_lsWatchers.begin(); it != m_lsWatchers.end(); it++) { + CWatchEntry& WatchEntry = *it; + CString sSave; + + sSave = WatchEntry.GetHostMask() + "\n"; + sSave += WatchEntry.GetTarget() + "\n"; + sSave += WatchEntry.GetPattern() + "\n"; + sSave += (WatchEntry.IsDisabled() ? "disabled\n" : "enabled\n"); + sSave += WatchEntry.GetSourcesStr(); + // Without this, loading fails if GetSourcesStr() + // returns an empty string + sSave += " "; + + SetNV(sSave, "", false); + } + + SaveRegistry(); + } + + void Load() { + // Just to make sure we dont mess up badly + m_lsWatchers.clear(); + + bool bWarn = false; + + for (MCString::iterator it = BeginNV(); it != EndNV(); it++) { + VCString vList; + it->first.Split("\n", vList); + + if (vList.size() != 5) { + bWarn = true; + continue; + } + + CWatchEntry WatchEntry(vList[0], vList[1], vList[2]); + if (vList[3].Equals("disabled")) + WatchEntry.SetDisabled(true); + else + WatchEntry.SetDisabled(false); + WatchEntry.SetSources(vList[4]); + m_lsWatchers.push_back(WatchEntry); + } + + if (bWarn) + PutModule("WARNING: malformed entry found while loading"); + } + list m_lsWatchers; CBuffer m_Buffer; };