예제 #1
0
CMString CJabberProto::ExtractImage(HXML node)
{
	HXML nHtml, nBody, nImg;
	LPCTSTR src;
	CMString link;

	if ((nHtml = XmlGetChild(node, "html")) != NULL &&
		(nBody = XmlGetChild(nHtml, "body")) != NULL &&
		(nImg = XmlGetChild(nBody, "img")) != NULL &&
		(src = XmlGetAttrValue(nImg, _T("src"))) != NULL) {

		CMString strSrc(src);
		if (strSrc.Left(11).Compare(L"data:image/") == 0) {
			int end = strSrc.Find(L';');
			if (end != -1) {
				CMString ext(strSrc.c_str() + 11, end - 11);
				int comma = strSrc.Find(L',', end);
				if (comma != -1) {
					CMString image(strSrc.c_str() + comma + 1, strSrc.GetLength() - comma - 1);
					image.Replace(L"%2B", L"+");
					image.Replace(L"%2F", L"/");
					image.Replace(L"%3D", L"=");

					TCHAR tszTempPath[MAX_PATH], tszTempFile[MAX_PATH];
					GetTempPath(_countof(tszTempPath), tszTempPath);
					GetTempFileName(tszTempPath, _T("jab"), InterlockedIncrement(&g_nTempFileId), tszTempFile);
					_tcsncat_s(tszTempFile, _T("."), 1);
					_tcsncat_s(tszTempFile, ext, ext.GetLength());

					HANDLE h = CreateFile(tszTempFile, GENERIC_READ | GENERIC_WRITE,
						FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
						FILE_ATTRIBUTE_NORMAL, NULL);

					if (h != INVALID_HANDLE_VALUE) {
						DWORD n;
						unsigned int bufferLen;
						ptrA buffer((char*)mir_base64_decode(_T2A(image), &bufferLen));
						WriteFile(h, buffer, bufferLen, &n, NULL);
						CloseHandle(h);

						link = _T(" file:///");
						link += tszTempFile;
					}
				}
			}
		}
	}
	return link;
}
예제 #2
0
파일: WebPage.cpp 프로젝트: nk39/mototool
// returned java script function name, input string is truncating
CString CWebPage::ScanJScript(CString& strAText, CStringArray& args)
{
    args.RemoveAll();
    CString strDelim(" \n\r\t"),strSrc(strAText);
    bool bFound = false;
    while(!strSrc.IsEmpty())
    {
        CString strStart = GetNextToken(strSrc,strDelim);
        if(strStart == "function")
        {
            bFound = true;
            break;
        }
        if(strStart == "/*")
        {
            // Skip comments
            while(!strSrc.IsEmpty())
            {
                CString strStop = GetNextToken(strSrc,strDelim);
                if(strStop == "*/")
                {
                    break;
                }
            }
        }
    }

    if(!bFound){
        return _T("");
    }

    CString strFunc = GetNextToken(strSrc, _T("("),true);
    CString strArgs = GetNextToken(strSrc, _T(")"),true);

    // Parse arguments
    CString strArg;
    while(!(strArg = GetNextToken(strArgs, _T(","))).IsEmpty())
        args.Add(strArg);

    strAText= strSrc;
    return strFunc;
}
예제 #3
0
String FormatNum(__int64 n)
{
	static bool first = true;
	static NUMBERFMT fmt;
	static wchar_t DecimalSep[4];
	static wchar_t ThousandSep[4];

	if (first)
	{
		GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_STHOUSAND,ThousandSep,ARRAYSIZE(ThousandSep));
		GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SDECIMAL,DecimalSep,ARRAYSIZE(DecimalSep));
		DecimalSep[1]=0;  //Â âèíäå ñåïàðàòîðû öèôð ìîãóò áûòü áîëüøå îäíîãî ñèìâîëà
		ThousandSep[1]=0; //íî äëÿ íàñ ýòî áóäåò íå î÷åíü õîðîøî

		/*
		if (LOWORD(Global->Opt->FormatNumberSeparators)) {
			*DecimalSep=LOWORD(Global->Opt->FormatNumberSeparators);
		}

		if (HIWORD(Global->Opt->FormatNumberSeparators)) {
			*ThousandSep=HIWORD(Global->Opt->FormatNumberSeparators);
		}
		*/

		fmt.LeadingZero = 1;
		fmt.Grouping = 3;
		fmt.lpDecimalSep = DecimalSep;
		fmt.lpThousandSep = ThousandSep;
		fmt.NegativeOrder = 1;
		fmt.NumDigits = 0;
		first = false;
	}
	
	String strSrc(n);
	int size = GetNumberFormat(LOCALE_USER_DEFAULT, 0, strSrc.c_str(), &fmt, nullptr, 0);
	wchar_t *lpwszDest = new wchar_t[size];
	GetNumberFormat(LOCALE_USER_DEFAULT, 0, strSrc.c_str(), &fmt, lpwszDest, size);
	String strDest(lpwszDest);
	delete(lpwszDest);
	
	return strDest;
}
예제 #4
0
BOOL CSxSParser::ExportFile(LPCTSTR szTag, LPCTSTR szName, LPCTSTR szSrc, LPCTSTR szDst, CString& strMsg) const
{
    CString strTag(szTag);
    strTag += _T("*.manifest");

    CString strSrc(szSrc);
    if(strSrc[strSrc.GetLength() - 1] != _T('\\'))
        strSrc += _T('\\');

    StringList folders = FindMatchedFSObjects(strSrc, strTag, TRUE);

    UINT uCount = folders.GetSize();
    if(uCount == 0)
    {
        strMsg.Format(IDS_ERR_SXS_FOLDER_NOT_EXISTS, szTag);
        return FALSE;
    }

    CString strDst(szDst);
    if(strDst[strDst.GetLength() - 1] != _T('\\'))
        strDst += _T('\\');
    strDst += szName;

    for(UINT i=0; i<uCount; ++ i)
    {
        CString strFrom(strSrc + folders[i]);
        CString strTo(strDst);
        strTo += _T("\\");
        strTo += szName;
        strTo += _T(".manifest");

        if(!::CopyFile(strFrom, strTo, FALSE))
        {
            strMsg.LoadString(IDS_ERR_COPY_FILES);
            return FALSE;
        }
    }
    return TRUE;
}
예제 #5
0
BOOL CSxSParser::ExportFolder(LPCTSTR szTag, LPCTSTR szName, LPCTSTR szSrc, LPCTSTR szDst, CString& strMsg) const
{
    CString strTag(szTag);
    strTag += _T("*");

    CString strSrc(szSrc);
    if(strSrc[strSrc.GetLength() - 1] != _T('\\'))
        strSrc += _T('\\');

    CString strDst(szDst);
    if(strDst[strDst.GetLength() - 1] != _T('\\'))
        strDst += _T('\\');

    StringList folders = FindMatchedFSObjects(strSrc, strTag, FALSE);

    UINT uCount = folders.GetSize();
    if(uCount == 0)
    {
        strMsg.Format(IDS_ERR_SXS_FOLDER_NOT_EXISTS, szTag);
        return FALSE;
    }

    CString strTo(strDst);
    strTo.AppendChar(0);
    CString orgFolder, targetFolder;

    for(UINT i=0; i<uCount; ++ i)
    {
        CString strFrom(strSrc + folders[i]);
        strFrom.AppendChar(0);

        if(!MakeEmptyFolder(strDst + szName))
        {
            strMsg.LoadString(IDS_ERR_MAKE_EMPTY_FOLDER);
            return FALSE;
        }

        SHFILEOPSTRUCT fo = {0};
        fo.hwnd = NULL;
        fo.wFunc = FO_COPY;
        fo.pFrom = strFrom;
        fo.pTo = strTo;
        fo.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_NORECURSION;
        if(0 != SHFileOperation(&fo))
        {
            strMsg.LoadString(IDS_ERR_COPY_FOLDERS);
            return FALSE;
        }

        orgFolder = strDst;
        orgFolder += folders[i];

        targetFolder = strDst;
        targetFolder += szName;

        if(!::MoveFile(orgFolder, targetFolder))
        {
            strMsg.LoadString(IDS_ERR_COPY_FOLDERS);
            return FALSE;
        }
    }
    return TRUE;
}
예제 #6
0
/*
    Deflates source stringstream, encodes compressed bytes into Base64
    and then puts the Base64 encoded data into destination stringstream
*/
int DeflateSStream( std::stringstream &ssSrc, std::stringstream &ssDst )
{
    int ret = Z_OK;

    int flush = true;

    //  Allocate deflate state
    z_stream c_stream; // Compression stream
    c_stream.zalloc = Z_NULL;
    c_stream.zfree  = Z_NULL;
    c_stream.opaque = Z_NULL;

    //  Initialize for deflation
    ret = deflateInit( &c_stream, s_nCompressionLevel );
    if ( ret != Z_OK )
        return ret;

    std::string strSrc( ssSrc.str() );

    //  Free up the source stringstream
    ssSrc.str("");

    int nInputSize  = strSrc.size();
    int nOutputSize = 0;

#ifndef USE_CHUNKS
    //  Allocate buffer for deflate to put data into
    char* out = new char[ nInputSize ];

    c_stream.avail_in   = nInputSize;
    c_stream.avail_out  = nInputSize;
    c_stream.next_in    = ( Bytef* ) strSrc.c_str();
    c_stream.next_out   = ( Bytef* ) out;

    //  Compress
    ret = deflate( &c_stream, Z_FULL_FLUSH /*Z_PARTIAL_FLUSH*/ );
    if ( ret != Z_OK )
        return ret;

    std::string base64Str   = ssDst.str();

    //  How big is the compressed result
    nOutputSize = nInputSize - c_stream.avail_out;

    //  Encode the compressed bytes to Base64
    StringToBase64( out, nOutputSize, base64Str );
    delete[] out;

    //  Put compressed Base64 data into the destination stringstream
    int nBase64 = base64Str.size();
    ssDst.write( base64Str.c_str(), nBase64 );

#else // USE_CHUNKS
    int nRemaining  = nInputSize;
    while ( nRemaining > 0 )
    {
        char out[ s_nChunkSize ];
        unsigned nHave = 0;

        strm.avail_in   = ( nRemaining > s_nChunkSize ) ? s_nChunkSize : nRemaining;
        strm.avail_out  = s_nChunkSize;
        strm.next_in    = ( Bytef* ) strSrc.c_str() + ( nInputSize - nRemaining );
        strm.next_out   = ( Bytef* ) out;

        nRemaining -= strm.avail_in;

        ret = deflate( &strm, flush );
        if ( ret != Z_OK )
            return ret;

        //  How big is the compressed result
        nHave = s_nChunkSize - strm.avail_out;

        ssDst.write( out, nOutputSize );

        nOutputSize += nHave;
    }
#endif // USE_CHUNKS

    //  Free all allocated state information referenced by stream
    ret = deflateEnd( &c_stream );

    return ret;
}