summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/HistoryStats/src/_consts.h2
-rw-r--r--plugins/HistoryStats/src/_format.h14
-rw-r--r--plugins/HistoryStats/src/colbase_words.cpp4
-rw-r--r--plugins/HistoryStats/src/dlgfilterwords.cpp2
-rw-r--r--plugins/HistoryStats/src/dlgoption_subglobal.cpp6
-rw-r--r--plugins/HistoryStats/src/dlgoption_subinput.cpp4
-rw-r--r--plugins/HistoryStats/src/main.cpp52
-rw-r--r--plugins/HistoryStats/src/message.cpp34
-rw-r--r--plugins/HistoryStats/src/message.h10
-rw-r--r--plugins/HistoryStats/src/mirandahistory.cpp129
-rw-r--r--plugins/HistoryStats/src/mirandahistory.h7
-rw-r--r--plugins/HistoryStats/src/settings.cpp2
-rw-r--r--plugins/HistoryStats/src/settingsserializer.cpp172
-rw-r--r--plugins/HistoryStats/src/settingsserializer.h1
-rw-r--r--plugins/HistoryStats/src/settingstree.cpp2
-rw-r--r--plugins/HistoryStats/src/statistic.cpp164
-rw-r--r--plugins/HistoryStats/src/statistic.h8
-rw-r--r--plugins/HistoryStats/src/utils.cpp1415
-rw-r--r--plugins/HistoryStats/src/version.h4
19 files changed, 912 insertions, 1120 deletions
diff --git a/plugins/HistoryStats/src/_consts.h b/plugins/HistoryStats/src/_consts.h
index cd06f27fe3..d2dbf156c2 100644
--- a/plugins/HistoryStats/src/_consts.h
+++ b/plugins/HistoryStats/src/_consts.h
@@ -5,7 +5,7 @@
#if defined(HISTORYSTATS_CONST_DEFINE)
#define CONST_A(nam, txt) extern const char* nam = txt;
-#define CONST_W(nam, txt) extern const WCHAR* nam = L#txt;
+#define CONST_W(nam, txt) extern const WCHAR* nam = L##txt;
#else
#define CONST_A(nam, txt) extern const char* nam;
#define CONST_W(nam, txt) extern const WCHAR* nam;
diff --git a/plugins/HistoryStats/src/_format.h b/plugins/HistoryStats/src/_format.h
index cecf23feca..c367f59202 100644
--- a/plugins/HistoryStats/src/_format.h
+++ b/plugins/HistoryStats/src/_format.h
@@ -13,13 +13,12 @@ namespace ext
public:
typedef typename T_ char_type;
typedef typename std::basic_string<T_> str_type;
- typedef typename std::basic_string<T_>::size_type size_type;
typedef typename ext::basic_strfunc<T_> _Func;
private:
str_type m_Str;
char_type m_Sep;
- size_type m_NextPos;
+ size_t m_NextPos;
public:
explicit basic_format(const str_type& str, char_type sep = '|')
@@ -34,11 +33,11 @@ namespace ext
basic_format& operator %(const char_type* szValue)
{
- str_type::size_type pos = m_Str.find(m_Sep, m_NextPos);
+ size_t pos = m_Str.find(m_Sep, m_NextPos);
if (pos != str_type::npos)
{
- size_type len = _Func::len(szValue);
+ size_t len = _Func::len(szValue);
m_Str.replace(pos, 1, szValue, len);
m_NextPos = pos + len;
@@ -89,7 +88,6 @@ namespace ext
public:
typedef typename T_ char_type;
typedef typename std::basic_string<T_> str_type;
- typedef typename std::basic_string<T_>::size_type size_type;
typedef typename ext::basic_strfunc<T_> _Func;
private:
@@ -119,9 +117,9 @@ namespace ext
{
if (!m_CurKey.empty())
{
- ext::string::size_type pos = 0;
- ext::string::size_type key_len = m_CurKey.length();
- ext::string::size_type value_len = _Func::len(szValue);
+ size_t pos = 0;
+ size_t key_len = m_CurKey.length();
+ size_t value_len = _Func::len(szValue);
while ((pos = m_Str.find(m_CurKey, pos)) != ext::string::npos)
{
diff --git a/plugins/HistoryStats/src/colbase_words.cpp b/plugins/HistoryStats/src/colbase_words.cpp
index 8bb4840924..9f80ba1f92 100644
--- a/plugins/HistoryStats/src/colbase_words.cpp
+++ b/plugins/HistoryStats/src/colbase_words.cpp
@@ -131,8 +131,8 @@ void ColBaseWords::parseMsg(WordMap* pWords, const ext::string& msg, bool bOutgo
}
// start parsing into words if not already filtered
- ext::string::size_type firstChar = 0;
- ext::string::size_type nextSpace;
+ size_t firstChar = 0;
+ size_t nextSpace;
while (firstChar < msg.length() && getCharMapper()->mapChar(msg[firstChar]) == ' ')
++firstChar;
diff --git a/plugins/HistoryStats/src/dlgfilterwords.cpp b/plugins/HistoryStats/src/dlgfilterwords.cpp
index 372b39d186..92b3143b84 100644
--- a/plugins/HistoryStats/src/dlgfilterwords.cpp
+++ b/plugins/HistoryStats/src/dlgfilterwords.cpp
@@ -229,7 +229,7 @@ void DlgFilterWords::onSetSelChanging(HANDLE hItem, INT_PTR dwData)
utils::replaceAllInPlace(strText, L"\r", L"");
pFilter->clearWords();
- ext::string::size_type nPos = strText.find('\n');
+ size_t nPos = strText.find('\n');
while (nPos != ext::string::npos) {
if (nPos > 0)
diff --git a/plugins/HistoryStats/src/dlgoption_subglobal.cpp b/plugins/HistoryStats/src/dlgoption_subglobal.cpp
index 51732bfa40..4727738845 100644
--- a/plugins/HistoryStats/src/dlgoption_subglobal.cpp
+++ b/plugins/HistoryStats/src/dlgoption_subglobal.cpp
@@ -33,8 +33,8 @@ INT_PTR CALLBACK DlgOption::SubGlobal::staticInfoProc(HWND hDlg, UINT msg, WPARA
if (!linkTexts.empty()) {
while (!linkTexts.empty() && nCurLink < _countof(LinkIDs)) {
- ext::string::size_type posTexts = linkTexts.rfind('|');
- ext::string::size_type posURLs = linkURLs.rfind('|');
+ size_t posTexts = linkTexts.rfind('|');
+ size_t posURLs = linkURLs.rfind('|');
if (posTexts == ext::string::npos || posURLs == ext::string::npos) {
posTexts = posURLs = -1;
@@ -246,7 +246,7 @@ void DlgOption::SubGlobal::onWMInitDialog()
{
m_hHideContactMenuProtos.push_back(m_Options.insertCheck(
m_hProtocols,
- Protocol::getDisplayName(protoList[i]->szModuleName).c_str(),
+ protoList[i]->tszAccountName,
0,
reinterpret_cast<INT_PTR>(protoList[i]->szModuleName)));
}
diff --git a/plugins/HistoryStats/src/dlgoption_subinput.cpp b/plugins/HistoryStats/src/dlgoption_subinput.cpp
index 23ec3e4fe2..e04765daa4 100644
--- a/plugins/HistoryStats/src/dlgoption_subinput.cpp
+++ b/plugins/HistoryStats/src/dlgoption_subinput.cpp
@@ -1,8 +1,6 @@
#include "stdafx.h"
#include "dlgoption.h"
-#include "protocol.h"
-
/*
* DlgOption::SubInput
*/
@@ -108,7 +106,7 @@ void DlgOption::SubInput::onWMInitDialog()
{
m_hProtosIgnore.push_back(m_Options.insertCheck(
m_hProtocols,
- Protocol::getDisplayName(protoList[i]->szModuleName).c_str(),
+ protoList[i]->tszAccountName,
0,
reinterpret_cast<INT_PTR>(protoList[i]->szModuleName)));
}
diff --git a/plugins/HistoryStats/src/main.cpp b/plugins/HistoryStats/src/main.cpp
index c37132df2c..19f1a84612 100644
--- a/plugins/HistoryStats/src/main.cpp
+++ b/plugins/HistoryStats/src/main.cpp
@@ -49,9 +49,8 @@ static HGENMENU g_hMenuToggleExclude = NULL;
static HGENMENU g_hHistoryCopyContact = NULL;
#endif
-/*
- * services (see m_historystats.h for details)
- */
+/////////////////////////////////////////////////////////////////////////////////////////
+// services(see m_historystats.h for details)
static INT_PTR SvcIsExcluded(WPARAM hContact, LPARAM)
{
@@ -75,28 +74,21 @@ static INT_PTR SvcSetExclude(WPARAM hContact, LPARAM lParam)
db.setContact(hContact);
db.setModule(con::ModHistoryStats);
- if (db.readBool(con::SettExclude, false))
- {
+ if (db.readBool(con::SettExclude, false)) {
if (!lParam)
- {
db.delSetting(con::SettExclude);
- }
}
- else
- {
+ else {
if (lParam)
- {
db.writeBool(con::SettExclude, true);
- }
}
}
return 0;
}
-/*
- * global menu stuff
- */
+/////////////////////////////////////////////////////////////////////////////////////////
+// global menu stuff
static void MenuIconsChanged(LPARAM)
{
@@ -113,9 +105,8 @@ static void MenuIconsChanged(LPARAM)
Menu_ModifyItem(g_hMenuToggleExclude, NULL, IconLib::getIcon(IconLib::iiContactMenu));
}
-/*
- * main menu related stuff
- */
+/////////////////////////////////////////////////////////////////////////////////////////
+// main menu related stuff
static INT_PTR MenuCreateStatistics(WPARAM, LPARAM)
{
@@ -144,9 +135,7 @@ static INT_PTR MenuConfigure(WPARAM, LPARAM)
void AddMainMenu()
{
if (!g_pSettings->m_ShowMainMenu || g_bMainMenuExists)
- {
return;
- }
g_bMainMenuExists = true;
@@ -171,9 +160,8 @@ void AddMainMenu()
0, 1910000002, IconLib::getIcon(IconLib::iiMenuConfigure), con::SvcConfigure, hRoot);
}
-/*
- * contact menu related stuff
- */
+/////////////////////////////////////////////////////////////////////////////////////////
+// contact menu related stuff
static INT_PTR MenuToggleExclude(WPARAM hContact, LPARAM)
{
@@ -283,11 +271,8 @@ static int EventPreBuildContactMenu(WPARAM hContact, LPARAM)
{
const char* szProto = GetContactProto(hContact);
- if ((!g_pSettings->m_ShowContactMenuPseudo && (!szProto || !(mu::protosvc::getCaps(szProto, PFLAGNUM_2) & ~mu::protosvc::getCaps(szProto, PFLAGNUM_5)))) ||
- g_pSettings->m_HideContactMenuProtos.find(szProto) != g_pSettings->m_HideContactMenuProtos.end())
- {
+ if ((!g_pSettings->m_ShowContactMenuPseudo && (!szProto || !(mu::protosvc::getCaps(szProto, PFLAGNUM_2) & ~mu::protosvc::getCaps(szProto, PFLAGNUM_5)))) || g_pSettings->m_HideContactMenuProtos.find(szProto) != g_pSettings->m_HideContactMenuProtos.end())
Menu_ShowItem(g_hMenuToggleExclude, false);
- }
else {
MirandaSettings db;
db.setContact(hContact);
@@ -345,9 +330,8 @@ void AddContactMenu()
HookEvent(ME_CLIST_PREBUILDCONTACTMENU, EventPreBuildContactMenu);
}
-/*
- * options integration
- */
+/////////////////////////////////////////////////////////////////////////////////////////
+// options integration
static int EventOptInitialise(WPARAM wParam, LPARAM)
{
@@ -363,9 +347,8 @@ static int EventOptInitialise(WPARAM wParam, LPARAM)
return 0;
}
-/*
- * second initialization phase
- */
+/////////////////////////////////////////////////////////////////////////////////////////
+// second initialization phase
static int EventModulesLoaded(WPARAM, LPARAM)
{
@@ -394,9 +377,8 @@ static int EventModulesLoaded(WPARAM, LPARAM)
return 0;
}
-/*
- * external interface
- */
+/////////////////////////////////////////////////////////////////////////////////////////
+// external interface
extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID)
{
diff --git a/plugins/HistoryStats/src/message.cpp b/plugins/HistoryStats/src/message.cpp
index a42974a8fe..bd632b043f 100644
--- a/plugins/HistoryStats/src/message.cpp
+++ b/plugins/HistoryStats/src/message.cpp
@@ -66,8 +66,8 @@ void Message::stripBBCodes()
int lenOpen = ext::strfunc::len(szOpenTag);
int lenClose = ext::strfunc::len(szCloseTag);
- ext::string::size_type posOpen = 0;
- ext::string::size_type posClose = 0;
+ size_t posOpen = 0;
+ size_t posClose = 0;
while (true) {
if ((posOpen = strRawLC.find(szOpenTag, posOpen)) == ext::string::npos)
@@ -94,9 +94,9 @@ void Message::stripBBCodes()
int lenOpen = ext::strfunc::len(szOpenTag);
int lenClose = ext::strfunc::len(szCloseTag);
- ext::string::size_type posOpen = 0;
- ext::string::size_type posOpen2 = 0;
- ext::string::size_type posClose = 0;
+ size_t posOpen = 0;
+ size_t posOpen2 = 0;
+ size_t posClose = 0;
while (true) {
if ((posOpen = strRawLC.find(szOpenTag, posOpen)) == ext::string::npos)
@@ -130,7 +130,7 @@ void Message::filterLinks()
m_WithoutLinks = getRaw();
ext::string& msg = m_WithoutLinks;
- ext::string::size_type pos = -1;
+ size_t pos = -1;
// detect: protocol://[user[:password]@]host[/path]
while (true) {
@@ -138,13 +138,13 @@ void Message::filterLinks()
break;
// find start of URL
- ext::string::size_type pos_proto = msg.find_last_not_of(szValidProtocol, pos - 1);
+ size_t pos_proto = msg.find_last_not_of(szValidProtocol, pos - 1);
(pos_proto == ext::string::npos) ? pos_proto = 0 : ++pos_proto;
if (pos_proto < pos) {
// find end of URL
- ext::string::size_type pos_last = msg.find_first_of(szSpaces, pos + 3);
+ size_t pos_last = msg.find_first_of(szSpaces, pos + 3);
(pos_last == ext::string::npos) ? pos_last = msg.length() - 1 : --pos_last;
@@ -153,20 +153,20 @@ void Message::filterLinks()
--pos_last;
// find slash: for host name validation
- ext::string::size_type pos_slash = msg.find('/', pos + 3);
+ size_t pos_slash = msg.find('/', pos + 3);
if (pos_slash == ext::string::npos || pos_slash > pos_last)
pos_slash = pos_last + 1;
// find at: for host name validation
- ext::string::size_type pos_at = msg.find('@', pos + 3);
+ size_t pos_at = msg.find('@', pos + 3);
if (pos_at == ext::string::npos || pos_at > pos_slash)
pos_at = pos + 2;
// check for valid host (x.x)
if (pos_slash - pos_at > 3) {
- ext::string::size_type pos_invalid = msg.find_first_not_of(szValidHost, pos_at + 1);
+ size_t pos_invalid = msg.find_first_not_of(szValidHost, pos_at + 1);
if (pos_invalid == ext::string::npos || pos_invalid >= pos_slash) {
if (std::count(msg.begin() + pos_at + 1, msg.begin() + pos_slash, '.') >= 1) {
@@ -191,7 +191,7 @@ void Message::filterLinks()
break;
// find end of URL
- ext::string::size_type pos_last = msg.find_first_of(szSpaces, pos + 4);
+ size_t pos_last = msg.find_first_of(szSpaces, pos + 4);
(pos_last == ext::string::npos) ? pos_last = msg.length() - 1 : --pos_last;
@@ -200,17 +200,17 @@ void Message::filterLinks()
--pos_last;
// find slash: for host name validation
- ext::string::size_type pos_slash = msg.find('/', pos + 4);
+ size_t pos_slash = msg.find('/', pos + 4);
if (pos_slash == ext::string::npos || pos_slash > pos_last)
pos_slash = pos_last + 1;
// find at: for host name validation
- ext::string::size_type pos_at = pos + 3;
+ size_t pos_at = pos + 3;
// check for valid host (x.x)
if (pos_slash - pos_at > 3) {
- ext::string::size_type pos_invalid = msg.find_first_not_of(szValidHost, pos_at + 1);
+ size_t pos_invalid = msg.find_first_not_of(szValidHost, pos_at + 1);
if (pos_invalid == ext::string::npos || pos_invalid >= pos_slash) {
if (std::count(msg.begin() + pos_at + 1, msg.begin() + pos_slash, '.') >= 1) {
@@ -235,7 +235,7 @@ void Message::filterLinks()
if (pos > 0 && pos < msg.length() - 1) {
// find end of address
- ext::string::size_type pos_last = msg.find_first_not_of(szValidHost, pos + 1);
+ size_t pos_last = msg.find_first_not_of(szValidHost, pos + 1);
(pos_last == ext::string::npos) ? pos_last = msg.length() - 1 : --pos_last;
@@ -244,7 +244,7 @@ void Message::filterLinks()
--pos_last;
// find start of address
- ext::string::size_type pos_first = msg.find_last_of(szSpaces, pos - 1);
+ size_t pos_first = msg.find_last_of(szSpaces, pos - 1);
(pos_first == ext::string::npos) ? pos_first = 0 : ++pos_first;
diff --git a/plugins/HistoryStats/src/message.h b/plugins/HistoryStats/src/message.h
index f3aa8e75a7..686ee103ee 100644
--- a/plugins/HistoryStats/src/message.h
+++ b/plugins/HistoryStats/src/message.h
@@ -27,7 +27,7 @@ private:
private:
bool m_bOutgoing;
DWORD m_Timestamp;
- ext::string::size_type m_nLength;
+ size_t m_nLength;
const void* m_RawSource;
int m_Available;
ext::string m_Raw;
@@ -56,7 +56,7 @@ public:
m_Timestamp = localTimestamp;
}
- void assignText(const wchar_t* msg, ext::string::size_type len)
+ void assignText(const wchar_t* msg, size_t len)
{
m_RawSource = msg;
m_nLength = len;
@@ -64,7 +64,7 @@ public:
}
#if defined(_UNICODE)
- void assignText(const char* msg, ext::string::size_type len)
+ void assignText(const char* msg, size_t len)
{
m_RawSource = msg;
m_nLength = len;
@@ -72,7 +72,7 @@ public:
}
#endif // _UNICODE
- void assignTextFromUTF8(const char* msg, ext::string::size_type len)
+ void assignTextFromUTF8(const char* msg, size_t len)
{
m_RawSource = msg;
m_nLength = len;
@@ -91,7 +91,7 @@ public:
}
// retrieving on-demand data
- ext::string::size_type getLength()
+ size_t getLength()
{
return (!m_bStripBBCodes && !m_bStripRawRTF) ? m_nLength : getRaw().length();
}
diff --git a/plugins/HistoryStats/src/mirandahistory.cpp b/plugins/HistoryStats/src/mirandahistory.cpp
index 2c79237346..93b834aa87 100644
--- a/plugins/HistoryStats/src/mirandahistory.cpp
+++ b/plugins/HistoryStats/src/mirandahistory.cpp
@@ -17,19 +17,15 @@ void MirandaHistory::populateProtocols()
upto_each_(i, protoCount)
{
ext::a::string protoName = protoList[i]->szModuleName;
-
- Protocol& curProto = m_Protocols[protoName];
-
- curProto.displayName = Protocol::getDisplayName(protoName);
+ m_Protocols[protoName] = protoList[i]->tszAccountName;
}
- m_DefaultProtocol.displayName = TranslateT("(Unknown)");
+ m_DefaultProtocol = TranslateT("(Unknown)");
}
-const Protocol& MirandaHistory::getProtocol(const ext::a::string& protocol) const
+const ext::string& MirandaHistory::getProtocol(const ext::a::string& protocol) const
{
- std::map<ext::a::string, Protocol>::const_iterator i = m_Protocols.find(protocol);
-
+ auto i = m_Protocols.find(protocol);
return (i != m_Protocols.end()) ? i->second : m_DefaultProtocol;
}
@@ -59,81 +55,72 @@ void MirandaHistory::readContacts()
{
bool bHandleMeta = m_Settings.m_MetaContactsMode != Settings::mcmIgnoreMeta;
ext::a::string strMetaProto = bHandleMeta ? META_PROTO : "";
+
MirandaSettings db;
+ db.setModule(con::ModCList);
std::vector<MCONTACT> sources;
- MCONTACT hContact = db_find_first();
- while (hContact) {
+ for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
db.setContact(hContact);
const char* pProtoName = GetContactProto(hContact);
- // if something leads to ignorance of conact jump to end of
- // processing this contact via 'break'
- do {
- // ignore because of bad or not loaded protocol?
- if (!pProtoName)
- pProtoName = con::ProtoUnknown; // MEMO: alternative would be "break;"
-
- ext::string curNick = pcli->pfnGetContactDisplayName(hContact, 0);
-
- // retrieve protocol
- const ext::a::string curProtoName = pProtoName;
- const Protocol& curProto = getProtocol(curProtoName);
-
- // retrieve group
- db.setModule(con::ModCList);
- ext::string curGroup = db.readStrDirect(con::SettGroup, TranslateT("(none)"));
-
- // ignore because of filtered protocol?
- if (m_Settings.m_ProtosIgnore.find(curProtoName) != m_Settings.m_ProtosIgnore.end())
- break;
-
- // init list of event sources
- sources.clear();
- sources.push_back(hContact);
-
- // handle meta-contacts
- if (bHandleMeta) {
- if (curProtoName == strMetaProto) {
- // don't include meta-contact history
- if (m_Settings.m_MetaContactsMode == Settings::mcmSubOnly)
- sources.clear();
-
- // include meta-contact's subcontact
- if (m_Settings.m_MetaContactsMode != Settings::mcmMetaOnly) {
- // find subcontacts to read history from
- int numSubs = db_mc_getSubCount(hContact);
- if (numSubs > 0) {
- for (int i = 0; i < numSubs; ++i) {
- MCONTACT hSubContact = db_mc_getSub(hContact, i);
- if (hSubContact)
- sources.push_back(hSubContact);
- }
+ // ignore because of bad or not loaded protocol?
+ if (!pProtoName)
+ pProtoName = con::ProtoUnknown; // MEMO: alternative would be "break;"
+
+ ext::string curNick = pcli->pfnGetContactDisplayName(hContact, 0);
+
+ // retrieve protocol
+ const ext::a::string curProtoName = pProtoName;
+ const ext::string& curProto = getProtocol(curProtoName);
+
+ // retrieve group
+ ext::string curGroup = db.readStrDirect(con::SettGroup, TranslateT("(none)"));
+
+ // ignore because of filtered protocol?
+ if (m_Settings.m_ProtosIgnore.find(curProtoName) != m_Settings.m_ProtosIgnore.end())
+ continue;
+
+ // init list of event sources
+ sources.clear();
+ sources.push_back(hContact);
+
+ // handle meta-contacts
+ if (bHandleMeta) {
+ if (curProtoName == strMetaProto) {
+ // don't include meta-contact history
+ if (m_Settings.m_MetaContactsMode == Settings::mcmSubOnly)
+ sources.clear();
+
+ // include meta-contact's subcontact
+ if (m_Settings.m_MetaContactsMode != Settings::mcmMetaOnly) {
+ // find subcontacts to read history from
+ int numSubs = db_mc_getSubCount(hContact);
+ if (numSubs > 0) {
+ for (int i = 0; i < numSubs; ++i) {
+ MCONTACT hSubContact = db_mc_getSub(hContact, i);
+ if (hSubContact)
+ sources.push_back(hSubContact);
}
}
}
- else {
- // ignore because of meta-contact?
- if (db_mc_isMeta(hContact))
- break;
- }
}
-
- // ignore because of exclude?
- db.setModule(con::ModHistoryStats);
-
- if (db.readBool(con::SettExclude, false))
- break;
-
- // finally add to list
- MirandaContact* pContact = MirandaContactFactory::makeMirandaContact(m_Settings.m_MergeMode, curNick, curProto.displayName, curGroup, sources);
- m_Contacts.push_back(pContact);
+ else {
+ // ignore because of meta-contact?
+ if (db_mc_isMeta(hContact))
+ continue;
+ }
}
- while (false);
- hContact = db_find_next(hContact);
+ // ignore because of exclude?
+ if (db_get_b(hContact, con::ModHistoryStats, con::SettExclude, false))
+ continue;
+
+ // finally add to list
+ MirandaContact* pContact = MirandaContactFactory::makeMirandaContact(m_Settings.m_MergeMode, curNick, curProto, curGroup, sources);
+ m_Contacts.push_back(pContact);
}
}
@@ -142,10 +129,10 @@ void MirandaHistory::mergeContacts()
if (!m_Settings.m_MergeContacts)
return;
- for (ContactList::size_type i = 0; i < m_Contacts.size(); ++i) {
+ for (size_t i = 0; i < m_Contacts.size(); ++i) {
MirandaContact& cur = *m_Contacts[i];
- for (ContactList::size_type j = i + 1; j < m_Contacts.size(); ++j) {
+ for (size_t j = i + 1; j < m_Contacts.size(); ++j) {
if (m_Contacts[j]->getNick() == cur.getNick()) {
if (!m_Settings.m_MergeContactsGroups || m_Contacts[j]->getGroup() == cur.getGroup()) {
cur.merge(*m_Contacts[j]);
diff --git a/plugins/HistoryStats/src/mirandahistory.h b/plugins/HistoryStats/src/mirandahistory.h
index f67540dece..4acb356f75 100644
--- a/plugins/HistoryStats/src/mirandahistory.h
+++ b/plugins/HistoryStats/src/mirandahistory.h
@@ -6,26 +6,25 @@
#include <vector>
#include "mirandacontact.h"
-#include "protocol.h"
#include "settings.h"
class MirandaHistory
: private pattern::NotCopyable<MirandaHistory>
{
private:
- typedef std::map<ext::a::string, Protocol> ProtocolMap;
+ typedef std::map<ext::a::string, ext::string> ProtocolMap;
typedef std::vector<MirandaContact*> ContactList;
private:
const Settings& m_Settings;
ProtocolMap m_Protocols;
- Protocol m_DefaultProtocol;
+ ext::string m_DefaultProtocol;
bool m_bContactsAvailable;
ContactList m_Contacts;
private:
void populateProtocols();
- const Protocol& getProtocol(const ext::a::string& protocol) const;
+ const ext::string& getProtocol(const ext::a::string& protocol) const;
void makeContactsAvailable();
void readContacts();
void mergeContacts();
diff --git a/plugins/HistoryStats/src/settings.cpp b/plugins/HistoryStats/src/settings.cpp
index 34fbf1d640..9ed6692ff7 100644
--- a/plugins/HistoryStats/src/settings.cpp
+++ b/plugins/HistoryStats/src/settings.cpp
@@ -566,7 +566,7 @@ void Settings::ensureConstraints()
utils::ensureRange(m_TableHeaderRepeat, 0, 1000, 0);
}
-void Settings::openURL(const wchar_t* szURL)
+void Settings::openURL(const wchar_t *szURL)
{
if (m_PathToBrowser.empty())
ShellExecute(NULL, L"open", szURL, NULL, NULL, SW_SHOWNORMAL);
diff --git a/plugins/HistoryStats/src/settingsserializer.cpp b/plugins/HistoryStats/src/settingsserializer.cpp
index 1c295460e9..cb6015eb8a 100644
--- a/plugins/HistoryStats/src/settingsserializer.cpp
+++ b/plugins/HistoryStats/src/settingsserializer.cpp
@@ -4,76 +4,8 @@
#include "settingstree.h"
#include "column.h"
-/*
- * SettingsSerializer
- */
-
-static const char* g_UsedSettings[] = {
- // special
- con::SettVersion,
- con::SettLastPage,
- con::SettShowColumnInfo,
- con::SettShowSupportInfo,
- con::SettLastStatisticsFile,
-
- // normal
- con::SettAutoOpenOptions,
- con::SettAutoOpenStartup,
- con::SettAutoOpenMenu,
- con::SettAverageMinTime,
- con::SettCalcTotals,
- con::SettChatSessionMinDur,
- con::SettChatSessionTimeout,
- con::SettColumns,
- con::SettFilterBBCodes,
- con::SettFilterWords,
- con::SettGraphicsMode,
- con::SettHeaderTooltips,
- con::SettHeaderTooltipsIfCustom,
- con::SettHideContactMenuProtos,
- con::SettIgnoreAfter,
- con::SettIgnoreBefore,
- con::SettIgnoreOld,
- con::SettMenuItem,
- con::SettMergeContacts,
- con::SettMergeContactsGroups,
- con::SettMergeMode,
- con::SettMetaContactsMode,
- con::SettNickname,
- con::SettOmitByRank,
- con::SettOmitByTime,
- con::SettOmitByTimeDays,
- con::SettOmitByValue,
- con::SettOmitByValueData,
- con::SettOmitByValueLimit,
- con::SettOmitContacts,
- con::SettOmitNumOnTop,
- con::SettOmittedInTotals,
- con::SettOmittedInExtraRow,
- con::SettOnStartup,
- con::SettOutput,
- con::SettOutputExtraFolder,
- con::SettOutputExtraToFolder,
- con::SettOutputVariables,
- con::SettOverwriteAlways,
- con::SettPathToBrowser,
- con::SettPNGMode,
- con::SettProtosIgnore,
- con::SettRemoveEmptyContacts,
- con::SettRemoveInChatsZero,
- con::SettRemoveInBytesZero,
- con::SettRemoveOutChatsZero,
- con::SettRemoveOutBytesZero,
- con::SettShowContactMenu,
- con::SettShowContactMenuPseudo,
- con::SettShowMenuSub,
- con::SettSort,
- con::SettTableHeader,
- con::SettTableHeaderRepeat,
- con::SettTableHeaderVerbose,
- con::SettThreadLowPriority,
- con::SettWordDelimiters,
-};
+/////////////////////////////////////////////////////////////////////////////////////////
+// SettingsSerializer
SettingsSerializer::SettingsSerializer(const char* module) : m_VersionInDB(0)
{
@@ -91,8 +23,7 @@ void SettingsSerializer::readFromDB()
// read version tag
m_VersionInDB = m_DB.readDWord(con::SettVersion, 0);
- // -- global settings --
-
+ // global settings
m_OnStartup = m_DB.readBool(con::SettOnStartup, false);
m_GraphicsMode = m_DB.readByte(con::SettGraphicsMode, gmHTML);
m_PNGMode = m_DB.readByte(con::SettPNGMode, pmHTMLFallBack);
@@ -113,7 +44,7 @@ void SettingsSerializer::readFromDB()
m_HideContactMenuProtos.insert(utils::toA(settingsTree.readStr(utils::intToString(i).c_str(), L"")));
}
- // -- input settings --
+ // input settings
m_ChatSessionMinDur = m_DB.readWord(con::SettChatSessionMinDur, 0);
m_ChatSessionTimeout = m_DB.readWord(con::SettChatSessionTimeout, 900);
m_AverageMinTime = m_DB.readWord(con::SettAverageMinTime, 0);
@@ -139,8 +70,7 @@ void SettingsSerializer::readFromDB()
m_MergeContactsGroups = m_DB.readBool(con::SettMergeContactsGroups, false);
m_MergeMode = m_DB.readByte(con::SettMergeMode, mmStrictMerge);
- // -- column settings --
-
+ // column settings
clearColumns();
m_DB.readTree(con::SettColumns, getDefaultColumns(), settingsTree);
@@ -152,8 +82,7 @@ void SettingsSerializer::readFromDB()
settingsTree.setKey(colPrefix.c_str());
- Column* pCol = Column::fromUID(settingsTree.readStr(con::KeyGUID, L""));
-
+ Column *pCol = Column::fromUID(settingsTree.readStr(con::KeyGUID, L""));
if (pCol) {
pCol->setEnabled(settingsTree.readBool(con::KeyEnabled, true));
pCol->setCustomTitle(settingsTree.readStr(con::KeyTitle, L""));
@@ -166,8 +95,7 @@ void SettingsSerializer::readFromDB()
}
}
- // -- output settings --
-
+ // output settings
m_RemoveEmptyContacts = m_DB.readBool(con::SettRemoveEmptyContacts, false);
m_RemoveOutChatsZero = m_DB.readBool(con::SettRemoveOutChatsZero, false);
m_RemoveOutBytesZero = m_DB.readBool(con::SettRemoveOutBytesZero, false);
@@ -210,8 +138,7 @@ void SettingsSerializer::readFromDB()
m_AutoOpenStartup = m_DB.readBool(con::SettAutoOpenStartup, false);
m_AutoOpenMenu = m_DB.readBool(con::SettAutoOpenMenu, false);
- // -- shared column data --
-
+ // shared column data
m_FilterWords.clear();
m_DB.readTree(con::SettFilterWords, getDefaultFilterWords(), settingsTree);
@@ -252,14 +179,16 @@ void SettingsSerializer::writeToDB()
{
// update silently if DB entries are from an older version
if (isDBUpdateNeeded()) {
- updateDB();
- }
+ db_delete_module(NULL, m_DB.getModule().c_str());
+ // write version tag
+ m_DB.writeDWord(con::SettVersion, m_VersionCurrent);
+ m_VersionInDB = m_VersionCurrent;
+ }
SettingsTree settingsTree;
- // -- global settings --
-
+ // global settings
m_DB.writeBool(con::SettOnStartup, m_OnStartup);
m_DB.writeBool(con::SettMenuItem, m_ShowMainMenu);
m_DB.writeBool(con::SettShowMenuSub, m_ShowMainMenuSub);
@@ -284,8 +213,7 @@ void SettingsSerializer::writeToDB()
m_DB.writeTree(con::SettHideContactMenuProtos, settingsTree);
- // -- input settings --
-
+ // input settings
m_DB.writeWord(con::SettChatSessionMinDur, m_ChatSessionMinDur);
m_DB.writeWord(con::SettChatSessionTimeout, m_ChatSessionTimeout);
m_DB.writeWord(con::SettAverageMinTime, m_AverageMinTime);
@@ -296,7 +224,6 @@ void SettingsSerializer::writeToDB()
{
int i = 0;
-
citer_each_(ProtoSet, j, m_ProtosIgnore)
{
settingsTree.writeStr(utils::intToString(i++).c_str(), utils::fromA(*j).c_str());
@@ -315,8 +242,7 @@ void SettingsSerializer::writeToDB()
m_DB.writeBool(con::SettMergeContactsGroups, m_MergeContactsGroups);
m_DB.writeByte(con::SettMergeMode, m_MergeMode);
- // -- column settings --
-
+ // column settings
settingsTree.clear();
settingsTree.writeInt(con::KeyNum, countCol());
@@ -341,8 +267,7 @@ void SettingsSerializer::writeToDB()
m_DB.writeTree(con::SettColumns, settingsTree);
- // -- output settings --
-
+ // output settings
m_DB.writeBool(con::SettRemoveEmptyContacts, m_RemoveEmptyContacts);
m_DB.writeBool(con::SettRemoveOutChatsZero, m_RemoveOutChatsZero);
m_DB.writeBool(con::SettRemoveOutBytesZero, m_RemoveOutBytesZero);
@@ -387,36 +312,33 @@ void SettingsSerializer::writeToDB()
m_DB.writeTree(con::SettSort, settingsTree);
- // -- shared column data --
-
+ // shared column data
settingsTree.clear();
settingsTree.writeInt(con::KeyNum, m_FilterWords.size());
+ int nFilterNr = 0;
+
+ citer_each_(FilterSet, i, m_FilterWords)
{
- int nFilterNr = 0;
+ ext::string strPrefix = utils::intToString(nFilterNr++);
- citer_each_(FilterSet, i, m_FilterWords)
- {
- ext::string strPrefix = utils::intToString(nFilterNr++);
+ // write filter attributes
+ settingsTree.setKey(strPrefix.c_str());
+ settingsTree.writeStr(con::KeyID, i->getID().c_str());
+ settingsTree.writeStr(con::KeyName, i->getName().c_str());
+ settingsTree.writeInt(con::KeyMode, i->getMode());
+ settingsTree.writeInt(con::KeyNumWords, i->getWords().size());
- // write filter attributes
+ if (!i->getWords().empty()) {
+ // write filter words
+ strPrefix += con::SuffixWords;
settingsTree.setKey(strPrefix.c_str());
- settingsTree.writeStr(con::KeyID, i->getID().c_str());
- settingsTree.writeStr(con::KeyName, i->getName().c_str());
- settingsTree.writeInt(con::KeyMode, i->getMode());
- settingsTree.writeInt(con::KeyNumWords, i->getWords().size());
-
- if (!i->getWords().empty()) {
- // write filter words
- strPrefix += con::SuffixWords;
- settingsTree.setKey(strPrefix.c_str());
-
- int nWordNr = 0;
-
- citer_each_(WordSet, j, i->getWords())
- {
- settingsTree.writeStr(utils::intToString(nWordNr++).c_str(), j->c_str());
- }
+
+ int nWordNr = 0;
+
+ citer_each_(WordSet, j, i->getWords())
+ {
+ settingsTree.writeStr(utils::intToString(nWordNr++).c_str(), j->c_str());
}
}
}
@@ -429,26 +351,6 @@ bool SettingsSerializer::isDBUpdateNeeded()
return (m_VersionInDB < m_VersionCurrent);
}
-void SettingsSerializer::updateDB()
-{
- std::set<ext::a::string> settings;
- m_DB.enumSettings(std::inserter(settings, settings.begin()));
-
- array_each_(i, g_UsedSettings)
- {
- settings.erase(g_UsedSettings[i]);
- }
-
- iter_each_(std::set<ext::a::string>, si, settings)
- {
- m_DB.delSetting((*si).c_str());
- }
-
- // write version tag
- m_DB.writeDWord(con::SettVersion, m_VersionCurrent);
- m_VersionInDB = m_VersionCurrent;
-}
-
int SettingsSerializer::getLastPage()
{
return m_DB.readDWord(con::SettLastPage, 0);
diff --git a/plugins/HistoryStats/src/settingsserializer.h b/plugins/HistoryStats/src/settingsserializer.h
index 88bd9e1c6d..3b1fc2269a 100644
--- a/plugins/HistoryStats/src/settingsserializer.h
+++ b/plugins/HistoryStats/src/settingsserializer.h
@@ -21,7 +21,6 @@ public:
void writeToDB();
bool isDBUpdateNeeded();
- void updateDB();
int getLastPage();
void setLastPage(int nPage);
diff --git a/plugins/HistoryStats/src/settingstree.cpp b/plugins/HistoryStats/src/settingstree.cpp
index a73ef0f442..21d6501cf8 100644
--- a/plugins/HistoryStats/src/settingstree.cpp
+++ b/plugins/HistoryStats/src/settingstree.cpp
@@ -30,7 +30,7 @@ void SettingsTree::fromString(const ext::string& config)
{
m_Keys.clear();
- ext::string::size_type i = 0;
+ size_t i = 0;
ext::string curKey;
while (i < config.length()) {
diff --git a/plugins/HistoryStats/src/statistic.cpp b/plugins/HistoryStats/src/statistic.cpp
index b2882ed476..2a633404bc 100644
--- a/plugins/HistoryStats/src/statistic.cpp
+++ b/plugins/HistoryStats/src/statistic.cpp
@@ -29,15 +29,13 @@ void Statistic::prepareColumns()
upto_each_(i, m_Settings.countCol())
{
- Column* pCol = m_Settings.getCol(i);
-
+ Column *pCol = m_Settings.getCol(i);
if (pCol->isEnabled()) {
int restrictions = pCol->configGetRestrictions(NULL);
// MEMO: checks for columns having no HTML-only support
- if (!bOutputPNG && !(restrictions & Column::crHTMLMask)) {
+ if (!bOutputPNG && !(restrictions & Column::crHTMLMask))
continue;
- }
m_ActiveCols.push_back(pCol);
@@ -132,13 +130,11 @@ DWORD Statistic::getFirstTime()
l.push_back(&getContact(i));
}
- if (hasOmitted()) {
+ if (hasOmitted())
l.push_back(&getOmitted());
- }
- if (hasTotals()) {
+ if (hasTotals())
l.push_back(&getTotals());
- }
if (l.size() > 0) {
DWORD nFirstTime = con::MaxDateTime, nLastTime = con::MinDateTime;
@@ -151,17 +147,14 @@ DWORD Statistic::getFirstTime()
}
}
- if (nFirstTime == con::MaxDateTime && nLastTime == con::MinDateTime) {
+ if (nFirstTime == con::MaxDateTime && nLastTime == con::MinDateTime)
m_nFirstTime = m_nLastTime = 0;
- }
else {
m_nFirstTime = nFirstTime;
m_nLastTime = nLastTime;
}
}
- else {
- m_nFirstTime = m_nLastTime = 0;
- }
+ else m_nFirstTime = m_nLastTime = 0;
// mark data as available
m_bHistoryTimeAvailable = true;
@@ -172,20 +165,16 @@ DWORD Statistic::getFirstTime()
DWORD Statistic::getLastTime()
{
- if (!m_bHistoryTimeAvailable) {
- // trigger calculation
+ if (!m_bHistoryTimeAvailable) // trigger calculation
getFirstTime();
- }
return m_nLastTime;
}
DWORD Statistic::getHistoryTime()
{
- if (!m_bHistoryTimeAvailable) {
- // trigger calculation
+ if (!m_bHistoryTimeAvailable) // trigger calculation
getFirstTime();
- }
return m_nLastTime - m_nFirstTime;
}
@@ -196,10 +185,8 @@ ext::string Statistic::createFile(const ext::string& desiredName)
wchar_t tempBuf[MAX_PATH];
UINT nUnique = GetTempFileName(m_TempPath.c_str(), L"his", 0, tempBuf);
-
- if (nUnique == 0) {
+ if (!nUnique)
abort();
- }
ext::string tempName = tempBuf;
@@ -236,31 +223,24 @@ bool Statistic::newFile(const wchar_t* fileExt, ext::string& writeFile, ext::str
bool Statistic::newFilePNG(Canvas& canvas, ext::string& finalURL)
{
Canvas::Digest digest;
-
- if (!canvas.getDigest(digest)) {
+ if (!canvas.getDigest(digest))
return false;
- }
ImageMap::const_iterator i = m_Images.find(digest);
if (i == m_Images.end()) {
ext::string writeFile;
- if (newFilePNG(writeFile, finalURL)) {
- canvas.writePNG(writeFile.c_str());
- m_Images.insert(std::make_pair(digest, finalURL));
-
- return true;
- }
- else {
+ if (!newFilePNG(writeFile, finalURL))
return false;
- }
- }
- else {
- finalURL = i->second;
+ canvas.writePNG(writeFile.c_str());
+ m_Images.insert(std::make_pair(digest, finalURL));
return true;
}
+
+ finalURL = i->second;
+ return true;
}
void Statistic::handleAddMessage(Contact& contact, Message& msg)
@@ -354,10 +334,8 @@ bool Statistic::stepInit()
// file management
wchar_t tempPath[MAX_PATH];
int nRes = GetTempPath(MAX_PATH, tempPath);
-
- if (nRes > 0) {
+ if (nRes > 0)
m_TempPath.assign(tempPath, nRes);
- }
m_OutputFile = m_Settings.getOutputFile(getTimeStarted());
m_OutputPath = utils::extractPath(m_OutputFile);
@@ -370,31 +348,26 @@ bool Statistic::stepInit()
m_TimeMin = 0;
m_TimeMax = 0xFFFFFFFF;
- if (m_Settings.m_IgnoreOld != 0) {
+ if (m_Settings.m_IgnoreOld != 0)
m_TimeMin = getTimeStarted() - 86400 * m_Settings.m_IgnoreOld;
- }
if (m_Settings.getIgnoreBefore() != 0) {
- if (m_Settings.m_IgnoreOld != 0) {
+ if (m_Settings.m_IgnoreOld != 0)
m_TimeMin = max(m_TimeMin, m_Settings.getIgnoreBefore());
- }
- else {
+ else
m_TimeMin = m_Settings.getIgnoreBefore();
- }
}
- if (m_Settings.getIgnoreAfter() != 0) {
+ if (m_Settings.getIgnoreAfter() != 0)
m_TimeMax = m_Settings.getIgnoreAfter() + 86399;
- }
return true;
}
bool Statistic::stepReadDB()
{
- if (shouldTerminate()) {
+ if (shouldTerminate())
return false;
- }
iter_each_(std::vector<Column*>, i, m_AcquireCols)
{
@@ -447,7 +420,6 @@ bool Statistic::stepReadDB()
char* pAnsiText = reinterpret_cast<char*>(dbei.pBlob);
int nAnsiLenP1 = ext::a::strfunc::len(pAnsiText) + 1;
-#if defined(_UNICODE)
WCHAR* pWideText = reinterpret_cast<WCHAR*>(pAnsiText + nAnsiLenP1);
int nWideLen = 0;
int nWideMaxLen = (dbei.cbBlob - nAnsiLenP1) / sizeof(WCHAR);
@@ -461,15 +433,10 @@ bool Statistic::stepReadDB()
}
}
- if (nWideLen > 0 && nWideLen < nAnsiLenP1) {
+ if (nWideLen > 0 && nWideLen < nAnsiLenP1)
curMsg.assignText(pWideText, nWideLen);
- }
- else {
+ else
curMsg.assignText(pAnsiText, nAnsiLenP1 - 1);
- }
-#else // _UNICODE
- curMsg.assignText(pAnsiText, nAnsiLenP1 - 1);
-#endif // _UNICODE
}
curMsg.assignInfo(bOutgoing, localTimestamp);
@@ -480,9 +447,8 @@ bool Statistic::stepReadDB()
// handle chats
if (localTimestamp - lastAddedTime >= (DWORD)m_Settings.m_ChatSessionTimeout || lastAddedTime == 0) {
// new chat started
- if (chatStartTime != 0) {
+ if (chatStartTime != 0)
handleAddChat(curContact, bChatOutgoing, chatStartTime, lastAddedTime - chatStartTime);
- }
chatStartTime = localTimestamp;
bChatOutgoing = bOutgoing;
@@ -493,17 +459,15 @@ bool Statistic::stepReadDB()
}
// non-message events
- if (dbei.eventType != etMessage) {
+ if (dbei.eventType != etMessage)
curContact.addEvent(dbei.eventType, bOutgoing);
- }
hisContact.readNext();
}
// post processing for chat detection
- if (chatStartTime != 0) {
+ if (chatStartTime != 0)
handleAddChat(curContact, bChatOutgoing, chatStartTime, lastAddedTime - chatStartTime);
- }
// signal end of history for this contact
curContact.endMessages();
@@ -511,9 +475,8 @@ bool Statistic::stepReadDB()
stepProgress(true);
- if (shouldTerminate()) {
+ if (shouldTerminate())
return false;
- }
}
iter_each_(std::vector<Column*>, i, m_AcquireCols)
@@ -526,30 +489,25 @@ bool Statistic::stepReadDB()
bool Statistic::stepRemoveContacts()
{
- if (!m_Settings.m_RemoveEmptyContacts && !m_Settings.m_RemoveOutChatsZero && !m_Settings.m_RemoveInChatsZero) {
+ if (!m_Settings.m_RemoveEmptyContacts && !m_Settings.m_RemoveOutChatsZero && !m_Settings.m_RemoveInChatsZero)
return true;
- }
- if (shouldTerminate()) {
+ if (shouldTerminate())
return false;
- }
vector_each_(i, m_Contacts)
{
bool bRemove = false;
Contact* pCur = m_Contacts[i];
- if (!bRemove && m_Settings.m_RemoveEmptyContacts) {
+ if (!bRemove && m_Settings.m_RemoveEmptyContacts)
bRemove = (pCur->getTotalMessages() == 0);
- }
- if (!bRemove && m_Settings.m_RemoveOutChatsZero) {
+ if (!bRemove && m_Settings.m_RemoveOutChatsZero)
bRemove = (pCur->getOutChats() == 0 && (!m_Settings.m_RemoveOutBytesZero || pCur->getOutBytes() == 0));
- }
- if (!bRemove && m_Settings.m_RemoveInChatsZero) {
+ if (!bRemove && m_Settings.m_RemoveInChatsZero)
bRemove = (pCur->getInChats() == 0 && (!m_Settings.m_RemoveInBytesZero || pCur->getInBytes() == 0));
- }
if (bRemove) {
freeContactData(*pCur);
@@ -565,9 +523,8 @@ bool Statistic::stepRemoveContacts()
bool Statistic::stepSortContacts()
{
- if (shouldTerminate()) {
+ if (shouldTerminate())
return false;
- }
ContactCompareBase cmpLast;
ContactCompareStr cmpName(&cmpLast, &Contact::getNick);
@@ -877,7 +834,7 @@ bool Statistic::stepCalcTotals()
// normal contacts
vector_each_(i, m_Contacts)
{
- Contact& curContact = *m_Contacts[i];
+ Contact &curContact = *m_Contacts[i];
setProgressLabel(true, curContact.getNick());
@@ -899,7 +856,6 @@ bool Statistic::stepCalcTotals()
}
stepProgress(true);
-
return true;
}
@@ -1130,10 +1086,7 @@ bool Statistic::stepWriteHTML()
stepProgress(true);
- /*
- * Output totals.
- */
-
+ // Output totals.
if (!bInterrupted && m_Settings.m_CalcTotals) {
setProgressLabel(true, TranslateT("Writing totals"));
@@ -1291,31 +1244,16 @@ bool Statistic::createStatistics()
DestroyWindow(m_hWndProgress);
}
- /*
- * Get result from thread.
- */
-
- bool bSuccess = false;
- DWORD threadRes;
- if (GetExitCodeThread(hThread, &threadRes))
- bSuccess = (threadRes == 0);
-
- /*
- * Cleanup.
- */
+ // Cleanup.
CloseHandle(m_hCancelEvent);
m_hCancelEvent = NULL;
m_hWndProgress = NULL;
- if (bSuccess) {
- /*
- * Save last successfully created statistics
- */
+ if (m_bResult) {
+ // Save last successfully created statistics
g_pSettings->setLastStatisticsFile(m_OutputFile.c_str());
- /*
- * Open afterwards, if requested.
- */
+ // Open afterwards, if requested.
bool bOpenAfterwards =
(m_InvokedFrom == fromOptions && m_Settings.m_AutoOpenOptions) ||
(m_InvokedFrom == fromStartup && m_Settings.m_AutoOpenStartup) ||
@@ -1325,10 +1263,10 @@ bool Statistic::createStatistics()
m_Settings.openURL(m_OutputFile.c_str());
}
- return bSuccess;
+ return m_bResult;
}
-bool Statistic::createStatisticsSteps()
+void Statistic::createStatisticsSteps()
{
static const struct
{
@@ -1348,6 +1286,7 @@ bool Statistic::createStatisticsSteps()
{ &Statistic::stepWriteHTML, LPGENW("Creating HTML") }
};
+ m_bResult = false;
setProgressMax(false, _countof(stepsInfo));
array_each_(i, stepsInfo)
@@ -1355,17 +1294,14 @@ bool Statistic::createStatisticsSteps()
setProgressLabel(false, TranslateW(stepsInfo[i].stepMsg));
if (!(this->*stepsInfo[i].stepFn)())
- return false;
+ return;
stepProgress(false);
}
- /*
- * Last step: We are done.
- */
+ // Last step: We are done.
+ m_bResult = true;
setProgressLabel(false, TranslateT("Done"));
-
- return true;
}
void __cdecl Statistic::threadProc(void *lpParameter)
@@ -1391,7 +1327,7 @@ void __cdecl Statistic::threadProc(void *lpParameter)
void __cdecl Statistic::threadProcSteps(void *lpParameter)
{
Thread_SetName("HistoryStats: Statistic::threadProcSteps");
- Statistic* pStats = reinterpret_cast<Statistic*>(lpParameter);
+ Statistic *pStats = reinterpret_cast<Statistic*>(lpParameter);
if (pStats->m_Settings.m_ThreadLowPriority)
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
@@ -1408,7 +1344,7 @@ INT_PTR CALLBACK Statistic::staticConflictProc(HWND hDlg, UINT uMsg, WPARAM wPar
utils::centerDialog(hDlg);
HWND hWndFiles = GetDlgItem(hDlg, IDC_FILES);
- ConflictingFiles* pFiles = reinterpret_cast<ConflictingFiles*>(lParam);
+ ConflictingFiles *pFiles = reinterpret_cast<ConflictingFiles*>(lParam);
LVCOLUMN lvc;
lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_FMT;
@@ -1467,8 +1403,8 @@ void Statistic::run(const Settings& settings, InvocationSource invokedFrom, HINS
// check if running and make running
if (m_bRunning) {
MessageBox(0,
- TranslateT("HistoryStats is already generating statistics. Please wait for the already running process to be finished or cancel it and try again."),
- TranslateT("HistoryStats"), MB_ICONINFORMATION | MB_OK);
+ TranslateT("HistoryStats is already generating statistics. Please wait for the already running process to be finished or cancel it and try again."),
+ TranslateT("HistoryStats"), MB_ICONINFORMATION | MB_OK);
return;
}
diff --git a/plugins/HistoryStats/src/statistic.h b/plugins/HistoryStats/src/statistic.h
index c08661a373..b3dbe6fc2a 100644
--- a/plugins/HistoryStats/src/statistic.h
+++ b/plugins/HistoryStats/src/statistic.h
@@ -10,7 +10,6 @@
#include <list>
#include "settings.h"
-#include "protocol.h"
#include "message.h"
class Contact; // forward declaration instead of #include "contact.h"
@@ -83,8 +82,9 @@ private:
Contact* m_pTotals;
Contact* m_pOmitted;
- // did we really omit something
- bool m_bActuallyOmitted;
+ bool
+ m_bActuallyOmitted, // did we really omit something
+ m_bResult; // result of calculations
// start time for statistics
DWORD m_TimeStarted;
@@ -159,7 +159,7 @@ private:
// private constructor & main statistic creation routine
explicit Statistic(const Settings& settings, InvocationSource invokedFrom, HINSTANCE hInst);
bool createStatistics();
- bool createStatisticsSteps();
+ void createStatisticsSteps();
static void __cdecl threadProc(void *lpParameter);
static void __cdecl threadProcSteps(void *lpParameter);
diff --git a/plugins/HistoryStats/src/utils.cpp b/plugins/HistoryStats/src/utils.cpp
index 7c2d0f3a93..9c58288dfe 100644
--- a/plugins/HistoryStats/src/utils.cpp
+++ b/plugins/HistoryStats/src/utils.cpp
@@ -6,941 +6,932 @@
#include <cstdio>
#include <stack>
-/*
- * utils
- */
+/////////////////////////////////////////////////////////////////////////////////////////
+// utils
-namespace utils
+ext::string utils::timestampToString(time_t value, const wchar_t* format)
{
- ext::string timestampToString(time_t value, const wchar_t* format)
- {
- wchar_t temp[100] = { 0 };
+ wchar_t temp[100] = { 0 };
- return (ext::strfunc::ftime(temp, 100, format, gmtime(&value)) > 0) ? temp : L"";
- }
+ return (ext::strfunc::ftime(temp, 100, format, gmtime(&value)) > 0) ? temp : L"";
+}
- ext::string tmStructToString(const tm& value, const wchar_t* format)
- {
- wchar_t temp[100] = { 0 };
+ext::string utils::tmStructToString(const tm& value, const wchar_t* format)
+{
+ wchar_t temp[100] = { 0 };
- return (ext::strfunc::ftime(temp, 100, format, &value) > 0) ? temp : L"";
- }
+ return (ext::strfunc::ftime(temp, 100, format, &value) > 0) ? temp : L"";
+}
- ext::string durationToString(DWORD value)
- {
- wchar_t temp[100] = { 0 };
+ext::string utils::durationToString(DWORD value)
+{
+ wchar_t temp[100] = { 0 };
- value += 59;
- value /= 60;
+ value += 59;
+ value /= 60;
- if (value >= 1440)
- ext::strfunc::sprintf(temp, L"%dd %02d:%02d", value / 1440, (value / 60) % 24, value % 60);
- else
- ext::strfunc::sprintf(temp, L"%02d:%02d", value / 60, value % 60);
+ if (value >= 1440)
+ ext::strfunc::sprintf(temp, L"%dd %02d:%02d", value / 1440, (value / 60) % 24, value % 60);
+ else
+ ext::strfunc::sprintf(temp, L"%02d:%02d", value / 60, value % 60);
- return temp;
- }
+ return temp;
+}
- DWORD parseDate(const ext::string& date)
- {
- if (date.length() != 10 || date[4] != '-' || date[7] != '-')
- return 0;
+DWORD utils::parseDate(const ext::string& date)
+{
+ if (date.length() != 10 || date[4] != '-' || date[7] != '-')
+ return 0;
- struct tm dateTM;
+ struct tm dateTM;
- dateTM.tm_year = _wtoi(date.c_str() + 0) - 1900;
- dateTM.tm_mon = _wtoi(date.c_str() + 5) - 1;
- dateTM.tm_mday = _wtoi(date.c_str() + 8);
- dateTM.tm_hour = dateTM.tm_min = dateTM.tm_sec = 0;
- dateTM.tm_isdst = dateTM.tm_wday = dateTM.tm_yday = 0;
+ dateTM.tm_year = _wtoi(date.c_str() + 0) - 1900;
+ dateTM.tm_mon = _wtoi(date.c_str() + 5) - 1;
+ dateTM.tm_mday = _wtoi(date.c_str() + 8);
+ dateTM.tm_hour = dateTM.tm_min = dateTM.tm_sec = 0;
+ dateTM.tm_isdst = dateTM.tm_wday = dateTM.tm_yday = 0;
- time_t dateTT = mktime(&dateTM);
+ time_t dateTT = mktime(&dateTM);
- if (dateTT == -1)
- return 0;
+ if (dateTT == -1)
+ return 0;
- dateTM.tm_year = 1970 - 1900;
- dateTM.tm_mon = 1 - 1;
- dateTM.tm_mday = 3;
- dateTM.tm_hour = dateTM.tm_min = dateTM.tm_sec = 0;
- dateTM.tm_isdst = dateTM.tm_wday = dateTM.tm_yday = 0;
+ dateTM.tm_year = 1970 - 1900;
+ dateTM.tm_mon = 1 - 1;
+ dateTM.tm_mday = 3;
+ dateTM.tm_hour = dateTM.tm_min = dateTM.tm_sec = 0;
+ dateTM.tm_isdst = dateTM.tm_wday = dateTM.tm_yday = 0;
- time_t baseTT = mktime(&dateTM);
+ time_t baseTT = mktime(&dateTM);
- if (baseTT == -1)
- return 0;
+ if (baseTT == -1)
+ return 0;
- return dateTT - baseTT + 2 * 86400;
- }
+ return dateTT - baseTT + 2 * 86400;
+}
- ext::string intToString(int value)
- {
- wchar_t temp[100] = { 0 };
+ext::string utils::intToString(int value)
+{
+ wchar_t temp[100] = { 0 };
- ext::strfunc::sprintf(temp, L"%d", value);
+ ext::strfunc::sprintf(temp, L"%d", value);
- return temp;
- }
-
- ext::string intToPadded(int value, int len)
- {
- wchar_t temp[100] = { 0 };
+ return temp;
+}
- ext::strfunc::sprintf(temp, L"%0*d", len, value);
+ext::string utils::intToPadded(int value, int len)
+{
+ wchar_t temp[100] = { 0 };
- return temp;
- }
+ ext::strfunc::sprintf(temp, L"%0*d", len, value);
- ext::string intToGrouped(int value)
- {
- wchar_t temp[100] = { 0 };
- const char* grouping = Locale::grouping();
+ return temp;
+}
- ext::strfunc::sprintf(temp, L"%d", value);
+ext::string utils::intToGrouped(int value)
+{
+ wchar_t temp[100] = { 0 };
+ const char* grouping = Locale::grouping();
- if (*grouping == CHAR_MAX || *grouping <= 0)
- return temp;
+ ext::strfunc::sprintf(temp, L"%d", value);
- ext::string str = temp;
- ext::string::size_type pos = str.length();
- ext::string::size_type prefix = (temp[0] == '+' || temp[0] == '-') ? 1 : 0;
+ if (*grouping == CHAR_MAX || *grouping <= 0)
+ return temp;
- while (*grouping != CHAR_MAX && *grouping > 0 && pos > prefix + *grouping) {
- str.insert(pos -= *grouping, 1, Locale::thousandSep());
+ ext::string str = temp;
+ size_t pos = str.length();
+ size_t prefix = (temp[0] == '+' || temp[0] == '-') ? 1 : 0;
- if (grouping[1] > 0)
- ++grouping;
- }
+ while (*grouping != CHAR_MAX && *grouping > 0 && pos > prefix + *grouping) {
+ str.insert(pos -= *grouping, 1, Locale::thousandSep());
- return str;
+ if (grouping[1] > 0)
+ ++grouping;
}
- ext::string floatToString(double value, int precision)
- {
- wchar_t temp[100] = { 0 };
+ return str;
+}
- ext::strfunc::sprintf(temp, L"%.*f", precision, value);
+ext::string utils::floatToString(double value, int precision)
+{
+ wchar_t temp[100] = { 0 };
- return temp;
- }
+ ext::strfunc::sprintf(temp, L"%.*f", precision, value);
- ext::string floatToGrouped(double value, int precision)
- {
- wchar_t temp[100] = { 0 };
- const char* grouping = Locale::grouping();
+ return temp;
+}
- ext::strfunc::sprintf(temp, L"%.*f", precision, value);
+ext::string utils::floatToGrouped(double value, int precision)
+{
+ wchar_t temp[100] = { 0 };
+ const char* grouping = Locale::grouping();
- if (*grouping == CHAR_MAX || *grouping <= 0)
- return temp;
+ ext::strfunc::sprintf(temp, L"%.*f", precision, value);
- ext::string str = temp;
- ext::string::size_type pos = str.find(Locale::decimalPoint());
- ext::string::size_type prefix = (temp[0] == '+' || temp[0] == '-') ? 1 : 0;
+ if (*grouping == CHAR_MAX || *grouping <= 0)
+ return temp;
- if (pos == ext::string::npos)
- pos = str.length();
+ ext::string str = temp;
+ size_t pos = str.find(Locale::decimalPoint());
+ size_t prefix = (temp[0] == '+' || temp[0] == '-') ? 1 : 0;
- while (*grouping != CHAR_MAX && *grouping > 0 && pos > prefix + *grouping) {
- str.insert(pos -= *grouping, 1, Locale::thousandSep());
+ if (pos == ext::string::npos)
+ pos = str.length();
- if (grouping[1] > 0)
- ++grouping;
- }
+ while (*grouping != CHAR_MAX && *grouping > 0 && pos > prefix + *grouping) {
+ str.insert(pos -= *grouping, 1, Locale::thousandSep());
- return str;
+ if (grouping[1] > 0)
+ ++grouping;
}
- ext::string ratioToPercent(int numerator, int denominator)
- {
- float value = 0.0;
- wchar_t temp[100] = { 0 };
-
- if (denominator != 0) {
- value = 1.0f * numerator / denominator;
- }
+ return str;
+}
- ext::strfunc::sprintf(temp, L"%.0f%%", 100.0f * value);
+ext::string utils::ratioToPercent(int numerator, int denominator)
+{
+ float value = 0.0;
+ wchar_t temp[100] = { 0 };
- return temp;
+ if (denominator != 0) {
+ value = 1.0f * numerator / denominator;
}
- void replaceAllInPlace(ext::string& text, const wchar_t* find, const wchar_t* replace)
- {
- ext::string::size_type pos = 0;
- ext::string::size_type find_len = ext::strfunc::len(find);
- ext::string::size_type replace_len = ext::strfunc::len(replace);
-
- while ((pos = text.find(find, pos, find_len)) != ext::string::npos) {
- text.erase(pos, find_len);
- text.insert(pos, replace, replace_len);
- pos += replace_len;
- }
- }
+ ext::strfunc::sprintf(temp, L"%.0f%%", 100.0f * value);
- void htmlEscapeInPlace(ext::string& text)
- {
- replaceAllInPlace(text, L"&", L"&amp;");
- replaceAllInPlace(text, L"\"", L"&quot;");
- replaceAllInPlace(text, L"<", L"&lt;");
- replaceAllInPlace(text, L">", L"&gt;");
+ return temp;
+}
+
+void utils::replaceAllInPlace(ext::string& text, const wchar_t* find, const wchar_t* replace)
+{
+ size_t pos = 0;
+ size_t find_len = ext::strfunc::len(find);
+ size_t replace_len = ext::strfunc::len(replace);
+
+ while ((pos = text.find(find, pos, find_len)) != ext::string::npos) {
+ text.erase(pos, find_len);
+ text.insert(pos, replace, replace_len);
+ pos += replace_len;
}
+}
- const wchar_t* stripPrefix(const wchar_t* szPrefix, const wchar_t* szText)
- {
- int i = 0;
+void utils::htmlEscapeInPlace(ext::string& text)
+{
+ utils::replaceAllInPlace(text, L"&", L"&amp;");
+ utils::replaceAllInPlace(text, L"\"", L"&quot;");
+ utils::replaceAllInPlace(text, L"<", L"&lt;");
+ utils::replaceAllInPlace(text, L">", L"&gt;");
+}
- while (szPrefix[i] != '\0' && szText[i] != '\0' && szPrefix[i] == szText[i])
- ++i;
+const wchar_t* utils::stripPrefix(const wchar_t* szPrefix, const wchar_t* szText)
+{
+ int i = 0;
- if (szPrefix[i] == '\0')
- return szText + i;
+ while (szPrefix[i] != '\0' && szText[i] != '\0' && szPrefix[i] == szText[i])
+ ++i;
- return szText;
- }
+ if (szPrefix[i] == '\0')
+ return szText + i;
- ext::string replaceVariables(const ext::string& strFormat, time_t timeValue, const wchar_t* szNick /* = L"" */)
- {
- static const wchar_t* szMonthName[][2] = {
- { LPGENW("month3:Jan"), LPGENW("monthF:January") },
- { LPGENW("month3:Feb"), LPGENW("monthF:February") },
- { LPGENW("month3:Mar"), LPGENW("monthF:March") },
- { LPGENW("month3:Apr"), LPGENW("monthF:April") },
- { LPGENW("month3:May"), LPGENW("monthF:May") },
- { LPGENW("month3:Jun"), LPGENW("monthF:June") },
- { LPGENW("month3:Jul"), LPGENW("monthF:July") },
- { LPGENW("month3:Aug"), LPGENW("monthF:August") },
- { LPGENW("month3:Sep"), LPGENW("monthF:September") },
- { LPGENW("month3:Oct"), LPGENW("monthF:October") },
- { LPGENW("month3:Nov"), LPGENW("monthF:November") },
- { LPGENW("month3:Dec"), LPGENW("monthF:December") },
- };
-
- static const wchar_t* szWDayName[][3] = {
- { LPGENW("wday2:Mo"), LPGENW("wday3:Mon"), LPGENW("wdayF:Monday") },
- { LPGENW("wday2:Tu"), LPGENW("wday3:Tue"), LPGENW("wdayF:Tuesday") },
- { LPGENW("wday2:We"), LPGENW("wday3:Wed"), LPGENW("wdayF:Wednesday") },
- { LPGENW("wday2:Th"), LPGENW("wday3:Thu"), LPGENW("wdayF:Thursday") },
- { LPGENW("wday2:Fr"), LPGENW("wday3:Fri"), LPGENW("wdayF:Friday") },
- { LPGENW("wday2:Sa"), LPGENW("wday3:Sat"), LPGENW("wdayF:Saturday") },
- { LPGENW("wday2:Su"), LPGENW("wday3:Sun"), LPGENW("wdayF:Sunday") },
- };
-
- struct tm* timeTM = gmtime(&timeValue);
-
- ext::string strOut = strFormat;
- ext::string::size_type posOpen = strOut.find('%');
-
- while (posOpen != ext::string::npos) {
- ext::string::size_type posClose = strOut.find('%', posOpen + 1);
-
- if (posOpen != ext::string::npos) {
- ext::string strVar = strOut.substr(posOpen + 1, posClose - posOpen - 1);
- ext::string strSubst;
-
- // match variable and generate substitution
- if (strVar == L"h") {
- strSubst = intToString(timeTM->tm_hour % 12 + (timeTM->tm_hour % 12 == 0 ? 12 : 0));
- }
- else if (strVar == L"hh") {
- strSubst = intToPadded(timeTM->tm_hour % 12 + (timeTM->tm_hour % 12 == 0 ? 12 : 0), 2);
- }
- else if (strVar == L"H") {
- strSubst = intToString(timeTM->tm_hour);
- }
- else if (strVar == L"HH") {
- strSubst = intToPadded(timeTM->tm_hour, 2);
- }
- else if (strVar == L"m") {
- strSubst = intToString(timeTM->tm_min);
- }
- else if (strVar == L"mm") {
- strSubst = intToPadded(timeTM->tm_min, 2);
- }
- else if (strVar == L"s") {
- strSubst = intToString(timeTM->tm_sec);
- }
- else if (strVar == L"ss") {
- strSubst = intToPadded(timeTM->tm_sec, 2);
- }
- else if (strVar == L"tt") {
- strSubst = timeTM->tm_hour / 12 ? TranslateT("pm") : TranslateT("am");
- }
- else if (strVar == L"TT") {
- strSubst = timeTM->tm_hour / 12 ? TranslateT("PM") : TranslateT("AM");
- }
- else if (strVar == L"yy") {
- strSubst = intToPadded((timeTM->tm_year + 1900) % 100, 2);
- }
- else if (strVar == L"yyyy") {
- strSubst = intToPadded(timeTM->tm_year + 1900, 4);
- }
- else if (strVar == L"M") {
- strSubst = intToString(timeTM->tm_mon + 1);
- }
- else if (strVar == L"MM") {
- strSubst = intToPadded(timeTM->tm_mon + 1, 2);
- }
- else if (strVar == L"MMM") {
- strSubst = stripPrefix(L"month3:", TranslateW(szMonthName[timeTM->tm_mon % 12][0]));
- }
- else if (strVar == L"MMMM") {
- strSubst = stripPrefix(L"monthF:", TranslateW(szMonthName[timeTM->tm_mon % 12][1]));
- }
- else if (strVar == L"d") {
- strSubst = intToString(timeTM->tm_mday);
- }
- else if (strVar == L"dd") {
- strSubst = intToPadded(timeTM->tm_mday, 2);
- }
- else if (strVar == L"ww") {
- strSubst = stripPrefix(L"wday2:", TranslateW(szWDayName[(timeTM->tm_wday + 6) % 7][0]));
- }
- else if (strVar == L"www") {
- strSubst = stripPrefix(L"wday3:", TranslateW(szWDayName[(timeTM->tm_wday + 6) % 7][1]));
- }
- else if (strVar == L"wwww") {
- strSubst = stripPrefix(L"wdayF:", TranslateW(szWDayName[(timeTM->tm_wday + 6) % 7][2]));
- }
- else if (strVar == L"miranda_path") {
- strSubst = getMirandaPath();
- }
- else if (strVar == L"profile_path") {
- strSubst = getProfilePath();
- }
- else if (strVar == L"profile_name") {
- strSubst = getProfileName();
- }
- else if (strVar == L"nick") {
- strSubst = szNick;
- }
- else if (strVar == L"") {
- strSubst = L"%";
- }
-
- // perform actual substitution
- if (!strSubst.empty()) {
- strOut.replace(posOpen, posClose - posOpen + 1, strSubst);
- posClose += strSubst.length() - strVar.length() - 2;
- }
+ return szText;
+}
+
+ext::string utils::replaceVariables(const ext::string& strFormat, time_t timeValue, const wchar_t* szNick /* = L"" */)
+{
+ static const wchar_t* szMonthName[][2] = {
+ { LPGENW("month3:Jan"), LPGENW("monthF:January") },
+ { LPGENW("month3:Feb"), LPGENW("monthF:February") },
+ { LPGENW("month3:Mar"), LPGENW("monthF:March") },
+ { LPGENW("month3:Apr"), LPGENW("monthF:April") },
+ { LPGENW("month3:May"), LPGENW("monthF:May") },
+ { LPGENW("month3:Jun"), LPGENW("monthF:June") },
+ { LPGENW("month3:Jul"), LPGENW("monthF:July") },
+ { LPGENW("month3:Aug"), LPGENW("monthF:August") },
+ { LPGENW("month3:Sep"), LPGENW("monthF:September") },
+ { LPGENW("month3:Oct"), LPGENW("monthF:October") },
+ { LPGENW("month3:Nov"), LPGENW("monthF:November") },
+ { LPGENW("month3:Dec"), LPGENW("monthF:December") },
+ };
+
+ static const wchar_t* szWDayName[][3] = {
+ { LPGENW("wday2:Mo"), LPGENW("wday3:Mon"), LPGENW("wdayF:Monday") },
+ { LPGENW("wday2:Tu"), LPGENW("wday3:Tue"), LPGENW("wdayF:Tuesday") },
+ { LPGENW("wday2:We"), LPGENW("wday3:Wed"), LPGENW("wdayF:Wednesday") },
+ { LPGENW("wday2:Th"), LPGENW("wday3:Thu"), LPGENW("wdayF:Thursday") },
+ { LPGENW("wday2:Fr"), LPGENW("wday3:Fri"), LPGENW("wdayF:Friday") },
+ { LPGENW("wday2:Sa"), LPGENW("wday3:Sat"), LPGENW("wdayF:Saturday") },
+ { LPGENW("wday2:Su"), LPGENW("wday3:Sun"), LPGENW("wdayF:Sunday") },
+ };
+
+ struct tm* timeTM = gmtime(&timeValue);
+
+ ext::string strOut = strFormat;
+ size_t posOpen = strOut.find('%');
+
+ while (posOpen != ext::string::npos) {
+ size_t posClose = strOut.find('%', posOpen + 1);
+
+ if (posOpen != ext::string::npos) {
+ ext::string strVar = strOut.substr(posOpen + 1, posClose - posOpen - 1);
+ ext::string strSubst;
+
+ // match variable and generate substitution
+ if (strVar == L"h") {
+ strSubst = intToString(timeTM->tm_hour % 12 + (timeTM->tm_hour % 12 == 0 ? 12 : 0));
+ }
+ else if (strVar == L"hh") {
+ strSubst = intToPadded(timeTM->tm_hour % 12 + (timeTM->tm_hour % 12 == 0 ? 12 : 0), 2);
+ }
+ else if (strVar == L"H") {
+ strSubst = intToString(timeTM->tm_hour);
+ }
+ else if (strVar == L"HH") {
+ strSubst = intToPadded(timeTM->tm_hour, 2);
+ }
+ else if (strVar == L"m") {
+ strSubst = intToString(timeTM->tm_min);
+ }
+ else if (strVar == L"mm") {
+ strSubst = intToPadded(timeTM->tm_min, 2);
+ }
+ else if (strVar == L"s") {
+ strSubst = intToString(timeTM->tm_sec);
+ }
+ else if (strVar == L"ss") {
+ strSubst = intToPadded(timeTM->tm_sec, 2);
+ }
+ else if (strVar == L"tt") {
+ strSubst = timeTM->tm_hour / 12 ? TranslateT("pm") : TranslateT("am");
+ }
+ else if (strVar == L"TT") {
+ strSubst = timeTM->tm_hour / 12 ? TranslateT("PM") : TranslateT("AM");
+ }
+ else if (strVar == L"yy") {
+ strSubst = intToPadded((timeTM->tm_year + 1900) % 100, 2);
+ }
+ else if (strVar == L"yyyy") {
+ strSubst = intToPadded(timeTM->tm_year + 1900, 4);
+ }
+ else if (strVar == L"M") {
+ strSubst = intToString(timeTM->tm_mon + 1);
+ }
+ else if (strVar == L"MM") {
+ strSubst = intToPadded(timeTM->tm_mon + 1, 2);
}
- else {
- break;
+ else if (strVar == L"MMM") {
+ strSubst = stripPrefix(L"month3:", TranslateW(szMonthName[timeTM->tm_mon % 12][0]));
+ }
+ else if (strVar == L"MMMM") {
+ strSubst = stripPrefix(L"monthF:", TranslateW(szMonthName[timeTM->tm_mon % 12][1]));
+ }
+ else if (strVar == L"d") {
+ strSubst = intToString(timeTM->tm_mday);
+ }
+ else if (strVar == L"dd") {
+ strSubst = intToPadded(timeTM->tm_mday, 2);
+ }
+ else if (strVar == L"ww") {
+ strSubst = stripPrefix(L"wday2:", TranslateW(szWDayName[(timeTM->tm_wday + 6) % 7][0]));
+ }
+ else if (strVar == L"www") {
+ strSubst = stripPrefix(L"wday3:", TranslateW(szWDayName[(timeTM->tm_wday + 6) % 7][1]));
+ }
+ else if (strVar == L"wwww") {
+ strSubst = stripPrefix(L"wdayF:", TranslateW(szWDayName[(timeTM->tm_wday + 6) % 7][2]));
+ }
+ else if (strVar == L"miranda_path") {
+ strSubst = getMirandaPath();
+ }
+ else if (strVar == L"profile_path") {
+ strSubst = getProfilePath();
+ }
+ else if (strVar == L"profile_name") {
+ strSubst = getProfileName();
+ }
+ else if (strVar == L"nick") {
+ strSubst = szNick;
+ }
+ else if (strVar == L"") {
+ strSubst = L"%";
}
- posOpen = strOut.find('%', posClose + 1);
+ // perform actual substitution
+ if (!strSubst.empty()) {
+ strOut.replace(posOpen, posClose - posOpen + 1, strSubst);
+ posClose += strSubst.length() - strVar.length() - 2;
+ }
+ }
+ else {
+ break;
}
- return strOut;
+ posOpen = strOut.find('%', posClose + 1);
}
- ext::string toLowerCase(const ext::string& text)
- {
- int len = text.length();
- wchar_t* buf = new wchar_t[len + 1];
-
- LCID lcid = GetUserDefaultLCID();
+ return strOut;
+}
- len = LCMapString(lcid, LCMAP_LINGUISTIC_CASING | LCMAP_LOWERCASE, text.c_str(), len, buf, len);
+ext::string utils::toLowerCase(const ext::string& text)
+{
+ int len = text.length();
+ wchar_t* buf = new wchar_t[len + 1];
- buf[len] = 0;
+ LCID lcid = GetUserDefaultLCID();
- ext::string ret_str(buf, len);
+ len = LCMapString(lcid, LCMAP_LINGUISTIC_CASING | LCMAP_LOWERCASE, text.c_str(), len, buf, len);
- delete[] buf;
+ buf[len] = 0;
- return ret_str;
- }
+ ext::string ret_str(buf, len);
- ext::string toUpperCase(const ext::string& text)
- {
- int len = text.length();
- wchar_t* buf = new wchar_t[len + 1];
+ delete[] buf;
- LCID lcid = GetUserDefaultLCID();
+ return ret_str;
+}
- len = LCMapString(lcid, LCMAP_LINGUISTIC_CASING | LCMAP_UPPERCASE, text.c_str(), len, buf, len);
+ext::string utils::toUpperCase(const ext::string& text)
+{
+ int len = text.length();
+ wchar_t* buf = new wchar_t[len + 1];
- buf[len] = 0;
+ LCID lcid = GetUserDefaultLCID();
- ext::string ret_str(buf, len);
+ len = LCMapString(lcid, LCMAP_LINGUISTIC_CASING | LCMAP_UPPERCASE, text.c_str(), len, buf, len);
- delete[] buf;
+ buf[len] = 0;
- return ret_str;
- }
+ ext::string ret_str(buf, len);
- DWORD dottedToVersion(ext::string version)
- {
- union
- {
- __int32 combined;
- __int8 parts[4];
- } res = { 0 };
+ delete[] buf;
- int part = 3;
+ return ret_str;
+}
- while (!version.empty() && part >= 0) {
- ext::string::size_type dotPos = version.find(L".");
+DWORD utils::dottedToVersion(ext::string version)
+{
+ union
+ {
+ __int32 combined;
+ __int8 parts[4];
+ } res = { 0 };
- if (dotPos == ext::string::npos) {
- dotPos = version.length();
- }
+ int part = 3;
- res.parts[part--] = _wtoi(version.substr(0, dotPos).c_str());
+ while (!version.empty() && part >= 0) {
+ size_t dotPos = version.find(L".");
- version.erase(0, dotPos + 1);
+ if (dotPos == ext::string::npos) {
+ dotPos = version.length();
}
- return res.combined;
+ res.parts[part--] = _wtoi(version.substr(0, dotPos).c_str());
+
+ version.erase(0, dotPos + 1);
}
- ext::string versionToDotted(DWORD version)
- {
- wchar_t temp[16] = { 0 };
+ return res.combined;
+}
- ext::strfunc::sprintf(
- temp,
- L"%d.%d.%d.%d",
- (version >> 24) & 0xFF,
- (version >> 16) & 0xFF,
- (version >> 8) & 0xFF,
- version & 0xFF);
+ext::string utils::versionToDotted(DWORD version)
+{
+ wchar_t temp[16] = { 0 };
- return temp;
- }
+ ext::strfunc::sprintf(
+ temp,
+ L"%d.%d.%d.%d",
+ (version >> 24) & 0xFF,
+ (version >> 16) & 0xFF,
+ (version >> 8) & 0xFF,
+ version & 0xFF);
- ext::a::string convertWToA(const WCHAR* str, size_t len)
- {
- char* buf = new char[len + 1];
+ return temp;
+}
- len = WideCharToMultiByte(CP_ACP, 0, str, len, buf, len, NULL, NULL);
+ext::a::string utils::convertWToA(const WCHAR* str, size_t len)
+{
+ char* buf = new char[len + 1];
- buf[len] = '\0';
+ len = WideCharToMultiByte(CP_ACP, 0, str, len, buf, len, NULL, NULL);
- ext::a::string ret_str(buf, len);
+ buf[len] = '\0';
- delete[] buf;
+ ext::a::string ret_str(buf, len);
- return ret_str;
- }
+ delete[] buf;
- ext::w::string convertAToW(const char* str, size_t len)
- {
- WCHAR* buf = new WCHAR[len + 1];
+ return ret_str;
+}
- len = MultiByteToWideChar(CP_ACP, 0, str, len, buf, len);
+ext::w::string utils::convertAToW(const char* str, size_t len)
+{
+ WCHAR* buf = new WCHAR[len + 1];
- buf[len] = '\0';
+ len = MultiByteToWideChar(CP_ACP, 0, str, len, buf, len);
- ext::w::string ret_str(buf, len);
+ buf[len] = '\0';
- delete[] buf;
+ ext::w::string ret_str(buf, len);
- return ret_str;
- }
+ delete[] buf;
- ext::a::string convertTToUTF8(const wchar_t* str, size_t str_len)
- {
+ return ret_str;
+}
+
+ext::a::string utils::convertTToUTF8(const wchar_t* str, size_t str_len)
+{
#if defined(_UNICODE)
- const WCHAR* conv_str = str;
+ const WCHAR* conv_str = str;
#else // _UNICODE
- const ext::w::string conv_strX = convertAToW(str, str_len);
- const WCHAR* conv_str = conv_strX.c_str();
+ const ext::w::string conv_strX = convertAToW(str, str_len);
+ const WCHAR* conv_str = conv_strX.c_str();
#endif // _UNICODE
- int len = 0;
+ int len = 0;
- upto_each_(i, str_len)
- {
- WCHAR c = conv_str[i];
+ upto_each_(i, str_len)
+ {
+ WCHAR c = conv_str[i];
- if (c <= 0x007F) {
- len++;
- }
- else if (c <= 0x07FF) {
- len += 2;
- }
- else {
- len += 3;
- }
+ if (c <= 0x007F) {
+ len++;
}
+ else if (c <= 0x07FF) {
+ len += 2;
+ }
+ else {
+ len += 3;
+ }
+ }
- ext::a::string out_str(len, '_');
+ ext::a::string out_str(len, '_');
- int pos = 0;
+ int pos = 0;
- upto_each_(i, str_len)
- {
- WCHAR c = conv_str[i];
+ upto_each_(i, str_len)
+ {
+ WCHAR c = conv_str[i];
- if (c <= 0x007F) {
- out_str[pos++] = (unsigned char)c;
- }
- else if (c <= 0x07FF) {
- out_str[pos++] = (unsigned char)0xC0 | (c >> 6);
- out_str[pos++] = (unsigned char)0x80 | (c & 0x3F);
- }
- else {
- out_str[pos++] = (unsigned char)0xE0 | (c >> 12);
- out_str[pos++] = (unsigned char)0x80 | ((c >> 6) & 0x3F);
- out_str[pos++] = (unsigned char)0x80 | (c & 0x3F);
- }
+ if (c <= 0x007F) {
+ out_str[pos++] = (unsigned char)c;
+ }
+ else if (c <= 0x07FF) {
+ out_str[pos++] = (unsigned char)0xC0 | (c >> 6);
+ out_str[pos++] = (unsigned char)0x80 | (c & 0x3F);
+ }
+ else {
+ out_str[pos++] = (unsigned char)0xE0 | (c >> 12);
+ out_str[pos++] = (unsigned char)0x80 | ((c >> 6) & 0x3F);
+ out_str[pos++] = (unsigned char)0x80 | (c & 0x3F);
}
-
- return out_str;
}
- ext::string convertUTF8ToT(const char* str, size_t str_len)
- {
- size_t len = 0, in_pos = 0;
+ return out_str;
+}
- while (in_pos < str_len) {
- char c = str[in_pos];
+ext::string utils::convertUTF8ToT(const char* str, size_t str_len)
+{
+ size_t len = 0, in_pos = 0;
- if ((c & 0x80) == 0x00) {
- in_pos++;
- }
- else if ((c & 0xE0) == 0xC0) {
- in_pos += 2;
- }
- else if ((c & 0xF0) == 0xE0) {
- in_pos += 3;
- }
- else {
- in_pos++;
- }
+ while (in_pos < str_len) {
+ char c = str[in_pos];
- len++;
+ if ((c & 0x80) == 0x00) {
+ in_pos++;
+ }
+ else if ((c & 0xE0) == 0xC0) {
+ in_pos += 2;
+ }
+ else if ((c & 0xF0) == 0xE0) {
+ in_pos += 3;
+ }
+ else {
+ in_pos++;
}
- ext::w::string out_str(len, '_');
+ len++;
+ }
- size_t out_pos = 0;
- in_pos = 0;
+ ext::w::string out_str(len, '_');
- while (in_pos < str_len) {
- unsigned char c = (unsigned char)str[in_pos];
+ size_t out_pos = 0;
+ in_pos = 0;
- if ((c & 0x80) == 0x00) {
- out_str[out_pos] = (WCHAR)c;
- in_pos++;
- }
- else if ((c & 0xE0) == 0xC0) {
- out_str[out_pos] = (WCHAR)(((c & 0x1F) << 6) | ((unsigned char)str[in_pos + 1] & 0x3F));
- in_pos += 2;
- }
- else if ((c & 0xF0) == 0xE0) {
- out_str[out_pos] = (WCHAR)(((c & 0x0F) << 12) | (((unsigned char)str[in_pos + 1] & 0x3F) << 6) | ((unsigned char)str[in_pos + 2] & 0x3F));
- in_pos += 3;
- }
- else {
- in_pos++;
- }
+ while (in_pos < str_len) {
+ unsigned char c = (unsigned char)str[in_pos];
- out_pos++;
+ if ((c & 0x80) == 0x00) {
+ out_str[out_pos] = (WCHAR)c;
+ in_pos++;
}
+ else if ((c & 0xE0) == 0xC0) {
+ out_str[out_pos] = (WCHAR)(((c & 0x1F) << 6) | ((unsigned char)str[in_pos + 1] & 0x3F));
+ in_pos += 2;
+ }
+ else if ((c & 0xF0) == 0xE0) {
+ out_str[out_pos] = (WCHAR)(((c & 0x0F) << 12) | (((unsigned char)str[in_pos + 1] & 0x3F) << 6) | ((unsigned char)str[in_pos + 2] & 0x3F));
+ in_pos += 3;
+ }
+ else {
+ in_pos++;
+ }
+
+ out_pos++;
+ }
#if defined(_UNICODE)
- return out_str;
+ return out_str;
#else // _UNICODE
- return convertWToA(out_str.c_str(), out_str.length());
+ return convertWToA(out_str.c_str(), out_str.length());
#endif // _UNICODE
- }
-
- size_t rawUTF8Encode(const WCHAR* pIn, size_t lenIn, char* pOut)
- {
- char* pOutBegin = pOut;
-
- upto_each_(i, lenIn)
- {
- WCHAR c = pIn[i];
-
- if (c <= 0x007F) {
- *pOut++ = (unsigned char)c;
- }
- else if (c <= 0x07FF) {
- *pOut++ = (unsigned char)0xC0 | (c >> 6);
- *pOut++ = (unsigned char)0x80 | (c & 0x3F);
- }
- else {
- *pOut++ = (unsigned char)0xE0 | (c >> 12);
- *pOut++ = (unsigned char)0x80 | ((c >> 6) & 0x3F);
- *pOut++ = (unsigned char)0x80 | (c & 0x3F);
- }
- }
+}
- return (pOut - pOutBegin);
- }
+size_t utils::rawUTF8Encode(const WCHAR* pIn, size_t lenIn, char* pOut)
+{
+ char* pOutBegin = pOut;
- size_t getUTF8Len(const char* str)
+ upto_each_(i, lenIn)
{
- size_t len = 0, in_pos = 0, str_len = ext::a::strfunc::len(str);
+ WCHAR c = pIn[i];
- while (in_pos < str_len) {
- char c = str[in_pos];
-
- if ((c & 0x80) == 0x00) {
- in_pos++;
- }
- else if ((c & 0xE0) == 0xC0) {
- in_pos += 2;
- }
- else if ((c & 0xF0) == 0xE0) {
- in_pos += 3;
- }
- else {
- in_pos++;
- }
-
- len++;
+ if (c <= 0x007F) {
+ *pOut++ = (unsigned char)c;
}
-
- return len;
- }
-
- bool fileExists(const ext::string& fileName)
- {
- WIN32_FIND_DATA wfd;
- HANDLE hFind = FindFirstFile(fileName.c_str(), &wfd);
-
- if (hFind != INVALID_HANDLE_VALUE) {
- FindClose(hFind);
-
- return true;
+ else if (c <= 0x07FF) {
+ *pOut++ = (unsigned char)0xC0 | (c >> 6);
+ *pOut++ = (unsigned char)0x80 | (c & 0x3F);
}
else {
- return false;
+ *pOut++ = (unsigned char)0xE0 | (c >> 12);
+ *pOut++ = (unsigned char)0x80 | ((c >> 6) & 0x3F);
+ *pOut++ = (unsigned char)0x80 | (c & 0x3F);
}
}
- bool pathExists(const ext::string& path)
- {
- WIN32_FIND_DATA wfd;
- HANDLE hFind = FindFirstFile((path + L".").c_str(), &wfd);
+ return (pOut - pOutBegin);
+}
+
+size_t utils::getUTF8Len(const char* str)
+{
+ size_t len = 0, in_pos = 0, str_len = ext::a::strfunc::len(str);
- if (hFind != INVALID_HANDLE_VALUE) {
- FindClose(hFind);
+ while (in_pos < str_len) {
+ char c = str[in_pos];
- return (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
+ if ((c & 0x80) == 0x00) {
+ in_pos++;
+ }
+ else if ((c & 0xE0) == 0xC0) {
+ in_pos += 2;
+ }
+ else if ((c & 0xF0) == 0xE0) {
+ in_pos += 3;
}
else {
- return false;
+ in_pos++;
}
+
+ len++;
}
- bool isRelative(const ext::string& fileName)
- {
- if (fileName.length() > 2)
- if ((fileName[1] == ':' && fileName[2] == '\\') || (fileName[0] == '\\' && fileName[1] == '\\'))
- return false;
+ return len;
+}
+
+bool utils::fileExists(const ext::string& fileName)
+{
+ WIN32_FIND_DATA wfd;
+ HANDLE hFind = FindFirstFile(fileName.c_str(), &wfd);
+
+ if (hFind != INVALID_HANDLE_VALUE) {
+ FindClose(hFind);
return true;
}
+ else {
+ return false;
+ }
+}
- bool isValidFilePart(ext::string filePart)
- {
- // check for disallowed chars
- if (filePart.find_first_of(L"<>:\"/\\|?*") != ext::string::npos)
- return false;
+bool utils::pathExists(const ext::string& path)
+{
+ WIN32_FIND_DATA wfd;
+ HANDLE hFind = FindFirstFile((path + L".").c_str(), &wfd);
- // check for dots only
- if (filePart.find_first_not_of('.') == ext::string::npos)
- return false;
+ if (hFind != INVALID_HANDLE_VALUE) {
+ FindClose(hFind);
- // check for disallowed names
- static const wchar_t* disallowedNames[] = {
- L"clock$",
- L"aux",
- L"con",
- L"nul",
- L"prn",
- L"com1",
- L"com2",
- L"com3",
- L"com4",
- L"com5",
- L"com6",
- L"com7",
- L"com8",
- L"com9",
- L"lpt1",
- L"lpt2",
- L"lpt3",
- L"lpt4",
- L"lpt5",
- L"lpt6",
- L"lpt7",
- L"lpt8",
- L"lpt9"
- };
-
- ext::string::size_type pos = filePart.find('.');
-
- if (pos != ext::string::npos) {
- filePart.erase(pos);
- }
+ return (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
+ }
+ else {
+ return false;
+ }
+}
- array_each_(i, disallowedNames)
- {
- if (filePart == disallowedNames[i]) {
- return false;
- }
- }
+bool utils::isRelative(const ext::string& fileName)
+{
+ if (fileName.length() > 2)
+ if ((fileName[1] == ':' && fileName[2] == '\\') || (fileName[0] == '\\' && fileName[1] == '\\'))
+ return false;
- return true;
+ return true;
+}
+
+bool utils::isValidFilePart(ext::string filePart)
+{
+ // check for disallowed chars
+ if (filePart.find_first_of(L"<>:\"/\\|?*") != ext::string::npos)
+ return false;
+
+ // check for dots only
+ if (filePart.find_first_not_of('.') == ext::string::npos)
+ return false;
+
+ // check for disallowed names
+ static const wchar_t* disallowedNames[] = {
+ L"clock$",
+ L"aux",
+ L"con",
+ L"nul",
+ L"prn",
+ L"com1",
+ L"com2",
+ L"com3",
+ L"com4",
+ L"com5",
+ L"com6",
+ L"com7",
+ L"com8",
+ L"com9",
+ L"lpt1",
+ L"lpt2",
+ L"lpt3",
+ L"lpt4",
+ L"lpt5",
+ L"lpt6",
+ L"lpt7",
+ L"lpt8",
+ L"lpt9"
+ };
+
+ size_t pos = filePart.find('.');
+
+ if (pos != ext::string::npos) {
+ filePart.erase(pos);
}
- bool isValidFile(const ext::string& fileName)
+ array_each_(i, disallowedNames)
{
- // find the last backslash to extract file name
- ext::string::size_type pos = fileName.rfind('\\');
-
- if (pos == ext::string::npos) {
- pos = 0;
+ if (filePart == disallowedNames[i]) {
+ return false;
}
- else {
- // is a path, if ends with a backslash
- if (pos == fileName.length() - 1)
- return false;
+ }
- ++pos;
- }
+ return true;
+}
- // extract file part
- return isValidFilePart(fileName.substr(pos));
- }
+bool utils::isValidFile(const ext::string& fileName)
+{
+ // find the last backslash to extract file name
+ size_t pos = fileName.rfind('\\');
- ext::string extractPath(const ext::string& fileName)
- {
- ext::string::size_type pos = fileName.rfind('\\');
+ if (pos == ext::string::npos) {
+ pos = 0;
+ }
+ else {
+ // is a path, if ends with a backslash
+ if (pos == fileName.length() - 1)
+ return false;
- if (pos == ext::string::npos) {
- return L"";
- }
- else {
- return fileName.substr(0, pos + 1);
- }
+ ++pos;
}
- ext::string extractFile(const ext::string& fileName)
- {
- ext::string::size_type pos = fileName.rfind('\\');
+ // extract file part
+ return isValidFilePart(fileName.substr(pos));
+}
- if (pos == ext::string::npos) {
- return fileName;
- }
- else {
- return fileName.substr(pos + 1);
- }
+ext::string utils::extractPath(const ext::string& fileName)
+{
+ size_t pos = fileName.rfind('\\');
+
+ if (pos == ext::string::npos) {
+ return L"";
+ }
+ else {
+ return fileName.substr(0, pos + 1);
}
+}
- bool createPath(const ext::string& path)
- {
- ext::string curPath = extractPath(path);
- std::stack<ext::string> subDirs;
+ext::string utils::extractFile(const ext::string& fileName)
+{
+ size_t pos = fileName.rfind('\\');
- // create stack of missing subdirs and validate them
- while (curPath.length() > 3 && !pathExists(curPath)) {
- ext::string::size_type pos = curPath.rfind('\\', curPath.length() - 2);
+ if (pos == ext::string::npos) {
+ return fileName;
+ }
+ else {
+ return fileName.substr(pos + 1);
+ }
+}
- if (pos == ext::string::npos) {
- pos = -1;
- }
+bool utils::createPath(const ext::string& path)
+{
+ ext::string curPath = extractPath(path);
+ std::stack<ext::string> subDirs;
- subDirs.push(curPath.substr(pos + 1, curPath.length() - pos - 2));
- curPath.erase(pos + 1);
+ // create stack of missing subdirs and validate them
+ while (curPath.length() > 3 && !pathExists(curPath)) {
+ size_t pos = curPath.rfind('\\', curPath.length() - 2);
- if (!isValidFilePart(subDirs.top())) {
- return false;
- }
+ if (pos == ext::string::npos) {
+ pos = -1;
}
- // try to create subdirs in reverse order
- while (!subDirs.empty()) {
- const ext::string& curDir = subDirs.top();
+ subDirs.push(curPath.substr(pos + 1, curPath.length() - pos - 2));
+ curPath.erase(pos + 1);
- curPath += curDir;
+ if (!isValidFilePart(subDirs.top())) {
+ return false;
+ }
+ }
- if (!CreateDirectory(curPath.c_str(), NULL)) {
- return false;
- }
+ // try to create subdirs in reverse order
+ while (!subDirs.empty()) {
+ const ext::string& curDir = subDirs.top();
- curPath += L"\\";
+ curPath += curDir;
- subDirs.pop();
+ if (!CreateDirectory(curPath.c_str(), NULL)) {
+ return false;
}
- return true;
+ curPath += L"\\";
+
+ subDirs.pop();
}
- ext::string colorToHTML(COLORREF crColor)
- {
- static const wchar_t hexDigits[] = L"0123456789ABCDEF";
+ return true;
+}
- ext::string htmlColor(7, '#');
+ext::string utils::colorToHTML(COLORREF crColor)
+{
+ static const wchar_t hexDigits[] = L"0123456789ABCDEF";
- upto_each_(i, 3)
- {
- htmlColor[2 * i + 1] = hexDigits[(crColor >> 4) & 0xF];
- htmlColor[2 * i + 2] = hexDigits[crColor & 0xF];
+ ext::string htmlColor(7, '#');
- crColor >>= 8;
- }
+ upto_each_(i, 3)
+ {
+ htmlColor[2 * i + 1] = hexDigits[(crColor >> 4) & 0xF];
+ htmlColor[2 * i + 2] = hexDigits[crColor & 0xF];
- return htmlColor;
+ crColor >>= 8;
}
- void generateGradient(COLORREF fromColor, COLORREF toColor, COLORREF colorTab[256])
- {
- struct rgb { int r, g, b; };
+ return htmlColor;
+}
- rgb fromRGB = { GetRValue(fromColor), GetGValue(fromColor), GetBValue(fromColor) };
- rgb toRGB = { GetRValue(toColor), GetGValue(toColor), GetBValue(toColor) };
+void utils::generateGradient(COLORREF fromColor, COLORREF toColor, COLORREF colorTab[256])
+{
+ struct rgb { int r, g, b; };
- upto_each_(i, 256)
- {
- colorTab[i] = RGB(
- (toRGB.r * i + fromRGB.r * (255 - i)) / 255,
- (toRGB.g * i + fromRGB.g * (255 - i)) / 255,
- (toRGB.b * i + fromRGB.b * (255 - i)) / 255);
- }
- }
+ rgb fromRGB = { GetRValue(fromColor), GetGValue(fromColor), GetBValue(fromColor) };
+ rgb toRGB = { GetRValue(toColor), GetGValue(toColor), GetBValue(toColor) };
- void ensureRange(int& value, int min, int max, int fallback)
+ upto_each_(i, 256)
{
- if (value < min || value > max) {
- value = fallback;
- }
+ colorTab[i] = RGB(
+ (toRGB.r * i + fromRGB.r * (255 - i)) / 255,
+ (toRGB.g * i + fromRGB.g * (255 - i)) / 255,
+ (toRGB.b * i + fromRGB.b * (255 - i)) / 255);
}
+}
- void ensureRange(unsigned int& value, unsigned int min, unsigned int max, unsigned int fallback)
- {
- if (value < min || value > max) {
- value = fallback;
- }
+void utils::ensureRange(int& value, int min, int max, int fallback)
+{
+ if (value < min || value > max) {
+ value = fallback;
}
+}
- ext::string getGUID()
- {
- static const wchar_t hexDigits[] = L"0123456789ABCDEF";
- GUID guid;
+void utils::ensureRange(unsigned int& value, unsigned int min, unsigned int max, unsigned int fallback)
+{
+ if (value < min || value > max) {
+ value = fallback;
+ }
+}
- CoCreateGuid(&guid);
+ext::string utils::getGUID()
+{
+ static const wchar_t hexDigits[] = L"0123456789ABCDEF";
+ GUID guid;
- ext::string strGUID(2 * sizeof(guid), '_');
+ CoCreateGuid(&guid);
- upto_each_(i, sizeof(guid))
- {
- BYTE val = reinterpret_cast<BYTE*>(&guid)[i];
+ ext::string strGUID(2 * sizeof(guid), '_');
- strGUID[2 * i] = hexDigits[(val >> 4) & 0xF];
- strGUID[2 * i + 1] = hexDigits[val & 0xF];
- }
+ upto_each_(i, sizeof(guid))
+ {
+ BYTE val = reinterpret_cast<BYTE*>(&guid)[i];
- return strGUID;
+ strGUID[2 * i] = hexDigits[(val >> 4) & 0xF];
+ strGUID[2 * i + 1] = hexDigits[val & 0xF];
}
- void centerDialog(HWND hDlg, HWND hParent /* = NULL */)
- {
- if (!hParent) {
- hParent = GetParent(hDlg);
- }
+ return strGUID;
+}
- RECT rDlg, rParent;
-
- if (GetWindowRect(hParent, &rParent) && GetWindowRect(hDlg, &rDlg)) {
- SetWindowPos(
- hDlg,
- 0,
- (rParent.right + rParent.left - rDlg.right + rDlg.left) / 2,
- (rParent.bottom + rParent.top - rDlg.bottom + rDlg.top) / 2,
- 0,
- 0,
- SWP_NOSIZE | SWP_NOZORDER);
- }
- else if (GetWindowRect(hDlg, &rDlg)) {
- SetWindowPos(
- hDlg,
- 0,
- (GetSystemMetrics(SM_CXSCREEN) - rDlg.right + rDlg.left) / 2,
- (GetSystemMetrics(SM_CYSCREEN) - rDlg.bottom + rDlg.top) / 2,
- 0,
- 0,
- SWP_NOSIZE | SWP_NOZORDER);
- }
+void utils::centerDialog(HWND hDlg, HWND hParent /* = NULL */)
+{
+ if (!hParent)
+ hParent = GetParent(hDlg);
+
+ RECT rDlg, rParent;
+
+ if (GetWindowRect(hParent, &rParent) && GetWindowRect(hDlg, &rDlg)) {
+ SetWindowPos(
+ hDlg,
+ 0,
+ (rParent.right + rParent.left - rDlg.right + rDlg.left) / 2,
+ (rParent.bottom + rParent.top - rDlg.bottom + rDlg.top) / 2,
+ 0,
+ 0,
+ SWP_NOSIZE | SWP_NOZORDER);
}
+ else if (GetWindowRect(hDlg, &rDlg)) {
+ SetWindowPos(
+ hDlg,
+ 0,
+ (GetSystemMetrics(SM_CXSCREEN) - rDlg.right + rDlg.left) / 2,
+ (GetSystemMetrics(SM_CYSCREEN) - rDlg.bottom + rDlg.top) / 2,
+ 0,
+ 0,
+ SWP_NOSIZE | SWP_NOZORDER);
+ }
+}
- RECT getWindowRect(HWND hParent, HWND hWnd)
- {
- RECT rWnd;
-
- GetWindowRect(hWnd, &rWnd);
+RECT utils::getWindowRect(HWND hParent, HWND hWnd)
+{
+ RECT rWnd;
- ScreenToClient(hParent, reinterpret_cast<POINT*>(&rWnd) + 0);
- ScreenToClient(hParent, reinterpret_cast<POINT*>(&rWnd) + 1);
+ GetWindowRect(hWnd, &rWnd);
- return rWnd;
- }
+ ScreenToClient(hParent, reinterpret_cast<POINT*>(&rWnd) + 0);
+ ScreenToClient(hParent, reinterpret_cast<POINT*>(&rWnd) + 1);
- void moveWindow(HWND hWnd, const RECT& rWnd)
- {
- MoveWindow(hWnd, rWnd.left, rWnd.top, rWnd.right - rWnd.left, rWnd.bottom - rWnd.top, TRUE);
- }
+ return rWnd;
+}
- const ext::string& getMirandaPath()
- {
- static ext::string strMirandaPath;
+void utils::moveWindow(HWND hWnd, const RECT& rWnd)
+{
+ MoveWindow(hWnd, rWnd.left, rWnd.top, rWnd.right - rWnd.left, rWnd.bottom - rWnd.top, TRUE);
+}
- if (strMirandaPath.empty()) {
- wchar_t szPath[MAX_PATH] = { 0 };
+const ext::string& utils::getMirandaPath()
+{
+ static ext::string strMirandaPath;
- PathToAbsoluteW(L"x", szPath);
- strMirandaPath = extractPath(szPath);
- }
+ if (strMirandaPath.empty()) {
+ wchar_t szPath[MAX_PATH] = { 0 };
- return strMirandaPath;
+ PathToAbsoluteW(L"x", szPath);
+ strMirandaPath = extractPath(szPath);
}
- const ext::string& getProfilePath()
- {
- static ext::string strProfilePath;
+ return strMirandaPath;
+}
- if (strProfilePath.empty()) {
- wchar_t szPath[MAX_PATH] = { 0 };
+const ext::string& utils::getProfilePath()
+{
+ static ext::string strProfilePath;
- Profile_GetPathW(MAX_PATH, szPath);
- strProfilePath = szPath;
+ if (strProfilePath.empty()) {
+ wchar_t szPath[MAX_PATH] = { 0 };
- if (strProfilePath.empty() || strProfilePath[strProfilePath.length() - 1] != '\\')
- {
- strProfilePath += L"\\";
- }
- }
+ Profile_GetPathW(MAX_PATH, szPath);
+ strProfilePath = szPath;
- return strProfilePath;
+ if (strProfilePath.empty() || strProfilePath[strProfilePath.length() - 1] != '\\')
+ strProfilePath += L"\\";
}
- const ext::string& getProfileName()
- {
- static ext::string strProfileName;
-
- if (strProfileName.empty()) {
- wchar_t szName[MAX_PATH] = { 0 };
+ return strProfilePath;
+}
- Profile_GetNameW(MAX_PATH, szName);
- strProfileName = szName;
+const ext::string& utils::getProfileName()
+{
+ static ext::string strProfileName;
- ext::string::size_type posDot = strProfileName.rfind('.');
+ if (strProfileName.empty()) {
+ wchar_t szName[MAX_PATH] = { 0 };
- if (posDot != ext::string::npos && posDot != 0) {
- strProfileName.erase(posDot);
- }
- }
+ Profile_GetNameW(MAX_PATH, szName);
+ strProfileName = szName;
- return strProfileName;
+ size_t posDot = strProfileName.rfind('.');
+ if (posDot != ext::string::npos && posDot != 0)
+ strProfileName.erase(posDot);
}
-};
+
+ return strProfileName;
+}
/*
* OS
diff --git a/plugins/HistoryStats/src/version.h b/plugins/HistoryStats/src/version.h
index 1447812888..5ffab5f265 100644
--- a/plugins/HistoryStats/src/version.h
+++ b/plugins/HistoryStats/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 2
-#define __RELEASE_NUM 0
-#define __BUILD_NUM 4
+#define __RELEASE_NUM 1
+#define __BUILD_NUM 1
#include <stdver.h>