From 47f4d5c03a16988eab91de5e26218f8e0d35b8b8 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Mon, 27 Apr 2015 08:58:18 +0000 Subject: Boltun common project git-svn-id: http://svn.miranda-ng.org/main/trunk@13194 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Boltun/src/Engine/Mind.cpp | 80 ++--- plugins/Boltun/src/Engine/Mind.h | 4 +- plugins/Boltun/src/Engine/MyCodeCvt.cpp | 34 +- plugins/Boltun/src/Engine/MyCodeCvt.h | 22 +- plugins/Boltun/src/Engine/PerContactData.h | 8 +- plugins/Boltun/src/Engine/TalkEngine.cpp | 82 +++-- plugins/Boltun/src/Engine/TalkEngine.h | 28 +- plugins/Boltun/src/Engine/UnrecentChooser.cpp | 2 +- plugins/Boltun/src/Engine/ValueChooser.h | 4 +- plugins/Boltun/src/Engine/WordsList.cpp | 32 +- plugins/Boltun/src/actionQueue.cpp | 38 +-- plugins/Boltun/src/boltun.cpp | 440 +++++++++++++------------- plugins/Boltun/src/boltun.h | 95 ------ plugins/Boltun/src/config.cpp | 4 +- plugins/Boltun/src/config.h | 4 +- plugins/Boltun/src/stdafx.cpp | 18 -- plugins/Boltun/src/stdafx.cxx | 18 ++ plugins/Boltun/src/stdafx.h | 93 ++++++ 18 files changed, 499 insertions(+), 507 deletions(-) delete mode 100644 plugins/Boltun/src/boltun.h delete mode 100644 plugins/Boltun/src/stdafx.cpp create mode 100644 plugins/Boltun/src/stdafx.cxx create mode 100644 plugins/Boltun/src/stdafx.h (limited to 'plugins/Boltun/src') diff --git a/plugins/Boltun/src/Engine/Mind.cpp b/plugins/Boltun/src/Engine/Mind.cpp index 1067711bdf..ec6c58528b 100644 --- a/plugins/Boltun/src/Engine/Mind.cpp +++ b/plugins/Boltun/src/Engine/Mind.cpp @@ -18,18 +18,18 @@ // //*********************************************************** -#include "..\boltun.h" +#include "..\stdafx.h" using namespace std; -typedef vector string_vec; -typedef multimap string_mmap; +typedef vector string_vec; +typedef multimap string_mmap; Mind::Mind() { data = new MindData(); data->referenceCount = 1; - data->maxSmileLen = 0; + data->maxSmileLen = 0; } Mind::~Mind() @@ -103,7 +103,7 @@ void Mind::Load(tstring filename) file.open(filename.c_str(), ios_base::in | ios_base::binary); tstring s1, st; - TCHAR *c, *co; + TCHAR *c, *co = NULL; size_t count; int error = 0; int line = 1; @@ -133,7 +133,7 @@ void Mind::Load(tstring filename) format(st); count = st.length(); - c = co = new TCHAR[count+1]; + c = co = new TCHAR[count + 1]; _tcscpy(c, st.c_str()); size_t pos = 0; while (pos < count && _istspace(*c)) @@ -213,41 +213,41 @@ void Mind::Load(tstring filename) ++c; count -= 2; c[count] = '\0'; - if (_tcscmp(c,_T("QUESTION")) == 0) + if (_tcscmp(c, _T("QUESTION")) == 0) { toLowerStr(c); data->question.insert(s1); } else - if (_tcscmp(c,_T("IGNORED")) == 0) - { - toLowerStr(c); - data->special.insert(s1); - } - else - if (_tcscmp(c,_T("ESCAPE")) == 0) - { - data->escape.push_back(s1); - } - else - if (_tcscmp(c,_T("FAILURE")) == 0) - { - data->failure.push_back(s1); - } - else - if (_tcscmp(c,_T("REPEAT")) == 0) - { - data->repeats.push_back(s1); - } - else - { - if (_tcscmp(c,_T("INITIAL")) != 0) - throw error; - data->initial.push_back(s1); - } + if (_tcscmp(c, _T("IGNORED")) == 0) + { + toLowerStr(c); + data->special.insert(s1); + } + else + if (_tcscmp(c, _T("ESCAPE")) == 0) + { + data->escape.push_back(s1); + } + else + if (_tcscmp(c, _T("FAILURE")) == 0) + { + data->failure.push_back(s1); + } + else + if (_tcscmp(c, _T("REPEAT")) == 0) + { + data->repeats.push_back(s1); + } + else + { + if (_tcscmp(c, _T("INITIAL")) != 0) + throw error; + data->initial.push_back(s1); + } break; case '@': - { + { if (file.eof()) throw error; getline(file, s1); @@ -267,8 +267,8 @@ void Mind::Load(tstring filename) data->raliases.insert(make_pair(sc, strs)); for (vector::const_iterator it = strs.begin(); it != strs.end(); ++it) data->aliases.insert(make_pair(*it, sc)); - } - break; + } + break; default: if (file.eof()) throw error; @@ -296,7 +296,7 @@ void Mind::Load(tstring filename) } delete co; } - catch(...) + catch (...) { throw CorruptedMind(line); delete co; @@ -375,7 +375,7 @@ void Mind::Save(tstring filename) const file << _T(" ") << _T('\r') << endl; file << (*it) << _T('\r') << endl; } - for (map>::const_iterator it = data->raliases.begin(); it != data->raliases.end(); ++it) + for (map>::const_iterator it = data->raliases.begin(); it != data->raliases.end(); ++it) { tstring s; const vector& v = (*it).second; @@ -408,7 +408,7 @@ void Mind::LoadSmiles(tstring filename) { getline(file, s); if (s.length() > l) - l = (int)s.length(); + l = (int)s.length(); data->smiles.insert(s); } data->maxSmileLen = l; @@ -427,7 +427,7 @@ void Mind::LoadSmiles(void *smiles, size_t size) lend++; tstring s(buf, lend - buf); if ((unsigned)(lend - buf) > l) - l = (int)s.length(); + l = (int)s.length(); data->smiles.insert(s); if (lend == end) break; diff --git a/plugins/Boltun/src/Engine/Mind.h b/plugins/Boltun/src/Engine/Mind.h index 2b1e6a20c5..d11eb6cd78 100644 --- a/plugins/Boltun/src/Engine/Mind.h +++ b/plugins/Boltun/src/Engine/Mind.h @@ -37,7 +37,7 @@ typedef struct std::vector escape; std::vector failure; std::vector repeats; - unsigned int maxSmileLen; + unsigned int maxSmileLen; std::set smiles; std::multimap keywords; std::multimap qkeywords; @@ -55,7 +55,7 @@ class Mind { private: MindData *data; - bool fileTypeMark; + bool fileTypeMark; std::vector Parse(std::tstring s); public: diff --git a/plugins/Boltun/src/Engine/MyCodeCvt.cpp b/plugins/Boltun/src/Engine/MyCodeCvt.cpp index e34575f811..39a4d064b5 100644 --- a/plugins/Boltun/src/Engine/MyCodeCvt.cpp +++ b/plugins/Boltun/src/Engine/MyCodeCvt.cpp @@ -18,47 +18,47 @@ // //*********************************************************** -#include "..\boltun.h" +#include "..\stdafx.h" using namespace std; MyCodeCvt::MyCodeCvt(size_t _R) - : MyCodeCvtBase(_R) -{ + : MyCodeCvtBase(_R) +{ } -MyCodeCvt::result MyCodeCvt::do_in(_St& _State , - const _To* _F1, const _To* _L1, const _To*& _Mid1, - _E* F2, _E* _L2, _E*& _Mid2) const +MyCodeCvt::result MyCodeCvt::do_in(_St&, + const _To*, const _To*, const _To*&, + _E*, _E*, _E*&) const { return noconv; } - + #ifdef MSVC MyCodeCvt::result MyCodeCvt::do_out(_St& _State, - const _E* _F1, const _E* _L1, const _E*& _Mid1, - _To* F2, _E* _L2, _To*& _Mid2) const + const _E* _F1, const _E* _L1, const _E*& _Mid1, + _To* F2, _E* _L2, _To*& _Mid2) const #else -MyCodeCvt::result MyCodeCvt::do_out(_St& _State, - const _E* _F1, const _E* _L1, const _E*& _Mid1, - _To* F2, _To* _L2, _To*& _Mid2) const +MyCodeCvt::result MyCodeCvt::do_out(_St&, + const _E*, const _E*, const _E*&, + _To*, _To*, _To*&) const #endif { return noconv; } -MyCodeCvt::result MyCodeCvt::do_unshift( _St& _State, - _To* _F2, _To* _L2, _To*& _Mid2) const +MyCodeCvt::result MyCodeCvt::do_unshift(_St&, + _To*, _To*, _To*&) const { return noconv; } #ifdef MSVC int MyCodeCvt::do_length(_St& _State, const _To* _F1, - const _To* _L1, size_t _N2) const _THROW0() + const _To* _L1, size_t _N2) const _THROW0() #else -int MyCodeCvt::do_length(const _St& _State, const _To* _F1, - const _To* _L1, size_t _N2) const _THROW0() +int MyCodeCvt::do_length(const _St&, const _To* _F1, + const _To* _L1, size_t _N2) const _THROW0() #endif { diff --git a/plugins/Boltun/src/Engine/MyCodeCvt.h b/plugins/Boltun/src/Engine/MyCodeCvt.h index 40ca093795..df78cbad1b 100644 --- a/plugins/Boltun/src/Engine/MyCodeCvt.h +++ b/plugins/Boltun/src/Engine/MyCodeCvt.h @@ -27,19 +27,19 @@ class MyCodeCvt : public MyCodeCvtBase { public: - typedef wchar_t _E; - typedef char _To; - typedef std::mbstate_t _St; - explicit MyCodeCvt( size_t _R=0 ); + typedef wchar_t _E; + typedef char _To; + typedef std::mbstate_t _St; + explicit MyCodeCvt(size_t _R = 0); protected: - virtual result do_in(_St& _State, const _To* _F1, const _To* _L1, const _To*& _Mid1, - _E* F2 , _E* _L2 , _E*& _Mid2) const; + virtual result do_in(_St& _State, const _To* _F1, const _To* _L1, const _To*& _Mid1, + _E* F2, _E* _L2, _E*& _Mid2) const; #ifdef MSVC virtual result do_out(_St& _State, const _E* _F1, const _E* _L1, const _E*& _Mid1, - _To* F2, _E* _L2 , _To*& _Mid2) const; + _To* F2, _E* _L2, _To*& _Mid2) const; #else virtual result do_out(_St& _State, const _E* _F1, const _E* _L1, const _E*& _Mid1, - _To* F2, _To* _L2 , _To*& _Mid2) const; + _To* F2, _To* _L2, _To*& _Mid2) const; #endif virtual result do_unshift(_St& _State, _To* _F2, _To* _L2, _To*& _Mid2) const; #ifdef MSVC @@ -48,8 +48,8 @@ protected: virtual int do_length(const _St& _State, const _To* _F1, const _To* _L1, size_t _N2) const _THROW0(); #endif virtual bool do_always_noconv() const _THROW0(); - virtual int do_max_length() const _THROW0(); - virtual int do_encoding() const _THROW0(); -} ; + virtual int do_max_length() const _THROW0(); + virtual int do_encoding() const _THROW0(); +}; #endif /* MYCODECVT_H */ \ No newline at end of file diff --git a/plugins/Boltun/src/Engine/PerContactData.h b/plugins/Boltun/src/Engine/PerContactData.h index d130a03838..e81192053f 100644 --- a/plugins/Boltun/src/Engine/PerContactData.h +++ b/plugins/Boltun/src/Engine/PerContactData.h @@ -41,7 +41,7 @@ class PerContactData } inline InternalData() - :data(NULL) + : data(NULL) { assert(false); } @@ -133,12 +133,12 @@ void PerContactData::CleanupData() mapLock.Enter(); time_t now; time(&now); - for (mapIt it = datas.begin(); it != datas.end(); ) + for (mapIt it = datas.begin(); it != datas.end();) { if ((*it).second->time) //it's being in use { int diff = (int)difftime(now, (*it).second->time); - if (diff >= 30*60) //half of an hour + if (diff >= 30 * 60) //half of an hour { mapIt tmp = it; it++; @@ -160,7 +160,7 @@ void PerContactData::CleanupData() } template -VOID CALLBACK RunTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) +VOID CALLBACK RunTimerProc(HWND, UINT, UINT_PTR idEvent, DWORD) { PerContactData* val = (PerContactData*)perContactDataObjects[idEvent]; val->CleanupData(); diff --git a/plugins/Boltun/src/Engine/TalkEngine.cpp b/plugins/Boltun/src/Engine/TalkEngine.cpp index 3fe283c64a..0391c11112 100644 --- a/plugins/Boltun/src/Engine/TalkEngine.cpp +++ b/plugins/Boltun/src/Engine/TalkEngine.cpp @@ -18,7 +18,7 @@ // //*********************************************************** -#include "..\boltun.h" +#include "..\stdafx.h" #ifdef _DEBUG @@ -61,7 +61,7 @@ void TalkBot::UpdateStartChar(tstring& str) TCHAR ncl = (TCHAR)CharLower((LPTSTR)(void*)(long)str[i + 1]); TCHAR ncu = (TCHAR)CharUpper((LPTSTR)(void*)(long)str[i + 1]); if (ncl != ncu && str[i + 1] == ncu) - break; + break; } if (cl != cu) { @@ -73,7 +73,7 @@ void TalkBot::UpdateStartChar(tstring& str) } TalkBot::TalkBot(const Mind& goodMind) - :mind(goodMind), beSilent(false), makeLowercase(false), + :mind(goodMind), beSilent(false), makeLowercase(false), understandAlways(false) { contactDatas = new PerContactData(mind); @@ -104,7 +104,7 @@ tstring TalkBot::ReplaceAliases(const tstring &message) { unsigned max = (int)(sentence.length() - i); if (max > mind.GetData()->maxSmileLen) - max = mind.GetData()->maxSmileLen; + max = mind.GetData()->maxSmileLen; for (unsigned j = max; j > 0; j--) { tstring item = sentence.substr(i, j); @@ -116,7 +116,7 @@ tstring TalkBot::ReplaceAliases(const tstring &message) } } } - len = (int)sentence.length(); + len = (int)sentence.length(); bool hadQuestionSigns = false; int it = 0; while (it != len) @@ -127,7 +127,7 @@ tstring TalkBot::ReplaceAliases(const tstring &message) hadQuestionSigns = true; map::iterator smit; if (sentence[it] == '\1') - { + { smit = sm.find(it); result.append((*smit).second); } @@ -162,7 +162,7 @@ tstring TalkBot::ReplaceAliases(const tstring &message) tstring TalkBot::AllReplies(const tstring &incomingMessage, ContactData *contactData, Level &maxValue, std::multimap &mm) { tstring res; - //Part 1 + //Part 1 if (FindExact(contactData, incomingMessage, mind.GetData()->widelyUsed, res)) //widelyUsed { return res; @@ -222,16 +222,16 @@ tstring TalkBot::AllReplies(const tstring &incomingMessage, ContactData *contact if (maxValue > LOOKSLIKE) maxValue = LOOKSLIKE; } -/* if (ures != _T("")) - { -#ifdef DEBUG_PREFIXES - mm.insert(make_pair(LOOKSLIKE2, _T("(keywords_unstrict) ")+ures)); -#else - mm.insert(make_pair(LOOKSLIKE2, ures)); -#endif - if (maxValue > LOOKSLIKE2) + /* if (ures != _T("")) + { + #ifdef DEBUG_PREFIXES + mm.insert(make_pair(LOOKSLIKE2, _T("(keywords_unstrict) ")+ures)); + #else + mm.insert(make_pair(LOOKSLIKE2, ures)); + #endif + if (maxValue > LOOKSLIKE2) maxValue = LOOKSLIKE2; - }*/ + }*/ //Part 9 if (FindByOthers(contactData, otherwords, res, isQuestion)) //specialEscapes { @@ -274,14 +274,14 @@ tstring TalkBot::AllReplies(const tstring &incomingMessage, ContactData *contact TalkBot::MessageInfo* TalkBot::Reply(MCONTACT contact, tstring incomingMessage, bool saveChoice) { - TCHAR* str = new TCHAR[incomingMessage.length()+1]; + TCHAR* str = new TCHAR[incomingMessage.length() + 1]; _tcscpy(str, incomingMessage.c_str()); CharLower(str); incomingMessage = str; - delete [] str; + delete[] str; ContactData *contactData = contactDatas->GetData(contact); - if (incomingMessage == contactData->lastMessage && GetTickCount() < contactData->lastMessageTime + 30*60*1000) + if (incomingMessage == contactData->lastMessage && GetTickCount() < contactData->lastMessageTime + 30 * 60 * 1000) { MessageInfo *info; //only 2-3 repeats @@ -400,7 +400,7 @@ void TalkBot::SplitSectences(const tstring &incomingMessage, vector& ve { //FIXME: (THINK ABOUT IT:-))these chars not always mark the end of sentence. const TCHAR symbols[] = _T(".?!"); - int it = 0, len = (int)incomingMessage.length(); + int it = 0, len = (int)incomingMessage.length(); while (it != len) { while (it != len && _istspace(incomingMessage[it])) @@ -411,9 +411,9 @@ void TalkBot::SplitSectences(const tstring &incomingMessage, vector& ve if (_tcschr(symbols, incomingMessage[it++])) { //Test for a :-! smile - if (it > 2 && incomingMessage[it-1] == _T('!') - && incomingMessage[it-2] == _T('-') - && incomingMessage[it-3] == _T(':')) + if (it > 2 && incomingMessage[it - 1] == _T('!') + && incomingMessage[it - 2] == _T('-') + && incomingMessage[it - 3] == _T(':')) continue; while (it != len && _tcschr(symbols, incomingMessage[it])) it++; @@ -427,14 +427,14 @@ void TalkBot::SplitSectences(const tstring &incomingMessage, vector& ve #ifdef _DEBUG tstring LevelToStr(TalkBot::Level target) { - tstring lev; + tstring lev; switch (target) { - case TalkBot::BEST: lev = _T("BEST(0)"); break; - case TalkBot::LOOKSLIKE: lev = _T("LOOKSLIKE(1)"); break; - case TalkBot::BAD: lev = _T("BAD(2)"); break; - case TalkBot::FAIL: lev = _T("FAIL(3)"); break; - case TalkBot::NOTHING: lev = _T("NOTHING(4)"); break; + case TalkBot::BEST: lev = _T("BEST(0)"); break; + case TalkBot::LOOKSLIKE: lev = _T("LOOKSLIKE(1)"); break; + case TalkBot::BAD: lev = _T("BAD(2)"); break; + case TalkBot::FAIL: lev = _T("FAIL(3)"); break; + case TalkBot::NOTHING: lev = _T("NOTHING(4)"); break; } return lev; } @@ -451,14 +451,8 @@ tstring TalkBot::ChooseResult(ContactData *contactData, Level maxValue, const mu if (maxValue == NOTHING) return _T(""); Level target = maxValue; - int num = (int)mm.count(target); -/* if (!num) - { - target = maxValue; - num = mm.count(target); - }*/ typedef multimap::const_iterator lt_cit; - pair range = mm.equal_range(target); + pair range = mm.equal_range(target); for (lt_cit it = range.first; it != range.second; ++it) contactData->chooser.AddChoice((*it).second); #ifdef DEBUG_SHOW_LEVEL @@ -474,16 +468,16 @@ void TalkBot::FindByKeywords(ContactData *contactData, const vector &ke { if (keywords.size() == 0) return; - const multimap &keys = isQuestion ? mind.GetData()->qkeywords : + const multimap &keys = isQuestion ? mind.GetData()->qkeywords : mind.GetData()->keywords; for (multimap::const_iterator it = keys.begin(); it != keys.end(); ++it) { float prio; if ((*it).first.MatchesAll(keywords/*, strict*/, prio)) #ifdef DEBUG_SHOW_SOLUTION_REASON - contactData->chooser.AddChoice((tstring)(*it).first + _T(": - ") + (*it).second, prio); + contactData->chooser.AddChoice((tstring)(*it).first + _T(": - ") + (*it).second, prio); #else - contactData->chooser.AddChoice((*it).second, prio); + contactData->chooser.AddChoice((*it).second, prio); #endif } res = contactData->chooser.Choose(); @@ -492,9 +486,9 @@ void TalkBot::FindByKeywords(ContactData *contactData, const vector &ke bool TalkBot::FindByOthers(ContactData *contactData, const vector &otherwords, tstring& res, bool isQuestion) { //vector results; - const multimap &specs = isQuestion ? mind.GetData()->qspecialEscapes : + const multimap &specs = isQuestion ? mind.GetData()->qspecialEscapes : mind.GetData()->specialEscapes; - for (multimap::const_iterator it = specs.begin(); + for (multimap::const_iterator it = specs.begin(); it != specs.end(); ++it) if ((*it).first.MatchesAny(otherwords)) { @@ -527,7 +521,7 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector& keywords, { unsigned max = (int)(sentence.length() - i); if (max > mind.GetData()->maxSmileLen) - max = mind.GetData()->maxSmileLen; + max = mind.GetData()->maxSmileLen; for (unsigned j = max; j > 0; j--) { tstring item = sentence.substr(i, j); @@ -540,7 +534,7 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector& keywords, } } } - len = (int)sentence.length(); + len = (int)sentence.length(); bool hadQuestionSigns = false; int it = 0; while (it != len) @@ -556,7 +550,7 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector& keywords, } if (it == len) break; - hadQuestionSigns = false; + hadQuestionSigns = false; int start = it; while (true) { diff --git a/plugins/Boltun/src/Engine/TalkEngine.h b/plugins/Boltun/src/Engine/TalkEngine.h index 423d6a2666..6f95541941 100644 --- a/plugins/Boltun/src/Engine/TalkEngine.h +++ b/plugins/Boltun/src/Engine/TalkEngine.h @@ -31,18 +31,18 @@ class TalkBot public: struct MessageInfo { - private: - std::tstring Question; - MessageInfo(std::tstring q, std::tstring a) - :Question(q), Answer(a) - { - } - public: - std::tstring Answer; - MessageInfo(std::tstring q) - :Question(q) - { - } + private: + std::tstring Question; + MessageInfo(std::tstring q, std::tstring a) + :Question(q), Answer(a) + { + } + public: + std::tstring Answer; + MessageInfo(std::tstring q) + :Question(q) + { + } friend class TalkBot; }; private: @@ -50,7 +50,7 @@ private: { BEST, LOOKSLIKE/*, LOOKSLIKE2*/, BAD, FAIL, NOTHING } Level; - friend std::tstring LevelToStr(TalkBot::Level target); + friend std::tstring LevelToStr(TalkBot::Level target); struct ContactData { @@ -80,7 +80,7 @@ private: bool makeLowercase; bool understandAlways; void UpdateStartChar(std::tstring &str); - typedef std::multimap::const_iterator mm_cit; + typedef std::multimap::const_iterator mm_cit; bool FindExact(ContactData *contactData, const std::tstring &incomingMessage, const std::multimap &map, std::tstring &res); bool FindAny(ValueChooser<> &ch, std::tstring &res); void FindByKeywords(ContactData *contactData, const std::vector &keywords, std::tstring &res/*, std::tstring& ures*/, bool isQuestion); diff --git a/plugins/Boltun/src/Engine/UnrecentChooser.cpp b/plugins/Boltun/src/Engine/UnrecentChooser.cpp index 5a3d4f7fd1..77e1a71d36 100644 --- a/plugins/Boltun/src/Engine/UnrecentChooser.cpp +++ b/plugins/Boltun/src/Engine/UnrecentChooser.cpp @@ -18,7 +18,7 @@ // //*********************************************************** -#include "..\boltun.h" +#include "..\stdafx.h" using namespace std; diff --git a/plugins/Boltun/src/Engine/ValueChooser.h b/plugins/Boltun/src/Engine/ValueChooser.h index e3f9f3c0b9..10256a5b70 100644 --- a/plugins/Boltun/src/Engine/ValueChooser.h +++ b/plugins/Boltun/src/Engine/ValueChooser.h @@ -37,12 +37,12 @@ public: numbers = NULL; UpdateLength(); } - + ~ValueChooser() { delete numbers; } - + void UpdateLength() { delete numbers; //normal if numbers == NULL diff --git a/plugins/Boltun/src/Engine/WordsList.cpp b/plugins/Boltun/src/Engine/WordsList.cpp index d9ba65aa90..439ee229dd 100644 --- a/plugins/Boltun/src/Engine/WordsList.cpp +++ b/plugins/Boltun/src/Engine/WordsList.cpp @@ -18,7 +18,7 @@ // //*********************************************************** -#include "..\boltun.h" +#include "..\stdafx.h" using namespace std; @@ -31,7 +31,7 @@ WordsList::operator tstring() const { tstring res; //if (unstrict) - // res = _T("~"); + // res = _T("~"); set::const_iterator it = words.begin(); if (!words.empty()) while (true) @@ -58,11 +58,11 @@ void WordsList::Parse(tstring s/*, bool allowUnstrict*/) isQuestion = false; /*if (allowUnstrict && s.length() && s[0] == _T('~')) { - s = s.substr(1, s.npos); - unstrict = true; + s = s.substr(1, s.npos); + unstrict = true; } else - unstrict = false;*/ + unstrict = false;*/ int len = (int)s.length() - 1; while (len != -1 && _istspace(s[len])) len--; @@ -94,15 +94,15 @@ bool WordsList::MatchesAll(const vector& s/*, bool& WasStrict*/, float& //WasStrict = true; for (vector::const_iterator it = s.begin(); it != s.end(); ++it) { -/* if (words.find(*it) == words.end()) - if (unstrict) - { - WasStrict = false; - continue; - } - else - return false; - temp.insert((*it));*/ + /* if (words.find(*it) == words.end()) + if (unstrict) + { + WasStrict = false; + continue; + } + else + return false; + temp.insert((*it));*/ if (words.find(*it) != words.end()) temp.insert((*it)); } @@ -137,10 +137,10 @@ vector WordsList::DoesntIncludeAny(const set& list) const res.push_back(*it); return res; } - + bool WordsList::operator<(const WordsList& value) const { - return (tstring)*this < (tstring)value; + return (tstring)*this < (tstring)value; } bool WordsList::operator!=(const WordsList& value) const diff --git a/plugins/Boltun/src/actionQueue.cpp b/plugins/Boltun/src/actionQueue.cpp index fa0ebe63b9..8625d3bde0 100644 --- a/plugins/Boltun/src/actionQueue.cpp +++ b/plugins/Boltun/src/actionQueue.cpp @@ -18,7 +18,7 @@ // //*********************************************************** -#include "boltun.h" +#include "stdafx.h" #include "newpluginapi.h" #include "m_database.h" @@ -29,7 +29,7 @@ using namespace std; extern TalkBot* bot; -typedef void (*ActionHandler)(MCONTACT hContact, const TalkBot::MessageInfo *inf); +typedef void(*ActionHandler)(MCONTACT hContact, const TalkBot::MessageInfo *inf); typedef struct _QueueElement { MCONTACT hContact; @@ -52,7 +52,7 @@ CriticalSection typingContactsLock; void UpdateTimer(); -VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) +VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) { cs.Enter(); QueueElement q = actionQueue.front(); @@ -67,7 +67,7 @@ void UpdateTimer() if (timerID) KillTimer(NULL, timerID); if (actionQueue.size()) - timerID = SetTimer(NULL, 0, actionQueue.front().TimeOffset, TimerProc); + timerID = SetTimer(NULL, 0, actionQueue.front().TimeOffset, TimerProc); else timerID = 0; } @@ -89,8 +89,8 @@ static void TimerAnswer(MCONTACT hContact, const TalkBot::MessageInfo* info) bufsize *= sizeof(TCHAR) + 1; msg = new char[bufsize]; - - if (!WideCharToMultiByte(CP_ACP, 0, info->Answer.c_str(), -1, msg, size, + + if (!WideCharToMultiByte(CP_ACP, 0, info->Answer.c_str(), -1, msg, size, NULL, NULL)) memset(msg, '-', (size - 1)); //In case of fault return "----" in ANSI part memcpy(msg + size, info->Answer.c_str(), size * 2); @@ -98,20 +98,20 @@ static void TimerAnswer(MCONTACT hContact, const TalkBot::MessageInfo* info) CallContactService(hContact, PSS_MESSAGE, PREF_TCHAR, (LPARAM)msg); memset(&ldbei, 0, sizeof(ldbei)); - ldbei.cbSize = sizeof(ldbei); + ldbei.cbSize = sizeof(ldbei); //FIXME: Error may happen - ldbei.cbBlob = bufsize; - ldbei.pBlob = (PBYTE)(void*)msg; + ldbei.cbBlob = bufsize; + ldbei.pBlob = (PBYTE)(void*)msg; ldbei.eventType = EVENTTYPE_MESSAGE; - ldbei.flags = DBEF_SENT; - ldbei.szModule = BOLTUN_NAME; + ldbei.flags = DBEF_SENT; + ldbei.szModule = BOLTUN_NAME; ldbei.timestamp = (DWORD)time(NULL); db_event_add(hContact, &ldbei); bot->AnswerGiven(hContact, *info); delete info; - delete [] msg; + delete[] msg; typingContactsLock.Enter(); typingContacts.erase(hContact); @@ -120,7 +120,7 @@ static void TimerAnswer(MCONTACT hContact, const TalkBot::MessageInfo* info) static void StartTyping(MCONTACT hContact, const TalkBot::MessageInfo*) { - CallService(MS_PROTO_SELFISTYPING, hContact, + CallService(MS_PROTO_SELFISTYPING, hContact, (LPARAM)PROTOTYPE_SELFTYPING_ON); typingContactsLock.Enter(); typingContacts.insert(hContact); @@ -140,13 +140,13 @@ void DoAnswer(MCONTACT hContact, const TalkBot::MessageInfo *info, bool sticky = if (Config.PauseRandom) { //Let it be up to 4 times longer. - waitTime = waitTime * (rand() % 300) / 100 + waitTime; + waitTime = waitTime * (rand() % 300) / 100 + waitTime; } if (waitTime == 0) waitTime = 50; //it's essential, because otherwise message will be added later - //then its response, that will cause incorrect ordering of - //messages in the opened history (reopening will - //help, but anyway it's no good) + //then its response, that will cause incorrect ordering of + //messages in the opened history (reopening will + //help, but anyway it's no good) if (NotifyTyping(hContact) && Config.AnswerThinkTime) { thinkTime = Config.AnswerThinkTime * 1000; @@ -154,7 +154,7 @@ void DoAnswer(MCONTACT hContact, const TalkBot::MessageInfo *info, bool sticky = { //Let it be up to 4 times longer. thinkTime = thinkTime * (rand() % 300) / 100 + thinkTime; - } + } } cs.Enter(); //Check if this contact's timer handler is now waiting for a cs. @@ -208,7 +208,7 @@ void DoAnswer(MCONTACT hContact, const TalkBot::MessageInfo *info, bool sticky = void AnswerToContact(MCONTACT hContact, const TCHAR* messageToAnswer) { - if (Config.TalkWarnContacts && db_get_b(hContact, BOLTUN_KEY, + if (Config.TalkWarnContacts && db_get_b(hContact, BOLTUN_KEY, DB_CONTACT_WARNED, FALSE) == FALSE) { DoAnswer(hContact, new TalkBot::MessageInfo((const TCHAR*)Config.WarnText), true); diff --git a/plugins/Boltun/src/boltun.cpp b/plugins/Boltun/src/boltun.cpp index c00713880b..13fbecfee9 100644 --- a/plugins/Boltun/src/boltun.cpp +++ b/plugins/Boltun/src/boltun.cpp @@ -18,7 +18,7 @@ // //*********************************************************** -#include "boltun.h" +#include "stdafx.h" int hLangpack; @@ -44,7 +44,7 @@ PLUGININFOEX pluginInfo = { __AUTHORWEB, UNICODE_AWARE, // {488C5C84-56DA-434F-96F1-B18900DEF760} - {0x488c5c84, 0x56da, 0x434f, {0x96, 0xf1, 0xb1, 0x89, 0x0, 0xde, 0xf7, 0x60}} + { 0x488c5c84, 0x56da, 0x434f, { 0x96, 0xf1, 0xb1, 0x89, 0x0, 0xde, 0xf7, 0x60 } } }; static HGENMENU hMenuItemAutoChat, hMenuItemNotToChat, hMenuItemStartChatting; @@ -72,7 +72,7 @@ TCHAR* GetFullName(const TCHAR* filename) if (!_tcschr(filename, _T(':'))) { size_t plen = _tcslen(path); - fullname = new TCHAR[plen+flen+1]; + fullname = new TCHAR[plen + flen + 1]; fullname[0] = NULL; _tcscat(fullname, path); _tcscat(fullname, filename); @@ -94,7 +94,7 @@ static bool LoadMind(const TCHAR* filename, int &line) { mind->Load(fullname); } - catch(Mind::CorruptedMind c) + catch (Mind::CorruptedMind c) { line = c.line; delete mind; @@ -103,7 +103,7 @@ static bool LoadMind(const TCHAR* filename, int &line) SetCursor(oldCur); return false; } - catch(...) + catch (...) { delete mind; if (fullname != filename) @@ -152,7 +152,7 @@ static bool LoadMind(const TCHAR* filename, int &line) { mind->LoadSmiles(data, size); } - catch(...) + catch (...) { res = false; } @@ -172,10 +172,10 @@ static bool LoadMind(const TCHAR* filename, int &line) /*static bool SaveMind(const TCHAR* filename) { - if (!bot) - return false; - bot->GetMind().Save(filename); - return true; +if (!bot) +return false; +bot->GetMind().Save(filename); +return true; }*/ static bool BoltunAutoChat(MCONTACT hContact) @@ -190,16 +190,16 @@ static bool BoltunAutoChat(MCONTACT hContact) if (Config.TalkEveryoneWhileAway) { int status = CallService(MS_CLIST_GETSTATUSMODE, 0, 0); - if (status == ID_STATUS_AWAY || - status == ID_STATUS_DND || - status == ID_STATUS_NA || - status == ID_STATUS_OCCUPIED || + if (status == ID_STATUS_AWAY || + status == ID_STATUS_DND || + status == ID_STATUS_NA || + status == ID_STATUS_OCCUPIED || status == ID_STATUS_ONTHEPHONE || status == ID_STATUS_OUTTOLUNCH) return true; } - if ((db_get_b(hContact,"CList","NotOnList",0) == 1) && + if ((db_get_b(hContact, "CList", "NotOnList", 0) == 1) && Config.TalkWithNotInList) return true; @@ -244,7 +244,7 @@ static int MessageEventAdded(WPARAM hContact, LPARAM hDbEvent) return 0; } -BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) { hInst = hinstDLL; return TRUE; @@ -266,78 +266,78 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPAR static bool loading = true; switch (uMsg) { - case WM_INITDIALOG: - loading = true; - TranslateDialogDefault(hwndDlg); - CheckDlgButton(hwndDlg, IDC_EVERYBODY, Config.TalkWithEverybody ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_NOTINLIST, Config.TalkWithNotInList ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_AUTOAWAY, Config.TalkEveryoneWhileAway ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_WARN, Config.TalkWarnContacts ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_MARKREAD, Config.MarkAsRead ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_PAUSEDEPENDS, Config.PauseDepends ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_PAUSERANDOM, Config.PauseRandom ? BST_CHECKED : BST_UNCHECKED); - SendDlgItemMessage(hwndDlg, IDC_WAITTIME, EM_SETLIMITTEXT, 3, 0); - SetDlgItemInt(hwndDlg, IDC_WAITTIME, Config.AnswerPauseTime, FALSE); - SendDlgItemMessage(hwndDlg, IDC_THINKTIME, EM_SETLIMITTEXT, 3, 0); - SetDlgItemInt(hwndDlg, IDC_THINKTIME, Config.AnswerThinkTime, FALSE); - SendDlgItemMessage(hwndDlg, IDC_WARNTXT, EM_SETLIMITTEXT, MAX_WARN_TEXT, 0); - SetDlgItemText(hwndDlg, IDC_WARNTXT, Config.WarnText); + case WM_INITDIALOG: + loading = true; + TranslateDialogDefault(hwndDlg); + CheckDlgButton(hwndDlg, IDC_EVERYBODY, Config.TalkWithEverybody ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_NOTINLIST, Config.TalkWithNotInList ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_AUTOAWAY, Config.TalkEveryoneWhileAway ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_WARN, Config.TalkWarnContacts ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_MARKREAD, Config.MarkAsRead ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_PAUSEDEPENDS, Config.PauseDepends ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_PAUSERANDOM, Config.PauseRandom ? BST_CHECKED : BST_UNCHECKED); + SendDlgItemMessage(hwndDlg, IDC_WAITTIME, EM_SETLIMITTEXT, 3, 0); + SetDlgItemInt(hwndDlg, IDC_WAITTIME, Config.AnswerPauseTime, FALSE); + SendDlgItemMessage(hwndDlg, IDC_THINKTIME, EM_SETLIMITTEXT, 3, 0); + SetDlgItemInt(hwndDlg, IDC_THINKTIME, Config.AnswerThinkTime, FALSE); + SendDlgItemMessage(hwndDlg, IDC_WARNTXT, EM_SETLIMITTEXT, MAX_WARN_TEXT, 0); + SetDlgItemText(hwndDlg, IDC_WARNTXT, Config.WarnText); + UpdateEverybodyCheckboxes(hwndDlg); + loading = false; + return TRUE; + case WM_COMMAND: + if (LOWORD(wParam) == IDC_EVERYBODY && HIWORD(wParam) == BN_CLICKED) UpdateEverybodyCheckboxes(hwndDlg); - loading = false; - return TRUE; - case WM_COMMAND: - if (LOWORD(wParam) == IDC_EVERYBODY && HIWORD(wParam) == BN_CLICKED) - UpdateEverybodyCheckboxes(hwndDlg); - if (!loading) - { - bool notify = true; - switch (LOWORD(wParam)) - { - case IDC_WARNTXT: - case IDC_WAITTIME: - case IDC_THINKTIME: - if (HIWORD(wParam) != EN_CHANGE) - notify = false; - break; - } - if (notify) - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } - break; - case WM_NOTIFY: + if (!loading) { - NMHDR* nmhdr = (NMHDR*)lParam; - switch (nmhdr->code) + bool notify = true; + switch (LOWORD(wParam)) { - case PSN_APPLY: - case PSN_KILLACTIVE: - { - Config.TalkWithEverybody = IsDlgButtonChecked(hwndDlg, IDC_EVERYBODY) == BST_CHECKED ? TRUE : FALSE; - Config.TalkWithNotInList = IsDlgButtonChecked(hwndDlg, IDC_NOTINLIST) == BST_CHECKED ? TRUE : FALSE; - Config.TalkEveryoneWhileAway = IsDlgButtonChecked(hwndDlg, IDC_AUTOAWAY) == BST_CHECKED ? TRUE : FALSE; - Config.TalkWarnContacts = IsDlgButtonChecked(hwndDlg, IDC_WARN) == BST_CHECKED ? TRUE : FALSE; - Config.MarkAsRead = IsDlgButtonChecked(hwndDlg, IDC_MARKREAD) == BST_CHECKED ? TRUE : FALSE; - Config.PauseDepends = IsDlgButtonChecked(hwndDlg, IDC_PAUSEDEPENDS) == BST_CHECKED ? TRUE : FALSE; - Config.PauseRandom = IsDlgButtonChecked(hwndDlg, IDC_PAUSERANDOM) == BST_CHECKED ? TRUE : FALSE; - Config.AnswerPauseTime = GetDlgItemInt(hwndDlg, IDC_WAITTIME, &bTranslated, FALSE); - if (!bTranslated) - Config.AnswerPauseTime = 2; - Config.AnswerThinkTime = GetDlgItemInt(hwndDlg, IDC_THINKTIME, &bTranslated, FALSE); - if (!bTranslated) - Config.AnswerThinkTime = 4; - TCHAR c[MAX_WARN_TEXT]; - bTranslated = GetDlgItemText(hwndDlg, IDC_WARNTXT, c, SIZEOF(c)); - if(bTranslated) - Config.WarnText = c; - else - Config.WarnText = TranslateTS(DEFAULT_WARN_TEXT); - } - return TRUE; + case IDC_WARNTXT: + case IDC_WAITTIME: + case IDC_THINKTIME: + if (HIWORD(wParam) != EN_CHANGE) + notify = false; + break; } - break; + if (notify) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + } + break; + case WM_NOTIFY: + { + NMHDR* nmhdr = (NMHDR*)lParam; + switch (nmhdr->code) + { + case PSN_APPLY: + case PSN_KILLACTIVE: + { + Config.TalkWithEverybody = IsDlgButtonChecked(hwndDlg, IDC_EVERYBODY) == BST_CHECKED ? TRUE : FALSE; + Config.TalkWithNotInList = IsDlgButtonChecked(hwndDlg, IDC_NOTINLIST) == BST_CHECKED ? TRUE : FALSE; + Config.TalkEveryoneWhileAway = IsDlgButtonChecked(hwndDlg, IDC_AUTOAWAY) == BST_CHECKED ? TRUE : FALSE; + Config.TalkWarnContacts = IsDlgButtonChecked(hwndDlg, IDC_WARN) == BST_CHECKED ? TRUE : FALSE; + Config.MarkAsRead = IsDlgButtonChecked(hwndDlg, IDC_MARKREAD) == BST_CHECKED ? TRUE : FALSE; + Config.PauseDepends = IsDlgButtonChecked(hwndDlg, IDC_PAUSEDEPENDS) == BST_CHECKED ? TRUE : FALSE; + Config.PauseRandom = IsDlgButtonChecked(hwndDlg, IDC_PAUSERANDOM) == BST_CHECKED ? TRUE : FALSE; + Config.AnswerPauseTime = GetDlgItemInt(hwndDlg, IDC_WAITTIME, &bTranslated, FALSE); + if (!bTranslated) + Config.AnswerPauseTime = 2; + Config.AnswerThinkTime = GetDlgItemInt(hwndDlg, IDC_THINKTIME, &bTranslated, FALSE); + if (!bTranslated) + Config.AnswerThinkTime = 4; + TCHAR c[MAX_WARN_TEXT]; + bTranslated = GetDlgItemText(hwndDlg, IDC_WARNTXT, c, SIZEOF(c)); + if (bTranslated) + Config.WarnText = c; + else + Config.WarnText = TranslateTS(DEFAULT_WARN_TEXT); + } + return TRUE; } break; } + break; + } return 0; } @@ -357,126 +357,126 @@ static INT_PTR CALLBACK EngineDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP static int changeCount = 0; switch (uMsg) { - case WM_INITDIALOG: - loading = true; - TranslateDialogDefault(hwndDlg); - CheckDlgButton(hwndDlg, IDC_ENGINE_SILENT, Config.EngineStaySilent ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_ENGINE_LOWERCASE, Config.EngineMakeLowerCase ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_ENGINE_UNDERSTAND_ALWAYS, Config.EngineUnderstandAlways ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemText(hwndDlg, IDC_MINDFILE, Config.MindFileName); - EnableWindow(GetDlgItem(hwndDlg, IDC_BTNSAVE), blInit); + case WM_INITDIALOG: + loading = true; + TranslateDialogDefault(hwndDlg); + CheckDlgButton(hwndDlg, IDC_ENGINE_SILENT, Config.EngineStaySilent ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_ENGINE_LOWERCASE, Config.EngineMakeLowerCase ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_ENGINE_UNDERSTAND_ALWAYS, Config.EngineUnderstandAlways ? BST_CHECKED : BST_UNCHECKED); + SetDlgItemText(hwndDlg, IDC_MINDFILE, Config.MindFileName); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTNSAVE), blInit); + UpdateUnderstandAlwaysCheckbox(hwndDlg); + loading = false; + return TRUE; + case WM_COMMAND: + param = LOWORD(wParam); + if (param == IDC_ENGINE_SILENT && HIWORD(wParam) == BN_CLICKED) UpdateUnderstandAlwaysCheckbox(hwndDlg); - loading = false; - return TRUE; - case WM_COMMAND: - param = LOWORD(wParam); - if (param == IDC_ENGINE_SILENT && HIWORD(wParam) == BN_CLICKED) - UpdateUnderstandAlwaysCheckbox(hwndDlg); - OPENFILENAME ofn; - switch(param) + OPENFILENAME ofn; + switch (param) + { + case IDC_BTNPATH: + { + const size_t fileNameSize = 5000; + TCHAR *filename = new TCHAR[fileNameSize]; + TCHAR *fullname = GetFullName(Config.MindFileName); + _tcscpy(filename, fullname); + if (fullname != Config.MindFileName) + delete[] fullname; + + memset(&ofn, 0, sizeof(ofn)); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = GetParent(hwndDlg); + + TCHAR* mind = TranslateTS(MIND_FILE_DESC); + TCHAR* anyfile = TranslateTS(ALL_FILES_DESC); + size_t l = _tcslen(MIND_DIALOG_FILTER) + + _tcslen(mind) + _tcslen(anyfile); + TCHAR *filt = new TCHAR[l]; + mir_sntprintf(filt, l, MIND_DIALOG_FILTER, mind, anyfile); + for (size_t i = 0; i < l; i++) + if (filt[i] == '\1') + filt[i] = '\0'; + ofn.lpstrFilter = filt; + + ofn.lpstrFile = filename; + ofn.nMaxFile = fileNameSize; + ofn.Flags = OFN_FILEMUSTEXIST; + ofn.lpstrInitialDir = path; + if (!GetOpenFileName(&ofn)) { - case IDC_BTNPATH: - { - const size_t fileNameSize = 5000; - TCHAR *filename = new TCHAR[fileNameSize]; - TCHAR *fullname = GetFullName(Config.MindFileName); - _tcscpy(filename, fullname); - if (fullname != Config.MindFileName) - delete[] fullname; - - memset(&ofn, 0, sizeof(ofn)); - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = GetParent(hwndDlg); - - TCHAR* mind = TranslateTS(MIND_FILE_DESC); - TCHAR* anyfile = TranslateTS(ALL_FILES_DESC); - size_t l = _tcslen(MIND_DIALOG_FILTER) - + _tcslen(mind) + _tcslen(anyfile); - TCHAR *filt = new TCHAR[l]; - mir_sntprintf(filt, l, MIND_DIALOG_FILTER, mind, anyfile); - for (size_t i = 0; i < l; i++) - if (filt[i] == '\1') - filt[i] = '\0'; - ofn.lpstrFilter = filt; - - ofn.lpstrFile = filename; - ofn.nMaxFile = fileNameSize; - ofn.Flags = OFN_FILEMUSTEXIST; - ofn.lpstrInitialDir = path; - if (!GetOpenFileName(&ofn)) - { - delete[] filename; - delete[] filt; - break; - } - delete[] filt; - TCHAR* origf = filename; - TCHAR* f = filename; - TCHAR* p = path; - while (*p && *f) - { - TCHAR p1 = (TCHAR)CharLower((TCHAR*)(long)*p++); - TCHAR f1 = (TCHAR)CharLower((TCHAR*)(long)*f++); - if (p1 != f1) - break; - } - if (!*p) - filename = f; - Config.MindFileName = filename; - SetDlgItemText(hwndDlg, IDC_MINDFILE, filename); - delete[] origf; - } - case IDC_BTNRELOAD: - { - const TCHAR *c = Config.MindFileName; - int line; - bTranslated = blInit = LoadMind(c, line); - if (!bTranslated) - { - TCHAR message[5000]; - mir_sntprintf(message, SIZEOF(message), TranslateTS(FAILED_TO_LOAD_BASE), line, c); - MessageBox(NULL, message, TranslateTS(BOLTUN_ERROR), MB_ICONERROR|MB_TASKMODAL|MB_OK); - } + delete[] filename; + delete[] filt; + break; + } + delete[] filt; + TCHAR* origf = filename; + TCHAR* f = filename; + TCHAR* p = path; + while (*p && *f) + { + TCHAR p1 = (TCHAR)CharLower((TCHAR*)(long)*p++); + TCHAR f1 = (TCHAR)CharLower((TCHAR*)(long)*f++); + if (p1 != f1) break; - } - default: - if (!loading) - { - if (param == IDC_MINDFILE/* && HIWORD(wParam) != EN_CHANGE*/) - break; - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } } - break; - case WM_NOTIFY: + if (!*p) + filename = f; + Config.MindFileName = filename; + SetDlgItemText(hwndDlg, IDC_MINDFILE, filename); + delete[] origf; + } + case IDC_BTNRELOAD: { - NMHDR* nmhdr = (NMHDR*)lParam; - switch (nmhdr->code) + const TCHAR *c = Config.MindFileName; + int line; + bTranslated = blInit = LoadMind(c, line); + if (!bTranslated) { - case PSN_APPLY: - case PSN_KILLACTIVE: - { - Config.EngineStaySilent = IsDlgButtonChecked(hwndDlg, IDC_ENGINE_SILENT) == BST_CHECKED ? TRUE : FALSE; - Config.EngineMakeLowerCase = IsDlgButtonChecked(hwndDlg, IDC_ENGINE_LOWERCASE) == BST_CHECKED ? TRUE : FALSE; - Config.EngineUnderstandAlways = IsDlgButtonChecked(hwndDlg, IDC_ENGINE_UNDERSTAND_ALWAYS) == BST_CHECKED ? TRUE : FALSE; - UpdateEngine(); - TCHAR c[MAX_MIND_FILE]; - bTranslated = GetDlgItemText(hwndDlg, IDC_MINDFILE, c, SIZEOF(c)); - if (bTranslated) - Config.MindFileName = c; - else - Config.MindFileName = DEFAULT_MIND_FILE; - } - return TRUE; + TCHAR message[5000]; + mir_sntprintf(message, SIZEOF(message), TranslateTS(FAILED_TO_LOAD_BASE), line, c); + MessageBox(NULL, message, TranslateTS(BOLTUN_ERROR), MB_ICONERROR | MB_TASKMODAL | MB_OK); } break; } + default: + if (!loading) + { + if (param == IDC_MINDFILE/* && HIWORD(wParam) != EN_CHANGE*/) + break; + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + } + } + break; + case WM_NOTIFY: + { + NMHDR* nmhdr = (NMHDR*)lParam; + switch (nmhdr->code) + { + case PSN_APPLY: + case PSN_KILLACTIVE: + { + Config.EngineStaySilent = IsDlgButtonChecked(hwndDlg, IDC_ENGINE_SILENT) == BST_CHECKED ? TRUE : FALSE; + Config.EngineMakeLowerCase = IsDlgButtonChecked(hwndDlg, IDC_ENGINE_LOWERCASE) == BST_CHECKED ? TRUE : FALSE; + Config.EngineUnderstandAlways = IsDlgButtonChecked(hwndDlg, IDC_ENGINE_UNDERSTAND_ALWAYS) == BST_CHECKED ? TRUE : FALSE; + UpdateEngine(); + TCHAR c[MAX_MIND_FILE]; + bTranslated = GetDlgItemText(hwndDlg, IDC_MINDFILE, c, SIZEOF(c)); + if (bTranslated) + Config.MindFileName = c; + else + Config.MindFileName = DEFAULT_MIND_FILE; + } + return TRUE; + } break; } + break; + } return 0; } -static int MessageOptInit(WPARAM wParam, LPARAM lParam) +static int MessageOptInit(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = { 0 }; odp.position = 910000000; @@ -487,7 +487,7 @@ static int MessageOptInit(WPARAM wParam, LPARAM lParam) odp.pszTemplate = MAKEINTRESOURCEA(IDD_MAIN); odp.pszTab = TAB_GENERAL; Options_AddPage(wParam, &odp); - + odp.pfnDlgProc = EngineDlgProc; odp.pszTemplate = MAKEINTRESOURCEA(IDD_ENGINE); odp.pszTab = TAB_ENGINE; @@ -495,7 +495,7 @@ static int MessageOptInit(WPARAM wParam, LPARAM lParam) return 0; } -static int ContactClick(WPARAM hContact, LPARAM lParam, BOOL clickNotToChat) +static int ContactClick(WPARAM hContact, LPARAM, BOOL clickNotToChat) { BOOL boltunautochat = db_get_b(hContact, BOLTUN_KEY, DB_CONTACT_BOLTUN_AUTO_CHAT, FALSE); BOOL boltunnottochat = db_get_b(hContact, BOLTUN_KEY, DB_CONTACT_BOLTUN_NOT_TO_CHAT, FALSE); @@ -503,7 +503,7 @@ static int ContactClick(WPARAM hContact, LPARAM lParam, BOOL clickNotToChat) if (clickNotToChat) { boltunnottochat = !boltunnottochat; - if(boltunnottochat) + if (boltunnottochat) { boltunautochat = FALSE; } @@ -511,7 +511,7 @@ static int ContactClick(WPARAM hContact, LPARAM lParam, BOOL clickNotToChat) else { boltunautochat = !boltunautochat; - if(boltunautochat) + if (boltunautochat) { boltunnottochat = FALSE; } @@ -537,17 +537,17 @@ static INT_PTR ContactClickNotToChat(WPARAM hContact, LPARAM lParam) return ContactClick(hContact, lParam, 1); } -static INT_PTR ContactClickStartChatting(WPARAM hContact, LPARAM lParam) +static INT_PTR ContactClickStartChatting(WPARAM hContact, LPARAM) { StartChatting(hContact); return 0; } -static int MessagePrebuild(WPARAM hContact, LPARAM lParam) +static int MessagePrebuild(WPARAM hContact, LPARAM) { CLISTMENUITEM clmi = { sizeof(clmi) }; - if (!blInit || (db_get_b(hContact,"CList","NotOnList",0) == 1)) { + if (!blInit || (db_get_b(hContact, "CList", "NotOnList", 0) == 1)) { clmi.flags = CMIM_FLAGS | CMIF_GRAYED; Menu_ModifyItem(hMenuItemAutoChat, &clmi); @@ -557,18 +557,18 @@ static int MessagePrebuild(WPARAM hContact, LPARAM lParam) BOOL boltunautochat = db_get_b(hContact, BOLTUN_KEY, DB_CONTACT_BOLTUN_AUTO_CHAT, FALSE); BOOL boltunnottochat = db_get_b(hContact, BOLTUN_KEY, DB_CONTACT_BOLTUN_NOT_TO_CHAT, FALSE); - clmi.flags = CMIM_FLAGS | CMIM_ICON | (boltunautochat ? CMIF_CHECKED : 0); - clmi.hIcon = LoadIcon( GetModuleHandle(NULL), MAKEINTRESOURCE((boltunautochat ? IDI_TICK : IDI_NOTICK))); + clmi.flags = CMIM_FLAGS | CMIM_ICON | (boltunautochat ? CMIF_CHECKED : 0); + clmi.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE((boltunautochat ? IDI_TICK : IDI_NOTICK))); Menu_ModifyItem(hMenuItemAutoChat, &clmi); - clmi.flags = CMIM_FLAGS | CMIM_ICON | (boltunnottochat ? CMIF_CHECKED : 0); - clmi.hIcon = LoadIcon( GetModuleHandle(NULL), MAKEINTRESOURCE((boltunnottochat ? IDI_TICK : IDI_NOTICK))); + clmi.flags = CMIM_FLAGS | CMIM_ICON | (boltunnottochat ? CMIF_CHECKED : 0); + clmi.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE((boltunnottochat ? IDI_TICK : IDI_NOTICK))); Menu_ModifyItem(hMenuItemNotToChat, &clmi); } return 0; } -extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) { return &pluginInfo; } @@ -590,7 +590,7 @@ extern "C" int __declspec(dllexport) Load(void) return false; } } - *(_tcsrchr(path, _T('\\'))+1) = _T('\0'); + *(_tcsrchr(path, _T('\\')) + 1) = _T('\0'); /*initialize miranda hooks and services on options dialog*/ HookEvent(ME_OPT_INITIALISE, MessageOptInit); @@ -603,21 +603,21 @@ extern "C" int __declspec(dllexport) Load(void) CreateServiceFunction(SERV_CONTACT_START_CHATTING, ContactClickStartChatting); { CLISTMENUITEM mi = { sizeof(mi) }; - mi.position = -50010002; //TODO: check the warning - mi.pszName = BOLTUN_AUTO_CHAT; - mi.pszService = SERV_CONTACT_AUTO_CHAT; - hMenuItemAutoChat = Menu_AddContactMenuItem(&mi); - - mi.position = -50010001; //TODO: check the warning - mi.pszName = BOLTUN_NOT_TO_CHAT; - mi.pszService = SERV_CONTACT_NOT_TO_CHAT; - hMenuItemNotToChat = Menu_AddContactMenuItem(&mi); - - mi.flags = CMIF_NOTOFFLINE; - mi.position = -50010000; //TODO: check the warning - mi.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_RECVMSG)); - mi.pszName = BOLTUN_START_CHATTING; - mi.pszService = SERV_CONTACT_START_CHATTING; + mi.position = -50010002; //TODO: check the warning + mi.pszName = BOLTUN_AUTO_CHAT; + mi.pszService = SERV_CONTACT_AUTO_CHAT; + hMenuItemAutoChat = Menu_AddContactMenuItem(&mi); + + mi.position = -50010001; //TODO: check the warning + mi.pszName = BOLTUN_NOT_TO_CHAT; + mi.pszService = SERV_CONTACT_NOT_TO_CHAT; + hMenuItemNotToChat = Menu_AddContactMenuItem(&mi); + + mi.flags = CMIF_NOTOFFLINE; + mi.position = -50010000; //TODO: check the warning + mi.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_RECVMSG)); + mi.pszName = BOLTUN_START_CHATTING; + mi.pszService = SERV_CONTACT_START_CHATTING; hMenuItemStartChatting = Menu_AddContactMenuItem(&mi); } @@ -627,7 +627,7 @@ extern "C" int __declspec(dllexport) Load(void) { TCHAR path[2000]; mir_sntprintf(path, SIZEOF(path), TranslateTS(FAILED_TO_LOAD_BASE), line, (const TCHAR*)Config.MindFileName); - MessageBox(NULL, path, TranslateTS(BOLTUN_ERROR), MB_ICONERROR|MB_TASKMODAL|MB_OK); + MessageBox(NULL, path, TranslateTS(BOLTUN_ERROR), MB_ICONERROR | MB_TASKMODAL | MB_OK); } return 0; } @@ -636,14 +636,14 @@ extern "C" int __declspec(dllexport) Unload(void) { if (pTimer) KillTimer(NULL, pTimer); - if(blInit) + if (blInit) { #if 0 //No need to save, we don't have studying algorithm if(Config.MindFileName && !SaveMind(Config.MindFileName)) { -//This causes errors with development core when calling MessageBox. -//It seems that it's now a Boltun problem. -//So in case of saving error we will remain silent + //This causes errors with development core when calling MessageBox. + //It seems that it's now a Boltun problem. + //So in case of saving error we will remain silent #if 0 TCHAR path[MAX_PATH]; mir_sntprintf(path, SIZEOF(path), TranslateTS(FAILED_TO_SAVE_BASE), (const TCHAR*)Config.MindFileName); diff --git a/plugins/Boltun/src/boltun.h b/plugins/Boltun/src/boltun.h deleted file mode 100644 index e831eaeb8d..0000000000 --- a/plugins/Boltun/src/boltun.h +++ /dev/null @@ -1,95 +0,0 @@ -//*********************************************************** -// Copyright © 2003-2008 Alexander S. Kiselev, Valentin Pavlyuchenko -// -// This file is part of Boltun. -// -// Boltun is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Boltun is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Boltun. If not, see . -// -//*********************************************************** - -#ifndef _BOLTUN_H -#define _BOLTUN_H - -#define _CRT_SECURE_NO_WARNINGS - -#include -#include -#include -#include - -#include -#include - -#include "newpluginapi.h" -#include "m_clist.h" -#include "m_system_cpp.h" -#include "m_database.h" -#include "m_options.h" -#include "m_langpack.h" - -#include "resource.h" -#include "version.h" -#include "config.h" -#include "actionQueue.h" -#include "Engine/TalkEngine.h" -#include "Engine/WordsList.h" -#include "Engine/UnrecentChooser.h" -#include "Engine/MyCodeCvt.h" -#include "Engine/Mind.h" - -#define BOLTUN_KEY "Boltun" - -//Service names -#define SERV_CONTACT_AUTO_CHAT "Boltun/ContactAutoChat" -#define SERV_CONTACT_NOT_TO_CHAT "Boltun/ContactNotToChat" -#define SERV_CONTACT_START_CHATTING "Boltun/ContactStartChatting" - -//Database keys -#define DB_CONTACT_BOLTUN_NOT_TO_CHAT "BoltunNotToChat" -#define DB_CONTACT_BOLTUN_AUTO_CHAT "BoltunAutoChat" -#define DB_CONTACT_WARNED "Warned" - -//Plugin group in settings -#define BOLTUN_GROUP LPGEN("Message sessions") - -//Filename depends on UNICODE -#define DEFAULT_MIND_FILE _T("boltun.mindw") - -//=============================================== -// These are strings for translation: -//=============================================== - -//Plugin name -#define BOLTUN_NAME "Boltun" - -#define MIND_FILE_DESC LPGENT("Mind Files") -#define ALL_FILES_DESC LPGENT("All Files") - -//UI strings -#define BOLTUN_AUTO_CHAT LPGEN("Boltun/Auto Chat") -#define BOLTUN_NOT_TO_CHAT LPGEN("Boltun/Not to Chat") -#define BOLTUN_START_CHATTING LPGEN("Boltun/Start Chatting") - -#define DEFAULT_WARN_TEXT LPGENT("Hello. I'm Boltun! I'll talk to you, while my owner is away. Please write without mistakes!") - -// Error messages -#define BOLTUN_ERROR LPGENT("Boltun Error") -#define FAILED_TO_LOAD_BASE LPGENT("Failed to load base of remarks. Error at line %d of %s. (Or few lines before).") -#define FAILED_TO_SAVE_BASE LPGENT("Failed to save base of remarks to %s") - -//Settings tab names -#define TAB_GENERAL LPGEN("General Settings") -#define TAB_ENGINE LPGEN("Engine Settings") - -#endif /*_BOLTUN_H*/ diff --git a/plugins/Boltun/src/config.cpp b/plugins/Boltun/src/config.cpp index b05a560b2b..40517216c1 100644 --- a/plugins/Boltun/src/config.cpp +++ b/plugins/Boltun/src/config.cpp @@ -18,7 +18,7 @@ // //*********************************************************** -#include "boltun.h" +#include "stdafx.h" //Database keys #define DB_EVERYBODY "Everybody" @@ -142,7 +142,7 @@ BoltunConfig::~BoltunConfig() class _BoltunConfigInit { public: - BoltunConfig cfg; + BoltunConfig cfg; }; _BoltunConfigInit inst; diff --git a/plugins/Boltun/src/config.h b/plugins/Boltun/src/config.h index a51240ad70..a1cd72c7de 100644 --- a/plugins/Boltun/src/config.h +++ b/plugins/Boltun/src/config.h @@ -27,8 +27,8 @@ template class Property { public: - typedef const T (__thiscall BaseClass::*Getter)(); - typedef const T (__thiscall BaseClass::*Setter)(const T); + typedef const T(__thiscall BaseClass::*Getter)(); + typedef const T(__thiscall BaseClass::*Setter)(const T); private: const Getter getter; const Setter setter; diff --git a/plugins/Boltun/src/stdafx.cpp b/plugins/Boltun/src/stdafx.cpp deleted file mode 100644 index b3cf38f181..0000000000 --- a/plugins/Boltun/src/stdafx.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright (C) 2012-15 Miranda NG project (http://miranda-ng.org) - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation version 2 -of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "boltun.h" \ No newline at end of file diff --git a/plugins/Boltun/src/stdafx.cxx b/plugins/Boltun/src/stdafx.cxx new file mode 100644 index 0000000000..6fb37564b7 --- /dev/null +++ b/plugins/Boltun/src/stdafx.cxx @@ -0,0 +1,18 @@ +/* +Copyright (C) 2012-15 Miranda NG project (http://miranda-ng.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation version 2 +of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "stdafx.h" \ No newline at end of file diff --git a/plugins/Boltun/src/stdafx.h b/plugins/Boltun/src/stdafx.h new file mode 100644 index 0000000000..2199be3cac --- /dev/null +++ b/plugins/Boltun/src/stdafx.h @@ -0,0 +1,93 @@ +//*********************************************************** +// Copyright © 2003-2008 Alexander S. Kiselev, Valentin Pavlyuchenko +// +// This file is part of Boltun. +// +// Boltun is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Boltun is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Boltun. If not, see . +// +//*********************************************************** + +#ifndef _BOLTUN_H +#define _BOLTUN_H + +#include +#include +#include +#include + +#include +#include + +#include "newpluginapi.h" +#include "m_clist.h" +#include "m_system_cpp.h" +#include "m_database.h" +#include "m_options.h" +#include "m_langpack.h" + +#include "resource.h" +#include "version.h" +#include "config.h" +#include "actionQueue.h" +#include "Engine/TalkEngine.h" +#include "Engine/WordsList.h" +#include "Engine/UnrecentChooser.h" +#include "Engine/MyCodeCvt.h" +#include "Engine/Mind.h" + +#define BOLTUN_KEY "Boltun" + +//Service names +#define SERV_CONTACT_AUTO_CHAT "Boltun/ContactAutoChat" +#define SERV_CONTACT_NOT_TO_CHAT "Boltun/ContactNotToChat" +#define SERV_CONTACT_START_CHATTING "Boltun/ContactStartChatting" + +//Database keys +#define DB_CONTACT_BOLTUN_NOT_TO_CHAT "BoltunNotToChat" +#define DB_CONTACT_BOLTUN_AUTO_CHAT "BoltunAutoChat" +#define DB_CONTACT_WARNED "Warned" + +//Plugin group in settings +#define BOLTUN_GROUP LPGEN("Message sessions") + +//Filename depends on UNICODE +#define DEFAULT_MIND_FILE _T("boltun.mindw") + +//=============================================== +// These are strings for translation: +//=============================================== + +//Plugin name +#define BOLTUN_NAME "Boltun" + +#define MIND_FILE_DESC LPGENT("Mind Files") +#define ALL_FILES_DESC LPGENT("All Files") + +//UI strings +#define BOLTUN_AUTO_CHAT LPGEN("Boltun/Auto Chat") +#define BOLTUN_NOT_TO_CHAT LPGEN("Boltun/Not to Chat") +#define BOLTUN_START_CHATTING LPGEN("Boltun/Start Chatting") + +#define DEFAULT_WARN_TEXT LPGENT("Hello. I'm Boltun! I'll talk to you, while my owner is away. Please write without mistakes!") + +// Error messages +#define BOLTUN_ERROR LPGENT("Boltun Error") +#define FAILED_TO_LOAD_BASE LPGENT("Failed to load base of remarks. Error at line %d of %s. (Or few lines before).") +#define FAILED_TO_SAVE_BASE LPGENT("Failed to save base of remarks to %s") + +//Settings tab names +#define TAB_GENERAL LPGEN("General Settings") +#define TAB_ENGINE LPGEN("Engine Settings") + +#endif /*_BOLTUN_H*/ -- cgit v1.2.3