示例#1
0
/******************************************************************************
 Function Name  :   OnChange

 Input(s)       :   -
 Output         :   -
 Functionality  :   Called by the frame work on keying a character. If floating
                    point is not allowed, then charactres until "." are 
                    considered as valid.
 Member of      :   CRadixEdit
 Friend of      :   

 Author(s)      :   Soj Thomas
 Date Created   :   08-03-2002
 Modifications  :   Ratnadip Choudhury, Amarnath Shastry
					Rajesh Kumar 05.03.2003 : call strtol/strtoul based on sign 
 Modifications  :   Amitesh Bharti, 05.06.2003,replace datatype for supporting 
                    64bits to __int64                             
******************************************************************************/
void CRadixEdit::OnChange() 
{
    int nBufLength = LineLength() + 1;
    TCHAR* acBuffer = new TCHAR[nBufLength];

    if (acBuffer != NULL)
    {
        GetWindowText(acBuffer, nBufLength);
        if (m_bFloatAllowed) 
        {
            m_fValue = (float) _tstof(acBuffer);
        }
        else 
        {
			if(m_nBase == BASE_DECIMAL )
			{
				m_n64Value = _tstoi64(acBuffer);
			}
			else 
			{
                INT nCurrentPost = 0;
                __int64 n64Val = 0;
                INT nActualLength = nBufLength - 1;
                BOOL bNegativeNumber = FALSE;
                m_n64Value = 0;

				while(nActualLength > nCurrentPost)
                {
                    if(acBuffer[nCurrentPost] >='0' 
                       && acBuffer[nCurrentPost] <='9')
                    {
                        acBuffer[nCurrentPost] -='0';
                    }
                    else if(acBuffer[nCurrentPost] != '-')
                    {
                        acBuffer[nCurrentPost] = (TCHAR)(tolower(acBuffer[nCurrentPost]));
                        acBuffer[nCurrentPost] -= 87;
                    }
                    else
                    {
                        bNegativeNumber = TRUE;
                    }
                    if(acBuffer[nCurrentPost] != '-')
                    {
                        n64Val = acBuffer[nCurrentPost];
                        n64Val <<= ((nActualLength - nCurrentPost - 1 )* 4 );
                        m_n64Value |= n64Val;
                    }
                    nCurrentPost++;
                }
                if(bNegativeNumber == TRUE )
                {
                    m_n64Value = -m_n64Value;
                }
			}
        }
        delete []acBuffer;
        acBuffer = NULL;
    }
}
示例#2
0
static bool bbCodeImageFunc(IFormattedTextDraw *ftd, CHARRANGE range, TCHAR *txt, DWORD cookie)
{
	ITextServices *ts = ftd->getTextService();
	ITextDocument *td = ftd->getTextDocument();

	long cnt;
	LRESULT lResult;
/*
	TEXTRANGE trg;
	trg.chrg = range;
	trg.lpstrText = new TCHAR[trg.chrg.cpMax - trg.chrg.cpMin + 1];
	ts->TxSendMessage(EM_GETTEXTRANGE, 0, (LPARAM)&trg, &lResult);
	MessageBox(0, txt, trg.lpstrText, MB_OK);
*/
	ts->TxSendMessage(EM_SETSEL, range.cpMin, range.cpMax, &lResult);
	IRichEditOle* RichEditOle;
	ts->TxSendMessage(EM_GETOLEINTERFACE, 0, (LPARAM)&RichEditOle, &lResult);
	td->Freeze(&cnt);
//	HDC emfdc = CreateEnhMetaFile(NULL, NULL, NULL, _T("icon"));
//	DrawIconEx(emfdc, 0, 0, (HICON)_ttol(txt), 16, 16, 0, NULL, DI_NORMAL);
//	InsertBitmap(RichEditOle, CloseEnhMetaFile(emfdc));
#ifdef _WIN64
	bool res = InsertBitmap(RichEditOle, CacheIconToEmf((HICON)_tstoi64(txt)));
#else
	bool res = InsertBitmap(RichEditOle, CacheIconToEmf((HICON)_ttoi(txt)));
#endif

	td->Unfreeze(&cnt);
	RichEditOle->Release();
	return res;
}
示例#3
0
void FormatMessageUrl(LPCTSTR format, LPTSTR buf, LPCTSTR mailbox, LPCTSTR tid)
{
	ULARGE_INTEGER iTid; iTid.QuadPart = _tstoi64(tid);
	size_t l = mir_tstrlen(buf);
	mir_sntprintf(buf, l, format, mailbox, iTid.HighPart, iTid.LowPart);
	assert(l >= mir_tstrlen(buf));
}
示例#4
0
//输入信息
void CDlgBank::OnEnChangeInCount()
{
	CString strCount;
	GetDlgItem(IDC_IN_COUNT)->GetWindowText(strCount);
	m_lInCount=_tstoi64(strCount);

	return ;
}
示例#5
0
void MakeUrlHex(LPTSTR url, LPCTSTR tid)
{
	ULARGE_INTEGER iTid; iTid.QuadPart = _tstoi64(tid);
	LPTSTR tidInUrl = _tcsstr(url, tid);
	LPTSTR trail = tidInUrl + mir_tstrlen(tid);
	wsprintf(tidInUrl, _T("%x%08x"), iTid.HighPart, iTid.LowPart); //!!!!!!!!!!!!
	wmemmove(tidInUrl + mir_tstrlen(tidInUrl), trail, mir_tstrlen(trail) + 1);
}
示例#6
0
void CFilePositionList::Load()
{
    bool hasNextEntry = true;
    CString strFilePos;
    CString strValue;
    FILE_POSITION filePosition;

    for (int i = 0; i < m_nMaxSize && hasNextEntry; i++) {
        strFilePos.Format(_T("File Name %d"), i);
        filePosition.strFile = m_pApp->GetProfileString(m_lpszSection, strFilePos, _T(""));

        strFilePos.Format(_T("File Position %d"), i);
        strValue = m_pApp->GetProfileString(m_lpszSection, strFilePos, _T(""));
        filePosition.llPosition = _tstoi64(strValue);

        if (!filePosition.strFile.IsEmpty()) {
            AddTail(filePosition);
        } else {
            hasNextEntry = false;
        }
    }
}
示例#7
0
static bool bbCodeImageFunc(IFormattedTextDraw *ftd, CHARRANGE range, TCHAR *txt, DWORD)
{
	ITextServices *ts = ftd->getTextService();
	ITextDocument *td = ftd->getTextDocument();

	long cnt;
	LRESULT lResult;
	ts->TxSendMessage(EM_SETSEL, range.cpMin, range.cpMax, &lResult);
	IRichEditOle* RichEditOle;
	ts->TxSendMessage(EM_GETOLEINTERFACE, 0, (LPARAM)&RichEditOle, &lResult);
	td->Freeze(&cnt);

#ifdef _WIN64
	bool res = InsertBitmap(RichEditOle, CacheIconToEmf((HICON)_tstoi64(txt)));
#else
	bool res = InsertBitmap(RichEditOle, CacheIconToEmf((HICON)_ttoi(txt)));
#endif

	td->Unfreeze(&cnt);
	RichEditOle->Release();
	return res;
}
示例#8
0
/////////////////////////////////////////////
// CED2KFileLink implementation
/////////////////////////////////////////////
CED2KFileLink::CED2KFileLink(const TCHAR* pszName, const TCHAR* pszSize, const TCHAR* pszHash, 
							 const CStringArray& astrParams, const TCHAR* pszSources)
	: m_size(pszSize)
{
	// Here we have a little problem.. Actually the proper solution would be to decode from UTF8,
	// only if the string does contain escape sequences. But if user pastes a raw UTF8 encoded
	// string (for whatever reason), we would miss to decode that string. On the other side, 
	// always decoding UTF8 can give flaws in case the string is valid for Unicode and UTF8
	// at the same time. However, to avoid the pasting of raw UTF8 strings (which would lead
	// to a greater mess in the network) we always try to decode from UTF8, even if the string
	// did not contain escape sequences.
	m_name = OptUtf8ToStr(URLDecode(pszName));
	m_name.Trim();
	if (m_name.IsEmpty())
		throw GetResString(IDS_ERR_NOTAFILELINK);

	SourcesList = NULL;
	m_hashset = NULL;
	m_bAICHHashValid = false;

	if (_tcslen(pszHash) != 32)
		throw GetResString(IDS_ERR_ILLFORMEDHASH);

	if (_tstoi64(pszSize)>=4294967295)
		throw GetResString(IDS_ERR_TOOLARGEFILE);
	if (_tstoi64(pszSize)<=0)
		throw GetResString(IDS_ERR_NOTAFILELINK);
	
	for (int idx = 0; idx < 16; ++idx) {
		m_hash[idx] = FromHexDigit(*pszHash++)*16;
		m_hash[idx] += FromHexDigit(*pszHash++);
	}

	bool bError = false;
	for (int i = 0; !bError && i < astrParams.GetCount(); i++)
	{
		const CString& strParam = astrParams.GetAt(i);
		ASSERT( !strParam.IsEmpty() );

		CString strTok;
		int iPos = strParam.Find(_T('='));
		if (iPos != -1)
			strTok = strParam.Left(iPos);
		if (strTok == _T("s"))
		{
			CString strURL = strParam.Mid(iPos + 1);
			if (!strURL.IsEmpty())
			{
				TCHAR szScheme[INTERNET_MAX_SCHEME_LENGTH];
				TCHAR szHostName[INTERNET_MAX_HOST_NAME_LENGTH];
				TCHAR szUrlPath[INTERNET_MAX_PATH_LENGTH];
				TCHAR szUserName[INTERNET_MAX_USER_NAME_LENGTH];
				TCHAR szPassword[INTERNET_MAX_PASSWORD_LENGTH];
				TCHAR szExtraInfo[INTERNET_MAX_URL_LENGTH];
				URL_COMPONENTS Url = {0};
				Url.dwStructSize = sizeof(Url);
				Url.lpszScheme = szScheme;
				Url.dwSchemeLength = ARRSIZE(szScheme);
				Url.lpszHostName = szHostName;
				Url.dwHostNameLength = ARRSIZE(szHostName);
				Url.lpszUserName = szUserName;
				Url.dwUserNameLength = ARRSIZE(szUserName);
				Url.lpszPassword = szPassword;
				Url.dwPasswordLength = ARRSIZE(szPassword);
				Url.lpszUrlPath = szUrlPath;
				Url.dwUrlPathLength = ARRSIZE(szUrlPath);
				Url.lpszExtraInfo = szExtraInfo;
				Url.dwExtraInfoLength = ARRSIZE(szExtraInfo);
				if (InternetCrackUrl(strURL, 0, 0, &Url) && Url.dwHostNameLength > 0)
				{
					SUnresolvedHostname* hostname = new SUnresolvedHostname;
					hostname->strURL = strURL;
					hostname->strHostname = szHostName;
					m_HostnameSourcesList.AddTail(hostname);
				}
			}
			else
				ASSERT(0);
		}
		else if (strTok == _T("p"))
		{
			CString strPartHashs = strParam.Tokenize(_T("="), iPos);

			if (m_hashset != NULL){
				ASSERT(0);
				bError = true;
				break;
			}

			m_hashset = new CSafeMemFile(256);
			m_hashset->WriteHash16(m_hash);
			m_hashset->WriteUInt16(0);

			int iPartHashs = 0;
			int iPosPH = 0;
			CString strHash = strPartHashs.Tokenize(_T(":"), iPosPH);
			while (!strHash.IsEmpty())
			{
				uchar aucPartHash[16];
				if (!strmd4(strHash, aucPartHash)){
					bError = true;
					break;
				}
				m_hashset->WriteHash16(aucPartHash);
				iPartHashs++;
				strHash = strPartHashs.Tokenize(_T(":"), iPosPH);
			}
			if (bError)
				break;

			m_hashset->Seek(16, CFile::begin);
			m_hashset->WriteUInt16(iPartHashs);
			m_hashset->Seek(0, CFile::begin);
		}
		else if (strTok == _T("h"))
		{
			CString strHash = strParam.Mid(iPos + 1);
			if (!strHash.IsEmpty())
			{
				if (DecodeBase32(strHash, m_AICHHash.GetRawHash(), CAICHHash::GetHashSize()) == CAICHHash::GetHashSize()){
					m_bAICHHashValid = true;
					ASSERT( m_AICHHash.GetString().CompareNoCase(strHash) == 0 );
				}
				else
					ASSERT( false );
			}
			else
				ASSERT( false );
		}
		else
			ASSERT(0);
	}

	if (bError)
	{
		delete m_hashset;
		m_hashset = NULL;
	}

	if (pszSources)
	{
		TCHAR* pNewString = _tcsdup(pszSources);
		autoFree liberator(pNewString);
		TCHAR* pCh = pNewString;
		TCHAR* pEnd;
		TCHAR* pIP;
		TCHAR* pPort;

		bool bAllowSources;
		TCHAR date[3];
		COleDateTime expirationDate;
		int nYear,nMonth,nDay;

		uint16 nCount = 0;
		uint32 dwID;
		uint16 nPort;
		uint32 dwServerIP = 0; 
		uint16 nServerPort = 0;
		unsigned long ul;

		int nInvalid = 0;

		pCh = _tcsstr( pCh, _T("sources") );
		if( pCh != NULL ) {
			pCh = pCh + 7; // point to char after "sources"
			pEnd = pCh;
			while( *pEnd ) pEnd++; // make pEnd point to the terminating NULL
			bAllowSources=true;
			// if there's an expiration date...
			if( *pCh == _T('@') && (pEnd-pCh) > 7 )
			{
				pCh++; // after '@'
				date[2] = 0; // terminate the two character string
				date[0] = *(pCh++); date[1] = *(pCh++);
				nYear = _tcstol( date, 0, 10 ) + 2000;
				date[0] = *(pCh++); date[1] = *(pCh++);
				nMonth = _tcstol( date, 0, 10 );
				date[0] = *(pCh++); date[1] = *(pCh++);
				nDay = _tcstol( date, 0, 10 );
				bAllowSources = ( expirationDate.SetDate(nYear,nMonth,nDay) == 0 );
				if (bAllowSources) bAllowSources=(COleDateTime::GetCurrentTime() < expirationDate);
			}

			// increment pCh to point to the first "ip:port" and check for sources
			if ( bAllowSources && ++pCh < pEnd ) {
				SourcesList = new CSafeMemFile(256);
				SourcesList->WriteUInt16(nCount); // init to 0, we'll fix this at the end.
				// for each "ip:port" source string until the end
				// limit to prevent overflow (uint16 due to CPartFile::AddClientSources)
				while( *pCh != 0 && nCount < MAXSHORT ) {
					pIP = pCh;
					// find the end of this ip:port string & start of next ip:port string.
					if( (pCh = _tcschr(pCh, _T(','))) != NULL ) {
						*pCh = 0; // terminate current "ip:port"
						pCh++; // point to next "ip:port"
					}
					else
						pCh = pEnd;

					// if port is not present for this ip, go to the next ip.
					if( (pPort = _tcschr(pIP, _T(':'))) == NULL )
					{	nInvalid++;	continue;	}

					*pPort = 0;	// terminate ip string
					pPort++;	// point pPort to port string.

					dwID = inet_addr(CStringA(pIP));
					ul = _tcstoul( pPort, 0, 10 );
					nPort = static_cast<uint16>(ul);

					// skip bad ips / ports
					if (ul > 0xFFFF || ul == 0 )	// port
					{	nInvalid++;	continue;	}
					if( dwID == INADDR_NONE) {	// hostname?
						if (_tcslen(pIP) > 512)
						{	nInvalid++;	continue;	}
						SUnresolvedHostname* hostname = new SUnresolvedHostname;
						hostname->nPort = nPort;
						hostname->strHostname = pIP;
						m_HostnameSourcesList.AddTail(hostname);
						continue;
					}
					//TODO: This will filter out *.*.*.0 clients. Is there a nice way to fix?
					if( IsLowID(dwID) )	// ip
					{	nInvalid++;	continue;	}

					SourcesList->WriteUInt32(dwID);
					SourcesList->WriteUInt16(nPort);
					SourcesList->WriteUInt32(dwServerIP);
					SourcesList->WriteUInt16(nServerPort);
					nCount++;
				}
				SourcesList->SeekToBegin();
				SourcesList->WriteUInt16(nCount);
				SourcesList->SeekToBegin();
				if (nCount==0) {
					delete SourcesList;
					SourcesList=NULL;
				}
			}
		}
	}
}
示例#9
0
/******************************************************************************
 Function Name  :   OnChange

 Input(s)       :   -
 Output         :   -
 Functionality  :   Called by the frame work on keying a character. If floating
                    point is not allowed, then charactres until "." are
                    considered as valid.
 Member of      :   CRadixEdit
 Friend of      :

 Author(s)      :   Soj Thomas
 Date Created   :   08-03-2002
 Modifications  :   Ratnadip Choudhury, Amarnath Shastry
                    Rajesh Kumar 05.03.2003 : call strtol/strtoul based on sign
 Modifications  :   Amitesh Bharti, 05.06.2003,replace datatype for supporting
                    64bits to __int64
******************************************************************************/
void CRadixEdit::OnChange()
{
    int nBufLength = LineLength() + 1;
    CString     strBuffer;
    //char* acBuffer= new char[1786];

    // if (strBuffer != "")
    {
        GetWindowText(strBuffer);
        if (m_bFloatAllowed)
        {
            m_fValue = (float) _tstof(strBuffer.GetBuffer(0));
        }
        else
        {
            if(m_nBase == BASE_DECIMAL )
            {
                if(bIsSigned())
                {
                    m_n64Value = _tstoi64(strBuffer.GetBuffer(0));
                    m_un64Value = m_n64Value;
                }
                else
                {
                    m_un64Value = _strtoui64(strBuffer.GetBuffer(0), NULL, 10);
                    m_n64Value = m_un64Value;
                }
            }
            else
            {
                INT nCurrentPost = 0;
                __int64 n64Val = 0;
                INT nActualLength = nBufLength - 1;
                BOOL bNegativeNumber = FALSE;
                m_n64Value = 0;

                while(nActualLength > nCurrentPost)
                {
                    if(strBuffer.GetAt(nCurrentPost) >='0'
                            && strBuffer.GetAt(nCurrentPost) <='9')
                    {
                        char cBuff = strBuffer.GetAt(nCurrentPost);
                        cBuff -='0';
                        strBuffer.SetAt(nCurrentPost, cBuff) ;
                    }
                    else if(strBuffer.GetAt(nCurrentPost) != '-')
                    {
                        char cBuff = strBuffer.GetAt(nCurrentPost);
                        cBuff = (char)(tolower(cBuff));
                        cBuff -= 87;
                        strBuffer.SetAt(nCurrentPost, cBuff) ;
                    }
                    else
                    {
                        bNegativeNumber = TRUE;
                    }
                    if(strBuffer.GetAt(nCurrentPost) != '-')
                    {
                        n64Val = strBuffer.GetAt(nCurrentPost);
                        n64Val <<= ((nActualLength - nCurrentPost - 1 )* 4 );
                        m_n64Value |= n64Val;
                    }
                    nCurrentPost++;
                }
                if(bNegativeNumber == TRUE )
                {
                    m_n64Value = -m_n64Value;
                }
            }
        }
        //delete []acBuffer;
        //acBuffer = NULL;
    }
}
示例#10
0
__int64  CBaseIni::ReadInt64( LPCTSTR lpszAppName, LPCTSTR lpszkeyName, __int64 nDefault )
{
	TCHAR buf[48];
	int nSize = GetPrivateProfileString( lpszAppName, lpszkeyName, _T("0"), buf, 48, m_strFileName.c_str() );
	return _tstoi64( buf );
}
DWORD WINAPI ThreadSend(LPVOID lpParameter)
{
	TCHAR szFile[MAX_PACKAGE_NAME];
	CString csValue;
	long long dirTime;
	long long dirOldTime;
	char buf[BUFSIZ+4];  //数据传送的缓冲区 
	int len = 0;
	SOCKET sockClient = (SOCKET)lpParameter;
	_stprintf(szFile, _T("%s\\%s"), APK_PATH_PARENT, APK_CFG_NAME);
	RegTool::GetPrivateProfileString(APK_CFG_INFO, APK_CFG_DIR, csValue, szFile);
	dirTime = _tstoi64(csValue.GetBuffer());
	//receive_socket_packs(sockClient, buf, BUFSIZ);
	//dirOldTime = _atoi64(buf);
	//if (dirTime == dirOldTime)
	//	printf("%s\n", buf);
	//else
	{
		memset(buf, 0, sizeof(buf));
		strcpy(buf, "-up");
		//send_socket_packs(sockClient, buf, strlen(buf)+1);
		//receive_socket_packs(sockClient, buf, BUFSIZ);

		//while (true)
		//{
			CStringArray apkArray;
			NeedUpdateApks(apkArray);
			for (int i = 0; i < apkArray.GetSize(); i++)
			{
				////FILE* fp;
				unsigned char* pBuf = NULL;
				////CString csFileName;
				////int fileLength = 0;
				////int readLen = BUFSIZ;
				//csFileName.Format(_T("%s\\%s.apk"), APK_PATH, apkArray[i]);
				//USES_CONVERSION;
				//char* szFilePath = T2A(csFileName.GetBuffer(0));
				//fp = fopen(szFilePath, "rb");
				////fileLength = file.GetLength();
				//char* szFile = T2A(apkArray[i]);
				//memset(buf, 0, sizeof(buf));
				//sprintf(buf, "s %s", szFile);
				////send_socket_packs(sockClient, buf, strlen(buf)+1);
				
				//while ((readLen = fread(buf + 4, 1, ROW_SIZE, fp)) > 0)
				//{
				//	if (readLen <= 0) break;
				//	memcpy(buf, (void*)&readLen, 4);
				//	if (send_socket_packs(sockClient, buf, readLen + 4)<0)
				//	{
				//		perror("write");
				//		fclose(fp);
				//		return 1;
				//	}
				//	//write(sockClient, buf, readLen);
				//	//receive_socket_packs(sockClient, buf, BUFSIZ);
				//	int recvLen = (int)(*buf);
				//	if (recvLen < readLen)
				//	{
				//		break;
				//	}
				//	memset(buf, 0, BUFSIZ);

				//}
				int readLen = GetFileByte(&pBuf, apkArray[i]);
				send_socket_packs(sockClient, (char*)pBuf, readLen);
				Sleep(1000);
				////fclose(fp);
			//}
		//receive_socket_packs(sockClient, buf, BUFSIZ);
		}
	}
	return 0;
}