///////////////////////////////////////////////////////////////////////////// // // [OnGetContentInformation] // // IWMSCacheProxyServerCallback // ///////////////////////////////////////////////////////////////////////////// HRESULT STDMETHODCALLTYPE CProxyPlugin::OnGetContentInformation( long lHr, IWMSContext *pContentInfo, VARIANT varContext ) { HRESULT returnHr = (HRESULT) lHr; HRESULT hr = S_OK; COpState *pOpState = NULL; WMS_CACHE_QUERY_MISS_RESPONSE CacheMissPolicy = WMS_CACHE_QUERY_MISS_SKIP; IWMSDataContainerVersion *pContentVersion = NULL; CComBSTR bstrUrl; BOOL fDownload = FALSE; long lContentType = 0; DWORD dwCacheFlags; WCHAR szPort[ 20 ]; if( ( VT_UNKNOWN != V_VT( &varContext ) ) || ( NULL == V_UNKNOWN( &varContext ) ) ) { return( E_INVALIDARG ); } pOpState = ( COpState *) V_UNKNOWN( &varContext ); if( FAILED( returnHr ) ) { if( NS_E_CONNECTION_FAILURE == returnHr ) { // Do protocol rollover pOpState->m_dwProtocolIndex++; if( NULL == g_ProxyProtocols[ pOpState->m_dwProtocolIndex ] ) { // we have tried all the protocols and failed hr = E_NOINTERFACE; goto abort; } bstrUrl = g_ProxyProtocols[ pOpState->m_dwProtocolIndex ]; bstrUrl.Append( L"://" ); bstrUrl.Append( pOpState->m_bstrHost ); // if we we are using the same protocol requested by the client, then we should // also use the port specified by the client (if one was specified) if( ( 0 != pOpState->m_wPort ) && ( 0 == _wcsicmp( g_ProxyProtocols[ pOpState->m_dwProtocolIndex ], pOpState->m_bstrProtocol ) ) ) { bstrUrl.Append( L":" ); _itow_s( pOpState->m_wPort, szPort,sizeof(szPort)/sizeof(WCHAR), 10 ); bstrUrl.Append( szPort ); } bstrUrl.Append( L"/" ); bstrUrl.Append( pOpState->m_bstrPath ); hr = m_pICacheProxyServer->GetContentInformation( bstrUrl, pOpState->m_pPresentationContext, this, NULL, (IWMSCacheProxyServerCallback *) this, varContext ); if( FAILED( hr ) ) { goto abort; } return( S_OK ); } else if( E_ACCESSDENIED == returnHr ) { // the origin server requires authentication to provide information about this content. // since we don't have the credentials, we can either proxy this stream on-demand (in // which case the player will be prompted for the credentials) or simply fail this request. // let's opt for proxying the stream. CacheMissPolicy = WMS_CACHE_QUERY_MISS_PLAY_ON_DEMAND; } else { hr = returnHr; goto abort; } } else { hr = pContentInfo->GetLongValue( WMS_CACHE_CONTENT_INFORMATION_CONTENT_TYPE, WMS_CACHE_CONTENT_INFORMATION_CONTENT_TYPE_ID, (long *) &lContentType, 0 ); if( FAILED( hr ) ) { goto abort; } if( WMS_CACHE_CONTENT_TYPE_BROADCAST & lContentType ) { hr = pContentInfo->GetAndQueryIUnknownValue( WMS_CACHE_CONTENT_INFORMATION_DATA_CONTAINER_VERSION, WMS_CACHE_CONTENT_INFORMATION_DATA_CONTAINER_VERSION_ID, IID_IWMSDataContainerVersion, (IUnknown **) &pContentVersion, 0 ); if( ( FAILED( hr ) ) || ( NULL == pContentVersion ) ) { hr = FAILED( hr ) ? hr : E_UNEXPECTED; goto abort; } hr = pContentVersion->GetCacheFlags( (long *) &dwCacheFlags ); if( FAILED( hr ) ) { goto abort; } if( dwCacheFlags & WMS_DATA_CONTAINER_VERSION_ALLOW_STREAM_SPLITTING ) { CacheMissPolicy = WMS_CACHE_QUERY_MISS_PLAY_BROADCAST; } else { CacheMissPolicy = WMS_CACHE_QUERY_MISS_PLAY_ON_DEMAND; } } else // It is an on-demand publishing point { CacheMissPolicy = WMS_CACHE_QUERY_MISS_PLAY_ON_DEMAND; } } hr = S_OK; bstrUrl = g_ProxyProtocols[ pOpState->m_dwProtocolIndex ]; bstrUrl.Append( L"://" ); bstrUrl.Append( pOpState->m_bstrHost ); // if we we are using the same protocol requested by the client, then we should // also use the port specified by the client (if one was specified) if( ( 0 != pOpState->m_wPort ) && ( 0 == _wcsicmp( g_ProxyProtocols[ pOpState->m_dwProtocolIndex ], pOpState->m_bstrProtocol ) ) ) { bstrUrl.Append( L":" ); _itow_s( pOpState->m_wPort, szPort,sizeof(szPort)/sizeof(WCHAR), 10 ); bstrUrl.Append( szPort ); } bstrUrl.Append( L"/" ); bstrUrl.Append( pOpState->m_bstrPath ); abort: hr = pOpState->m_pCacheProxyCallback->OnQueryCacheMissPolicy( hr, CacheMissPolicy, bstrUrl, NULL, pContentInfo, pOpState->m_varContext ); if( FAILED( hr ) ) { hr = S_OK; } if( NULL != pOpState ) { pOpState->Release(); } if( NULL != pContentVersion ) { pContentVersion->Release(); } return( S_OK ); }
virtual void PostRender() override { IRenderer* pRenderer = GLOBAL::Engine()->Renderer(); eTRANSFORM_MODE mode = GLOBAL::SelectionMgr()->GetTransformMode(); int FPS = GLOBAL::Engine()->GlobalTimer()->GetFPS(); RENDER_TEXT_QUAD textFPS; _itow_s(FPS, textFPS.strMsg, 5, 10); textFPS.rc.left = 0; textFPS.rc.top = 0; textFPS.rc.right = 100; textFPS.rc.bottom = 100; textFPS.clr = CColor( 1.0f, 1.0f, 1.0f, 1.0f ); pRenderer->RenderText(&textFPS); pRenderer->RenderWorldGrid( XMMatrixIdentity(), 5000, 100 ); TYPE_SELECTED_ENTITIES* selcetedEntities = GLOBAL::SelectionMgr()->List(); for( UINT i=0; i< selcetedEntities->size() ; ++i) { IEntity* pEntity = (*selcetedEntities)[i]; // Draw transform helper CQuat rot; XMMATRIX tm = XMMatrixIdentity(); tm.r[3] = pEntity->GetWorldTM().r[3]; if( mode == TRANSFORM_MOVE) { pRenderer->RenderMover( tm ); } else if( mode == TRANSFORM_ROTATE) { pRenderer->RenderRotator( tm); } else if( mode == TRANSFORM_SCALE) { pRenderer->RenderScaler( tm ); } pRenderer->RenderAxis( pEntity->GetWorldTM() ); const CAABB* pWorldAABB = pEntity->GetWorldAABB(); // Draw Bounding Box if( pWorldAABB->IsValid() ) { pRenderer->RenderBox( XMMatrixIdentity(), pWorldAABB->GetMin(), pWorldAABB->GetMax() ,COLOR_GRAY ); const CAABB* pLocalEntityAABB = pEntity->GetLocalEntityAABB(); if( pLocalEntityAABB->IsValid() ) pRenderer->RenderBox( pEntity->GetWorldTM(), pLocalEntityAABB->GetMin(), pLocalEntityAABB->GetMax() ,COLOR_WHITE ); } // Draw skeleton if it has a actor IEntityProxyActor* pActor = (IEntityProxyActor*)pEntity->GetProxy(ENTITY_PROXY_ACTOR); if( pActor != NULL) { JOINT_ENTITY_LIST* pJointEntitesList = pActor->GetJointEntities(); CVertexPC buff[512]; int vertIndex = 0; for( UINT i=1; i < pJointEntitesList->size(); ++i) { buff[vertIndex].vPos = (*pJointEntitesList)[i]->GetWorldPos(); buff[vertIndex].color = COLOR_RED; vertIndex++; buff[vertIndex].vPos = (*pJointEntitesList)[i]->GetParent()->GetWorldPos(); buff[vertIndex].color = COLOR_RED; vertIndex++; } pRenderer->RenderLine( buff, vertIndex ); } } { /* const LIGHT_LIST* pLightList = GLOBAL::Engine()->LightMgr()->GetVisibleLights(); for( UINT i =0; i < pLightList->size(); ++i ) { CLightDesc* pLightDesc = (*pLightList)[i]; pRenderer->RenderSphere( &pLightDesc->pos, pLightDesc->range ); }*/ } }
void setIniInt(LPCTSTR lpKeyName, int nValue) { TCHAR value[128]; _itow_s(nValue,value,128,10); WritePrivateProfileString( _T("properties"), lpKeyName, value, getIniPath()); }
PLUGIN_EXPORT LPCWSTR GetString(void* data) { Measure* measure = (Measure*)data; ParentMeasure* parent = measure->parent; if (!parent) return nullptr; const Player* player = parent->player; static WCHAR buffer[32]; switch (measure->type) { case MEASURE_ARTIST: return player->GetArtist(); case MEASURE_TITLE: return player->GetTitle(); case MEASURE_ALBUM: return player->GetAlbum(); case MEASURE_LYRICS: return player->GetLyrics(); case MEASURE_COVER: return player->GetCoverPath(); case MEASURE_FILE: return player->GetFilePath(); case MEASURE_DURATION: SecondsToTime(player->GetDuration(), parent->disableLeadingZero, buffer); return buffer; case MEASURE_POSITION: SecondsToTime(player->GetPosition(), parent->disableLeadingZero, buffer); return buffer; case MEASURE_PROGRESS: _itow_s(player->GetDuration() ? ((player->GetPosition() * 100) / player->GetDuration()) : 0, buffer, 10); return buffer; case MEASURE_RATING: _itow_s(player->GetRating(), buffer, 10); return buffer; case MEASURE_VOLUME: _itow_s(player->GetVolume(), buffer, 10); return buffer; case MEASURE_STATE: _itow_s(player->GetState(), buffer, 10); return buffer; case MEASURE_STATUS: _itow_s((int)player->IsInitialized(), buffer, 10); return buffer; case MEASURE_SHUFFLE: _itow_s((int)player->GetShuffle(), buffer, 10); return buffer; case MEASURE_REPEAT: _itow_s((int)player->GetRepeat(), buffer, 10); return buffer; case MEASURE_NUMBER: _itow_s(player->GetNumber(), buffer, 10); return buffer; case MEASURE_YEAR: _itow_s(player->GetYear(), buffer, 10); return buffer; } return nullptr; }
void GUI::MenuDraw() { ///////////// //WATERMARK// ///////////// if(Cvars.misc_watermark==1) { gNeeded.DrawString2((HFont)6,55,5,255,255,255,255,L"h00k"); } if (IsKeyPressed(VK_INSERT)) { bActive = !bActive; } if (!bActive) return; int x = Cvars.menu_x; int y = Cvars.menu_y; int h = 16; int w = 130; gNeeded.FillRGBA(x,y,w,h,240,150,46,170); //TITLE BOX gNeeded.blackBorder(x,y,w,h); gNeeded.DrawString2((HFont)10,x + 15,y,255,255,255,255,L"h00k by johnny"); gNeeded.FillRGBA(x,y + h + 5,w,menuItems * 16,130,130,130,170); //MENU BOX gNeeded.blackBorder(x,y + h + 5,w,menuItems * 16); for(int i=0;i<menuItems;i++) { int vIn = (int)*menu[i].value; wchar_t vOut [12]; _itow_s(vIn,vOut,sizeof(vOut)/2,10); if( i!=menuIndex) { gNeeded.DrawString2((HFont)10,x + 3, y + (16*i) + 20, 60, 60, 60,255,menu[i].title); gNeeded.DrawString2((HFont)10,x + 100, y + (16*i) + 20, 60,60,60,255,vOut); } else { gNeeded.DrawString2((HFont)10,x + 3, y + (16*i) + 20, 255, 255, 255,255,menu[i].title); gNeeded.DrawString2((HFont)10,x + 100, y + (16*i) + 20, 255,255,255,255,vOut); } } if(IsKeyPressed(VK_UP)) //uparrow || mwheelup { if( menuIndex>0 ) menuIndex--; else menuIndex = menuItems - 1; } else if( IsKeyPressed(VK_DOWN)) //downarrow || mwheeldown { if( menuIndex<menuItems-1 ) menuIndex++; else menuIndex = 0; } else if( IsKeyPressed(VK_LEFT) ) //leftarrow || leftbutton { if( menu[menuIndex].value ) { menu[menuIndex].value[0] -= menu[menuIndex].step; if( menu[menuIndex].value[0] < menu[menuIndex].min ) menu[menuIndex].value[0] = menu[menuIndex].max; } } else if( IsKeyPressed(VK_RIGHT) ) //rightarrow || rightbutton { if( menu[menuIndex].value ) { menu[menuIndex].value[0] += menu[menuIndex].step; if( menu[menuIndex].value[0] > menu[menuIndex].max ) menu[menuIndex].value[0] = menu[menuIndex].min; } } }
void CBkInfoDownloadManager::MyBankUsbKeyDownload(LPUSBRECORD pUsbNode) // 下载USBKEY// LPSTR lpBankID, LPVOID lpVoid, int nSize { std::string strBankID = pUsbNode->fav; std::string strXml = pUsbNode->xml; std::string strVer = pUsbNode->ver; //检测银行控件是否已经安装 CBankData* pBankData = CBankData::GetInstance(); // 2者条件满足一个就进行安装 bool bAddBkCtrl = false; CBkInfoDownloadManager* pManager = CBkInfoDownloadManager::GetInstance (); bool bSetup = pManager->IsSetupAlready (pUsbNode->fav); bool bExist = pBankData->IsFavExist(strBankID); if ((!bSetup) || (!bExist)) { m_bAddBkCtrl = true; // 标记下载的银行控件是USBKEY触发的 CNotifyFavProgress::GetInstance()->AddFav(pUsbNode->fav);//调用js开始安装 bAddBkCtrl = true; } // 得到USBKEY保存的名字,VID+PID+MID std::wstring strSaveName; wchar_t wchTemp[20] = {0}; _itow_s (pUsbNode->vid, wchTemp, 19, 10); strSaveName += wchTemp; memset (wchTemp, 0, sizeof (wchTemp)); _itow_s (pUsbNode->pid, wchTemp, 19, 10); strSaveName += wchTemp; memset (wchTemp, 0, sizeof (wchTemp)); _itow_s (pUsbNode->mid, wchTemp, 19, 10); strSaveName += wchTemp; // 得到ID的下载控件对象指针 CDownloadManagerThread* pTempThread = FindBankCtrlDLManager((LPSTR)strBankID.c_str ()); if (NULL == pTempThread) { pTempThread = new CDownloadManagerThread (); // 创建一个管理对象 ::EnterCriticalSection(&m_cs); m_BankManager.insert (std::make_pair (strBankID.c_str (), pTempThread)); // 将新生成的加入到map ::LeaveCriticalSection (&m_cs); } std::wstring strXmlPath, strCtrlPath; if (m_wstrDLTempPath.empty ()) m_wstrDLTempPath = GetTempCachePath (); // 得到下载的临时路径 strXmlPath = m_wstrDLTempPath; strCtrlPath = m_wstrDLTempPath; strXmlPath += strSaveName; strXmlPath += L".xml"; strCtrlPath += strSaveName; strCtrlPath += L".exe"; //做base64编码 DWORD dwBufLen = strlen(strXml.c_str()) + 32; LPSTR lpszXmlInfo = new char[dwBufLen]; strcpy_s(lpszXmlInfo,dwBufLen,strXml.c_str()); int dwSize = strlen(lpszXmlInfo) * 2 + 1; unsigned char* pszOut = new unsigned char[dwSize]; base64_encode((LPBYTE)lpszXmlInfo, strlen(lpszXmlInfo), pszOut, &dwSize); pszOut[dwSize] = 0; strXml = "xml="; strXml += UrlEncode((char *)pszOut); // 从服务器端下载检验码和下载连接(采用阻塞方式下载,没有创建新的线程下载,因为要校验码) std::wstring downPath = CHostContainer::GetInstance()->GetHostName(kWeb); downPath += CA2W(MONEYHUB_USBKEY_URL); DOWN_LOAD_PARAM_NODE myNode; myNode.bCreateThread = false; myNode.strHWID = m_strHWID; myNode.strSendData = strXml; //myNode.dwPostDataLength = strXml.size (); myNode.strSaveFile = strXmlPath; myNode.strUrl = downPath; if (!pTempThread->CreateDownLoadTask (&myNode)) { CRecordProgram::GetInstance()->FeedbackError(MY_ERROR_PRO_CORE, ERR_DOWNLOAD_XML_USBKEY, L"MyBankUsbKeyDownload从服务器端下载XML文件失败!"); } // 检验验证码,并得到下载连接 std::string strNewCk; std::string strVersion; std::list<std::wstring> UrlList; if (!CheckUsbKeyXml(strXmlPath.c_str (), UrlList, strNewCk, strVersion)) { CRecordProgram::GetInstance()->FeedbackError(MY_ERROR_PRO_CORE, ERR_READ_XML_USBKEY, CRecordProgram::GetInstance()->GetRecordInfo(L"MyBankUsbKeyDownload解析%s数据失败!",strXmlPath.c_str ())); } bool bUpData = false; // 进行版本比较 int nVerComp = MyTwoVersionCompare (strVersion, strVer); // 表示要弹出版本要更新的提示 if (nVerComp > 0) bUpData = true; if(strVer == DEFAULT_INSTALL_VERSION) { bUpData = false; } // 检验该usb控件是否已经安装,没有安装就下载安装 bool bCheck = m_staticpICheckFile->CheckServerXmlFile (bUpData, *pUsbNode); if(bCheck == false) return; int nStatus = pUsbNode->status; // 用这个来判定是否安装 if (200 == nStatus) { // 如果银行控件已经收藏 if (bAddBkCtrl == false || bSetup == true || bUpData == false) { USBKeyInfo* pusb = CUSBHardWareDetector::GetInstance()->CheckUSBHardWare(pUsbNode->vid, pUsbNode->pid, pUsbNode->mid);//从内存文件中获得相关信息 if(!pusb) return; wstring msg; msg = pusb->hardware.goodsname + L"软件安装正常,可以使用"; mhShowMessage( GetActiveWindow(), msg.c_str()); return; } } // 更新USBKEY的版本 CBankData::GetInstance ()->UpdateUSB (pUsbNode->vid, pUsbNode->pid, pUsbNode->mid, strVersion); if (UrlList.size() <= 0) { CRecordProgram::GetInstance()->FeedbackError(MY_ERROR_PRO_CORE, ERR_DOWNLOAD_URL_NOFOUND_USBKEY, L"MyBankUsbKeyDownload没有检测到下载链接!"); } std::list<std::wstring>::iterator it; for (it = UrlList.begin (); it != UrlList.end (); it ++) // 创建下载任务 { DOWN_LOAD_PARAM_NODE myNode; myNode.bCreateThread = true; myNode.strHWID = m_strHWID; myNode.emKind = emUsbKey; // 下载USBKEY myNode.strSetupPath = m_wstrSetupPath; myNode.bSetupDlFile = true; myNode.strSaveFile = strCtrlPath; myNode.strUrl = (*it); // 初始化USBKEY特有的参数 myNode.dwUsbKeyParam.nMid = pUsbNode->mid; myNode.dwUsbKeyParam.nPid = pUsbNode->pid; myNode.dwUsbKeyParam.nVid = pUsbNode->vid; myNode.dwUsbKeyParam.strVersion = pUsbNode->ver; pTempThread->CreateDownLoadTask (&myNode); } }
void clsGame::QuitGame(int instance) { clsGame::GameFound[instance] = false; SendMessage(clsBot::hStatus[instance], WM_SETTEXT, NULL, (LPARAM)L"Quitting"); // Add 1 game to the game control wchar_t buffer[255] = {NULL}; SendMessage(clsBot::hGames[instance], WM_GETTEXT, 10, (LPARAM)buffer); _itow_s(_wtoi(buffer)+1, buffer, 10); SendMessage(clsBot::hGames[instance], WM_SETTEXT, NULL, (LPARAM)buffer); // Determine if game was a win or loss string test = clsMemory::ScreenChat(clsGame::Process[instance]); if (test != "") { SendMessage(clsBot::hWon[instance], WM_GETTEXT, 10, (LPARAM)buffer); _itow_s(_wtoi(buffer)+1, buffer, 10); SendMessage(clsBot::hWon[instance], WM_SETTEXT, NULL, (LPARAM)buffer); } else { SendMessage(clsBot::hLoss[instance], WM_GETTEXT, 10, (LPARAM)buffer); _itow_s(_wtoi(buffer)+1, buffer, 10); SendMessage(clsBot::hLoss[instance], WM_SETTEXT, NULL, (LPARAM)buffer); } wchar_t surrender[255] = {NULL}; SendMessage(clsBot::hSurrender, WM_GETTEXT, 255, (LPARAM)surrender); wchar_t scorescreen[255] = {NULL}; SendMessage(clsBot::hScoreScreen, WM_GETTEXT, 255, (LPARAM)scorescreen); if (surrender[0] >= 'a' && surrender[0] <= 'z') { surrender[0] += 'A' - 'a'; } if (scorescreen[0] >= 'a' && scorescreen[0] <= 'z') { scorescreen[0] += 'A' - 'a'; } do { PostMessage(clsGame::Handle[instance], WM_SYSKEYDOWN, VK_F10, 4456449); PostMessage(clsGame::Handle[instance], WM_SYSKEYUP, VK_F10, -1069285375); PostMessage(clsGame::Handle[instance], WM_KEYDOWN, surrender[0], 3211265); PostMessage(clsGame::Handle[instance], WM_CHAR, (WPARAM)surrender[0], 3211265); PostMessage(clsGame::Handle[instance], WM_KEYUP, surrender[0], -1070530559); PostMessage(clsGame::Handle[instance], WM_KEYDOWN, scorescreen[0], 2031617); PostMessage(clsGame::Handle[instance], WM_CHAR, (WPARAM)scorescreen[0], 2031617); PostMessage(clsGame::Handle[instance], WM_KEYUP, scorescreen[0], -1071710207); Sleep(100); } while (clsMemory::MapName(clsGame::Process[instance]) != ""); // Check if game limit has been reached wchar_t gameLimit[255] = {NULL}; SendMessage(clsBot::hGameLimit[instance], WM_GETTEXT, 255, (LPARAM)gameLimit); if (wstring(gameLimit) != L"0") { wchar_t gameTotal[255] = {NULL}; SendMessage(clsBot::hGames[instance], WM_GETTEXT, 255, (LPARAM)gameTotal); if (_wtoi(gameTotal) >= _wtoi(gameLimit)) { SendMessage(clsBot::hStatus[instance], WM_SETTEXT, NULL, (LPARAM)L"Limit Reached"); clsGame::PID[instance] = NULL; } } }
// // Draw overlay // PLUGIN_EXPORT void PluginUpdateOverlay() { if (!pRenderHelper) return; // lock overlay image auto pLock = pRenderHelper->BeginFrame(); if (!pLock) return; int w = pLock->dwWidth; int h = pLock->dwHeight; Gdiplus::Graphics *pGraphics = pRenderHelper->GetGraphics(); //----------------------------------------- // draw Text Overlay // set options pGraphics->SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias); // clear back pGraphics->Clear(Gdiplus::Color(0, 0, 0, 0)); WCHAR s[128]; _itow_s(PC_GetConfirmedProcessID(), s, 10); if (PathFileExists(pFileName)) { string textContents = ""; WIN32_FILE_ATTRIBUTE_DATA attribs; GetFileAttributesExW(pFileName, GetFileExInfoStandard, &attribs); FILETIME modifyTime = attribs.ftLastWriteTime; if (CompareFileTime(&modifyTime, &oldModifyTime) > 0) { oldModifyTime = modifyTime; string line; ifstream myfile; myfile.open(pFileName); if (myfile.is_open()) { while (getline(myfile, line)) { textContents += line; } myfile.close(); } textLength = textContents.length(); wcTextContents[textLength] = 0; std::copy(textContents.begin(), textContents.end(), wcTextContents); } } // draw back if required if (bShowBackground) { Gdiplus::RectF bound; pRenderHelper->GetTextExtent(wcTextContents, pFont, &bound); pGraphics->FillRectangle(pBackBrush, bound); } // draw text Gdiplus::RectF bound; pRenderHelper->GetTextExtent(wcTextContents, pFont, &bound); if (bound.Width > w) { wchar_t wcNewTextContents[256]; wcNewTextContents[textLength * 2 + 5] = 0; swprintf_s(wcNewTextContents, L"%s %s", wcTextContents, wcTextContents); Gdiplus::RectF newbound; pRenderHelper->GetTextExtent(wcNewTextContents, pFont, &newbound); pRenderHelper->DrawString(wcNewTextContents, pFont, Gdiplus::Point(0 - scroll, 0), pTextBrush, pBackBrush); scroll += 2; if (scroll > newbound.Width - bound.Width) scroll = 0; } else { pRenderHelper->DrawString(wcTextContents, pFont, Gdiplus::Point(0, 0), pTextBrush, pBackBrush); } // fill overlay image pRenderHelper->EndFrame(); }
int __cdecl main(int argc, char **argv) { wchar_t result[20]; wchar_t *pResult = NULL; char *PrintResult = NULL; /* Use with convertC so we can */ char *PrintCorrectResult = NULL; /* print out the results */ int i = 0; WCHAR case1[] = {'5','0','\0'}; WCHAR case2[] = {'5','5','5','\0'}; WCHAR case3[] = {'1','0','1','0','\0'}; WCHAR case4[] = {'2','2','\0'}; WCHAR case5[] = {'a','\0'}; WCHAR case6[] = {'c','g','\0'}; /* Correct Result, Value to Convert, Radix to use */ struct testCase testCases[] = { {case1, 50, 10}, {case2,555,10}, {case3,10,2}, {case4,10,4}, {case5,10,16}, {case6,400,32} }; /* * Initialize the PAL and return FAIL if this fails */ if (0 != (PAL_Initialize(argc, argv))) { return FAIL; } /* Loop through each case. Convert the ints to strings. Check to ensure they were converted properly. */ for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) { errno_t err = _itow_s(testCases[i].value, result, sizeof(result) / sizeof(result[0]), testCases[i].radix); if(err != 0) { Fail("ERROR: _itow_s didn't return success, error code %d.\n", err); } if (0 != wcscmp(testCases[i].CorrectResult, result)) { PrintResult = convertC(pResult); PrintCorrectResult = convertC(testCases[i].CorrectResult); Fail("ERROR: _itow_s was called on %i, returning the string %s " "when it should have returned the string %s.\n" , testCases[i].value, PrintResult, PrintCorrectResult); } } PAL_Terminate(); return PASS; }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static uint32_t lanLastPing = 0; static HFONT _hFont = 0; switch (message) { case WM_CREATE: { HFONT hFont = 0; NONCLIENTMETRICS ncm = { sizeof(ncm) }; if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0)) { hFont = CreateFontIndirect(&ncm.lfMessageFont); _hFont = hFont; } if (!hFont) hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); RECT rcClient; GetClientRect(hWnd, &rcClient); g_hWndListViewServers = CreateWindow(WC_LISTVIEW, nullptr, WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_AUTOARRANGE | LVS_OWNERDATA, 1, 21, rcClient.right - UI_PLAYERLIST_WIDTH - 4, rcClient.bottom - UI_SERVERINFO_HEIGHT - 21 - 2, hWnd, nullptr, g_hInst, nullptr); if (g_hWndListViewServers) { SetWindowTheme(g_hWndListViewServers, L"Explorer", nullptr); ListView_SetExtendedListViewStyle(g_hWndListViewServers, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER); LVCOLUMN lvc; lvc.mask = LVCF_WIDTH; lvc.cx = 30; ListView_InsertColumn(g_hWndListViewServers, 0, &lvc); lvc.mask = LVCF_WIDTH | LVCF_TEXT; lvc.cx = 240; lvc.pszText = LoadStr(L"Server Name", IDS_SERVERNAME); ListView_InsertColumn(g_hWndListViewServers, 1, &lvc); lvc.cx = 60; lvc.pszText = LoadStr(L"Ping", IDS_PING); ListView_InsertColumn(g_hWndListViewServers, 2, &lvc); lvc.cx = 80; lvc.pszText = LoadStr(L"Players", IDS_PLAYERS); ListView_InsertColumn(g_hWndListViewServers, 3, &lvc); lvc.cx = 70; lvc.pszText = LoadStr(L"Version", IDS_VERSION); ListView_InsertColumn(g_hWndListViewServers, 4, &lvc); lvc.cx = 120; lvc.pszText = LoadStr(L"Gamemode", IDS_GAMEMODE); ListView_InsertColumn(g_hWndListViewServers, 5, &lvc); lvc.cx = 100; lvc.pszText = LoadStr(L"Map Name", IDS_MAPNAME); ListView_InsertColumn(g_hWndListViewServers, 6, &lvc); } g_hWndListViewHistory = CreateWindow(WC_LISTVIEW, nullptr, WS_CHILD | WS_CLIPSIBLINGS | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_AUTOARRANGE | LVS_OWNERDATA, 1, 21, rcClient.right - UI_PLAYERLIST_WIDTH - 4, rcClient.bottom - UI_SERVERINFO_HEIGHT - 21 - 2, hWnd, nullptr, g_hInst, nullptr); if (g_hWndListViewHistory) { SetWindowTheme(g_hWndListViewHistory, L"Explorer", nullptr); ListView_SetExtendedListViewStyle(g_hWndListViewHistory, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER); LVCOLUMN lvc; lvc.mask = LVCF_WIDTH; lvc.cx = 30; ListView_InsertColumn(g_hWndListViewHistory, 0, &lvc); lvc.mask = LVCF_WIDTH | LVCF_TEXT; lvc.cx = 220; lvc.pszText = LoadStr(L"Server Name", IDS_SERVERNAME); ListView_InsertColumn(g_hWndListViewHistory, 1, &lvc); lvc.cx = 60; lvc.pszText = LoadStr(L"Ping", IDS_PING); ListView_InsertColumn(g_hWndListViewHistory, 2, &lvc); lvc.cx = 80; lvc.pszText = LoadStr(L"Players", IDS_PLAYERS); ListView_InsertColumn(g_hWndListViewHistory, 3, &lvc); lvc.cx = 70; lvc.pszText = LoadStr(L"Version", IDS_VERSION); ListView_InsertColumn(g_hWndListViewHistory, 4, &lvc); lvc.cx = 100; lvc.pszText = LoadStr(L"Gamemode", IDS_GAMEMODE); ListView_InsertColumn(g_hWndListViewHistory, 5, &lvc); lvc.cx = 160; lvc.pszText = LoadStr(L"Last Played", IDS_LASTPLAYED); ListView_InsertColumn(g_hWndListViewHistory, 6, &lvc); } g_hWndTab = CreateWindow(WC_TABCONTROL, nullptr, WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, 0, 0, rcClient.right - UI_PLAYERLIST_WIDTH, rcClient.bottom - UI_SERVERINFO_HEIGHT, hWnd, nullptr, g_hInst, nullptr); if (g_hWndTab) { SetWindowFont(g_hWndTab, hFont, FALSE); HIMAGELIST hTabIml = ImageList_Create(16, 16, ILC_COLOR32, 0, 0); if (hTabIml) { for (int i = IDI_FAVORITE; i <= IDI_HISTORY; ++i) ImageList_AddIcon(hTabIml, LoadIcon(g_hInst, MAKEINTRESOURCE(i))); TabCtrl_SetImageList(g_hWndTab, hTabIml); } TCITEM tie; tie.mask = TCIF_TEXT | TCIF_IMAGE; tie.iImage = 0; tie.pszText = LoadStr(L"Favorites", IDS_FAVORITES); TabCtrl_InsertItem(g_hWndTab, 0, &tie); tie.iImage = 1; tie.pszText = LoadStr(L"Internet", IDS_INTERNET); TabCtrl_InsertItem(g_hWndTab, 1, &tie); tie.iImage = 1; tie.pszText = LoadStr(L"Official", IDS_OFFICIAL); TabCtrl_InsertItem(g_hWndTab, 2, &tie); tie.iImage = 2; tie.pszText = LoadStr(L"Lan", IDS_LAN); TabCtrl_InsertItem(g_hWndTab, 3, &tie); tie.iImage = 3; tie.pszText = LoadStr(L"History", IDS_HISTORY); TabCtrl_InsertItem(g_hWndTab, 4, &tie); } g_hWndListViewPlayers = CreateWindowEx(0, WC_LISTVIEW, nullptr, WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_NOCOLUMNHEADER | LVS_SINGLESEL | LVS_OWNERDATA, rcClient.right - UI_PLAYERLIST_WIDTH + 1, 18, UI_PLAYERLIST_WIDTH - 2, rcClient.bottom - UI_SERVERINFO_HEIGHT - 18 - 2, hWnd, nullptr, g_hInst, nullptr); if (g_hWndListViewPlayers) { SetWindowTheme(g_hWndListViewPlayers, L"Explorer", nullptr); ListView_SetExtendedListViewStyle(g_hWndListViewPlayers, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER); LVCOLUMN lvc; lvc.mask = LVCF_WIDTH; lvc.cx = UI_PLAYERLIST_WIDTH - 2; ListView_InsertColumn(g_hWndListViewPlayers, 0, &lvc); } g_hWndGroupBox1 = CreateWindow(WC_BUTTON, LoadStr(L"Players", IDS_PLAYERSLIST), WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | BS_GROUPBOX, rcClient.right - UI_PLAYERLIST_WIDTH, 0, UI_PLAYERLIST_WIDTH, rcClient.bottom - UI_SERVERINFO_HEIGHT, hWnd, nullptr, g_hInst, nullptr); if (g_hWndGroupBox1) { SetWindowFont(g_hWndGroupBox1, hFont, FALSE); } g_hWndGroupBox2 = CreateWindow(WC_BUTTON, LoadStr(L"Server Info", IDS_SERVERINFO), WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | BS_GROUPBOX, 0, rcClient.bottom - UI_SERVERINFO_HEIGHT, rcClient.right, 118, hWnd, nullptr, g_hInst, nullptr); if (g_hWndGroupBox2) { SetWindowFont(g_hWndGroupBox2, hFont, FALSE); int y = 18; #define LINE_GAP 20 HWND hStatic = CreateWindow(WC_STATIC, LoadStr(L"Server Name:", IDS_SERVERNAME_), WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, 10, y, 100, 16, g_hWndGroupBox2, nullptr, g_hInst, nullptr); if (hStatic) SetWindowFont(hStatic, hFont, FALSE); HWND hEdit = CreateWindow(WC_EDIT, nullptr, WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | ES_READONLY, 112, y, 300, 16, g_hWndGroupBox2, (HMENU)1001, g_hInst, nullptr); if (hEdit) SetWindowFont(hEdit, hFont, FALSE); y += LINE_GAP; hStatic = CreateWindow(WC_STATIC, LoadStr(L"Server IP:", IDS_SERVERIP), WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, 10, y, 100, 16, g_hWndGroupBox2, nullptr, g_hInst, nullptr); if (hStatic) SetWindowFont(hStatic, hFont, FALSE); hEdit = CreateWindow(WC_EDIT, nullptr, WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | ES_READONLY, 112, y, 300, 16, g_hWndGroupBox2, (HMENU)1002, g_hInst, nullptr); if (hEdit) SetWindowFont(hEdit, hFont, FALSE); y += LINE_GAP; hStatic = CreateWindow(WC_STATIC, LoadStr(L"Server Players:", IDS_SERVERPLAYERS), WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, 10, y, 100, 16, g_hWndGroupBox2, nullptr, g_hInst, nullptr); if (hStatic) SetWindowFont(hStatic, hFont, FALSE); hEdit = CreateWindow(WC_EDIT, nullptr, WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | ES_READONLY, 112, y, 300, 16, g_hWndGroupBox2, (HMENU)1003, g_hInst, nullptr); if (hEdit) SetWindowFont(hEdit, hFont, FALSE); y += LINE_GAP; hStatic = CreateWindow(WC_STATIC, LoadStr(L"Server Ping:", IDS_SERVERPING), WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, 10, y, 100, 16, g_hWndGroupBox2, nullptr, g_hInst, nullptr); if (hStatic) SetWindowFont(hStatic, hFont, FALSE); hEdit = CreateWindow(WC_EDIT, nullptr, WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | ES_READONLY, 112, y, 300, 16, g_hWndGroupBox2, (HMENU)1004, g_hInst, nullptr); if (hEdit) SetWindowFont(hEdit, hFont, FALSE); y += LINE_GAP; hStatic = CreateWindow(WC_STATIC, LoadStr(L"Server Gamemode:", IDS_SERVERGAMEMODE), WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, 10, y, 100, 16, g_hWndGroupBox2, nullptr, g_hInst, nullptr); if (hStatic) SetWindowFont(hStatic, hFont, FALSE); hEdit = CreateWindow(WC_EDIT, nullptr, WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | ES_READONLY, 112, y, 300, 16, g_hWndGroupBox2, (HMENU)1005, g_hInst, nullptr); if (hEdit) SetWindowFont(hEdit, hFont, FALSE); } g_hWndStatusBar = CreateWindow(STATUSCLASSNAME, nullptr, WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0, hWnd, nullptr, g_hInst, nullptr); do { g_UDPSocket = socket(AF_INET, SOCK_DGRAM, 0); if (g_UDPSocket == INVALID_SOCKET) break; uint32_t timeout = 2000; setsockopt(g_UDPSocket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)); struct sockaddr_in bindaddr = { AF_INET }; if (bind(g_UDPSocket, (sockaddr *)&bindaddr, 16) != NO_ERROR) { closesocket(g_UDPSocket); break; } if (WSAAsyncSelect(g_UDPSocket, hWnd, WM_SOCKET, FD_READ) == SOCKET_ERROR) { closesocket(g_UDPSocket); break; } return 0; } while (0); } break; case WM_COMMAND: { int wmId = LOWORD(wParam); switch (wmId) { case IDM_TOOLS_SETTINGS: ShowSettings(); break; case IDM_ABOUT: DialogBox(g_hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } } break; case WM_NOTIFY: { switch (((LPNMHDR)lParam)->code) { case TCN_SELCHANGE: { g_currentTab = TabCtrl_GetCurSel(((LPNMHDR)lParam)->hwndFrom); switch (g_currentTab) { case 0: // Favorites case 1: // Internet case 2: // Official case 3: // Lan ListView_DeleteAllItems(g_hWndListViewServers); ListView_DeleteAllItems(g_hWndListViewPlayers); g_serversList.clear(); ShowWindow(g_hWndListViewServers, SW_SHOW); ShowWindow(g_hWndListViewHistory, SW_HIDE); UpdateWindow(g_hWndListViewServers); if (g_currentTab == 1 || g_currentTab == 2) { HWND hDialog = CreateDialog(g_hInst, MAKEINTRESOURCEW(IDD_LOADING), hWnd, nullptr); SetWindowPos(hDialog, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); UpdateWindow(hDialog); if (g_serversMasterList) { delete g_serversMasterList; g_serversMasterList = nullptr; } std::string data; data.reserve(2048); const char *url; if (g_currentTab == 1) url = (g_browserSettings.masterlistURL + "/servers").c_str(); else url = (g_browserSettings.masterlistURL + "/official").c_str(); CURLcode curlRet = CurlRequset(url, data, "VCMP/0.4"); if (curlRet == CURLE_OK) { serverMasterList serversList; if (ParseJson(data.data(), serversList)) { for (auto it = serversList.begin(); it != serversList.end(); ++it) { SendQuery(it->address, 'i'); it->lastPing = GetTickCount(); } g_serversMasterList = new serverMasterList(serversList); } else { MessageBox(hWnd, LoadStr(L"Can't parse master list data.", IDS_MASTERLISTDATA), LoadStr(L"Error", IDS_ERROR), MB_ICONWARNING); } } else { wchar_t message[512]; swprintf_s(message, LoadStr(L"Can't get information from master list.\n%hs", IDS_MASTERLISTFAILED), curl_easy_strerror(curlRet)); MessageBox(hWnd, message, LoadStr(L"Error", IDS_ERROR), MB_ICONWARNING); } DestroyWindow(hDialog); } else if (g_currentTab == 3) { BOOL broadcast = TRUE; setsockopt(g_UDPSocket, SOL_SOCKET, SO_BROADCAST, (char *)&broadcast, sizeof(broadcast)); for (uint16_t port = 8000; port <= 8200; ++port) { serverAddress address = { INADDR_BROADCAST, port }; SendQuery(address, 'i'); } broadcast = FALSE; setsockopt(g_UDPSocket, SOL_SOCKET, SO_BROADCAST, (char *)&broadcast, sizeof(broadcast)); lanLastPing = GetTickCount(); } break; case 4: // History ShowWindow(g_hWndListViewHistory, SW_SHOW); ShowWindow(g_hWndListViewServers, SW_HIDE); break; } } break; case LVN_GETDISPINFO: { LPNMLVDISPINFOW di = (LPNMLVDISPINFOW)lParam; if (di->hdr.hwndFrom == g_hWndListViewServers) { size_t i = di->item.iItem; if (g_serversList.size() > i) { if (di->item.iSubItem == 0 && di->item.mask & LVIF_IMAGE) di->item.iImage = 0; if (di->item.mask & LVIF_TEXT) { switch (di->item.iSubItem) { case 0: // Icon break; case 1: // Server Name if (di->item.cchTextMax > 0 && di->item.pszText) { MultiByteToWideChar(CP_ACP, 0, g_serversList[i].info.serverName.c_str(), -1, di->item.pszText, di->item.cchTextMax); } break; case 2: // Ping { uint32_t ping = g_serversList[i].lastRecv - g_serversList[i].lastPing[1]; _itow_s(ping, di->item.pszText, di->item.cchTextMax, 10); } break; case 3: // Players swprintf_s(di->item.pszText, di->item.cchTextMax, L"%hu/%hu", g_serversList[i].info.players, g_serversList[i].info.maxPlayers); break; case 4: // Version { MultiByteToWideChar(CP_ACP, 0, g_serversList[i].info.versionName, -1, di->item.pszText, di->item.cchTextMax); } break; case 5: // Gamemode { MultiByteToWideChar(CP_ACP, 0, g_serversList[i].info.gameMode.c_str(), -1, di->item.pszText, di->item.cchTextMax); } break; case 6: // Map name { MultiByteToWideChar(CP_ACP, 0, g_serversList[i].info.mapName.c_str(), -1, di->item.pszText, di->item.cchTextMax); } break; } } } } else if (di->hdr.hwndFrom == g_hWndListViewHistory) // FIXME { } else if (di->hdr.hwndFrom == g_hWndListViewPlayers) { size_t i = ListView_GetSelectionMark(g_hWndListViewServers); if (g_serversList.size() > i) { serverPlayers &players = g_serversList[i].players; size_t j = di->item.iItem; if (players.size() > j) { if (di->item.mask & LVIF_TEXT) { MultiByteToWideChar(CP_ACP, 0, players[j].name, -1, di->item.pszText, di->item.cchTextMax); } } } } } break; case NM_CUSTOMDRAW: { LPNMLVCUSTOMDRAW nmcd = (LPNMLVCUSTOMDRAW)lParam; if (nmcd->nmcd.hdr.hwndFrom == g_hWndListViewServers) { switch (nmcd->nmcd.dwDrawStage) { case CDDS_PREPAINT: return CDRF_NOTIFYITEMDRAW; case CDDS_ITEMPREPAINT: { COLORREF crText; size_t i = nmcd->nmcd.dwItemSpec; if (g_serversList.size() > i && g_serversList[i].isOfficial) crText = g_browserSettings.officialColor; else crText = 0; nmcd->clrText = crText; return CDRF_DODEFAULT; } } } } break; case LVN_ITEMCHANGED: { LPNMITEMACTIVATE nmitem = (LPNMITEMACTIVATE)lParam; if (nmitem->hdr.hwndFrom == g_hWndListViewServers) { size_t i = nmitem->iItem; if (i != -1 && g_serversList.size() > i) { if (g_serversList[i].info.players == 0) ListView_DeleteAllItems(g_hWndListViewPlayers); std::wstring wstr; ConvertCharset(g_serversList[i].info.serverName.c_str(), wstr); SetDlgItemText(g_hWndGroupBox2, 1001, wstr.c_str()); // Server Name wchar_t ipstr[22]; char *ip = (char *)&(g_serversList[i].address.ip); swprintf_s(ipstr, L"%hhu.%hhu.%hhu.%hhu:%hu", ip[0], ip[1], ip[2], ip[3], g_serversList[i].address.port); SetDlgItemText(g_hWndGroupBox2, 1002, ipstr); // Server IP wchar_t playersstr[12]; swprintf_s(playersstr, L"%hu/%hu", g_serversList[i].info.players, g_serversList[i].info.maxPlayers); SetDlgItemText(g_hWndGroupBox2, 1003, playersstr); // Server Players wchar_t pingsstr[12]; uint32_t ping = g_serversList[i].lastRecv - g_serversList[i].lastPing[1]; _itow_s(ping, pingsstr, 10); SetDlgItemText(g_hWndGroupBox2, 1004, pingsstr); // Server Ping ConvertCharset(g_serversList[i].info.gameMode.c_str(), wstr); SetDlgItemText(g_hWndGroupBox2, 1005, wstr.c_str()); // Server Gamemode SendQuery(g_serversList[i].address, 'i'); SendQuery(g_serversList[i].address, 'c'); g_serversList[i].lastPing[0] = GetTickCount(); } else { ListView_DeleteAllItems(g_hWndListViewPlayers); for (int i = 1001; i <= 1005; ++i) SetDlgItemText(g_hWndGroupBox2, i, nullptr); } } } break; case LVN_ITEMACTIVATE: { LPNMITEMACTIVATE nmia = (LPNMITEMACTIVATE)lParam; if (nmia->hdr.hwndFrom == g_hWndListViewServers) { size_t i = nmia->iItem; if (i != -1 && g_serversList.size() > i) { char ipstr[16]; char *ip = (char *)&(g_serversList[i].address.ip); snprintf(ipstr, sizeof(ipstr), "%hhu.%hhu.%hhu.%hhu", ip[0], ip[1], ip[2], ip[3]); char vcmpDll[MAX_PATH]; snprintf(vcmpDll, sizeof(vcmpDll), "%ls%s\\vcmp-game.dll", g_exePath, g_serversList[i].info.versionName); LaunchVCMP(ipstr, g_serversList[i].address.port, g_browserSettings.playerName, nullptr, g_browserSettings.gamePath, vcmpDll); } } } break; } } break; case WM_SIZE: { int clientWidth = GET_X_LPARAM(lParam), clientHeight = GET_Y_LPARAM(lParam); SetWindowPos(g_hWndTab, 0, 0, 0, clientWidth - UI_PLAYERLIST_WIDTH, clientHeight - UI_SERVERINFO_HEIGHT, SWP_NOZORDER); SetWindowPos(g_hWndListViewServers, 0, 1, 21, clientWidth - UI_PLAYERLIST_WIDTH - 4, clientHeight - UI_SERVERINFO_HEIGHT - 21 - 2, SWP_NOZORDER); SetWindowPos(g_hWndListViewHistory, 0, 1, 21, clientWidth - UI_PLAYERLIST_WIDTH - 4, clientHeight - UI_SERVERINFO_HEIGHT - 21 - 2, SWP_NOZORDER); SetWindowPos(g_hWndGroupBox1, 0, clientWidth - UI_PLAYERLIST_WIDTH, 0, UI_PLAYERLIST_WIDTH, clientHeight - UI_SERVERINFO_HEIGHT, SWP_NOZORDER); SetWindowPos(g_hWndListViewPlayers, 0, clientWidth - UI_PLAYERLIST_WIDTH + 1, 18, UI_PLAYERLIST_WIDTH - 2, clientHeight - UI_SERVERINFO_HEIGHT - 18 - 2, SWP_NOZORDER); SetWindowPos(g_hWndGroupBox2, 0, 0, clientHeight - UI_SERVERINFO_HEIGHT, clientWidth, 118, SWP_NOZORDER); SendMessage(g_hWndStatusBar, WM_SIZE, 0, 0); } break; case WM_GETMINMAXINFO: ((LPMINMAXINFO)lParam)->ptMinTrackSize = { 750, 500 }; break; case WM_DESTROY: if (_hFont) DeleteObject(_hFont); PostQuitMessage(0); break; case WM_SOCKET: { if (WSAGETSELECTEVENT(lParam) == FD_READ) { char *recvBuf = (char *)calloc(1024, sizeof(char)); if (recvBuf) { struct sockaddr_in recvAddr; int addrLen = sizeof(recvAddr); int recvLen = recvfrom(g_UDPSocket, recvBuf, 1024, 0, (sockaddr *)&recvAddr, &addrLen); if (recvLen != -1 && recvLen >= 11) { if (recvLen > 1024) recvLen = 1024; if (*(int *)recvBuf == 0x3430504D) // MP04 { char opcode = recvBuf[10]; if (opcode == 'i' || opcode == 'c') { uint32_t ip = recvAddr.sin_addr.s_addr; uint16_t port = ntohs(recvAddr.sin_port); bool found = false; serverMasterListInfo masterInfo; if (g_currentTab == 1 || g_currentTab == 2) { for (auto it = g_serversMasterList->begin(); it != g_serversMasterList->end(); ++it) { if (it->address.ip == ip && it->address.port == port) { found = true; masterInfo = *it; break; } } } else if (g_currentTab == 3) // Lan { found = true; masterInfo.address = { ip, port }; masterInfo.isOfficial = false; masterInfo.lastPing = lanLastPing; } if (found) { switch (opcode) { case 'i': { serverInfo info; if (GetServerInfo(recvBuf, recvLen, info)) { bool inList = false; for (auto it = g_serversList.begin(); it != g_serversList.end(); ++it) { if (it->address.ip == ip && it->address.port == port) { inList = true; it->lastRecv = GetTickCount(); it->lastPing[1] = it->lastPing[0]; it->info = info; auto i = it - g_serversList.begin(); ListView_Update(g_hWndListViewServers, i); break; } } if (!inList) { serverAllInfo allInfo; allInfo.address = masterInfo.address; allInfo.info = info; allInfo.isOfficial = masterInfo.isOfficial; allInfo.lastPing[0] = masterInfo.lastPing; allInfo.lastPing[1] = masterInfo.lastPing; allInfo.lastRecv = GetTickCount(); g_serversList.push_back(allInfo); LVITEM lvi = { 0 }; ListView_InsertItem(g_hWndListViewServers, &lvi); } } } break; case 'c': { serverPlayers players; if (GetServerPlayers(recvBuf, recvLen, players)) { for (auto it = g_serversList.begin(); it != g_serversList.end(); ++it) { if (it->address.ip == ip && it->address.port == port) { it->lastRecv = GetTickCount(); it->lastPing[1] = it->lastPing[0]; it->players = players; auto i = it - g_serversList.begin(); ListView_SetItemCount(g_hWndListViewPlayers, players.size()); break; } } } } break; } } } } } free(recvBuf); } } } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
//add Id array to a document fragment node HRESULT AddIdsNode( IXMLDOMDocument* pDOM, BSTR indentBstr, const wchar_t* wszIdsNodeName, const wchar_t* wszIdsNodeAttribute, const wchar_t* wszIdNode, const std::vector<int>& ids, IXMLDOMDocumentFragment* pdf // Release is completed outside ) { VARIANT var; BSTR bstr = NULL; BSTR bstr_wst = SysAllocString(L"\t"); IXMLDOMElement* pe = NULL; IXMLDOMDocumentFragment* pdfSub = NULL; IXMLDOMAttribute *pa = NULL; IXMLDOMAttribute *pa1 = NULL; HRESULT hr = S_OK; do { //create a Node to hold ids. bstr = SysAllocString(wszIdsNodeName); HR_SUCCESSCALL( pDOM->createElement(bstr, &pe), hr ); SAFE_BSTR_RELEASE(bstr); //create a attribute for the <wszIdsNodeName> element, and //assign the element num as the attribute value. //get ids num string size_t idsNum = ids.size(); const int radix = 10; const size_t sizeOfstr = 30; wchar_t wszIdsNumString[sizeOfstr] = {0}; _ultow_s(static_cast<unsigned long>(idsNum), wszIdsNumString, sizeOfstr, radix); //put num string into attribute bstr = SysAllocString(wszIdsNodeAttribute); VariantInit(&var); V_BSTR(&var) = SysAllocString(wszIdsNumString); V_VT(&var) = VT_BSTR; HR_SUCCESSCALL( pDOM->createAttribute(bstr, &pa), hr ); HR_SUCCESSCALL( pa->put_value(var), hr ); HR_SUCCESSCALL( pe->setAttributeNode(pa, &pa1), hr ); //create a document fragment to hold ids sub-elements. HR_SUCCESSCALL( pDOM->createDocumentFragment(&pdfSub), hr ); //add ids to pdfSub for( size_t i=0; i < idsNum; ++i ) { int id = ids[i]; WCHAR wszIdString[sizeOfstr] = {0}; _itow_s(id, wszIdString, sizeOfstr, radix); //add white space before <id> HR_SUCCESSCALL( AddWhiteSpaceToNode(pDOM, indentBstr, pdfSub), hr ); HR_SUCCESSCALL( AddWhiteSpaceToNode(pDOM, bstr_wst, pdfSub), hr ); HR_SUCCESSCALL( AddSubNodeToDocumentFragment(pDOM, wszIdNode, wszIdString, pdfSub), hr ); } //test whether it is successful in "add ids to pdfSub" HR_SUCCESSCALL( hr, hr ); //add ids array to document fragment node HR_SUCCESSCALL( AppendChildToParent(pdfSub, pe), hr ); HR_SUCCESSCALL( AddWhiteSpaceToNode(pDOM, indentBstr, pe), hr ); HR_SUCCESSCALL( AppendChildToParent(pe, pdf), hr ); }while(0); //release the com objects SAFE_COM_RELEASE(pa1); SAFE_COM_RELEASE(pa); SAFE_COM_RELEASE(pdfSub); SAFE_COM_RELEASE(pe); //release the bstr and variant SAFE_BSTR_RELEASE(bstr); SAFE_BSTR_RELEASE(bstr_wst); VariantClear(&var); return hr; }
//add boundary to shot or sub shot fragment node HRESULT AddBoundaryNodeToDocumentFragment( IXMLDOMDocument* pDOM, BSTR indentBstr, IXMLDOMDocumentFragment* pdf, // Release is completed outside unsigned int bgnFrameId, unsigned int endFrameId, __int64 bgnFrameTime, __int64 endFrameTime) { BSTR bstr = NULL; BSTR bstr_wst = SysAllocString(L"\t"); IXMLDOMElement* pe = NULL; IXMLDOMDocumentFragment* pdfSub = NULL; HRESULT hr = S_OK; do { //create a Node to hold boundary. bstr = SysAllocString(L"Boundary"); HR_SUCCESSCALL( pDOM->createElement(bstr, &pe), hr ); SAFE_BSTR_RELEASE(bstr); //create a document fragment to hold boundary's sub-elements. HR_SUCCESSCALL( pDOM->createDocumentFragment(&pdfSub), hr ); //add sub elements to pdfSub //add white space before <BgnFrameId> HR_SUCCESSCALL( AddWhiteSpaceToNode(pDOM, indentBstr, pdfSub), hr ); HR_SUCCESSCALL( AddWhiteSpaceToNode(pDOM, bstr_wst, pdfSub), hr ); const int radix = 10; const size_t sizeOfstr = 30; wchar_t wszBgnFrmIdString[sizeOfstr] = {0}; _itow_s(bgnFrameId, wszBgnFrmIdString, sizeOfstr, radix); HR_SUCCESSCALL( AddSubNodeToDocumentFragment(pDOM, L"BgnFrameId", wszBgnFrmIdString, pdfSub), hr ); //<EndFrameId> HR_SUCCESSCALL( AddWhiteSpaceToNode(pDOM, indentBstr, pdfSub), hr ); HR_SUCCESSCALL( AddWhiteSpaceToNode(pDOM, bstr_wst, pdfSub), hr ); wchar_t wszEndFrmIdString[sizeOfstr] = {0}; _itow_s(endFrameId, wszEndFrmIdString, sizeOfstr, radix); HR_SUCCESSCALL( AddSubNodeToDocumentFragment(pDOM, L"EndFrameId", wszEndFrmIdString, pdfSub), hr ); //<BgnFrameTime> HR_SUCCESSCALL( AddWhiteSpaceToNode(pDOM, indentBstr, pdfSub), hr ); HR_SUCCESSCALL( AddWhiteSpaceToNode(pDOM, bstr_wst, pdfSub), hr ); //begintime wchar_t wszBgnFrmTimeString[sizeOfstr*2] = {0}; _i64tow_s(bgnFrameTime, wszBgnFrmTimeString, sizeOfstr*2, 10); HR_SUCCESSCALL( AddSubNodeToDocumentFragment(pDOM, L"BgnFrameTime", wszBgnFrmTimeString, pdfSub), hr ); //<EndFrameId> HR_SUCCESSCALL( AddWhiteSpaceToNode(pDOM, indentBstr, pdfSub), hr ); HR_SUCCESSCALL( AddWhiteSpaceToNode(pDOM, bstr_wst, pdfSub), hr ); //endtime wchar_t wszEndFrmTimeString[sizeOfstr*2] = {0}; _i64tow_s(endFrameTime, wszEndFrmTimeString, sizeOfstr*2, 10); HR_SUCCESSCALL( AddSubNodeToDocumentFragment(pDOM, L"EndFrameTime", wszEndFrmTimeString, pdfSub), hr ); //add Boundary to document fragment node HR_SUCCESSCALL( AppendChildToParent(pdfSub, pe), hr ); HR_SUCCESSCALL( AddWhiteSpaceToNode(pDOM, indentBstr, pe), hr ); HR_SUCCESSCALL( AppendChildToParent(pe, pdf), hr ); }while(0); //release com object SAFE_COM_RELEASE(pdfSub); SAFE_COM_RELEASE(pe); //release bstr SAFE_BSTR_RELEASE(bstr); SAFE_BSTR_RELEASE(bstr_wst); return hr; }
unsigned int ConstructPowerShellVersion(int iPSMajorVersion, int iPSMinorVersion, __deref_out_opt PWSTR *pwszMonadVersion) { unsigned int exitCode = EXIT_CODE_SUCCESS; wchar_t* wszMajorVersion = new wchar_t[10]; wchar_t* wszMinorVersion = new wchar_t[10]; do { if ((NULL == pwszMonadVersion) || ( 0 > iPSMajorVersion) || (0 > iPSMinorVersion)) { exitCode = EXIT_CODE_BAD_INPUT; break; } if (0 != _itow_s(iPSMajorVersion, wszMajorVersion, 10, 10)) { exitCode = EXIT_CODE_BAD_INPUT; break; } if (0 != _itow_s(iPSMinorVersion, wszMinorVersion, 10, 10)) { exitCode = EXIT_CODE_BAD_INPUT; break; } size_t iMajorLength; size_t iMinorLength; if (SUCCEEDED(StringCchLength(wszMajorVersion, 10, &iMajorLength)) && SUCCEEDED(StringCchLength(wszMinorVersion, 10, &iMinorLength))) { size_t totalLength = iMajorLength + iMinorLength + 2; *pwszMonadVersion = new wchar_t[totalLength]; if (NULL == *pwszMonadVersion) { exitCode = ERROR_NOT_ENOUGH_MEMORY; break; } *pwszMonadVersion[0] = L'\0'; if (SUCCEEDED(StringCchCopyW(*pwszMonadVersion, totalLength, wszMajorVersion)) && SUCCEEDED(StringCchCatW(*pwszMonadVersion, totalLength, L".")) && SUCCEEDED(StringCchCatW(*pwszMonadVersion, totalLength, wszMinorVersion))) { break; } else { exitCode = EXIT_CODE_BAD_INPUT; break; } } else { exitCode = EXIT_CODE_BAD_INPUT; break; } }while(false); if (NULL != wszMajorVersion) { delete[] wszMajorVersion; } if (NULL != wszMinorVersion) { delete[] wszMinorVersion; } return exitCode; }
int init_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus) { const char *__function_name = "init_cpu_collector"; int cpu_num, ret = FAIL; #ifdef _WINDOWS TCHAR cpu[8]; char counterPath[PDH_MAX_COUNTER_PATH]; PDH_COUNTER_PATH_ELEMENTS cpe; #else #ifdef HAVE_KSTAT_H kstat_ctl_t *kc; kstat_t *k, *kd; #endif #endif zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); #ifdef _WINDOWS cpe.szMachineName = NULL; cpe.szObjectName = get_counter_name(PCI_PROCESSOR); cpe.szInstanceName = cpu; cpe.szParentInstance = NULL; cpe.dwInstanceIndex = -1; cpe.szCounterName = get_counter_name(PCI_PROCESSOR_TIME); for (cpu_num = 0; cpu_num <= pcpus->count; cpu_num++) { if (0 == cpu_num) zbx_wsnprintf(cpu, sizeof(cpu) / sizeof(TCHAR), TEXT("_Total")); else _itow_s(cpu_num - 1, cpu, sizeof(cpu) / sizeof(TCHAR), 10); if (ERROR_SUCCESS != zbx_PdhMakeCounterPath(__function_name, &cpe, counterPath)) goto clean; if (NULL == (pcpus->cpu_counter[cpu_num] = add_perf_counter(NULL, counterPath, MAX_CPU_HISTORY))) goto clean; } cpe.szObjectName = get_counter_name(PCI_SYSTEM); cpe.szInstanceName = NULL; cpe.szCounterName = get_counter_name(PCI_PROCESSOR_QUEUE_LENGTH); if (ERROR_SUCCESS != zbx_PdhMakeCounterPath(__function_name, &cpe, counterPath)) goto clean; if (NULL == (pcpus->queue_counter = add_perf_counter(NULL, counterPath, MAX_CPU_HISTORY))) goto clean; ret = SUCCEED; clean: #else /* not _WINDOWS */ if (ZBX_MUTEX_ERROR == zbx_mutex_create_force(&cpustats_lock, ZBX_MUTEX_CPUSTATS)) { zbx_error("unable to create mutex for cpu collector"); exit(FAIL); } for (cpu_num = 0; cpu_num <= pcpus->count; cpu_num++) pcpus->cpu[cpu_num].cpu_num = cpu_num; #ifdef HAVE_KSTAT_H /* Solaris */ if (NULL != (kc = kstat_open())) { if (NULL != (k = kstat_lookup(kc, "unix", 0, "kstat_headers")) && -1 != kstat_read(kc, k, NULL)) { int i; for (i = 0, cpu_num = 1; i < k->ks_ndata; i++) { kd = (kstat_t *)k->ks_data; if (0 == strcmp(kd[i].ks_module, "cpu_info")) pcpus->cpu[cpu_num++].cpu_num = kd[i].ks_instance + 1; } } kstat_close(kc); } #endif /* HAVE_KSTAT_H */ ret = SUCCEED; #endif /* _WINDOWS */ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
void clsGame::Setup(void) { bool delayError = false; wstring msg1st = L""; wstring msg2nd = L""; int wc3Instance; wchar_t buffer[255] = {NULL}; wstring title; // Count the number of wc3's currently setup for (wc3Instance = 0; wc3Instance < 8; wc3Instance++) { _itow_s(wc3Instance+1, buffer, 10); title = L"SC2 #"; title += buffer; clsGame::Handle[wc3Instance] = FindWindow(L"Starcraft II", title.c_str()); if (clsGame::Handle[wc3Instance] != NULL) { GetWindowThreadProcessId(clsGame::Handle[wc3Instance], &clsGame::PID[wc3Instance]); clsBot::SetupWarcraft(wc3Instance); } else { // check if running in sandbox clsGame::Handle[wc3Instance] = FindWindow(L"Sandbox:DefaultBox:StarCraft II", title.c_str()); if (clsGame::Handle[wc3Instance] != NULL) { GetWindowThreadProcessId(clsGame::Handle[wc3Instance], &clsGame::PID[wc3Instance]); clsBot::SetupWarcraft(wc3Instance); } } } // Rename the remaining wc3's for (wc3Instance = 0; wc3Instance < 8; wc3Instance++) { if (clsGame::Handle[wc3Instance] == NULL) { clsGame::Handle[wc3Instance] = FindWindow(L"Starcraft II", L"Starcraft II"); if (clsGame::Handle[wc3Instance] == NULL) { // check for sandbox clsGame::Handle[wc3Instance] = FindWindow(L"Sandbox:DefaultBox:StarCraft II", L"[#] StarCraft II [#]"); if (clsGame::Handle[wc3Instance] != NULL) { GetWindowThreadProcessId(clsGame::Handle[wc3Instance], &clsGame::PID[wc3Instance]); clsBot::SetupWarcraft(wc3Instance); _itow_s(wc3Instance+1, buffer, 10); title = L"SC2 #"; title += buffer; SetWindowText(clsGame::Handle[wc3Instance], title.c_str()); } else { SendMessage(clsBot::hStatus[wc3Instance], WM_SETTEXT, NULL, (LPARAM)L"Not Found"); } } else { GetWindowThreadProcessId(clsGame::Handle[wc3Instance], &clsGame::PID[wc3Instance]); clsBot::SetupWarcraft(wc3Instance); _itow_s(wc3Instance+1, buffer, 10); title = L"SC2 #"; title += buffer; SetWindowText(clsGame::Handle[wc3Instance], title.c_str()); } } // Calculate if chat delays are great than leave delays SendMessage(clsBot::hLeaveDelay[wc3Instance], WM_GETTEXT, 10, (LPARAM)buffer); int delayLeave = _wtoi(buffer); SendMessage(clsBot::h1stChatDelay[wc3Instance], WM_GETTEXT, 10, (LPARAM)buffer); int delay1stChat = _wtoi(buffer); SendMessage(clsBot::h2ndChatDelay[wc3Instance], WM_GETTEXT, 10, (LPARAM)buffer); int delay2ndChat = _wtoi(buffer); // Check to see if show chat is enabled, then show a warning if it is if (SendMessage(clsBot::hShow1stChat, BM_GETCHECK, NULL, NULL) == BST_CHECKED && delay1stChat > delayLeave) { SendMessage(clsBot::hStatus[wc3Instance], WM_GETTEXT, 255, (LPARAM)&buffer); if (wstring(buffer) != L"Not Found") { msg1st += L"SC2 #"; _itow_s(wc3Instance+1, buffer, 10); msg1st += buffer; msg1st += L", "; delayError = true; } if (wc3Instance == 7 && delayError == true) { msg1st.insert(0, L"1st Chat Delay for "); msg1st = msg1st.substr(0, msg1st.find_last_of(L',')); msg1st += L" is greater than the Leave delay so 1st Chat will never be displayed."; } } if (SendMessage(clsBot::hShow2ndChat, BM_GETCHECK, NULL, NULL) == BST_CHECKED && delay2ndChat > delayLeave) { SendMessage(clsBot::hStatus[wc3Instance], WM_GETTEXT, 255, (LPARAM)buffer); if (wstring(buffer) != L"Not Found") { msg2nd += L"SC2 #"; _itow_s(wc3Instance+1, buffer, 10); msg2nd += buffer; msg2nd += L", "; delayError = true; } if (wc3Instance == 7 && delayError == true && msg2nd != L"") { msg2nd.insert(0, L"2nd Chat Delay for "); msg2nd = msg2nd.substr(0, msg2nd.find_last_of(L',')); msg2nd += L" is greater than the Leave delay so 2nd Chat will never be displayed."; if (msg1st != L"") msg2nd.insert(0, L"\n\n"); } } } // Display an error if show chats are enabled but the delays are greater than the leave delay if (delayError == true) MessageBox(NULL, (msg1st + msg2nd).c_str(), L"Warning", MB_ICONWARNING); }
void sqlite_db::pragma_synchronous(int mode) { wchar_t buffer[64]; _itow_s(mode,buffer,10); query(wstring(L"pragma synchronous = ")+buffer+L";"); }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_COMMAND: case BN_CLICKED: if (LOWORD(wParam) == ID_Button) { wchar_t str [100]; SendMessage(EditBox, WM_GETTEXT, sizeof(str), (LPARAM)str); errno_t res = SendMessage(ListBox, LB_FINDSTRING, -1, (LPARAM) str); if (res == LB_ERR) MessageBox(hWnd, L"Строка не найдена.", L"", MB_OK); else { wchar_t num[20]; _itow_s(res + 1, num, 10); wcscat_s(num, L"-я строка."); MessageBox(hWnd, num, L"", MB_OK); } } break; case WM_CREATE: { GetClientRect(hWnd, &cr); ListBox = CreateWindowEx( WS_EX_CLIENTEDGE, L"listbox", L"", WS_CHILD | WS_VISIBLE | WS_VSCROLL, cr.right / 4, cr.bottom / 5, cr.right / 2, cr.bottom / 3, hWnd, (HMENU)ID_ListBox, hinst, NULL); EditBox = CreateWindowEx( WS_EX_CLIENTEDGE, L"edit", L"", WS_CHILD | WS_VISIBLE, cr.right / 4, cr.bottom / 5 * 3.5, cr.right / 2, 20, hWnd, (HMENU)ID_EditBox, hinst, NULL); std::wstring Agatha_Christie[10] = { L"Я на тебе, как на войне,", L"а на войне, как на тебе,", L"Но я устал, окончен бой,", L"беру портвейн, иду домой.", L" ", L"Окончен бой, зачах огонь,", L"и не осталось ничего.", L"А мы живём, а нам с тобою повезло", L"назло.", L" (c) \"Агата Кристи\" 1993 г." }; for (int i = 0; i < 10; i++) SendMessage(ListBox, LB_ADDSTRING, 0, (LPARAM)Agatha_Christie[i].c_str()); Button = CreateWindowEx( WS_EX_CLIENTEDGE, L"button", L"Найти", WS_CHILD | WS_VISIBLE, cr.right / 2 - 8 * 6, cr.bottom - 50, 80, 30, hWnd, (HMENU)ID_Button, hinst, NULL); break; } case WM_PAINT: hdc = BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); break; } return 0; }
//------------------------------------------------------------------------------ // Name: PrintAttribute() // Desc: Display the specified attribute. //------------------------------------------------------------------------------ HRESULT PrintAttribute( WORD wIndex, WORD wStream, __in LPWSTR wszName, WMT_ATTR_DATATYPE AttribDataType, WORD wLangID, BYTE * pbValue, DWORD dwValueLen ) { WCHAR pwszValue[256]; WCHAR wszNum[256]; ZeroMemory( pwszValue, sizeof( pwszValue ) ); ZeroMemory( wszNum, sizeof( wszNum ) ); // // Make the data type string // WCHAR * pwszType = L"Unknown"; WCHAR * pTypes[] = { L"DWORD", L"STRING", L"BINARY", L"BOOL", L"QWORD", L"WORD", L"GUID" }; if( ( sizeof( pTypes ) / sizeof( pTypes[0] ) ) > AttribDataType ) { pwszType = pTypes[AttribDataType]; } // // The attribute value. // switch ( AttribDataType ) { // // string // case WMT_TYPE_STRING: if( 0 == dwValueLen ) { StringCbCatW( pwszValue, sizeof( pwszValue ), L"***** NULL *****" ); } else { if( 0xFEFF == *(WCHAR*)pbValue ) { StringCbCatW( pwszValue, sizeof( pwszValue ), L"UTF-16LE BOM+" ); StringCbCatW( pwszValue, sizeof( pwszValue ), L"\"" ); if( 4 <= dwValueLen ) { StringCbCatW( pwszValue, sizeof( pwszValue ), (WCHAR *)pbValue + 1 ); } StringCbCatW( pwszValue, sizeof( pwszValue ), L"\"" ); } else if( 0xFFFE == *(WCHAR*)pbValue ) { StringCbCatW( pwszValue, sizeof( pwszValue ), L"UTF-16BE BOM+" ); StringCbCatW( pwszValue, sizeof( pwszValue ), L"\"" ); if( 4 <= dwValueLen ) { StringCbCatW( pwszValue, sizeof( pwszValue ), (WCHAR *)pbValue + 1 ); } StringCbCatW( pwszValue, sizeof( pwszValue ), L"\"" ); } else { StringCbCatW( pwszValue, sizeof( pwszValue ), L"\"" ); if( 2 <= dwValueLen ) { StringCbCatW( pwszValue, sizeof( pwszValue ), (WCHAR *)pbValue ); } StringCbCatW( pwszValue, sizeof( pwszValue ), L"\"" ); } } break; // // Binary // case WMT_TYPE_BINARY: StringCbCatW( pwszValue, sizeof( pwszValue ), L"[" ); _itow_s( dwValueLen, wszNum, 10 ); StringCbCatW( pwszValue, sizeof( pwszValue ), wszNum ); StringCbCatW( pwszValue, sizeof( pwszValue ), L" bytes]" ); break; // // Boolean // case WMT_TYPE_BOOL: if( *( (BOOL* )pbValue ) == FALSE ) { StringCbCatW( pwszValue, sizeof( pwszValue ), L"False" ); } else { StringCbCatW( pwszValue, sizeof( pwszValue ), L"True" ); } break; // // DWORD // case WMT_TYPE_DWORD: StringCbPrintfW( wszNum, sizeof(wszNum), L"%ld, 0x%08lx", ( (DWORD *)pbValue )[0], ( (DWORD *)pbValue )[0] ); StringCbCatW( pwszValue, sizeof( pwszValue ), wszNum ); break; // // QWORD // case WMT_TYPE_QWORD: _ui64tow_s( *( (QWORD* )pbValue ), wszNum, sizeof(wszNum) / sizeof(wszNum[0]), 10 ); StringCbCatW( pwszValue, sizeof( pwszValue ), wszNum ); StringCbPrintfW( wszNum, sizeof( wszNum ), L", 0x%08lx%08lx", ( (DWORD *)pbValue )[1], ( (DWORD *)pbValue )[0] ); StringCbCatW( pwszValue, sizeof( pwszValue ), wszNum ); break; // // WORD // case WMT_TYPE_WORD: StringCbPrintfW( wszNum, sizeof( wszNum ), L"%d, 0x%04x", ( ( WORD* )pbValue )[0], ( ( WORD* )pbValue )[0] ); StringCbCatW( pwszValue, sizeof( pwszValue ), wszNum ); break; // // GUID // case WMT_TYPE_GUID: if( !StringFromGUID2( *(GUID *)pbValue, pwszValue, 256 ) ) { StringCbCatW( pwszValue, sizeof( pwszValue ), L"ERROR" ); } break; default: StringCbPrintfW( pwszValue, sizeof( pwszValue ), L"Bad data type (%hu): value not displayed", AttribDataType ); break; } // // Dump the string to the screen. // _tprintf( _T( "* %3u %-25ls %3hu %3hu %7ls %ls\n" ), wIndex, wszName, wStream, wLangID, pwszType, pwszValue ); return( S_OK ); }
void DateImplementation::GetDateComponent(CompoundString *bs, DateData componentType, int adjust) { double value = this->GetDateData(componentType, true /* fUTC */, m_scriptContext); if(Js::NumberUtilities::IsFinite(value)) { const int ival = (int)value + adjust; const int ivalAbs = ival < 0 ? -ival : ival; switch(componentType) { case DateData::FullYear: if(ival < 0 || ival > 9999) { // ES5 spec section 15.9.1.15.1 states that for years outside the range 0-9999, the expanded year // representation should: // - always include the sign // - have 2 extra digits (6 digits total) bs->AppendChars(ival < 0 ? _u('-') : _u('+')); if(ivalAbs < 100000) { bs->AppendChars(_u('0')); if(ivalAbs < 10000) { bs->AppendChars(_u('0')); } } } // Years are zero-padded to at least 4 digits in ES5 if(ivalAbs < 1000) { bs->AppendChars(_u('0')); // will fall through to next case for additional padding } else { break; } // fall through case DateData::Milliseconds: if (ivalAbs < 100) { bs->AppendChars(_u('0')); // will fall through to next case for additional padding } else { break; } // fall through default: if (ivalAbs < 10) { bs->AppendChars(_u('0')); } } // _itow_s makes use of max 12 bytes for a base-10 32-bit int (_u("-2147483648\0")), although we don't need the sign // and our numbers shouldn't be that big anyway bs->AppendChars( ivalAbs, 10, [](const int value, char16 *const buffer, const CharCount charCapacity) { errno_t err = _itow_s(value, buffer, charCapacity, 10); Assert(err == 0); }); } }
/** * Static helper: InjectDLL */ bool FrameProxy::InjectDLL(HINSTANCE instance, DWORD processId) { logger->debug(L"FrameProxy::InjectDLL"); STARTUPINFO startupInfo; ::ZeroMemory(&startupInfo, sizeof(startupInfo)); startupInfo.cb = sizeof(startupInfo); startupInfo.dwFlags |= STARTF_USESHOWWINDOW; startupInfo.wShowWindow = FALSE; PROCESS_INFORMATION processInfo; ::ZeroMemory(&processInfo, sizeof(processInfo)); wchar_t params[MAX_PATH]; _itow_s(processId, params, MAX_PATH, 10); // get module path wchar_t buf[MAX_PATH]; ::GetModuleFileName(instance, buf, MAX_PATH); bfs::wpath path = bfs::wpath(buf).parent_path(); // get os version: http://msdn.microsoft.com/en-us/library/ms724833(v=vs.85).aspx OSVERSIONINFO version; ::ZeroMemory(&version, sizeof(OSVERSIONINFO)); version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); ::GetVersionEx(&version); // get cpu arch: http://msdn.microsoft.com/en-us/library/ms724958(v=vs.85).aspx SYSTEM_INFO sysinfo; ::GetNativeSystemInfo(&sysinfo); logger->debug(L"Windows Version " L" -> dwMajorVersion " + boost::lexical_cast<wstring>(version.dwMajorVersion) + L" -> dwMinorVersion " + boost::lexical_cast<wstring>(version.dwMinorVersion) + L" -> wProcessorArchitecture " + boost::lexical_cast<wstring>(sysinfo.wProcessorArchitecture) + L" -> PROCESSOR_ARCHITECTURE_INTEL " + boost::lexical_cast<wstring>(PROCESSOR_ARCHITECTURE_INTEL) + L" -> PROCESSOR_ARCHITECTURE_AMD64 " + boost::lexical_cast<wstring>(PROCESSOR_ARCHITECTURE_AMD64)); logger->debug(L"int IS: " + boost::lexical_cast<wstring>(sizeof(int))); // 4 logger->debug(L"INT32 IS: " + boost::lexical_cast<wstring>(sizeof(INT32))); // 4 logger->debug(L"INT64 IS: " + boost::lexical_cast<wstring>(sizeof(INT64))); // 8 // spawn correct forgeXX.exe for os version and arch if (version.dwMajorVersion >= 6 && version.dwMinorVersion >= 2 && sysinfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) { // windows 8 x86 path = path / L"forge32.exe"; } else if (version.dwMajorVersion >= 6 && version.dwMinorVersion >= 2) { // Windows 8 x64 - frame process is ALWAYS 64 bit path = path / L"forge64.exe"; } else { // everyone else #ifdef _WIN64 path = path / L"forge64.exe"; #else path = path / L"forge32.exe"; #endif } logger->debug(L"FrameProxy::InjectDLL spawning process" L" -> " + path.wstring()); if (!::CreateProcess(path.wstring().c_str(), params, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &processInfo)) { logger->debug(L"FrameProxy::InjectDLL failed to create process" L" -> " + path.wstring()); return false; } ::WaitForSingleObject(processInfo.hProcess, INFINITE); ::CloseHandle(processInfo.hThread); ::CloseHandle(processInfo.hProcess); return true; }
int CschedulerDlg::storeNote(void) { // FILE *f; // char abuff[KS_MAX_NOTE]; // TCHAR wbuff[KS_MAX_NOTE]; // int count,i; // CString tempstr; // // fopen_s(&f,KS_CONF_FILE,"w+"); // if(f!=0) // { // count=m_list.GetItemCount(); // fprintf(f,"%d\n",count); // for(i=0;i<count;i++) // { // abuff[0]=0; // tempstr=m_list.GetItemText(i,0); // tempstr.Replace(' ','*'); // WideCharToMultiByte(CP_UTF8,0,tempstr,-1,abuff,KS_MAX_NOTE,0,0); // fprintf(f,"%s\n",abuff); // // abuff[0]=0; // //m_list.GetItemText(i,1,wbuff,KS_MAX_NOTE); // //WideCharToMultiByte(CP_UTF8,0,wbuff,-1,abuff,KS_MAX_NOTE,0,0); // tempstr=m_list.GetItemText(i,1); // tempstr.Replace(' ','*'); // WideCharToMultiByte(CP_UTF8,0,tempstr,-1,abuff,KS_MAX_NOTE,0,0); // fprintf(f,"%s\n",abuff); // // abuff[0]=0; // // m_list.GetItemText(i,2,wbuff,KS_MAX_NOTE); // // WideCharToMultiByte(CP_UTF8,0,wbuff,-1,abuff,KS_MAX_NOTE,0,0); // tempstr=m_list.GetItemText(i,2); // tempstr.Replace(' ','*'); // WideCharToMultiByte(CP_UTF8,0,tempstr,-1,abuff,KS_MAX_NOTE,0,0); // fprintf(f,"%s\n",abuff); // } // fclose(f); // return 1; // } CStdioFile iof; int count; CString tempstr; TCHAR wbuff[KS_MAX_NOTE]; if(iof.Open(_T(KS_CONF_FILE), CFile::modeCreate |CFile::modeWrite|CFile::typeText)) { count=m_list.GetItemCount(); _itow_s(count,wbuff,KS_MAX_NOTE,10); iof.WriteString(wbuff); iof.WriteString(_T("\n")); for (int i=0;i<count;i++) { tempstr=m_list.GetItemText(i,0); iof.WriteString(tempstr); iof.WriteString(_T("\n")); tempstr=m_list.GetItemText(i,1); iof.WriteString(tempstr); iof.WriteString(_T("\n")); tempstr=m_list.GetItemText(i,2); iof.WriteString(tempstr); iof.WriteString(_T("\n")); } iof.Close(); return 1; } iof.Close(); return 0; }
void FillTcpTable(HWND hwnd) { MIB_TCPTABLE *tcpTable = (MIB_TCPTABLE*)malloc(sizeof(MIB_TCPTABLE)); HWND listView = GetDlgItem(hwnd, TCP_LIST); LVITEM item; memset(&item, 0, sizeof(item)); item.mask = LVIF_TEXT; item.cchTextMax = 256; struct in_addr IpAddr; TCHAR szLocalAddr[128]; TCHAR szLocalPort[6]; TCHAR szRemoteAddr[128]; TCHAR szRemotePort[6]; size_t num; DWORD expSize = sizeof(MIB_TCPTABLE); if(GetTcpTable(tcpTable, &expSize, TRUE) == ERROR_INSUFFICIENT_BUFFER) { free(tcpTable); tcpTable = (MIB_TCPTABLE*)malloc(expSize); } if(GetTcpTable(tcpTable, &expSize, TRUE) != NO_ERROR) { MessageBox(NULL, TEXT("Error retrieving TCP table!"), NULL, 0); } else { SendMessage(listView, LVM_DELETEALLITEMS, 0, 0); for(int i = 0; i < (int)tcpTable->dwNumEntries; ++i) { item.iItem = i; item.iSubItem = 0; switch(tcpTable->table[i].dwState) { case MIB_TCP_STATE_CLOSED: item.pszText = TEXT("CLOSED"); break; case MIB_TCP_STATE_LISTEN: item.pszText = TEXT("LISTEN"); break; case MIB_TCP_STATE_SYN_SENT: item.pszText = TEXT("SYN-SENT"); break; case MIB_TCP_STATE_SYN_RCVD: item.pszText = TEXT("SYN-RECEIVED"); break; case MIB_TCP_STATE_ESTAB: item.pszText = TEXT("ESTABLISHED"); break; case MIB_TCP_STATE_FIN_WAIT1: item.pszText = TEXT("FIN-WAIT-1"); break; case MIB_TCP_STATE_FIN_WAIT2: item.pszText = TEXT("FIN-WAIT-2"); break; case MIB_TCP_STATE_CLOSE_WAIT: item.pszText = TEXT("CLOSE-WAIT"); break; case MIB_TCP_STATE_CLOSING: item.pszText = TEXT("CLOSING"); break; case MIB_TCP_STATE_LAST_ACK: item.pszText = TEXT("LAST-ACK"); break; case MIB_TCP_STATE_TIME_WAIT: item.pszText = TEXT("TIME-WAIT"); break; case MIB_TCP_STATE_DELETE_TCB: item.pszText = TEXT("DELETE-TCB"); break; default: item.pszText = TEXT("UNKNOWN"); break; } SendMessage(listView, LVM_INSERTITEM, i, (LPARAM)&item); IpAddr.S_un.S_addr = (u_long)tcpTable->table[i].dwLocalAddr; mbstowcs_s(&num, szLocalAddr, inet_ntoa(IpAddr), 128); item.iSubItem = 1; item.pszText = szLocalAddr; SendMessage(listView, LVM_SETITEM, i, (LPARAM)&item); _itow_s((u_short)tcpTable->table[i].dwLocalPort, szLocalPort, 6, 10); item.iSubItem = 2; item.pszText = szLocalPort; SendMessage(listView, LVM_SETITEM, i, (LPARAM)&item); IpAddr.S_un.S_addr = (u_long)tcpTable->table[i].dwRemoteAddr; mbstowcs_s(&num, szRemoteAddr, inet_ntoa(IpAddr), 128); item.iSubItem = 3; item.pszText = szRemoteAddr; SendMessage(listView, LVM_SETITEM, i, (LPARAM)&item); _itow_s((u_short)tcpTable->table[i].dwRemotePort, szRemotePort, 6, 10); item.iSubItem = 4; item.pszText = szRemotePort; SendMessage(listView, LVM_SETITEM, i, (LPARAM)&item); } } if(tcpTable) { free(tcpTable); } }
int init_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus) { const char *__function_name = "init_cpu_collector"; int cpu_num, ret = FAIL; #ifdef _WINDOWS TCHAR cpu[8]; char counterPath[PDH_MAX_COUNTER_PATH]; PDH_COUNTER_PATH_ELEMENTS cpe; #endif zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); #ifdef _WINDOWS cpe.szMachineName = NULL; cpe.szObjectName = get_counter_name(PCI_PROCESSOR); cpe.szInstanceName = cpu; cpe.szParentInstance = NULL; cpe.dwInstanceIndex = -1; cpe.szCounterName = get_counter_name(PCI_PROCESSOR_TIME); for (cpu_num = 0; cpu_num <= pcpus->count; cpu_num++) { if (0 == cpu_num) zbx_wsnprintf(cpu, sizeof(cpu) / sizeof(TCHAR), TEXT("_Total")); else _itow_s(cpu_num - 1, cpu, sizeof(cpu) / sizeof(TCHAR), 10); if (ERROR_SUCCESS != zbx_PdhMakeCounterPath(__function_name, &cpe, counterPath)) goto clean; if (NULL == (pcpus->cpu_counter[cpu_num] = add_perf_counter(NULL, counterPath, MAX_CPU_HISTORY))) goto clean; } cpe.szObjectName = get_counter_name(PCI_SYSTEM); cpe.szInstanceName = NULL; cpe.szCounterName = get_counter_name(PCI_PROCESSOR_QUEUE_LENGTH); if (ERROR_SUCCESS != zbx_PdhMakeCounterPath(__function_name, &cpe, counterPath)) goto clean; if (NULL == (pcpus->queue_counter = add_perf_counter(NULL, counterPath, MAX_CPU_HISTORY))) goto clean; ret = SUCCEED; clean: #else /* not _WINDOWS */ if (ZBX_MUTEX_ERROR == zbx_mutex_create_force(&cpustats_lock, ZBX_MUTEX_CPUSTATS)) { zbx_error("unable to create mutex for cpu collector"); exit(EXIT_FAILURE); } #ifndef HAVE_KSTAT_H for (cpu_num = 0; cpu_num <= pcpus->count; cpu_num++) pcpus->cpu[cpu_num].cpu_num = cpu_num; #else /* Solaris */ /* CPU instance numbers on Solaris can be non-contiguous, we don't know them yet */ pcpus->cpu[0].cpu_num = 0; for (cpu_num = 1; cpu_num <= pcpus->count; cpu_num++) pcpus->cpu[cpu_num].cpu_num = -1; if (NULL == (kc = kstat_open())) { zbx_error("kstat_open() failed"); exit(EXIT_FAILURE); } kc_id = kc->kc_chain_id; if (NULL == ksp) ksp = zbx_malloc(ksp, sizeof(kstat_t *) * pcpus->count); if (SUCCEED != refresh_kstat(pcpus)) { zbx_error("kstat_chain_update() failed"); exit(EXIT_FAILURE); } #endif /* HAVE_KSTAT_H */ ret = SUCCEED; #endif /* _WINDOWS */ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }