bool UserStatsLoader::Update(string const & userName) { { lock_guard<mutex> g(m_mutex); m_userName = userName; } auto const url = kUserStatsUrl + "&name=" + UrlEncode(userName); TRequest request(url); if (!request.RunHTTPRequest()) { LOG(LWARNING, ("Network error while connecting to", url)); return false; } if (request.error_code() != 200) { LOG(LWARNING, ("Server returned", request.error_code(), "for url", url)); return false; } auto const response = request.server_response(); pugi::xml_document document; if (!document.load_buffer(response.data(), response.size())) { LOG(LWARNING, ("Cannot parse server response:", response)); return false; } auto changesCount = document.select_node("mmwatch/edits/@value").attribute().as_int(-1); auto rank = document.select_node("mmwatch/rank/@value").attribute().as_int(-1); auto levelUpFeat = document.select_node("mmwatch/levelUpFeat/@value").attribute().as_string(); lock_guard<mutex> g(m_mutex); if (m_userName != userName) return false; m_lastUpdate = time(nullptr); m_userStats = UserStats(m_lastUpdate, rank, changesCount, levelUpFeat); SaveToSettings(); return true; }
int CPropPerf::DialogProc(HWND hwndDlg, UINT uMsg,WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_INITDIALOG: { if (!CDlgBase::DialogProc(hwndDlg, uMsg, wParam, lParam)) return FALSE; InitCombo(_hInst, _hwndDlg, IDC_CBO_PERF_OPTIMIZE, gaPerfCombo, sizeof(gaPerfCombo)/sizeof(ComboItem)); return LoadFromSettings(); break; } case WM_COMMAND: { if (HIWORD(wParam) == CBN_SELCHANGE) { int nSel = SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0); if (nSel < 0) break; for (int i=0; i<MAX_PERF_CHECK_BOXES; i++) { BOOL fCheck = (nSel == MAX_COMBO_ITEMS - 1) ? (HIWORD(gaPerfCombo[nSel].dwVal) & (1 << i) ) : (i < LOWORD(gaPerfCombo[nSel].dwVal) ); SendDlgItemMessage(_hwndDlg, gadwPerfChkBox[i], BM_SETCHECK, fCheck ? BST_CHECKED : BST_UNCHECKED, 0); } break; } if (HIWORD(wParam) == BN_CLICKED) { UpdatePerfComboBox(); break; } break; } case MSG_TSC_CONNECT: { SaveToSettings(); EnableControls(_hwndDlg, gadwDisableCtls, sizeof(gadwDisableCtls)/sizeof(gadwDisableCtls[0]), FALSE); return TRUE; } case MSG_TSC_DISCONNECTED: { EnableControls(_hwndDlg, gadwDisableCtls, sizeof(gadwDisableCtls)/sizeof(gadwDisableCtls[0]), TRUE); return TRUE; } case WM_DESTROY: { return SaveToSettings(); } default: break; } return CDlgBase::DialogProc(hwndDlg, uMsg, wParam, lParam); }