From 38517d7f3b0a1dd04ee111fa721d9f4ec4c3a104 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 22 Dec 2016 18:58:01 +0300 Subject: ughm --- plugins/HistoryStats/src/utils.cpp | 1415 ++++++++++++++++++------------------ 1 file changed, 703 insertions(+), 712 deletions(-) (limited to 'plugins/HistoryStats/src/utils.cpp') 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 #include -/* - * 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"&"); - replaceAllInPlace(text, L"\"", L"""); - replaceAllInPlace(text, L"<", L"<"); - replaceAllInPlace(text, L">", L">"); + 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"&"); + utils::replaceAllInPlace(text, L"\"", L"""); + utils::replaceAllInPlace(text, L"<", L"<"); + utils::replaceAllInPlace(text, L">", L">"); +} - 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 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 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(&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(&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(&rWnd) + 0); - ScreenToClient(hParent, reinterpret_cast(&rWnd) + 1); + GetWindowRect(hWnd, &rWnd); - return rWnd; - } + ScreenToClient(hParent, reinterpret_cast(&rWnd) + 0); + ScreenToClient(hParent, reinterpret_cast(&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 -- cgit v1.2.3