PerformanceMonitor::PerformanceMonitor(const wchar_t* function) : m_function(function) { try { if(PerformanceMonitor::m_timer == PerformanceMonitor::UnknownTimer) { DetermineTimer(); PerformanceMonitor::m_enableLogging = IsLoggingSystemEnabled(); } if(!PerformanceMonitor::m_enableLogging) return; if(PerformanceMonitor::m_timer == PerformanceMonitor::HighResolutionTimer) QueryPerformanceCounter(&m_start); else m_startClock = clock(); CStdStringW sFunction; sFunction.Format(_T("Starting %s"), m_function.c_str()); LOG_WS_INFO(sFunction.c_str()); } catch(...) { } }
CStdStringW CompressedRedlineBuilder::BuildOmissionString() { CStdStringW sText; CStdStringW sNumber; sNumber.Format(L"%d", m_iOmittedChars); /* TXTEX_IGNORE */ sText = CStdString::FormatMessage(CStdString::LoadResource(IDS_TXTEX_omittedCharactersWithNoChanges5002,"[omitted %1 characters with no changes]"), sNumber); return sText; }
void CHTMLUtil::ConvertHTMLToW(const CStdStringW& strHTML, CStdStringW& strStripped) { if (strHTML.size() == 0) { strStripped.Empty(); return ; } int iPos = 0; strStripped = strHTML; while (mappings[iPos].html) { strStripped.Replace(mappings[iPos].html,CStdStringW(1, mappings[iPos].w)); iPos++; } iPos = strStripped.Find(L"&#"); while (iPos > 0 && iPos < (int)strStripped.size()-4) { int iStart = iPos + 1; iPos += 2; CStdStringW num; int base = 10; if (strStripped[iPos+1] == L'x') { base = 16; iPos++; } int i=iPos; while ( iPos < (int)strStripped.size() && (base==16?iswxdigit(strStripped[iPos]):iswdigit(strStripped[iPos]))) iPos++; num = strStripped.Mid(i,iPos-i); wchar_t val = (wchar_t)wcstol(num.c_str(),NULL,base); if (base == 10) num.Format(L"&#%ls;",num.c_str()); else num.Format(L"&#x%ls;",num.c_str()); strStripped.Replace(num,CStdStringW(1,val)); iPos = strStripped.Find(L"&#", iStart); } }
PerformanceMonitor::~PerformanceMonitor(void) { try { if(!PerformanceMonitor::m_enableLogging) return; double time = 0.0; if(PerformanceMonitor::m_timer == PerformanceMonitor::HighResolutionTimer) { QueryPerformanceCounter(&m_end); LARGE_INTEGER frequency = m_ticksPerSecond; unsigned int high32 = m_end.HighPart - m_start.HighPart; DWORD reduceMagnitude = 0; while(high32) { high32 >>= 1; reduceMagnitude++; } INT_PTR overheadTicks = m_numberOfTicksUsedForOverhead; if(reduceMagnitude || m_adjustPerformanceFrequency) { if(m_adjustPerformanceFrequency > reduceMagnitude) reduceMagnitude = m_adjustPerformanceFrequency; m_start.QuadPart = Int64ShrlMod32(m_start.QuadPart, reduceMagnitude); m_end.QuadPart = Int64ShrlMod32(m_end.QuadPart, reduceMagnitude); frequency.QuadPart = Int64ShrlMod32(frequency.QuadPart, reduceMagnitude); overheadTicks >>= reduceMagnitude; } if(frequency.LowPart == 0) time = 0.0; else time = ((double)(m_end.LowPart - m_start.LowPart - overheadTicks))/frequency.LowPart; } else { m_endClock = clock(); time = ((double)(m_endClock - m_startClock))/CLOCKS_PER_SEC; } CStdStringW sFunction; sFunction.Format(_T("%s took %f seconds"), m_function.c_str(), time); LOG_WS_INFO(sFunction.c_str()); }
bool CWIN32Util::IsUsbDevice(const CStdStringW &strWdrive) { CStdStringW strWDevicePath; strWDevicePath.Format(L"\\\\.\\%s",strWdrive.Left(2)); HANDLE deviceHandle = CreateFileW( strWDevicePath.c_str(), 0, // no access to the drive FILE_SHARE_READ | // share mode FILE_SHARE_WRITE, NULL, // default security attributes OPEN_EXISTING, // disposition 0, // file attributes NULL); // do not copy file attributes if(deviceHandle == INVALID_HANDLE_VALUE) return false; // setup query STORAGE_PROPERTY_QUERY query; memset(&query, 0, sizeof(query)); query.PropertyId = StorageDeviceProperty; query.QueryType = PropertyStandardQuery; // issue query DWORD bytes; STORAGE_DEVICE_DESCRIPTOR devd; STORAGE_BUS_TYPE busType = BusTypeUnknown; if (DeviceIoControl(deviceHandle, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), &devd, sizeof(devd), &bytes, NULL)) { busType = devd.BusType; } CloseHandle(deviceHandle); return BusTypeUsb == busType; }
MSXML2::IXMLDOMDocument2Ptr ValidateConfigXML() { wchar_t moduleFileName[MAX_PATH] = {0}; if(0 == GetModuleFileNameW(GetModuleHandle(_T("TestConnectSdk.dll")/*"TestConnectAPITool.dll"*/), moduleFileName, MAX_PATH)) throw Workshare::Exception(_T("Failed to obtain the filename of the current module")); CStdStringW schemaUrl; schemaUrl.Format(L"res://%s/ConnectAPITestTool.xsd", moduleFileName); MSXML2::IXMLDOMDocument2Ptr spConfigSchema; HRESULT hr = spConfigSchema.CreateInstance(__uuidof(MSXML2::DOMDocument60)); if(FAILED(hr)) throw Workshare::ClassNotFoundException(_T("Msxml2.DOMDocument.6.0"), _T("Failed to create an XML dom object.")); if(VARIANT_TRUE != spConfigSchema->load(schemaUrl.c_str())) ThrowMSXMLParseError(spConfigSchema->parseError, _T("Failed to load 'ConnectAPITestTool.xsd'.")); MSXML2::IXMLDOMSchemaCollection2Ptr spSchemaCollection; hr = spSchemaCollection.CreateInstance(__uuidof(MSXML2::XMLSchemaCache60)); if(FAILED(hr)) throw Workshare::ClassNotFoundException(_T("Msxml2.XMLSchemaCache.6.0"), _T("Failed to create an XML schema collection.")); hr = spSchemaCollection->add(L"", spConfigSchema.GetInterfacePtr()); if(S_OK != hr) throw Workshare::Exception(_T("Failed to add 'ConnectAPITestTool.xsd' to schema collection.")); MSXML2::IXMLDOMDocument2Ptr spConfigXML; hr = spConfigXML.CreateInstance(__uuidof(MSXML2::DOMDocument60)); if(FAILED(hr)) throw Workshare::ClassNotFoundException(_T("Msxml2.DOMDocument.6.0"), _T("Failed to create an XML dom object.")); spConfigXML->async = VARIANT_FALSE; spConfigXML->resolveExternals = VARIANT_FALSE; spConfigXML->validateOnParse = VARIANT_FALSE; spConfigXML->schemas = spSchemaCollection.GetInterfacePtr(); if(VARIANT_TRUE != spConfigXML->load(L"ConnectAPITestTool.xml")) ThrowMSXMLParseError(spConfigXML->parseError, _T("Failed to load 'ConnectAPITestTool.xml'.")); MSXML2::IXMLDOMParseErrorPtr spError = spConfigXML->validate(); if(S_OK != spError->errorCode) ThrowMSXMLParseError(spError, _T("Failed to validate 'ConnectAPITestTool.xml'.")); return spConfigXML; }
void CGUILabelControl::Render() { CStdString label(m_infoLabel.GetLabel(m_dwParentID)); if (m_bShowCursor) { // cursor location assumes utf16 text, so deal with that (inefficient, but it's not as if it's a high-use area // virtual keyboard only) CStdStringW utf16; g_charsetConverter.utf8ToW(label, utf16); CStdStringW col; if ((++m_dwCounter % 50) > 25) col.Format(L"|"); else col.Format(L"[COLOR %x]|[/COLOR]", 0x1000000); utf16.Insert(m_iCursorPos, col); g_charsetConverter.wToUTF8(utf16, label); } else if (m_startHighlight || m_endHighlight) { // this is only used for times/dates, so working in ascii (utf8) is fine CStdString colorLabel; colorLabel.Format("[COLOR %x]%s[/COLOR]%s[COLOR %x]%s[/COLOR]", (DWORD)m_label.disabledColor, label.Left(m_startHighlight), label.Mid(m_startHighlight, m_endHighlight - m_startHighlight), (DWORD)m_label.disabledColor, label.Mid(m_endHighlight)); label = colorLabel; } if (m_textLayout.Update(label, m_width)) { // reset the scrolling as we have a new label m_ScrollInfo.Reset(); } // check for scrolling bool bNormalDraw = true; if (m_ScrollInsteadOfTruncate && m_width > 0 && !IsDisabled()) { // ignore align center - just use align left/right float width, height; m_textLayout.GetTextExtent(width, height); if (width > m_width) { // need to scroll - set the viewport. Should be set just using the height of the text bNormalDraw = false; float fPosX = m_posX; if (m_label.align & XBFONT_RIGHT) fPosX -= m_width; float fPosY = m_posY; if (m_label.align & XBFONT_CENTER_Y) fPosY += m_height * 0.5f; m_textLayout.RenderScrolling(fPosX, fPosY, m_label.angle, m_label.textColor, m_label.shadowColor, (m_label.align & ~3), m_width, m_ScrollInfo); } } if (bNormalDraw) { float fPosX = m_posX; if (m_label.align & XBFONT_CENTER_X) fPosX += m_width * 0.5f; float fPosY = m_posY; if (m_label.align & XBFONT_CENTER_Y) fPosY += m_height * 0.5f; if (IsDisabled()) m_textLayout.Render(fPosX, fPosY, m_label.angle, m_label.disabledColor, m_label.shadowColor, m_label.align | XBFONT_TRUNCATED, m_width, true); else m_textLayout.Render(fPosX, fPosY, m_label.angle, m_label.textColor, m_label.shadowColor, m_label.align | XBFONT_TRUNCATED, m_width); } CGUIControl::Render(); }
void CGUIEditControl::RenderText() { if (m_smsTimer.GetElapsedMilliseconds() > smsDelay) UpdateText(); if (m_bInvalidated) RecalcLabelPosition(); float leftTextWidth = m_textLayout.GetTextWidth(); float maxTextWidth = m_width - m_label.offsetX * 2; // start by rendering the normal text float posX = m_posX + m_label.offsetX; float posY = m_posY; uint32_t align = m_label.align & XBFONT_CENTER_Y; if (m_label.align & XBFONT_CENTER_Y) posY += m_height*0.5f; if (leftTextWidth > 0) { // render the text on the left if (IsDisabled()) m_textLayout.Render(posX, posY, m_label.angle, m_label.disabledColor, m_label.shadowColor, align, leftTextWidth, true); else if (HasFocus() && m_label.focusedColor) m_textLayout.Render(posX, posY, m_label.angle, m_label.focusedColor, m_label.shadowColor, align, leftTextWidth); else m_textLayout.Render(posX, posY, m_label.angle, m_label.textColor, m_label.shadowColor, align, leftTextWidth); posX += leftTextWidth + spaceWidth; maxTextWidth -= leftTextWidth + spaceWidth; } if (g_graphicsContext.SetClipRegion(posX, m_posY, maxTextWidth, m_height)) { if (m_textWidth < maxTextWidth) { // align text as our text fits if (leftTextWidth > 0) { // right align as we have 2 labels posX = m_posX + m_width - m_label.offsetX; align |= XBFONT_RIGHT; } else { // align by whatever the skinner requests if (m_label.align & XBFONT_CENTER_X) posX += 0.5f*maxTextWidth; if (m_label.align & XBFONT_RIGHT) posX += maxTextWidth; align |= (m_label.align & 3); } } CStdStringW text = GetDisplayedText(); // let's render it ourselves if (HasFocus() && !m_highlighted) { // cursor location assumes utf16 text, so deal with that (inefficient, but it's not as if it's a high-use area // virtual keyboard only) CStdStringW col; if ((SDL_GetTicks() % 800) <= 400) col.Format(L"|"); else col.Format(L" "); text.Insert(m_cursorPos, col); } m_textLayout2.SetText(text); if (m_highlighted && m_text2.size() > 0) { float highlightY = posY; if (m_label.align & XBFONT_CENTER_Y) highlightY -= m_textHeight * 0.5f; CRect rect(posX, highlightY, posX + m_textLayout2.GetTextWidth(), highlightY + m_textHeight); #if defined(HAS_GLES) CGUITextureGLES::DrawQuad(rect, (color_t) m_label.selectedBackColor); #elif defined(HAS_GL) CGUITextureGL::DrawQuad(rect, (color_t) m_label.selectedBackColor); #elif defined(HAS_DX) CGUITextureD3D::DrawQuad(rect, (color_t) m_label.selectedBackColor); #endif } if (IsDisabled()) m_textLayout2.Render(posX + m_textOffset, posY, m_label.angle, m_label.disabledColor, m_label.shadowColor, align, m_textWidth, true); else if (m_highlighted) m_textLayout2.Render(posX + m_textOffset, posY, m_label.angle, m_label.selectedColor, m_label.shadowColor, align, m_textWidth); else if (HasFocus() && m_label.focusedColor) m_textLayout2.Render(posX + m_textOffset, posY, m_label.angle, m_label.focusedColor, m_label.shadowColor, align, m_textWidth); else m_textLayout2.Render(posX + m_textOffset, posY, m_label.angle, m_label.textColor, m_label.shadowColor, align, m_textWidth); if (m_text2.size() == 0) { m_emptyLayout.Render(posX + 5, posY, m_emptyLabelInfo.angle, m_emptyLabelInfo.textColor, m_emptyLabelInfo.shadowColor, align, m_emptyLayout.GetTextWidth(), true); } g_graphicsContext.RestoreClipRegion(); } }