Пример #1
5
//************************************
// Method:    ApplyProcessor
// FullName:  CPHEEqualizer::ApplyProcessor
// Access:    public 
// Returns:   procStatus
// Qualifier:
// Parameter: CImgSource * in_pImgSrc
// Parameter: CImgSource * out_ImgResult
//************************************
procStatus CPHEEqualizer::ApplyProcessor(CImgSource *in_pImgSrc, CImgSource *out_ImgResult)
{
	ASSERT(in_pImgSrc);
	ASSERT(in_pImgSrc->GetSourceRef());
	ASSERT(out_ImgResult);

	procStatus eRetCode = eNormal;
	//CDWordArray arrProbalility;
	CByteArray arrNewTable;

	CHistogram oSrcHis;
	eRetCode = in_pImgSrc->GetHistoram(oSrcHis);

#ifdef _DEBUG
// 	for (INT i=0; i<IMP_GRAY_LEVELS; i++)
// 	{
// 		TRACE("\nPos:%d \tVal:%d", i, oSrcHis.GetAt(i));
// 	}
// 	TRACE("\nTOTAL:%d", oSrcHis.Accumulate(IMP_GRAY_LEVELS-1));
#endif

	INT nHisSize = oSrcHis.GetSize();
	//arrProbalility.SetSize(nHisSize);
	arrNewTable.SetSize(nHisSize);

	DOUBLE nTotal = oSrcHis.Accumulate(nHisSize-1);
	
	if(eRetCode == eNormal)
	{
		for(INT k=0; k<nHisSize; k++)
		{
			DOUBLE ta = oSrcHis.Accumulate(k);
			DOUBLE dTemp = ((DOUBLE)oSrcHis.Accumulate(k)/nTotal) * (IMP_GRAY_LEVELS -1);
			arrNewTable.SetAt(k, (BYTE) dTemp);
		}
		
		CProcGrayTransformer oTransformer;
		oTransformer.m_eType = eCustomTrans;
		oTransformer.InitCustomTransform(&arrNewTable);
		
		eRetCode = oTransformer.ApplyProcessor(in_pImgSrc, out_ImgResult);
	}
	
	return eRetCode;
}
Пример #2
0
void NS_ISERVER::CLocalServer::LocalAskNotice(BOOL bSigned)
{
	NET_HEAD_MAN head = {0};
	head.Version = COM_VER;
	head.Length = sizeof tag_ask_read_notice;
	head.Cmd = C_MANGER_ASKREADNOTICE;

	tag_ask_read_notice notice = {0};
	notice.nAsk = (UINT)bSigned;

	CByteArray buffer;
	buffer.SetSize(sizeof NET_HEAD_MAN + head.Length);

	memcpy(buffer.GetData(), &head, sizeof NET_HEAD_MAN);
	memcpy(buffer.GetData() + sizeof NET_HEAD_MAN, &notice, sizeof tag_ask_read_notice);

	m_lpSocket->SendBuffer(buffer.GetData(), buffer.GetSize());

	buffer.RemoveAll();

	if (bSigned)
	{
		CIBALog::GetInstance()->Write(_T("发送通告签收成功"));
	}
	else
	{
		CIBALog::GetInstance()->Write(_T("发送获取通告的请求"));
	}
	
}
Пример #3
0
void NS_ISERVER::CLocalServer::LocalAuditUserQuit(CString strTermID, CString strIP,UINT nMemberID)
{
	NET_HEAD_MAN head = {0};
	head.Version = COM_VER;
	head.Length = sizeof TIBAAuditUserQuit;
	head.Cmd = C_MANGER_AUDITUSERQUIT;

	TIBAAuditUserQuit info = {0};

	_snprintf(info.termID, LEN_TERMID, CT2A(strTermID));
	_snprintf(info.termIP, LEN_IPADDR, CT2A(strIP));
	info.memberID=nMemberID;

	CByteArray buffer;
	buffer.SetSize(sizeof NET_HEAD_MAN + head.Length);

	memcpy(buffer.GetData(), &head, sizeof NET_HEAD_MAN);
	memcpy(buffer.GetData() + sizeof NET_HEAD_MAN, &info, sizeof TIBAAuditUserQuit);

	m_lpSocket->SendBuffer(buffer.GetData(), buffer.GetSize());

	buffer.RemoveAll();

	IBA_LOG(_T("发送实名下机信息,TermID=%s,IP=%s,MemberID=%d"),strTermID,strIP,nMemberID);
}
Пример #4
0
bool CMinizip::Extract(LPCTSTR FileName, LPCTSTR DestPath, UINT BufSize)
{
    USES_CONVERSION;
    if (unzLocateFile(m_ZipFile, T2CA(FileName), 0) != UNZ_OK)
        return(FALSE);
    if (unzOpenCurrentFile(m_ZipFile) != UNZ_OK)
        return(FALSE);
    CByteArray	ba;
    ba.SetSize(BufSize);
    bool	retc = FALSE;	// assume failure
    TRY {
        CFile	DestFile(DestPath, CFile::modeCreate | CFile::modeWrite);
        int	BytesRead;
        while ((BytesRead = unzReadCurrentFile(m_ZipFile, ba.GetData(), BufSize)) > 0) {
            DestFile.Write(ba.GetData(), BytesRead);
        }
        if (!BytesRead)	// if EOF
            retc = TRUE;	// success provided current file closes OK
    }
    CATCH (CFileException, e) {
        e->ReportError();
    }
    END_CATCH
    if (unzCloseCurrentFile(m_ZipFile) != UNZ_OK)	// close fails if bad CRC
        return(FALSE);
    return(retc);
}
// 从串口发送数据
//************************************
// Method:    OnSendFromSerialPort
// FullName:  CUartToUdpSocket::OnSendFromSerialPort
// Access:    private 
// Returns:   void
// Qualifier:
// Parameter: unsigned char * TXDATA
// Parameter: unsigned int uiCount
//************************************
void CUartToUdpSocket::OnSendFromSerialPort(unsigned char* TXDATA, unsigned int uiCount)
{
	// 如果端口未打开则不发送数据
// 	if(NULL == hCom)
// 	{
// 		return;
// 	}
// 
// 	OVERLAPPED wol;
// 	wol.Internal=0;
// 	wol.InternalHigh=0;
// 	wol.Offset=0;
// 	wol.OffsetHigh=0;
// 	wol.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
// 	
// 	WriteFile(hCom,TXDATA,uiCount,NULL,&wol);
	if (m_pctrlMSComm1 == NULL)
	{
		AfxMessageBox(_T("串口MSCOMM控件指针为空!"));
		return;
	}
	if(m_pctrlMSComm1->get_PortOpen() == FALSE)
	{
		return;
	}
	CByteArray array;
	array.RemoveAll();
	array.SetSize(uiCount);
	for(unsigned int i=0; i<uiCount; i++)
	{
		array.SetAt(i, TXDATA[i]);
	}
	m_pctrlMSComm1->put_Output(COleVariant(array)); // 发送数据
}
Пример #6
0
BOOL CRegistry::Read (LPCTSTR pszKey, CByteArray& bcArray)
{
	ASSERT(m_hKey);
	const int iMaxChars = 4096;
	int OldSize = (int) bcArray.GetSize();
	DWORD dwType;
	DWORD dwData = iMaxChars;
	BYTE* byData = (BYTE*)::calloc(iMaxChars, sizeof(TCHAR));
	ASSERT(byData);

	LONG lReturn = RegQueryValueEx(m_hKey, pszKey, NULL, &dwType,
		byData, &dwData);

	m_Info.lMessage = lReturn;
	m_Info.dwType = dwType;
	m_Info.dwSize = dwData;

	if(lReturn == ERROR_SUCCESS && dwType == REG_BINARY)
	{
		ASSERT(dwData < iMaxChars);
		CMemFile file(byData, dwData);
		CArchive ar(&file, CArchive::load);
		ar.m_bForceFlat = FALSE;
		ASSERT(ar.IsLoading());
		ASSERT(bcArray.IsSerializable());
		bcArray.RemoveAll();
		bcArray.SetSize(10);
		bcArray.Serialize(ar);
		bcArray.SetSize(OldSize);
		ar.Close();
		file.Close();
	}

	if(byData)
	{
		free(byData);
		byData = NULL;
	}

	if(lReturn == ERROR_SUCCESS)
		return TRUE;

	return FALSE;
}
Пример #7
0
bool CPackets::WriteHostNameReply()
{
	static const int MAX_HOST_NAME = 256;
	DWORD	PktLen = sizeof(PACKET_HDR) + MAX_HOST_NAME;
	CByteArray	pkt;
	pkt.SetSize(PktLen);
	FRAP_HOST_NAME_REPLY	*pp = (FRAP_HOST_NAME_REPLY *)pkt.GetData();
	if (gethostname(pp->HostName, MAX_HOST_NAME) == SOCKET_ERROR)
		return(FALSE);
	InitHdr(*pp, PMID_HOST_NAME_REPLY, PktLen);
	return(Write(*pp, PktLen));
}
Пример #8
0
// Read Operation
int CFanmotorDlg::rreg(int reg_addr)
{
success=1;

	CString s;
	int dat=0;
	long r;
	int timeout_counter=0;
	CByteArray baAddr;
	baAddr.SetSize (1);   
	baAddr.SetAt(0,reg_addr); 
	COleVariant ReadAddress(baAddr); // Create ReadAddress argument
	VARIANT dataIn;
	VariantInit(&dataIn);
	int datalen=2;//in bytes

	if(this->virtual_board)
	{
		dat = ReadVirtualBoardReg(reg_addr, fOTP);
	}

	else
	{
		r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress,datalen, &dataIn); 
		//r = Bridge->ReadIICdataReg(L"0000011", reg_addr, ReadAddress,datalen, &dataIn); 
		//Sleep(500);
		//r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress,datalen, &dataIn);//no data received.????
		//do{
		//	timeout_counter++;
		//	if (timeout_counter == TIMEOUT){
		//		DisplayInforMessageBox((LPCWSTR)L"Error", (LPCWSTR)L"Device is not available.\nPlease check your hardware connection and power supply!");
		//		success = 0;
		//	}
		//	r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress,datalen, &dataIn); 
		//}while ((r !=34) && (timeout_counter != TIMEOUT));

			CString strByte;
			for (long i = 0; i < datalen; i++) {
				BYTE ReadByte;
				SafeArrayGetElement(dataIn.parray, &i, &ReadByte);
				strByte.Format(L"%02x",ReadByte);
				s += strByte;
			}
			dat=use_debugdlg_main.string2int(s,2*datalen);
		//	success=1;
		//}
		//else {ErrorMsg(r);};
		VariantClear(&dataIn);
	}
	return dat;
	Sleep(20);
}
Пример #9
0
//由于这个转换函数的格式限制,在发送框中的十六制字符应该每两个字符之间插入一个空隔
//如:A1 23 45 0B 00 29
//CByteArray是一个动态字节数组,可参看MSDN帮助
int CPageDebug::String2Hex(CString str, CByteArray &sendData)
{
	int hexdata,lowhexdata;
	int hexdatalen = 0;
	int len = str.GetLength();
	sendData.SetSize(len/2);

	for(int i = 0; i < len;)
	{
		char lstr,hstr=str[i];
		if(hstr == ' ')
		{
			i++;
			continue;
		}
		i++;
		if(i>len)
		{
			break;
		}
		lstr=str[i];
		hexdata = ConvertHexChar(hstr);
		lowhexdata = ConvertHexChar(lstr);
		if((hexdata==16)||(lowhexdata==16))
		{
			break;
		}
		else
		{
			hexdata = hexdata*16+lowhexdata;
		}
		i++;
		sendData[hexdatalen] = (char)hexdata;
		hexdatalen++;
	}

	sendData.SetSize(hexdatalen);
	return hexdatalen;
}
Пример #10
0
void CCommandProcessor::OnRespondGetLog(BYTE *pBuffer, size_t /*bufLen*/)
{
	if (!m_bGetLog)
	{
		return;
	}
	
	m_bGetLog = FALSE;

	try
	{
		NET_HEAD_MAN head = {0};
		SCREEN_TERMINFO stTermInfo = {0};

		GetHead(pBuffer, &head);
		GetBody(pBuffer, &stTermInfo, sizeof(stTermInfo));

		CByteArray buf;
		buf.SetSize(head.Length - sizeof(stTermInfo));
		CopyMemory(buf.GetData(), pBuffer + sizeof(head) + sizeof(stTermInfo), buf.GetSize());

		CString strPicFile(theApp.GetWorkPath() + _T("\\IBATermLog\\"));
		CIBAHelpper::MakeSurePathExists(strPicFile);

		strPicFile.Append(CA2W(stTermInfo.termID));
		strPicFile.Trim();

		if (head.Version == 1) //zip
		{
			strPicFile.AppendFormat(_T("[%s].zip"), CIBAHelpper::GetCurrentTimeAsString());
		}
		else
		{
			strPicFile.AppendFormat(_T("[%s].log"), CIBAHelpper::GetCurrentTimeAsString());
		}
		
		SaveFile(strPicFile, buf);

	}
	catch (CFileException* e)
	{		
		e->Delete();
		CIBALog::GetInstance()->Write(_T("Get Log: Operation file failed."));
	}
	catch (...)
	{
		CIBALog::GetInstance()->Write(_T("Get Log failed."));
	}
}
Пример #11
0
void CMFCControlContainer::SetControlData(WORD nIDC, DWORD dwSize, BYTE* pbData)
{
	CByteArray* pArray = new CByteArray;
	pArray->SetSize(dwSize);

	BYTE* pbBuffer = pArray->GetData();
	if (memcpy_s(pbBuffer, dwSize, pbData, dwSize) != 0)
	{
		delete pArray;
		ASSERT(FALSE);
		return;
	}

	m_mapControlData.SetAt(nIDC, pArray);
}
Пример #12
0
//从串口发送数据
void SerialComm::SendComm(BYTE* sendData, int sendLength)
{
	CByteArray send;
	send.RemoveAll();
	send.SetSize(sendLength);
	for (size_t i = 0; i<sendLength; i++)
	{
		send.SetAt(i, sendData[i]);
	}	
	myComm.put_Output(COleVariant(send));

	for (size_t i = 0; i < 105; i++)
	{
		myReceiveDate[i] = 0;
	}
}
Пример #13
0
bool CPackets::WriteStripDone(UINT JobID, UINT ThreadIdx, float RenderTime, UINT y1, UINT y2, const ESCTIME *Strip, UINT StripSize)
{
	UINT	PktLen = sizeof(FRAP_STRIP_DONE_HDR) + StripSize;
	CByteArray	pkt;
	pkt.SetSize(PktLen);
	FRAP_STRIP_DONE	*pp = (FRAP_STRIP_DONE *)pkt.GetData();
	InitHdr(*pp, PMID_STRIP_DONE, PktLen);
	pp->JobID = JobID;
	pp->ThreadIdx = ThreadIdx;
	pp->RenderTime = RenderTime;
	pp->y1 = y1;
	pp->y2 = y2;
	pp->StripSize = StripSize;
	memcpy(pp->Strip, Strip, StripSize);
	return(Write(*pp, PktLen));
}
Пример #14
0
void COscillDlg::OnbtnMSCommSend() 
{
	// TODO: Add your control notification handler code here

	UpdateData( true );
	
	CByteArray sendArr; 
	WORD wLength;

	wLength = m_szMSCommSend.GetLength();
	sendArr.SetSize( wLength );
	for( int i =0; i<wLength; i++ )
	{
		sendArr.SetAt( i, m_szMSCommSend.GetAt( i ) );
	}
//	m_mscom.SetOutput( COleVariant(sendArr) );
}
Пример #15
0
bool CPackets::WriteDib(UINT JobID, UINT FrameID, float RenderTime, PVOID DibBits, const DIB_INFO& DibInfo)
{
	UINT	DibLen = DibInfo.Length;
	UINT	PktLen = sizeof(FRAP_DIB_HDR) + DibLen;
	CByteArray	pkt;
	pkt.SetSize(PktLen);
	FRAP_DIB	*pp = (FRAP_DIB *)pkt.GetData();
	InitHdr(*pp, PMID_DIB, PktLen);
	pp->JobID = JobID;
	pp->FrameID = FrameID;
	pp->RenderTime = RenderTime;
	pp->Width = DibInfo.Size.cx;
	pp->Height = DibInfo.Size.cy;
	pp->BitCount = DibInfo.BitCount;
	pp->DibLen = DibLen;
	memcpy(pp->DibBits, DibBits, DibLen);
	return(Write(*pp, PktLen));
}
Пример #16
0
void CChordEaseDoc::ReadSongText(CFile& File, CString& Text)
{
	ULONGLONG	LongLen = File.GetLength();
	ASSERT(LongLen <= UINT_MAX);
	UINT	len = static_cast<UINT>(LongLen);
	// assume input file is ANSI text
#ifdef UNICODE
	USES_CONVERSION;
	CByteArray	buf;
	buf.SetSize(len + 1);	// allocate buffer; extra byte for terminator
	File.Read(buf.GetData(), len);	// read ANSI text into byte buffer
	LPCSTR	pText = reinterpret_cast<LPCSTR>(buf.GetData());
	Text = A2W(pText);	// convert text from ANSI to Unicode and store
#else	// ANSI
	LPTSTR	pText = Text.GetBuffer(len);	// allocate text buffer
	File.Read(pText, len);	// read text into buffer
	Text.ReleaseBuffer(len);	// not null-terminated, so specify length
#endif
}
Пример #17
0
void NS_ISERVER::CLocalServer::LocalLoginZdReturn(ID_LOGINRETURN_ZD *pLogin_zd )
{
	NET_HEAD_MAN head = {0};
	head.Version = COM_VER;
	head.Length = sizeof ID_LOGINRETURN_ZD;
	head.Cmd = C_LOGIN_ZD;

	CByteArray buffer;
	buffer.SetSize(sizeof NET_HEAD_MAN + head.Length);

	memcpy(buffer.GetData(), &head, sizeof NET_HEAD_MAN);
	memcpy(buffer.GetData() + sizeof NET_HEAD_MAN, pLogin_zd, sizeof ID_LOGINRETURN_ZD);

	m_lpSocket->SendBuffer(buffer.GetData(), buffer.GetSize());

	buffer.RemoveAll();

	IBA_LOG0(_T("发送智多实名登录"));
}
Пример #18
0
void CHtmlView::BeforeNavigate2(LPDISPATCH /* pDisp */, VARIANT* URL,
		VARIANT* Flags, VARIANT* TargetFrameName,
		VARIANT* PostData, VARIANT* Headers, BOOL* Cancel)
{
	ASSERT(V_VT(URL) == VT_BSTR);
	ASSERT(V_VT(TargetFrameName) == VT_BSTR);
	ASSERT(V_VT(PostData) == (VT_VARIANT | VT_BYREF));
	ASSERT(V_VT(Headers) == VT_BSTR);
	ASSERT(Cancel != NULL);

	USES_CONVERSION;

	VARIANT* vtPostedData = V_VARIANTREF(PostData);
	CByteArray array;
	if (V_VT(vtPostedData) & VT_ARRAY)
	{
		// must be a vector of bytes
		ASSERT(vtPostedData->parray->cDims == 1 && vtPostedData->parray->cbElements == 1);

		vtPostedData->vt |= VT_UI1;
		COleSafeArray safe(vtPostedData);

		DWORD dwSize = safe.GetOneDimSize();
		LPVOID pVoid;
		safe.AccessData(&pVoid);

		array.SetSize(dwSize);
		LPBYTE lpByte = array.GetData();

		memcpy(lpByte, pVoid, dwSize);
		safe.UnaccessData();
	}
	// make real parameters out of the notification

	CString strTargetFrameName(V_BSTR(TargetFrameName));
	CString strURL = V_BSTR(URL);
	CString strHeaders = V_BSTR(Headers);
	DWORD nFlags = V_I4(Flags);

	// notify the user's class
	OnBeforeNavigate2(strURL, nFlags, strTargetFrameName,
		array, strHeaders, Cancel);
}
Пример #19
0
void CLocalServer::SendBuffer(const NET_HEAD_MAN* pHead, const void* pBuf, BOOL bCheckStatus)
{
	if (bCheckStatus && m_CheckInStatus != 1)
	{
		return;
	}

	CByteArray buffer;
	buffer.SetSize(sizeof NET_HEAD_MAN + pHead->Length);

	memcpy(buffer.GetData(), pHead, sizeof NET_HEAD_MAN);

	if (pBuf != NULL)
	{
		memcpy(buffer.GetData() + sizeof NET_HEAD_MAN, pBuf, pHead->Length);
	}

	m_lpSocket->SendBuffer(buffer.GetData(), buffer.GetSize());
	buffer.RemoveAll();
}
void CXTPSyntaxEditLexCfgFileReader::WriteString(CFile& file, LPCTSTR pcszString)
{
	int nStrLen = (int)_tcslen(pcszString);

#ifdef _UNICODE
	CByteArray arBufferMBCS;
	arBufferMBCS.SetSize(nStrLen*2+4);

	char* pTextMBCS = (char*)arBufferMBCS.GetData();

	int nNewLen = WideCharToMultiByte(CP_ACP, 0,
		pcszString, -1, pTextMBCS, nStrLen*2+1, NULL, NULL);

	nStrLen = nNewLen ? nNewLen-1 : 0;
#else
	char* pTextMBCS = (char*)pcszString;
#endif

	file.Write(pTextMBCS, nStrLen);
	file.Write("\r\n", 2);
}
Пример #21
0
int CFanmotorDlg::rFWData(int fType, int nByte)
{
	success=1;
	CString s;
	int dat=0;
	int timeout_counter=0;
	long r;
	CByteArray baAddr;
	baAddr.SetSize (1);   
	baAddr.SetAt(0,fType); 
	COleVariant ReadAddress(baAddr); // Create ReadAddress argument
	VARIANT dataIn;
	VariantInit(&dataIn);

	///*Sleep(50);*/
	//long r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress, 
 //                                  1, &dataIn);  
	do{
		timeout_counter++;
		if (timeout_counter == TIMEOUT){
			DisplayInforMessageBox((LPCWSTR)L"Error", (LPCWSTR)L"Device is not available.\nPlease check your hardware connection and power supply!");
			success = 0;
		}
		r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress,nByte, &dataIn); 
	}while ((r !=34) && (timeout_counter != TIMEOUT));
	//{
		CString strByte;
		for (long i = 0; i < nByte; i++) {
			BYTE ReadByte;
			SafeArrayGetElement(dataIn.parray, &i, &ReadByte);
			strByte.Format(L"%02x",ReadByte);
			s += strByte;
		}
		dat=use_debugdlg_main.string2int(s,2*nByte);
		success=1;
	//}
	//else {ErrorMsg(r);};
	VariantClear(&dataIn);
	return dat;	
}
Пример #22
0
void CRichEditCtrlGS::SetRTF(const UINT resID)
{ // Obtain a handle and the memory to the resource
  HINSTANCE hApp = ::GetModuleHandle(0);
  ASSERT(hApp);
  HRSRC hResInfo = ::FindResource(hApp, MAKEINTRESOURCE(resID), TEXT("RTF"));
  if( NULL == hResInfo ) return;
  HGLOBAL hRes = ::LoadResource(hApp, hResInfo);
  if( NULL == hRes ) return;
  LPVOID pRTFText = ::LockResource(hRes);
  if( NULL == pRTFText ) return;
  DWORD dwRTFSize = ::SizeofResource(hApp, hResInfo);
  if( 0 == dwRTFSize )
    { ::FreeResource(hRes);
	  return;
    }
  CByteArray arrbRTF;
  arrbRTF.SetSize(dwRTFSize);
  LPBYTE pArrRTF = arrbRTF.GetData();
  ::CopyMemory(pArrRTF,pRTFText,dwRTFSize);
  ::FreeResource(hRes);
  SetRTF(arrbRTF);
}
Пример #23
0
void CLocalServer::LocalUnlockScreen(INT_PTR nIndex, CString strUnlockPwd)
{
	if (m_CheckInStatus != 1)
	{
		return;
	}

	if (ComputerList.IsInvaildIndex(nIndex))
	{
		return;
	}

	CComputerInfo& computer = ComputerList.GetComputer(nIndex);

	SCREEN_TERMINFO snapComputer = {0};
	_snprintf(snapComputer.termID, LEN_TERMID, CW2A(computer.GetTerminalID()));
	_snprintf(snapComputer.termIP, LEN_IPADDR, CW2A(computer.GetComputerIP()));

	NET_HEAD_MAN head = {0};

	head.Version = COM_VER;
	head.Length = sizeof SCREEN_TERMINFO + sizeof CHECK_PASSWORD;
	head.Cmd = C_MANGER_UNLOCKSCREEN;

	CHECK_PASSWORD pwd = {0};

	_snprintf(pwd.cPassword, LEN_CLIPASSWORD, CW2A(strUnlockPwd));
	
	CByteArray buffer;
	buffer.SetSize(sizeof NET_HEAD_MAN + head.Length);

	memcpy(buffer.GetData(), &head, sizeof NET_HEAD_MAN);
	memcpy(buffer.GetData() + sizeof NET_HEAD_MAN, &snapComputer, sizeof SCREEN_TERMINFO);
	memcpy(buffer.GetData() + sizeof NET_HEAD_MAN + sizeof SCREEN_TERMINFO, &pwd, sizeof CHECK_PASSWORD);

	m_lpSocket->SendBuffer(buffer.GetData(), buffer.GetSize());

	buffer.RemoveAll();
}
Пример #24
0
HRESULT CClipboard::AddData(BYTE *pData, UINT nDataLength, UINT nClipboardKey)
{
   if (pData == NULL && nDataLength > 0)
      return E_POINTER;
   if (nClipboardKey == 0)
      return E_INVALIDARG;

   CByteArray *pByteArray = new CByteArray();
   pByteArray->SetSize(nDataLength, 0);
   memcpy(pByteArray->GetData(), pData, nDataLength);

   CByteArray *pByteArrayOld = NULL;
   if (m_mapData.Lookup(nClipboardKey, pByteArrayOld))
   {
      m_mapData.RemoveKey(nClipboardKey);
      delete pByteArrayOld;
   }

   m_mapData.SetAt(nClipboardKey, pByteArray);

   return S_OK;
}
Пример #25
0
DWORD CALLBACK CRichEditCtrlGS::StreamOutCByteArray(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb)
{ SCookieByteArray *pCookie = (SCookieByteArray *)dwCookie;
  long lWriteSize = cb; // We can only Write such much
  *pcb = 0;             // Till now we have nothing written so far

  if( pCookie->lStart < 0 )
	{ return (0); // Nothing to do
	}
  if( 0 == cb )
	{ return(0); // Nothing to do
	}
  if( NULL == pCookie->pOutText )
	{ return(0); // Nothing to do
	}
  CByteArray arrBuffer;
  arrBuffer.SetSize(lWriteSize);
  BYTE *pByte = arrBuffer.GetData();
  memcpy(pByte,pbBuff,lWriteSize);
  pCookie->pOutText->Append(arrBuffer);
  *pcb = lWriteSize;   
  pCookie->lStart += lWriteSize;
  return 0;
}
Пример #26
0
int CPartFileConvert::performConvertToeMule(CString folder)
{
	BOOL bWorking;
	CString filepartindex,newfilename;
	CString buffer;
	UINT fileindex;
	CFileFind finder;
	
	CString partfile=folder;
	folder.Delete(folder.ReverseFind('\\'),folder.GetLength());
	partfile=partfile.Mid(partfile.ReverseFind('\\')+1,partfile.GetLength());


	UpdateGUI(0,GetResString(IDS_IMP_STEPREADPF),true);

	filepartindex=partfile.Left(partfile.Find('.'));
	//int pos=filepartindex.ReverseFind('\\');
	//if (pos>-1) filepartindex=filepartindex.Mid(pos+1,filepartindex.GetLength()-pos);

	UpdateGUI(4,GetResString(IDS_IMP_STEPBASICINF));

	CPartFile* file=new CPartFile();
	EPartFileFormat eFormat = PMT_UNKNOWN;
		
	if (file->LoadPartFile(folder, partfile, &eFormat) == PLR_CHECKSUCCESS)
	{
		pfconverting->partmettype = (uint8_t)eFormat;
		switch (pfconverting->partmettype)
		{
			case PMT_UNKNOWN:
			case PMT_BADFORMAT:
				delete file;
				return CONV_BADFORMAT;
				break;
		}
	}
	else
	{
		delete file;
		return CONV_BADFORMAT;
	}

	CString oldfile=folder+_T("\\")+partfile.Left(partfile.GetLength()- ((pfconverting->partmettype==PMT_SHAREAZA)?3:4) );

	pfconverting->size=file->GetFileSize();
	pfconverting->filename=file->GetFileName();
	pfconverting->filehash= EncodeBase16( file->GetFileHash() ,16);
	UpdateGUI(pfconverting);

	if (theApp.downloadqueue->GetFileByID(file->GetFileHash())!=0) {
		delete file;
		return CONV_ALREADYEXISTS;
	}
	
	if (pfconverting->partmettype==PMT_SPLITTED ) {
		try {
			CByteArray ba;
			ba.SetSize(PARTSIZE);

			CFile inputfile;
			int pos1,pos2;
			CString filename;

			// just count
			UINT maxindex=0;
			UINT partfilecount=0;
			bWorking = finder.FindFile(folder+_T("\\")+filepartindex+_T(".*.part"));
			while (bWorking)
			{
				bWorking = finder.FindNextFile();
				++partfilecount;
				buffer=finder.GetFileName();
				pos1=buffer.Find('.');
				pos2=buffer.Find('.',pos1+1);
				fileindex=_tstoi(buffer.Mid(pos1+1,pos2-pos1) );
				if (fileindex==0) continue;
				if (fileindex>maxindex) maxindex=fileindex;
			}
			float stepperpart;
			if (partfilecount>0) {
				stepperpart=(80.0f / partfilecount );
				if ((uint64_t)maxindex*PARTSIZE<=pfconverting->size) pfconverting->spaceneeded=(uint64_t)maxindex*PARTSIZE;
					else pfconverting->spaceneeded=((uint64_t)(pfconverting->size / PARTSIZE) * PARTSIZE)+(pfconverting->size % PARTSIZE);
			} else {
				stepperpart=80.0f;
				pfconverting->spaceneeded=0;
			}
			
			UpdateGUI(pfconverting);

			if (GetFreeDiskSpaceX(thePrefs.GetTempDir()) < ((uint64_t)maxindex*PARTSIZE) ) {
				delete file;
				return CONV_OUTOFDISKSPACE;
			}

			// create new partmetfile, and remember the new name
			file->CreatePartFile();
			newfilename=file->GetFullName();

			UpdateGUI(8,GetResString(IDS_IMP_STEPCRDESTFILE));
			file->m_hpartfile.SetLength( pfconverting->spaceneeded );

			uint16_t curindex=0;
			bWorking = finder.FindFile(folder+_T("\\")+filepartindex+_T(".*.part"));
			while (bWorking)
			{
				bWorking = finder.FindNextFile();
				
				//stats
				++curindex;
				buffer.Format(GetResString(IDS_IMP_LOADDATA),curindex,partfilecount);
				UpdateGUI( 10+(curindex*stepperpart) ,buffer);

				filename=finder.GetFileName();
				pos1=filename.Find('.');
				pos2=filename.Find('.',pos1+1);
				fileindex=_tstoi(filename.Mid(pos1+1,pos2-pos1) );
				if (fileindex==0) continue;

				uint32_t chunkstart=(uint32_t)(fileindex-1) * PARTSIZE ;

				// open, read data of the part-part-file into buffer, close file
				inputfile.Open(finder.GetFilePath(),CFile::modeRead|CFile::shareDenyWrite);
				uint32_t readed=inputfile.Read( ba.GetData() ,PARTSIZE);
				inputfile.Close();

				buffer.Format(GetResString(IDS_IMP_SAVEDATA),curindex,partfilecount);
				UpdateGUI( 10+(curindex*stepperpart) ,buffer);

				// write the buffered data
				file->m_hpartfile.Seek(chunkstart, CFile::begin );
				file->m_hpartfile.Write(ba.GetData(),readed);
			}
		}
		catch(CFileException* error) {
			CString strError(GetResString(IDS_IMP_IOERROR));
			TCHAR szError[MAX_CFEXP_ERRORMSG];
			if (error->GetErrorMessage(szError, _countof(szError))){
				strError += _T(" - ");
				strError += szError;
			}
			LogError(false, _T("%s"), strError);
			error->Delete();
			delete file;
			return CONV_IOERROR;
		}
		file->m_hpartfile.Close();
	}
	// import an external common format partdownload
	else //if (pfconverting->partmettype==PMT_DEFAULTOLD || pfconverting->partmettype==PMT_NEWOLD || Shareaza  ) 
	{
		
		if (!pfconverting->removeSource) 
			pfconverting->spaceneeded = (UINT)GetDiskFileSize(oldfile);

		UpdateGUI(pfconverting);

		if (!pfconverting->removeSource && (GetFreeDiskSpaceX(thePrefs.GetTempDir()) < pfconverting->spaceneeded) ) {
			delete file;
			return CONV_OUTOFDISKSPACE;
		}

		file->CreatePartFile();
		newfilename=file->GetFullName();

		file->m_hpartfile.Close();

		BOOL ret=FALSE;
		UpdateGUI( 92 ,GetResString(IDS_COPY));
		DeleteFile(newfilename.Left(newfilename.GetLength()-4));

		if (!PathFileExists(oldfile)) {
			// data file does not exist. well, then create a 0 byte big one
			HANDLE hFile = CreateFile( newfilename.Left(newfilename.GetLength()-4) ,    // file to open
							GENERIC_WRITE,          // open for reading
							FILE_SHARE_READ,       // share for reading
							NULL,                  // default security
							CREATE_NEW,         // existing file only
							FILE_ATTRIBUTE_NORMAL, // normal file
							NULL);                 // no attr. template
			 
			ret= !(hFile == INVALID_HANDLE_VALUE) ;

			CloseHandle(hFile);
		}
			else 
		if (pfconverting->removeSource) 
			ret=MoveFile( oldfile, newfilename.Left(newfilename.GetLength()-4) );
		else 
			ret=CopyFile( oldfile, newfilename.Left(newfilename.GetLength()-4) ,false);

		if (!ret) {
			file->DeleteFile();
			//delete file;
			return CONV_FAILED;
		}

	}


	UpdateGUI( 94 ,GetResString(IDS_IMP_GETPFINFO));

	DeleteFile(newfilename);
	if (pfconverting->removeSource)
		MoveFile(folder+_T("\\")+partfile,newfilename);
	else CopyFile(folder+_T("\\")+partfile,newfilename,false);


	file->m_hasharray.release();
	for ( GapList::iterator it = file->gaplist.begin(); it != file->gaplist.end(); ++it ) {
		delete *it;
	}
	file->gaplist.clear();

	if (file->LoadPartFile(thePrefs.GetTempDir(), file->GetPartMetFileName()) != PLR_LOADSUCCESS) {
		//delete file;
		file->DeleteFile();
		return CONV_BADFORMAT;
	}

	if (pfconverting->partmettype==PMT_NEWOLD || pfconverting->partmettype==PMT_SPLITTED ) {
		file->completedsize = file->m_uTransferred;
		file->m_uCompressionGain = 0;
		file->m_uCorruptionLoss = 0;
	}

	UpdateGUI( 100 ,GetResString(IDS_IMP_ADDDWL));

	theApp.downloadqueue->AddDownload(file,thePrefs.AddNewFilesPaused());
	file->SavePartFile();
	
	if (file->GetStatus(true) == PS_READY)
		theApp.sharedfiles->SafeAddKFile(file); // part files are always shared files


	if (pfconverting->removeSource) {

		bWorking = finder.FindFile(folder+_T("\\")+filepartindex+_T(".*"));
		while (bWorking)
		{
			bWorking = finder.FindNextFile();
			VERIFY( _tunlink(finder.GetFilePath()) == 0 );
		}

		if (pfconverting->partmettype==PMT_SPLITTED)
			RemoveDirectory(folder+_T("\\"));
	}

	return CONV_OK;
}
/**
 * Modifies a user param byte array with the ExtParam data passed with
 * argument pParam. ExtParam data objects will be build from 
 * Ext_User_Prm_Data_Const/Ref fields within the GSD. Extparam data 
 * describes the datatype of the Ext_User_Prm_Data, the offset within
 * the user param byte array and the value. The passed user param byte
 * array (see argument UserParam) grows as necessary.
 * Existing user param bytes within the array will be or-ed with the
 * new byte value.
 *
 * @param			CByteArray & UserParam - user param byte array to
 *                  modify. The byte array will grow as necessary.
 * @param			ExtParam *pParam - Reference to ExtParam data 
 *                  object describing the Ext_User_Prm_Data. Shall not
 *                  be NULL.
 * @exception		CMemoryException
 * @see			    GSD: Ext_User_Prm_Data_Const/Ref
*/
void ModifyParamArray(CByteArray & UserParam, ExtParam *pParam)
{
	int offset = 0;
    int sizeArray = 0;
    int sizeBytes = 0;


    ASSERT(pParam);

    switch(pParam->GetParamType()) {
    case Array:
        {
		    CByteArray* pBytes = pParam->GetByteArray();

		    sizeBytes = pBytes->GetSize();
            sizeArray = UserParam.GetSize();
		    offset = pParam->GetByteOffset();

            if(offset + sizeBytes > sizeArray) {
                //grow the array
                UserParam.SetSize(offset + sizeBytes);
                BYTE *pb = UserParam.GetData();
                //preset array
                size_t sizeSet = offset + sizeBytes - sizeArray;
                memset(&pb[sizeArray],0,sizeSet);
            }

		    for (int x = 0; x < sizeBytes; x++) {
			    BYTE userbyte = UserParam.GetAt(offset);
			    BYTE setbyte  = pBytes->GetAt(x);
			    userbyte |= setbyte;
			    UserParam.SetAt(offset++, userbyte);
		    }// next x
	    }
        break;
    case Byte:
	    {
		    offset = pParam->GetByteOffset();
            sizeArray = UserParam.GetSize();
            sizeBytes = sizeof(BYTE);

            if(offset + sizeBytes > sizeArray) {
                //grow the array
                UserParam.SetSize(offset + sizeBytes);
                BYTE *pb = UserParam.GetData();
                //preset array
                size_t sizeSet = offset + sizeBytes - sizeArray;
                memset(&pb[sizeArray],0,sizeSet);
            }

			BYTE userbyte = UserParam.GetAt(offset);	// Get current value in Bytearray
			if (pParam->IsBitArea())	{
				userbyte &= ~MakeBitFieldInByte(pParam->GetBitAreaStart(),
											   pParam->GetBitAreaLength());
				userbyte |= (BYTE)(pParam->GetUsedValue() << pParam->GetBitAreaStart());
			}
			else	{
				userbyte = (BYTE)pParam->GetUsedValue();
			}
			UserParam.SetAt(offset, userbyte);		// Set new value in ByteArray

	    }
        break;
    case Word:
	    {
            BYTE setbyte = 0;
		    WORD data = (WORD)pParam->GetUsedValue();

		    offset = pParam->GetByteOffset();
            sizeArray = UserParam.GetSize();
            sizeBytes = sizeof(data);
            
            if(offset + sizeBytes > sizeArray) {
                //grow the array
                UserParam.SetSize(offset + sizeBytes);
                BYTE *pb = UserParam.GetData();
                //preset array
                size_t sizeSet = offset + sizeBytes - sizeArray;
                memset(&pb[sizeArray],0,sizeSet);
            }
            
            for (int i = sizeBytes - 1; i >= 0 ; i--)	{
			    BYTE userbyte = UserParam.GetAt(offset);
			    setbyte = (BYTE)((data  >> (i*8)) & 0x000000FF);
			    userbyte = setbyte;
			    UserParam.SetAt(offset++, userbyte);
		    }
	    }
        break;
    case DWord:
	    {
		    BYTE setbyte = 0;
		    DWORD data = (DWORD)pParam->GetUsedValue();

		    offset = pParam->GetByteOffset();
            sizeArray = UserParam.GetSize();
            sizeBytes = sizeof(data);
            
            if(offset + sizeBytes > sizeArray) {
                //grow the array
                UserParam.SetSize(offset + sizeBytes);
                BYTE *pb = UserParam.GetData();
                //preset array
                size_t sizeSet = offset + sizeBytes - sizeArray;
                memset(&pb[sizeArray],0,sizeSet);
            }

		    for (int i = sizeBytes - 1; i >= 0 ; i--)	{
			    BYTE userbyte = UserParam.GetAt(offset);
			    setbyte = (BYTE)((data  >> (i*8)) & 0x000000FF);
			    userbyte = setbyte;
			    UserParam.SetAt(offset++, userbyte);
		    }
	    }
        break;
    default:
        break;
    }
}
Пример #28
0
BOOL ConvertStringToSendData(const CString & s, CByteArray & msg)
    {
#ifdef _UNICODE
     int n = ::WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL);
     if(n == 0)
        { /* failed */
         //DWORD err = ::GetLastError();
         msg.SetSize(0);
         return FALSE;
        } /* failed */
     else
        { /* success */
         msg.SetSize(n);
         n = ::WideCharToMultiByte(CP_UTF8, 0, s, -1, (LPSTR)msg.GetData(), n, NULL, NULL);
         if(n == 0)
            { /* conversion failed */
             DWORD err = ::GetLastError();
             msg.SetSize(0);
             return FALSE;
            } /* conversion failed */
         else
            { /* use multibyte string */
             msg.SetSize(n - 1);
             return TRUE;
            } /* use multibyte string */
        } /* success */
#else // ANSI
     CArray<WCHAR, WCHAR> wc;

     int n = ::MultiByteToWideChar(CP_ACP, 0, s, -1, NULL, 0);
     if(n == 0)
        { /* failed */
         DWORD err = ::GetLastError();
         msg.SetSize(0);
         return FALSE;
        } /* failed */
     else
        { /* success */
         wc.SetSize(n);
         n = ::MultiByteToWideChar(CP_ACP, 0, s, -1, wc.GetData(), n);
        } /* success */     

     n = ::WideCharToMultiByte(CP_UTF8, 0, wc.GetData(), -1, NULL, 0, NULL, NULL);
     if(n == 0)
        { /* failed */
         DWORD err = ::GetLastError();
         msg.SetSize(0);
         return FALSE;
        } /* failed */
     else
        { /* success */
         msg.SetSize(n);
         n = ::WideCharToMultiByte(CP_UTF8, 0, wc.GetData(), -1, (LPSTR)msg.GetData(), n, NULL, NULL);
         if(n == 0)
            { /* conversion failed */
             DWORD err = ::GetLastError();
             msg.SetSize(0);
             return FALSE;
            } /* conversion failed */
         else
            { /* use multibyte string */
             msg.SetSize(n - 1);
             return TRUE;
            } /* use multibyte string */
        } /* success */
#endif
    } // ConvertStringToSendData