Esempio n. 1
0
CDebugLog::~CDebugLog()
{
    LISTNODE                                 pos = NULL;
    CDebugLogElement                        *pLogElem = NULL;

    for(DWORD i = 0; i < FUSION_BIND_LOG_CATEGORY_MAX; i++) {
        pos = _listDbgMsg[i].GetHeadPosition();

        while (pos) {
            pLogElem = _listDbgMsg[i].GetNext(pos);
            SAFEDELETE(pLogElem);
        }

        _listDbgMsg[i].RemoveAll();

    }

    SAFEDELETEARRAY(_pwzAsmName);

    pos = _listHeaderMsg.GetHeadPosition();
    while(pos) {
        pLogElem = _listHeaderMsg.GetNext(pos);
        SAFEDELETE(pLogElem);
    }

    _listHeaderMsg.RemoveAll();

    SAFEDELETEARRAY(_wzEXEName);

    
}
Esempio n. 2
0
HRESULT UrlCombineUnescape(LPCWSTR pszBase, LPCWSTR pszRelative, LPWSTR pszCombined, LPDWORD pcchCombined, DWORD dwFlags)
{
    HRESULT                                   hr = S_OK;
    DWORD                                     dwSize;
    LPWSTR                                    pwzCombined = NULL;
    LPWSTR                                    pwzFileCombined = NULL;

    pwzCombined = NEW(WCHAR[MAX_URL_LENGTH]);
    if (!pwzCombined) {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }
    // If we're just combining an absolute file path to an relative file
    // path, do this by concatenating the strings, and canonicalizing it.
    // This avoids UrlCombine randomness where you could end up with
    // a partially escaped (and partially unescaped) resulting URL!

    if (!PathIsURLW(pszBase) && PathIsRelativeWrap(pszRelative)) {
        pwzFileCombined = NEW(WCHAR[MAX_URL_LENGTH]);
        if (!pwzFileCombined) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }

        wnsprintfW(pwzFileCombined, MAX_URL_LENGTH, L"%ws%ws", pszBase, pszRelative);

        hr = UrlCanonicalizeUnescape(pwzFileCombined, pszCombined, pcchCombined, 0);
        goto Exit;
    }
    else {
        dwSize = MAX_URL_LENGTH;
        hr = UrlCombineW(pszBase, pszRelative, pwzCombined, &dwSize, dwFlags);
        if (FAILED(hr)) {
            goto Exit;
        }
    }

    // Don't unescape if the relative part was already an URL because
    // URLs wouldn't have been escaped during the UrlCombined.

    if (UrlIsW(pwzCombined, URLIS_FILEURL)) {
        hr = UrlUnescapeW(pwzCombined, pszCombined, pcchCombined, 0);
        if (FAILED(hr)) {
            goto Exit;
        }
    }
    else {
        if (*pcchCombined >= dwSize) {
            lstrcpyW(pszCombined, pwzCombined);
        }

        *pcchCombined = dwSize;
    }

Exit:
    SAFEDELETEARRAY(pwzCombined);
    SAFEDELETEARRAY(pwzFileCombined);

    return hr;
}
Esempio n. 3
0
HRESULT CNodeFactory::ProcessCodebaseTag(XML_NODE_INFO **aNodeInfo,
        USHORT cNumRecs,
        CCodebaseHint *pCB)
{
    HRESULT                                            hr = S_OK;
    LPWSTR                                             pwzAttributeNS = NULL;
    USHORT                                             idx = 1;

    ASSERT(aNodeInfo && cNumRecs && pCB);
    ASSERT(!pCB->_pwzVersion && !pCB->_pwzCodebase);

    while (idx < cNumRecs) {
        if (aNodeInfo[idx]->dwType == XML_ATTRIBUTE) {
            // Found an attribute. Find out which one, and extract the data.
            // Note: ::ExtractXMLAttribute increments idx.

            hr = ApplyNamespace(aNodeInfo[idx], &pwzAttributeNS, 0);
            if (FAILED(hr)) {
                goto Exit;
            }

            if (!lstrcmpW(pwzAttributeNS, XML_ATTRIBUTE_VERSION)) {

                hr = ::ExtractXMLAttribute(&(pCB->_pwzVersion), aNodeInfo, &idx, cNumRecs);
                if (FAILED(hr)) {
                    SAFEDELETEARRAY(pwzAttributeNS);
                    goto Exit;
                }
            }
            else if (!lstrcmpW(pwzAttributeNS, XML_ATTRIBUTE_HREF)) {

                hr = ::ExtractXMLAttribute(&(pCB->_pwzCodebase), aNodeInfo, &idx, cNumRecs);
                if (FAILED(hr)) {
                    SAFEDELETEARRAY(pwzAttributeNS);
                    goto Exit;
                }
            }
            else {
                idx++;
            }

            SAFEDELETEARRAY(pwzAttributeNS);
        }
        else {
            idx++;
        }
    }

    if (!pCB->_pwzCodebase) {
        // Data was incomplete.

        hr = HRESULT_FROM_WIN32(ERROR_TAG_NOT_PRESENT);
        goto Exit;
    }

Exit:
    return hr;
}
Esempio n. 4
0
HRESULT CNodeFactory::ProcessBindingRedirectTag(XML_NODE_INFO **aNodeInfo,
        USHORT cNumRecs,
        CBindingRedir *pRedir)
{
    HRESULT                                            hr = S_OK;
    LPWSTR                                             pwzAttributeNS = NULL;
    USHORT                                             idx = 1;

    ASSERT(aNodeInfo && cNumRecs && pRedir);
    ASSERT(!pRedir->_pwzVersionOld && !pRedir->_pwzVersionNew);

    while (idx < cNumRecs) {
        if (aNodeInfo[idx]->dwType == XML_ATTRIBUTE) {
            // Found an attribute. Find out which one, and extract the data.
            // Note: ::ExtractXMLAttribute increments idx.

            hr = ApplyNamespace(aNodeInfo[idx], &pwzAttributeNS, 0);
            if (FAILED(hr)) {
                goto Exit;
            }

            if (!lstrcmpW(pwzAttributeNS, XML_ATTRIBUTE_OLDVERSION)) {

                hr = ::ExtractXMLAttribute(&(pRedir->_pwzVersionOld), aNodeInfo, &idx, cNumRecs);
                if (FAILED(hr)) {
                    SAFEDELETEARRAY(pwzAttributeNS);
                    goto Exit;
                }
            }
            else if (!lstrcmpW(pwzAttributeNS, XML_ATTRIBUTE_NEWVERSION)) {

                hr = ::ExtractXMLAttribute(&(pRedir->_pwzVersionNew), aNodeInfo, &idx, cNumRecs);
                if (FAILED(hr)) {
                    SAFEDELETEARRAY(pwzAttributeNS);
                    goto Exit;
                }
            }
            else {
                idx++;
            }

            SAFEDELETEARRAY(pwzAttributeNS);
        }
        else {
            idx++;
        }
    }

    if (!pRedir->_pwzVersionOld || !pRedir->_pwzVersionNew) {
        // Data was incomplete. These are required fields.

        hr = HRESULT_FROM_WIN32(ERROR_TAG_NOT_PRESENT);
        goto Exit;
    }

Exit:
    return hr;
}
Esempio n. 5
0
MD5Parser::~MD5Parser(){
	SAFEDELETEARRAY(joints);
	SAFEDELETEARRAY(meshes);
	SAFEDELETEARRAY(bounds);
	for (unsigned int i = 0; i < numFrames; i++){
		SAFEDELETEARRAY(frames[i]);
	}
	frames.clear();
}
Esempio n. 6
0
HRESULT CNodeFactory::ProcessPublisherPolicyTag(XML_NODE_INFO **aNodeInfo,
        USHORT cNumRecs,
        BOOL bGlobal)
{
    HRESULT                                            hr = S_OK;
    LPWSTR                                             pwzAttributeNS = NULL;
    LPWSTR                                             pwzTmp = NULL;
    USHORT                                             idx = 1;

    ASSERT(aNodeInfo && cNumRecs);

    while (idx < cNumRecs) {
        if (aNodeInfo[idx]->dwType == XML_ATTRIBUTE) {
            // Found an attribute. Find out which one, and extract the data.
            // Node: ::ExtractXMLAttribute increments idx.

            hr = ApplyNamespace(aNodeInfo[idx], &pwzAttributeNS, 0);
            if (FAILED(hr)) {
                goto Exit;
            }

            if (!lstrcmpW(pwzAttributeNS, XML_ATTRIBUTE_APPLY)) {
                hr = ::ExtractXMLAttribute(&pwzTmp, aNodeInfo, &idx, cNumRecs);
                if (FAILED(hr)) {
                    SAFEDELETEARRAY(pwzAttributeNS);
                    goto Exit;
                }

                if (!lstrcmpW(pwzTmp, L"no")) {
                    if (bGlobal) {
                        _bGlobalSafeMode = TRUE;
                    }
                    else {
                        _pAsmInfo->_bApplyPublisherPolicy = FALSE;
                    }
                }

                SAFEDELETEARRAY(pwzTmp);
            }
            else {
                idx++;
            }

            SAFEDELETEARRAY(pwzAttributeNS);
        }
        else {
            idx++;
        }
    }

Exit:
    return hr;
}
void CSampleGrabberCallback2::ReleaseCusBuffer()
	{
	SAFEDELETEARRAY(m_CusBuffer.pBuffer0);
	SAFEDELETEARRAY(m_CusBuffer.pBuffer1);

	m_CusBuffer.sizeBuf0.cx = 0;
	m_CusBuffer.sizeBuf0.cy = 0;
	m_CusBuffer.sizeBuf1.cx = 0;
	m_CusBuffer.sizeBuf1.cy = 0;
	m_CusBuffer.ulBufLen0 = 0;
	m_CusBuffer.ulBufLen1 = 0;

	m_CusBuffer.bIsTwoBuffer = FALSE;
	}
Esempio n. 8
0
HRESULT ExtractXMLAttribute(LPWSTR *ppwzValue, XML_NODE_INFO **aNodeInfo,
                            USHORT *pCurIdx, USHORT cNumRecs)
{
    HRESULT                                  hr = S_OK;
    LPWSTR                                   pwzCurBuf = NULL;

    ASSERT(ppwzValue && aNodeInfo && pCurIdx && cNumRecs);

    // There shouldn't really be a previous value, but clear just to be safe.

    SAFEDELETEARRAY(*ppwzValue);

    (*pCurIdx)++;
    while (*pCurIdx < cNumRecs) {
        
        if (aNodeInfo[*pCurIdx]->dwType == XML_PCDATA ||
            aNodeInfo[*pCurIdx]->dwType == XML_ENTITYREF) {

            hr = AppendString(&pwzCurBuf, aNodeInfo[*pCurIdx]->pwcText,
                              aNodeInfo[*pCurIdx]->ulLen);
            if (FAILED(hr)) {
                goto Exit;
            }
        }
        else {
            // Reached end of data
            break;
        }

        (*pCurIdx)++;
    }

    if (!pwzCurBuf || !lstrlenW(pwzCurBuf)) {
        *ppwzValue = NULL;

        goto Exit;
    }

    *ppwzValue = WSTRDupDynamic(pwzCurBuf);
    if (!*ppwzValue) {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

Exit:
    SAFEDELETEARRAY(pwzCurBuf);

    return hr;
}
Esempio n. 9
0
void ArrayImpl::setCapacity(size_t capacity) {
  if(capacity != m_capacity) {
    if((int)capacity < m_size) {
      capacity = m_size;
    }
    if(capacity == 0) {
      capacity = 1;
    }

    void **newBuffer = new void*[capacity]; TRACE_NEW(newBuffer);
    if(m_size > 0) {
      memcpy(newBuffer,m_elem,sizeof(m_elem[0])*m_size);
    }
    SAFEDELETEARRAY(m_elem);
    m_elem = newBuffer;

#ifdef DEBUG_ARRAYIMPL
    if(capacity > m_capacity)
      resizeUpCounter++;
    else
      resizeDownCounter++;
#endif

    m_capacity = capacity;
  }
}
Esempio n. 10
0
CNodeFactory::~CNodeFactory()
{
    LISTNODE                           pos = NULL;
    CAsmBindingInfo                   *pAsmInfo = NULL;
    CQualifyAssembly                  *pqa = NULL;

    SAFEDELETEARRAY(_pwzPrivatePath);
    SAFERELEASE(_pdbglog);

    pos = _listAsmInfo.GetHeadPosition();
    while (pos) {
        pAsmInfo = _listAsmInfo.GetNext(pos);
        SAFEDELETE(pAsmInfo);
    }

    _listAsmInfo.RemoveAll();

    pos = _listQualifyAssembly.GetHeadPosition();
    while (pos) {
        pqa = _listQualifyAssembly.GetNext(pos);
        SAFEDELETE(pqa);
    }

    _listQualifyAssembly.RemoveAll();

    SAFEDELETE(_pAsmInfo);
}
Esempio n. 11
0
HRESULT CNodeFactory::ApplyNamespace(XML_NODE_INFO *pNodeInfo, LPWSTR *ppwzTokenNS,
                                     DWORD dwFlags)
{
    HRESULT                                  hr = S_OK;
    LPWSTR                                   pwzToken = NULL;

    ASSERT(pNodeInfo && ppwzTokenNS);

    if (!StrCmpN(pNodeInfo->pwcText, XML_NAMESPACE_TAG, XML_NAMESPACE_TAG_LEN)) {
        hr = S_FALSE;
        goto Exit;
    }

    pwzToken = NEW(WCHAR[pNodeInfo->ulLen + 1]);
    if (!pwzToken) {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

    StrCpyNW(pwzToken, pNodeInfo->pwcText, pNodeInfo->ulLen + 1);

    hr = _nsmgr.Map(pwzToken, ppwzTokenNS, dwFlags);
    if (FAILED(hr)) {
        goto Exit;
    }

Exit:
    SAFEDELETEARRAY(pwzToken);

    return hr;
}
Esempio n. 12
0
CDebugLog::~CDebugLog()
{
    LISTNODE                                 pos = NULL;
    CDebugLogElement                        *pLogElem = NULL;

    pos = _listDbgMsg.GetHeadPosition();

    while (pos) {
        pLogElem = _listDbgMsg.GetNext(pos);
        SAFEDELETE(pLogElem);
    }

    _listDbgMsg.RemoveAll();

    SAFEDELETEARRAY(_pwzAsmName);
    SAFEDELETEARRAY(_wzEXEName);
}
BOOL CSampleGrabberCallback2::ImageConvert_900M()
	{
	ASSERT(NULL != m_CusBuffer.pBuffer0);
	ASSERT(NULL != m_CusBuffer.pBuffer1);
	if (NULL == m_CusBuffer.pBuffer0 || NULL == m_CusBuffer.pBuffer1)
		{
		return FALSE;
		}

	// +++++
	BYTE *pAllBuffer = NULL;	
	long lAllBufferLen = m_CusBuffer.sizeBuf0.cx * m_CusBuffer.sizeBuf0.cy * 2;
	pAllBuffer = new BYTE[lAllBufferLen];
	if (NULL == pAllBuffer)
		{
		return FALSE;
		}
	memset(pAllBuffer, 0, lAllBufferLen);	
	RGB24_GeomMirV(m_CusBuffer.pBuffer1, m_CusBuffer.sizeBuf1.cy/2, m_CusBuffer.sizeBuf1.cx);
	memcpy(pAllBuffer, m_CusBuffer.pBuffer0, m_CusBuffer.ulBufLen0);	
	memcpy(pAllBuffer+m_CusBuffer.ulBufLen0, m_CusBuffer.pBuffer1, m_CusBuffer.ulBufLen1);
	// -----

	BYTE *pImage = NULL;
	long lsize = m_CusBuffer.sizeBuf0.cx * m_CusBuffer.sizeBuf0.cy * 3;
	long lwidth = m_CusBuffer.sizeBuf0.cx;
	long lheight = m_CusBuffer.sizeBuf0.cy;
	pImage = new BYTE[lsize];
	if (NULL == pImage)
		{
		return FALSE;
		}

	m_FmtConvAtc.RAW8ToRGB24(pAllBuffer, pImage, lwidth, lheight);
	SAFEDELETEARRAY(pAllBuffer);	

	BITMAPFILEHEADER	hdr;
	hdr.bfType		= MAKEWORD('B', 'M');	// always is "BM"
	hdr.bfSize		= lsize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
	hdr.bfReserved1 = 0;
	hdr.bfReserved2 = 0;
	hdr.bfOffBits	 = (DWORD) (sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER));

	BITMAPINFOHEADER bih; 
	ZeroMemory(&bih, sizeof(bih));
	bih.biSize = sizeof(BITMAPINFOHEADER); 
	bih.biWidth = lwidth; 
	bih.biHeight = lheight; 		
	bih.biBitCount = 24;
	bih.biPlanes = 1;
	bih.biCompression = BI_RGB;
	bih.biSizeImage = 0;		

	// 初始化Bitmap		
	g_lpBits = pImage;
	g_fhdr = hdr;
	g_ihdr = bih;		
	}
Esempio n. 14
0
HRESULT CNodeFactory::ProcessProbingTag(XML_NODE_INFO **aNodeInfo, USHORT cNumRecs)
{
    HRESULT                                            hr = S_OK;
    USHORT                                             idx = 1;
    LPWSTR                                             pwzAttributeNS = NULL;

    ASSERT(aNodeInfo && cNumRecs);

    while (idx < cNumRecs) {
        if (aNodeInfo[idx]->dwType == XML_ATTRIBUTE) {
            // Found an attribute. Find out which one, and extract the data.
            // Node: ::ExtractXMLAttribute increments idx.

            hr = ApplyNamespace(aNodeInfo[idx], &pwzAttributeNS, 0);
            if (FAILED(hr)) {
                goto Exit;
            }

            if (!lstrcmpW(pwzAttributeNS, XML_ATTRIBUTE_PRIVATEPATH)) {
                SAFEDELETEARRAY(pwzAttributeNS);

                if (_pwzPrivatePath) {
                    DEBUGOUT(_pdbglog, 1, ID_FUSLOG_PRIVATE_PATH_DUPLICATE);
                    idx++;
                }
                else {
                    hr = ::ExtractXMLAttribute(&_pwzPrivatePath, aNodeInfo, &idx, cNumRecs);
                    if (FAILED(hr)) {
                        goto Exit;
                    }
                }
            }
            else {
                SAFEDELETEARRAY(pwzAttributeNS);
                idx++;
            }
        }
        else {
            idx++;
        }
    }

Exit:
    return hr;
}
Esempio n. 15
0
ArrayImpl::~ArrayImpl() {
  clear();
  SAFEDELETE(m_objectManager);
  SAFEDELETEARRAY(m_elem);

#ifdef DEBUG_ARRAYIMPL
  descounter++;
#endif
}
Esempio n. 16
0
String Tokenizer::next() {
  StringIndex tmp;
  nextIndex(tmp);
  if(tmp.m_length >= m_stringBufferSize) {
    SAFEDELETEARRAY(m_stringBuffer);
    m_stringBuffer = new TCHAR[m_stringBufferSize = 2 * (tmp.m_length+1)]; TRACE_NEW(m_stringBuffer);
  }
  _tcsncpy(m_stringBuffer,(const TCHAR*)m_str+tmp.m_start, tmp.m_length);
  m_stringBuffer[tmp.m_length] = 0;
  return m_stringBuffer;
}
Esempio n. 17
0
HRESULT VersionFromString(LPCWSTR wzVersionIn, WORD *pwVerMajor, WORD *pwVerMinor,
                          WORD *pwVerBld, WORD *pwVerRev)
{
    HRESULT                                  hr = S_OK;
    LPWSTR                                   wzVersion = NULL;
    WCHAR                                   *pchStart = NULL;
    WCHAR                                   *pch = NULL;
    WORD                                    *pawVersions[4] = {pwVerMajor, pwVerMinor, pwVerBld, pwVerRev};
    int                                      i;

    if (!wzVersionIn || !pwVerMajor || !pwVerMinor || !pwVerRev || !pwVerBld) {
        hr = E_INVALIDARG;
        goto Exit;
    }                          

    wzVersion = WSTRDupDynamic(wzVersionIn);
    if (!wzVersion) {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

    pchStart = wzVersion;
    pch = wzVersion;

    *pwVerMajor = 0;
    *pwVerMinor = 0;
    *pwVerRev = 0;
    *pwVerBld = 0;

    for (i = 0; i < 4; i++) {

        while (*pch && *pch != L'.') {
            pch++;
        }
    
        if (i < 3) {
            if (!*pch) {
                // Badly formatted string
                hr = E_UNEXPECTED;
                goto Exit;
            }

            *pch++ = L'\0';
        }
    
        *(pawVersions[i]) = (WORD)StrToIntW(pchStart);
        pchStart = pch;
    }

Exit:
    SAFEDELETEARRAY(wzVersion);

    return hr;
}
Esempio n. 18
0
HRESULT CDebugLog::DebugOut(DWORD dwDetailLvl, DWORD dwResId, ...)
{
    HRESULT                                  hr = S_OK;
    va_list                                  args;
    LPWSTR                                   wzFormatString = NULL;
    LPWSTR                                   wzDebugStr = NULL;

    wzFormatString = NEW(WCHAR[MAX_DBG_STR_LEN]);
    if (!wzFormatString) {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

    wzDebugStr = NEW(WCHAR[MAX_DBG_STR_LEN]);
    if (!wzDebugStr) {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }
    
    wzFormatString[0] = L'\0';

    if (!_LoadString(dwResId, wzFormatString, MAX_DBG_STR_LEN)) {
        hr = HRESULT_FROM_WIN32(GetLastError());
        goto Exit;
    }

    va_start(args, dwResId);
    wvnsprintfW(wzDebugStr, MAX_DBG_STR_LEN, wzFormatString, args);
    va_end(args);

    hr = LogMessage(dwDetailLvl, wzDebugStr, FALSE);
    if (FAILED(hr)) {
        goto Exit;
    }

Exit:
    SAFEDELETEARRAY(wzDebugStr);
    SAFEDELETEARRAY(wzFormatString);

    return hr;
}
Esempio n. 19
0
BitSet &BitSet::operator=(const BitSet &rhs) {
  if(this == &rhs) {
    return *this;
  }
  const size_t atomCount = _BS_ATOMCOUNT(rhs.m_capacity);
  if(rhs.m_capacity != m_capacity) {
    SAFEDELETEARRAY(m_p);
    m_capacity = rhs.m_capacity;
    m_p = new Atom[atomCount]; TRACE_NEW(m_p);
  }
  memcpy(m_p,rhs.m_p,atomCount * sizeof(Atom));
  return *this;
}
Esempio n. 20
0
void Texture::Destroy(void)
{
	mCreated = false;

	SAFERELEASE(mTexture);
	SAFEDELETEARRAY(mBuffer);

	mSize = NULL;
	mWidth = NULL;
	mHeight = NULL;
	mMipmaps = NULL;
	mUsage = NULL;
	mLevels = NULL;
}
Esempio n. 21
0
FileVersion::FileVersion(const String &filename) {
  DWORD dummyhandle;
  TCHAR filename1[256];
  _tcscpy(filename1, filename.cstr()); // take a copy. Used for windows-functions which are not const.
  int fvsize = GetFileVersionInfoSize(filename1, &dummyhandle);
  if(fvsize == 0) {
    throwLastErrorOnSysCallException(_T("GetFileVersionInfoSize"));
  }
  __assume(dummyhandle);
  BYTE *data = new BYTE[fvsize]; TRACE_NEW(data);
  try {
    if(GetFileVersionInfo(filename1,dummyhandle,fvsize,data) == 0) {
      throwLastErrorOnSysCallException(_T("GetFileVersionInfo"));
    }
    void *p;
    UINT pulen;
    if(VerQueryValue(data,_T("\\"),&p,&pulen) == 0) {
      throwException(_T("No rootelement in ressource"));
    }
    m_fixedFileInfo = *(VS_FIXEDFILEINFO*)p;

    if(VerQueryValue(data,_T("\\VarFileInfo\\Translation"),&p,&pulen) == 0) {
      SAFEDELETEARRAY(data);
      return;
    }
    int transcount = pulen / 4;
    VarFileInfoTranslation *trans = (VarFileInfoTranslation*)p;
    for(int i = 0; i < transcount; i++) {
      m_fileInfo.add(StringFileInfo(data,trans+i));
    }
    SAFEDELETEARRAY(data);
  } catch(...) {
    SAFEDELETEARRAY(data);
    throw;
  }
}
Esempio n. 22
0
DWORD PAL_IniReadStringEx(HINI hIni, LPCWSTR lpAppName, LPCWSTR lpKeyName,
                                 LPWSTR *ppwzReturnedString)
{
    DWORD                                        dwRet;
    LPWSTR                                       pwzBuf = NULL;
    int                                          iSizeCur = INI_READ_BUFFER_SIZE;


    for (;;) {
        pwzBuf = NEW(WCHAR[iSizeCur]);
        if (!pwzBuf) {
            dwRet = 0;
            *ppwzReturnedString = NULL;
            goto Exit;
        }
    
        dwRet = PAL_IniReadString(hIni, lpAppName, lpKeyName, 
                                        pwzBuf, iSizeCur);
        if (lpAppName && lpKeyName && dwRet == (DWORD) (iSizeCur - 1)) {
            SAFEDELETEARRAY(pwzBuf);
            iSizeCur += INI_READ_BUFFER_SIZE;
        }
        else if ((!lpAppName || !lpKeyName) && dwRet == (DWORD) (iSizeCur - 2)) {
            SAFEDELETEARRAY(pwzBuf);
            iSizeCur += INI_READ_BUFFER_SIZE;
        }
        else {
            break;
        }
    }

    *ppwzReturnedString = pwzBuf;

Exit:
    return dwRet;
}
Esempio n. 23
0
void BitSet::setCapacity(size_t newCapacity) {
  const size_t newAtomCount = _BS_ATOMCOUNT(newCapacity);
  const size_t oldAtomCount = _BS_ATOMCOUNT(m_capacity );
  if(newAtomCount != oldAtomCount) {
    Atom *p = new Atom[newAtomCount]; TRACE_NEW(p);
    if(newAtomCount > oldAtomCount) {
      memcpy(p, m_p, oldAtomCount * sizeof(Atom));
      memset(p + oldAtomCount, 0, (newAtomCount-oldAtomCount) * sizeof(Atom));
    } else {
      memcpy(p, m_p, newAtomCount * sizeof(Atom));
    }
    SAFEDELETEARRAY(m_p);
    m_p = p;
  }
  m_capacity = newCapacity;
}
Esempio n. 24
0
HRESULT CDebugLogElement::Dump(HANDLE hFile)
{
    HRESULT                                        hr = S_OK;
    DWORD                                          dwLen = 0;
    DWORD                                          dwWritten = 0;
    DWORD                                          dwSize = 0;
    DWORD                                          dwBufSize = 0;
    LPSTR                                          szBuf = NULL;
    BOOL                                           bRet;

    if (!hFile) {
        hr = E_INVALIDARG;
        goto Exit;
    }

    dwSize = lstrlenW(_pszMsg) + 1;

    // Allocate for worst-case scenario where the UTF-8 size is 3 bytes
    // (ie. 1 byte greater than the 2-byte UNICODE char)./
    
    dwBufSize = dwSize * (sizeof(WCHAR) + 1);

    szBuf = NEW(CHAR[dwBufSize]);
    if (!szBuf) {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }
    
    dwLen = WszWideCharToMultiByte(CP_UTF8, 0, _pszMsg, dwSize, szBuf, dwBufSize, NULL, NULL);
    if (!dwLen) {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

    bRet = WriteFile(hFile, szBuf, dwLen, &dwWritten, NULL);
    if (!bRet) {
        hr = HRESULT_FROM_WIN32(GetLastError());
        goto Exit;
    }
    
Exit:
    SAFEDELETEARRAY(szBuf);

    return hr;
}
Esempio n. 25
0
HRESULT CNodeFactory::QualifyAssembly(LPCWSTR pwzDisplayName, IAssemblyName **ppNameQualified, CDebugLog *pdbglog)
{
    HRESULT                                  hr = S_OK;
    LPWSTR                                   wzDispName=NULL;
    DWORD                                    dwSize;
    CQualifyAssembly                        *pqa;
    LISTNODE                                 pos;

    wzDispName = NEW(WCHAR[MAX_URL_LENGTH+1]);
    if (!wzDispName)
    {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

    pos = _listQualifyAssembly.GetHeadPosition();
    while (pos) {
        pqa = _listQualifyAssembly.GetNext(pos);
        if (!lstrcmpW(pwzDisplayName, pqa->_pwzPartialName)) {
            // Found match

            *ppNameQualified = pqa->_pNameFull;
            (*ppNameQualified)->AddRef();

            dwSize = MAX_URL_LENGTH;
            if ((*ppNameQualified)->GetDisplayName(wzDispName, &dwSize, 0) == S_OK) {
                DEBUGOUT1(pdbglog, 0, ID_FUSLOG_QUALIFIED_ASSEMBLY, wzDispName);
            }

            goto Exit;
        }
    }

    // No match found

    hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND);

Exit:
    SAFEDELETEARRAY(wzDispName);
    return hr;
}
Esempio n. 26
0
HRESULT AppendString(LPWSTR *ppwzHead, LPCWSTR pwzTail, DWORD dwLen)
{
    HRESULT                                    hr = S_OK;
    LPWSTR                                     pwzBuf = NULL;
    DWORD                                      dwLenBuf;
    
    ASSERT(ppwzHead && pwzTail);

    if (!*ppwzHead) {
        *ppwzHead = NEW(WCHAR[dwLen + 1]);

        if (!*ppwzHead) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
 
        // StrCpyN takes length in chars *including* NULL char

        StrCpyNW(*ppwzHead, pwzTail, dwLen + 1);
    }
    else {
        dwLenBuf = lstrlenW(*ppwzHead) + dwLen + 1;

        pwzBuf = NEW(WCHAR[dwLenBuf]);
        if (!pwzBuf) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }

        StrCpyW(pwzBuf, *ppwzHead);
        StrNCatW(pwzBuf, pwzTail, dwLen + 1);

        SAFEDELETEARRAY(*ppwzHead);

        *ppwzHead = pwzBuf;
    }

Exit:
    return hr;
}
Esempio n. 27
0
HRESULT CDebugLog::SetProperties(IApplicationContext *pAppCtx)
{
    HRESULT                                  hr = S_OK;
    LPWSTR                                   wzAppName = NULL;

    // Get the executable name
    if (pAppCtx) {
        hr = ::AppCtxGetWrapper(pAppCtx, ACTAG_APP_NAME, &wzAppName);
        if (FAILED(hr)) {
            goto Exit;
        }
    }

    if (wzAppName && lstrlenW(wzAppName)) {
        _wzEXEName = WSTRDupDynamic(wzAppName);
        if (!_wzEXEName) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
    }
    else {
        LPWSTR               wzFileName;

        // Didn't find EXE name in appctx. Use the .EXE name.
        wzFileName = PathFindFileName(g_wzEXEPath);
        _ASSERTE(wzFileName);

        _wzEXEName = WSTRDupDynamic(wzFileName);
        if (!_wzEXEName) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
    }

Exit:
    SAFEDELETEARRAY(wzAppName);

    return hr;
}
Esempio n. 28
0
HRESULT GetHash(LPCTSTR szFileName, ALG_ID iHashAlg, PBYTE pbHash, DWORD *pdwHash)
{

#define MAX_ARRAY_SIZE  16384
#define HASH_BUFFER_SIZE (MAX_ARRAY_SIZE-4)

    HRESULT    hr = E_FAIL;
    HCRYPTPROV hProv = 0;
    HCRYPTHASH hHash = 0;
    DWORD      dwBufferLen;
    BYTE      *pbBuffer = NULL;
    HANDLE     hSourceFile = INVALID_HANDLE_VALUE; 

    pbBuffer = NEW(BYTE[MAX_ARRAY_SIZE]);
    if (!pbBuffer) {
        hr = E_OUTOFMEMORY;
        goto exit;
    }

    if(!WszCryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) 
    {
        hr = HRESULT_FROM_WIN32(GetLastError());
        goto exit;
    }

    if(!CryptCreateHash(hProv, iHashAlg, 0, 0, &hHash)) 
    {
        hr = HRESULT_FROM_WIN32(GetLastError());
        goto exit;
    }

    // Open source file.
    hSourceFile = WszCreateFile (szFileName, GENERIC_READ, FILE_SHARE_READ,
        NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
    if (hSourceFile == INVALID_HANDLE_VALUE)
    {
        hr = HRESULT_FROM_WIN32(GetLastError());
        goto exit;
    }

    while (TRUE) 
    {   
        if (!ReadFile (hSourceFile, pbBuffer, HASH_BUFFER_SIZE, &dwBufferLen, NULL)) 
        {
            hr = HRESULT_FROM_WIN32(GetLastError());
            goto exit;
        }
        
        if (!dwBufferLen) {
            break;
        }
                
        // Add data to hash object.
        if(!CryptHashData(hHash, pbBuffer, dwBufferLen, 0)) {
            hr = HRESULT_FROM_WIN32(GetLastError());
            goto exit;
        }
    }

    if(!CryptGetHashParam(hHash, HP_HASHVAL, pbHash, pdwHash, 0)) {
        hr = HRESULT_FROM_WIN32(GetLastError());
        goto exit;
    }

    hr = S_OK;

 exit:
    SAFEDELETEARRAY(pbBuffer);
    
    if (hHash)
        CryptDestroyHash(hHash);
    if (hProv)
        CryptReleaseContext(hProv,0);
    if (hSourceFile != INVALID_HANDLE_VALUE)
        CloseHandle(hSourceFile);

    return hr;
}
Esempio n. 29
0
/**
*
* CTexture class LoadFromTarga
*
* @author Christopher Howlett
* @param _pRenderer OpenGLRenderer
* @param _pcFilename texture filename
* @param _uiTextureUnit Texture ID
* @return Returns success
*
*/
bool
Texture::LoadFromPNG( const char* _pcFilename, unsigned int _uiTextureUnit)
{
	bool bResult = false;

	std::vector< unsigned char > imageData;
	unsigned int iWidth;
	unsigned int iHeight;
	bResult = ( lodepng::decode( imageData, iWidth, iHeight, _pcFilename  ) == 0 );
	ErrAssert( bResult, L"Could not load PNG" );

	char* pData = new char[imageData.size()];
	for ( unsigned int i = 0; i < imageData.size( ); i += 4 )
	{
		pData[i] = imageData[i];
		pData[i + 1] = imageData[i + 1];
		pData[i + 2] = imageData[i + 2];
		pData[i + 3] = imageData[i + 3];
	}

	//Setup openGL Texture
	glEnable( GL_TEXTURE_2D );
	glActiveTexture( GL_TEXTURE0 + _uiTextureUnit );
	glGenTextures( 1, &m_uiResourceID );
	glBindTexture( GL_TEXTURE_2D, m_uiResourceID ); //Bind texture to ID
	glTexImage2D( GL_TEXTURE_2D,
					0,
					GL_RGBA,
					static_cast<int>( iWidth ),
					static_cast<int>( iHeight ),
					0,
					GL_RGBA,
					GL_UNSIGNED_BYTE,
					pData );

	//Set to Wrap texture
	//glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_WRAP );
	//glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_WRAP );

	//Set texture filtering
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );

	//Generate mipmaps
	glGenerateMipmap( GL_TEXTURE_2D );

	printf( "Loaded %s %iBit texture (%i x %i) at [%i]\n", _pcFilename, 32, iWidth, iHeight, m_uiResourceID );
	m_bIsLoaded = true;
	
	SAFEDELETEARRAY( pData );

	return bResult;
	//
	//
	//std::vector<unsigned char> imageData;
	//unsigned int iWidth;
	//unsigned int iHeight;
	//lodepng::decode(imageData, iWidth, iHeight, _pcFilename);
	//
	////Copy data to a buffer
	//unsigned char* pcBuffer = new unsigned char[imageData.size()];
	//for (unsigned int iChar = 0; iChar < imageData.size(); ++iChar)
	//{
	//	pcBuffer[iChar] = imageData[iChar];
	//}
	//
	////Setup openGL Texture
	//glActiveTexture(GL_TEXTURE0 + _uiTextureUnit);
	//glGenTextures(	1, &m_uiTextureID);
	//glBindTexture(	GL_TEXTURE_2D, m_uiTextureID); //Bind texture to ID
	//glTexImage2D(	GL_TEXTURE_2D,
	//				0,
	//				GL_RGBA,
	//				static_cast<int>(iWidth),
	//				static_cast<int>(iHeight),
	//				0,
	//				GL_BGRA,
	//				GL_UNSIGNED_BYTE,
	//				pcBuffer);
	//
	////Set to Wrap texture
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	//
	////Set texture filtering
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	//
	////Generate mipmaps
	//glGenerateMipmap(GL_TEXTURE_2D);
	//
	//if (m_uiTextureID == 0)
	//{
	//	printf("Failed to load PNG: %s\n", _pcFilename); 
	//	bResult = false;
	//}
	//else
	//{
	//	printf("Loaded Texture: %s (%i x %i)\n", _pcFilename, iWidth, iHeight);
	//	m_bIsLoaded = true;
	//}
	//delete[] pcBuffer;
	//pcBuffer = 0;

	return bResult;
}
Esempio n. 30
0
void  ByteArray::deallocateBytes(BYTE *buffer) {
  SAFEDELETEARRAY(buffer);
}