Exemplo n.º 1
0
void CGenethonDoc::writeToReport(CString& output) {
    if (m_pTextView == NULL) {

        ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->OpenTextView();
    }
    else {

        m_pTextView->GetParentFrame()->ActivateFrame();
        m_pTextView->Invalidate();
    }

    CMemFile* memFile = new CMemFile();
    //serialize object into the pData
    //	char* cBuff = new char[128];
    //	sprintf_s(cBuff, 128, "%s", "Test test test test test test\n");

    memFile->Write(output, output.GetLength());
    memFile->SeekToBegin();

    //	txtFile->Open(PathName, CFile::modeRead);
    //	CArchive archive(&txtFile, CArchive::load);

    //	SerializeRaw( archive );
    m_pTextView->LoadMemfile(memFile);

    memFile->Close();
    delete memFile;
}
Exemplo n.º 2
0
BOOL CRegistry::Write(LPCTSTR lpszKey, CWnd *pWnd)
{
	ASSERT(lpszKey);
	ASSERT(pWnd);

	WINDOWPLACEMENT wp;
	wp.length = sizeof(WINDOWPLACEMENT);
	pWnd->GetWindowPlacement(&wp);

	CMemFile file;
	CArchive ar(&file, CArchive::store);

	ar << wp.flags
		 << wp.showCmd
		 << wp.ptMinPosition
		 << wp.ptMaxPosition
		 << wp.rcNormalPosition;
	ar.Close();

	DWORD dwSize = file.GetLength();
	BYTE* pByte = file.Detach();

	LONG lResult = RegSetValueEx(m_hKey, lpszKey, NULL, REG_BINARY, pByte, dwSize);

	if (pByte)
		free(pByte);

	if(lResult == ERROR_SUCCESS)
		return TRUE;
	
	return FALSE;
}
Exemplo n.º 3
0
// Property Data-> Object Data Change
BOOL CGXGridCellData::SetMultiCaptionBlobDataChange ( CString  strPropertyData )
{
	DeleteContents();
	if ( strPropertyData.IsEmpty() )
	{
		return FALSE;
	}

	BYTE*	pvData = NULL;
	pvData = StringToBinaryEx( strPropertyData );
	ASSERT( pvData != NULL );
    if( pvData != NULL )
	{
		DWORD	dwDataLen;
		dwDataLen = *(long*)pvData;
		
		CMemFile memFile;
		memFile.Attach ( (BYTE*)pvData+sizeof(DWORD), dwDataLen - sizeof(DWORD) );
		
		CArchive arMem(&memFile, CArchive::load );
		Serialize ( arMem );

		free ( pvData );
		return TRUE;
	}
	return FALSE;
}
Exemplo n.º 4
0
void CUpdateServersDlg::OnTimer(UINT_PTR nIDEvent)
{
	CSkinDialog::OnTimer( nIDEvent );

	if ( m_pRequest.IsPending() )
	{
		int n = m_wndProgress.GetPos();
		if ( n < 5 )
			n = 5;
		else if ( n < 100 )
			n++;
		m_wndProgress.SetPos( n );
	}
	else
	{
		KillTimer( 1 );

		if ( m_pRequest.GetStatusSuccess() )
		{
			const CString strExt = CString( PathFindExtension( m_sURL ) ).MakeLower();
			if ( strExt == L".met" || m_sURL.Find( _T("//server"), 8 ) > 8 )		// || strExt == L".php"
				Settings.eDonkey.ServerListURL = m_sURL;
			else if ( strExt == L".bz2" || m_sURL.Find( _T("hublist"), 8 ) > 8 )
				Settings.DC.HubListURL = m_sURL;
		//	else if ( strExt == L".xml" )
		//		Settings.Gnutella.CacheURL = m_sURL;
		//	else if ( strExt == L".dat" )
		//		Settings.KAD.NodesListURL = m_sURL;

			const CBuffer* pBuffer = m_pRequest.GetResponseBuffer();

			CMemFile pFile;
			pFile.Write( pBuffer->m_pBuffer, pBuffer->m_nLength );
			pFile.Seek( 0, CFile::begin );

			if ( ( strExt == L".bz2" && HostCache.ImportHubList( &pFile ) ) ||
				 HostCache.ImportMET( &pFile ) )
			//	 HostCache.ImportCache( &pFile ) || 	// ToDo: G2/Gnutella loading
			//	 HostCache.ImportNodes( &pFile ) )		// ToDo: KAD
			{
				HostCache.Save();

				m_sURL.Empty();
				EndDialog( IDOK );
				return;
			}
		}

		CString strError;
		strError.Format( LoadString( IDS_DOWNLOAD_DROPPED ), m_sURL );
		MsgBox( strError, MB_OK | MB_ICONEXCLAMATION );

		m_sURL.Empty();
		EndDialog( IDCANCEL );
	}

	UpdateWindow();
}
Exemplo n.º 5
0
	CBeginGame::CBeginGame(CPeerData *pDoc) : CMessage(MSGID_BEGINGAME), m_nSize(0), m_pData(NULL)
	{
		ASSERT(pDoc);

		// Dokument serialisieren
		CMemFile memFile;
		CArchive ar(&memFile, CArchive::store);
		pDoc->SerializeBeginGameData(ar);
		ar.Flush();
		m_nSize = memFile.GetLength();
		m_pData = memFile.Detach();
	}
void CDonkeyServersDlg::OnRun()
{
	if ( m_hInternet == NULL ) return;

	HINTERNET hRequest = InternetOpenUrl( m_hInternet, m_sURL, NULL, 0,
		INTERNET_FLAG_RELOAD|INTERNET_FLAG_DONT_CACHE, 0 );

	if ( hRequest == NULL )
	{
		InternetCloseHandle( m_hInternet );
		m_hInternet = NULL;
		PostMessage( WM_TIMER, FALSE );
		return;
	}

	DWORD nLength, nlLength = 4;
	DWORD nRemaining = 0;
	BYTE pBuffer[1024];
	CMemFile pFile;

	if ( HttpQueryInfo( hRequest, HTTP_QUERY_CONTENT_LENGTH|HTTP_QUERY_FLAG_NUMBER,
		&nLength, &nlLength, NULL ) )
	{
		m_wndProgress.PostMessage( PBM_SETRANGE32, 0, nLength );
	}

	nLength = 0;

	while ( InternetQueryDataAvailable( hRequest, &nRemaining, 0, 0 ) && nRemaining > 0 )
	{
		nLength += nRemaining;
		m_wndProgress.PostMessage( PBM_SETPOS, nLength );

		while ( nRemaining > 0 )
		{
			DWORD nBuffer = min( nRemaining, DWORD(1024) );
			InternetReadFile( hRequest, pBuffer, nBuffer, &nBuffer );
			pFile.Write( pBuffer, nBuffer );
			nRemaining -= nBuffer;
		}
	}

	pFile.Seek( 0, CFile::begin );

	BOOL bSuccess = HostCache.eDonkey.ImportMET( &pFile );
	if ( bSuccess ) HostCache.Save();

	InternetCloseHandle( m_hInternet );
	m_hInternet = NULL;

	PostMessage( WM_TIMER, bSuccess ? 1 : 0 );
}
Exemplo n.º 7
0
// 添加到数据包对象
bool CPackMgr::AddPack( DataBuffer &pack, const char *carid, const int msgid,
		const int index, const int count, const int seq, const char *buf, int len )
{
	share::Guard g( _mutex ) ;
	{
		if ( count <= 0 || index <= 0 ) {
			OUT_ERROR( NULL, 0, "packmgr" , "msg id %x, add pack car id %s, count %d, index %d error" , msgid, carid, count, index ) ;
			return false ;
		}

		char key[1024] = {0} ;
		// 这里ID是由手机号以及消息ID和分包数
		sprintf( key, "%s-%d-%d-%d" , carid, msgid, count , (seq-index)+1 ) ;

		CMemFile *p = NULL ;

		CMapFile::iterator it = _mapPack.find( key ) ;
		if ( it == _mapPack.end() ) {
			p = new CMemFile(key) ;
			if ( p == NULL ) {
				OUT_ERROR( NULL, 0, "packmgr" , "msg id %x, add pack car id %s, count %d, index %d malloc data faild" , msgid, carid, count, index ) ;
				return false ;
			}
		} else {
			p = it->second ;
			// 移除不必要时间索引
			p = _queue.erase( p ) ;
		}

		// 如果成功将多个数据合成一个数据包则直接从内存删除
		if ( p->AddBuffer( pack, index, count, buf, len ) ) {
			// 打印数据信息
			OUT_INFO( NULL, 0, "packmgr" , "msg id %x, build msg pack success", msgid ) ;
			// 只有不为一个数据长消息才会有索引
			if ( it != _mapPack.end() ) {
				// 从队列中移除
				_mapPack.erase( it ) ;
			}
			delete p ;
			return true ;
		}

		// 只有第一次添加时才添加到队列中
		if ( it == _mapPack.end() ) {
			_mapPack.insert( pair<string,CMemFile*>( key, p ) ) ;
		}
		// 添加时间索引
		_queue.push( p ) ;

		return false ;
	}
}
Exemplo n.º 8
0
bool CKnownFileList::Append(CKnownFile *Record, bool afterHashing)
{
	if (Record->GetFileSize() > 0) {
		const CMD4Hash& tkey = Record->GetFileHash();
		CKnownFileMap::iterator it = m_knownFileMap.find(tkey);
		if (it == m_knownFileMap.end()) {
			m_knownFileMap[tkey] = Record;
			return true;
		} else {
			CKnownFile *existing = it->second;
			if (KnownFileMatches(Record, existing->GetFileName(), existing->GetLastChangeDatetime(), existing->GetFileSize())) {
				// The file is already on the list, ignore it.
				AddDebugLogLineN(logKnownFiles, CFormat(wxT("%s is already on the list")) % Record->GetFileName().GetPrintable());
				return false;
			} else if (IsOnDuplicates(Record->GetFileName(), Record->GetLastChangeDatetime(), Record->GetFileSize())) {
				// The file is on the duplicates list, ignore it.
				// Should not happen, at least not after hashing. Or why did it get hashed in the first place then?
				AddDebugLogLineN(logKnownFiles, CFormat(wxT("%s is on the duplicates list")) % Record->GetFileName().GetPrintable());
				return false;
			} else {
				if (afterHashing && existing->GetFileSize() == Record->GetFileSize()) {
					// We just hashed a "new" shared file and find it's already known under a different name or date.
					// Guess what - it was probably renamed or touched.
					// So copy over all properties from the existing known file and just keep name/date.
					time_t newDate = Record->GetLastChangeDatetime();
					CPath newName = Record->GetFileName();
					CMemFile f;
					existing->WriteToFile(&f);
					f.Reset();
					Record->LoadFromFile(&f);
					Record->SetLastChangeDatetime(newDate);
					Record->SetFileName(newName);
				}
				// The file is a duplicated hash. Add THE OLD ONE to the duplicates list.
				// (This is used when reading the known file list where the duplicates are stored in front.)
				m_duplicateFileList.push_back(existing);
				if (theApp->sharedfiles) {
					// Removing the old kad keywords created with the old filename
					theApp->sharedfiles->RemoveKeywords(existing);
				}
				m_knownFileMap[tkey] = Record;
				return true;
			}
		}
	} else {
		AddDebugLogLineN(logGeneral,
			CFormat(wxT("%s is 0-size, not added")) %
			Record->GetFileName());

		return false;
	}
}
Exemplo n.º 9
0
	CEndOfRound::CEndOfRound(CPeerData *pDoc) : CMessage(MSGID_ENDOFROUND), m_nSize(0), m_pDeletableData(NULL),
		m_pElseData(NULL)
	{
		ASSERT(pDoc);

		// Dokument serialisieren
		CMemFile memFile;
		CArchive ar(&memFile, CArchive::store);
		pDoc->SerializeEndOfRoundData(ar, RACE_NONE);
		ar.Flush();
		m_nSize = memFile.GetLength();
		m_pElseData = memFile.Detach();
	}
Exemplo n.º 10
0
void CSimpleReport::LayoutSave(const char* id, const char* tag)
{
	CMemFile memFile;
	CArchive ar (&memFile,CArchive::store);
	SerializeState(ar);
	ar.Flush();
	DWORD nBytes = (DWORD)memFile.GetPosition();
	LPBYTE pData = memFile.Detach();
	AfxGetApp()->WriteProfileBinary(id, tag, pData, nBytes);
	ar.Close();
	memFile.Close();
	free(pData);
}
//***************************************************************************************
BOOL CBCGPXMLSettings::Write (LPCTSTR pszKey, CWordArray& wcArray)
{
	if (m_bReadOnly)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	BOOL bRes = FALSE;
	try
	{
		CMemFile file;

		{
			CArchive ar (&file, CArchive::store);

			ar << (int)wcArray.GetSize ();
			for (int i = 0; i < wcArray.GetSize (); i ++)
			{
				ar << wcArray [i];
			}

			ar.Flush ();
		}

#if _MSC_VER >= 1300
		ULONGLONG dwDataSize = file.GetLength ();
#else
		DWORD dwDataSize = file.GetLength ();
#endif
		LPBYTE lpbData = file.Detach ();

		if (lpbData == NULL)
		{
			return FALSE;
		}

		bRes = Write (pszKey, lpbData, (UINT) dwDataSize);
		free (lpbData);
	}
	catch (CMemoryException* pEx)
	{
		pEx->Delete ();
		TRACE(_T("Memory exception in CBCGPXMLSettings::Write ()!\n"));
		return FALSE;
	}

	return bRes;
}
//************************************************************************************************
BOOL CBCGPMouseManager::SaveState (LPCTSTR lpszProfileName)
{
	CString strProfileName = ::BCGPGetRegPath (strMouseProfile, lpszProfileName);

	BOOL bResult = FALSE;

	try
	{
		CMemFile file;

		{
			CArchive ar (&file, CArchive::store);

			Serialize (ar);
			ar.Flush ();
		}

		UINT uiDataSize = (UINT) file.GetLength ();
		LPBYTE lpbData = file.Detach ();

		if (lpbData != NULL)
		{
			CBCGPRegistrySP regSP;
			CBCGPRegistry& reg = regSP.Create (FALSE, FALSE);

			if (reg.CreateKey (strProfileName))
			{
				bResult = reg.Write (strRegEntryName, lpbData, uiDataSize);
			}

			free (lpbData);
		}
	}
	catch (CMemoryException* pEx)
	{
		pEx->Delete ();
		TRACE(_T("Memory exception in CBCGPMouseManager::SaveState ()!\n"));
	}
	catch (CArchiveException* pEx)
	{
		pEx->Delete ();
		TRACE(_T("CArchiveException exception in CBCGPMouseManager::SaveState ()!\n"));
	}

	return bResult;
}
Exemplo n.º 13
0
CMapMgrDoc::CMapMgrDoc() {
	// TODO: add one-time construction code here
	HRSRC hRes = ::FindResource( AfxGetResourceHandle(), "HIST_UNCOMPR", "COLORPARAM" );
	if( NULL != hRes ) {
		HGLOBAL	hMem = ::LoadResource( AfxGetResourceHandle(), hRes );
		DWORD	dwSize = ::SizeofResource( AfxGetResourceHandle(), hRes );
		HPBYTE pData = (HPBYTE) ::LockResource( hMem );
		CMemFile memFile;
		memFile.Write( (LPVOID) pData, dwSize );
		memFile.SeekToBegin();

		CArchive	ar( &memFile, CArchive::load );
		WORD v;		// Version
		ar >> v;
		m_listOfFilters.Serialize( ar );

		UnlockResource( hMem );
		FreeResource( hMem );
	}
Exemplo n.º 14
0
BOOL CRegistry::Write (LPCTSTR pszKey, CDWordArray& dwcArray)
{
	ASSERT (m_hKey != NULL);
	ASSERT (pszKey != NULL);

	if (m_bReadOnly)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	BOOL bRes = FALSE;
	try
	{
		CMemFile file;

		{
			CArchive ar (&file, CArchive::store);
			dwcArray.Serialize(ar);
			ar.Flush ();
		}

		DWORD dwDataSize = (DWORD) file.GetLength ();
		LPBYTE lpbData = file.Detach ();

		if (lpbData == NULL)
		{
			return FALSE;
		}

		bRes = Write (pszKey, lpbData, (UINT) dwDataSize);
		free (lpbData);
	}
	catch (CMemoryException* pEx)
	{
		pEx->Delete ();
		TRACE(_T("Memory exception in CRegistry::Write ()!\n"));
		return FALSE;
	}

	return bRes;
}
Exemplo n.º 15
0
void CSortListCtrl::SaveColumnInfo()
{
	ASSERT( m_iNumColumns > 0 );

	CString strKey;
	strKey.Format( _T("%d"), GetDlgCtrlID() );

	CMemFile memFile;

	CArchive ar( &memFile, CArchive::store );
	m_ctlHeader.Serialize( ar );
	ar.Close();

	DWORD dwLen = memFile.GetLength();
	BYTE* buf = memFile.Detach();	

	VERIFY( AfxGetApp()->WriteProfileBinary( g_pszSection, strKey, buf, dwLen ) );

	free( buf );
}
Exemplo n.º 16
0
bool CPackets::WriteStripSnapshot(UINT JobID, UINT StripRows, CSnapshot& Snap)
{
	CMemFile	mf;
	FRAP_STRIP_SNAPSHOT_HDR	hdr;
	ZeroMemory(&hdr, sizeof(hdr));
	mf.Write(&hdr, sizeof(hdr));	// reserve space for header
	{
		CArchive	ar(&mf, CArchive::store);
		Snap.Serialize(ar);
	}
	DWORD	PktLen = static_cast<DWORD>(mf.GetLength());
	DWORD	SnapLen = PktLen - sizeof(FRAP_STRIP_SNAPSHOT_HDR);
	FRAP_STRIP_SNAPSHOT	*pp = (FRAP_STRIP_SNAPSHOT *)mf.Detach();
	InitHdr(*pp, PMID_STRIP_SNAPSHOT, PktLen);
	pp->JobID = JobID;
	pp->StripRows = StripRows;
	pp->SnapLen = SnapLen;
	bool	retc = Write(*pp, PktLen);
	delete pp;	// buffer detached from CMemFile
	return(retc);
}
Exemplo n.º 17
0
BOOL CBCGPRegistry::Write(LPCTSTR pszKey, const CRect& rect)
{
	if (m_bReadOnly)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	BOOL bRes = FALSE;
	try
	{
		CMemFile file;

		{
			CArchive ar (&file, CArchive::store);

			ar << rect;
			ar.Flush ();
		}

		DWORD dwDataSize = (DWORD) file.GetLength ();
		LPBYTE lpbData = file.Detach ();

		if (lpbData == NULL)
		{
			return FALSE;
		}

		bRes = Write (pszKey, lpbData, (UINT) dwDataSize);
		free (lpbData);
	}
	catch (CMemoryException* pEx)
	{
		pEx->Delete ();
		TRACE(_T("Memory exception in CBCGPRegistry::Write ()!\n"));
		return FALSE;
	}

	return bRes;
}
Exemplo n.º 18
0
//*********************************************************************************
static void createSnapshotTestSectrion()
{
    CTBSection xCurrentUser;
    xCurrentUser.Open(&CTBSection::tbRootSection, "CurrentUser");

    CTBSection xSnapshotTest;
    xSnapshotTest.Create(&xCurrentUser, "SnapshotTest", 0);
    //--------------------------------------------------------------
    {
        CTBSection xSection1;
        xSection1.Create(&xSnapshotTest, "Section1", 0);
    }
    //--------------------------------------------------------------
    CMemFile memFile;

    for(int i = 0; i < 64; ++i)
    {
        BYTE buff[1024] = {0};
        memset(buff, i, sizeof(buff));
        memFile.Write(buff, sizeof(buff));
    }
    //--------------------------------------------------------------
    xSnapshotTest.SetLongBinary("Blob1", &memFile);

    for(int i = 0; i < 200; ++i)
    {
        CTBValue vName("Name");
        CTBValue vAge(i);
        
        CString name, age;
        name.Format("Name %d", i);
        age.Format("Age %d", i);

        xSnapshotTest.SetValue(name, &vName);
        xSnapshotTest.SetValue(age, &vAge);
    }
    //--------------------------------------------------------------
    xSnapshotTest.Update();
}
Exemplo n.º 19
0
void CDonkeyServersDlg::OnTimer(UINT_PTR nIDEvent)
{
	CSkinDialog::OnTimer( nIDEvent );

	if ( m_pRequest.IsPending() )
	{
		int n = m_wndProgress.GetPos();
		if ( ++n >= 100 )
			n = 0;
		m_wndProgress.SetPos( n );
	}
	else
	{
		KillTimer( 1 );

		if ( m_pRequest.GetStatusSuccess() )
		{
			const CBuffer* pBuffer = m_pRequest.GetResponseBuffer();

			CMemFile pFile;
			pFile.Write( pBuffer->m_pBuffer, pBuffer->m_nLength );
			pFile.Seek( 0, CFile::begin );

			if ( HostCache.ImportMET( &pFile ) )
				HostCache.Save();
		}
		else
		{
			CString strError;
			strError.Format( LoadString( IDS_DOWNLOAD_DROPPED ), m_sURL );
			AfxMessageBox( strError, MB_OK | MB_ICONEXCLAMATION );
		}

		EndDialog( IDOK );
	}

	UpdateWindow();
}
Exemplo n.º 20
0
void CFTPProtocolOutput::WriteLine(const CString& cszLine, COLORREF crText)
{
   if( m_hWnd )
   {
      CHARFORMAT cf;
      cf.dwMask    = CFM_BOLD|CFM_COLOR;
      cf.dwEffects = CFE_BOLD;
      cf.crTextColor = crText;

      CMemFile mf;
      mf.Write(nsHelper::CCnv::ConvertToString(tstring(cszLine)).c_str(), cszLine.GetLength());
      mf.SeekToBegin();
   
      SetSelectionCharFormat(cf);

      EDITSTREAM es;
      es.dwCookie = reinterpret_cast<DWORD_PTR>(&mf);
      es.pfnCallback = CFTPProtocolOutput::ProtocolStreamInCallback; 
      StreamIn(SF_TEXT|SFF_SELECTION, es);
      SetSel(-1, -1);
      LineScroll(1);
   }
}
Exemplo n.º 21
0
/////////////////////////////////////////////////////////////////////////////
// serialization
void CGXGridCellData::SerializeEx(CArchive& ar, CString& strProperty )
{
	ASSERT_VALID(this);
	DWORD dwDataLen;
	if (ar.IsStoring())		// Write
	{
		CMemFile  memFile;
		CArchive  arMem(&memFile, CArchive::store );
		Serialize ( arMem );
		arMem.Flush();

		dwDataLen = memFile.GetLength();
		if ( dwDataLen > 0 )
		{
			BYTE *pTemp = new BYTE [dwDataLen+1];
			memFile.Seek(0, CFile::begin);
			memFile.Read(pTemp, dwDataLen );
		
			ar.Write(&dwDataLen, sizeof(DWORD));
			ar.Write(pTemp, dwDataLen);

			// Property Save CString
			strProperty = BinaryToStringEx ( pTemp, dwDataLen );

			if ( pTemp )
				delete []pTemp;
		}
	}
	else					// Read
	{
		ar >> dwDataLen;
		if ( dwDataLen > 0 )
		{
			BYTE *pTemp = new BYTE[dwDataLen+1];
			ar.Read(pTemp, dwDataLen );
			
			CMemFile memFile;
			memFile.Attach ( (BYTE*)pTemp, dwDataLen );

			CArchive arMem(&memFile, CArchive::load );
			Serialize ( arMem );

			// Property Save CString
			DWORD dwTotLen = 	dwDataLen + sizeof(DWORD);
			BYTE *pvData = new BYTE[dwTotLen];
			*(DWORD*)pvData = dwTotLen;
			memcpy ( pvData + sizeof(DWORD), pTemp, dwDataLen );
			
			if ( pTemp )
				delete[] pTemp;

			strProperty = BinaryToStringEx ( pvData, dwTotLen );
			if ( pvData )
				delete[] pvData;
		}
	}
}
Exemplo n.º 22
0
CString CGXGridCellData::GetMultiCaptionBlobDataChange ( )
{
	CString strProperty;

	ASSERT_VALID(this);

//	if ( !m_bSingleMode )
//		DeleteContents();

	CMemFile  memFile;
	CArchive arMem(&memFile, CArchive::store );
	Serialize ( arMem );
	arMem.Flush();

	DWORD dwDataLen = memFile.GetLength();
	if ( dwDataLen > 0 )
	{
		BYTE *pTemp = new BYTE [dwDataLen+1];
		memFile.Seek(0, CFile::begin);
		memFile.Read(pTemp, dwDataLen );

		DWORD dwTotLen = 	dwDataLen + sizeof(DWORD);
		BYTE *pvData = new BYTE[dwTotLen];
		*(DWORD*)pvData = dwTotLen;
		memcpy ( pvData + sizeof(DWORD), pTemp, dwDataLen );
		if ( pTemp )
			delete[] pTemp;

		// Property Save CString
		strProperty = BinaryToStringEx ( pvData, dwTotLen );
		if ( pvData )
			delete[] pvData;
	}	

	return strProperty;
}
Exemplo n.º 23
0
//*********************************************************************************
BOOL CBCGPOutlookBar::SaveState (LPCTSTR lpszProfileName, int nIndex, UINT uiID)
{
	CBCGPBaseTabbedBar::SaveState (lpszProfileName, nIndex, uiID);

	for (POSITION pos = m_lstCustomPages.GetHeadPosition (); pos != NULL;)
	{
		CBCGPOutlookBarPane* pPage = (CBCGPOutlookBarPane*)m_lstCustomPages.GetNext (pos);
		ASSERT_VALID (pPage);
		int nID = pPage->GetDlgCtrlID ();
		pPage->SaveState (lpszProfileName, nID, nID);
	}

	CString strProfileName = ::BCGPGetRegPath (strOutlookBarProfile, lpszProfileName);

	if (nIndex == -1)
	{
		nIndex = GetDlgCtrlID ();
	}

	CString strSection;
	if (uiID == (UINT) -1)
	{
		strSection.Format (REG_SECTION_FMT, strProfileName, nIndex);
	}
	else
	{
		strSection.Format (REG_SECTION_FMT_EX, strProfileName, nIndex, uiID);
	}

	try
	{
		CMemFile file;

		{
			CArchive ar (&file, CArchive::store);

			ar << (int) m_lstCustomPages.GetCount ();
			for (POSITION pos = m_lstCustomPages.GetHeadPosition (); pos != NULL;)
			{
				CBCGPOutlookBarPane* pPage = (CBCGPOutlookBarPane*)m_lstCustomPages.GetNext (pos);
				ASSERT_VALID (pPage);

				ar << pPage->GetDlgCtrlID ();
				
				CString strName;
				if (pPage->IsTabbed ())
				{
					pPage->GetWindowText (strName);
				}
				else
				{
					pPage->GetParent ()->GetWindowText (strName);
				}

				ar << strName;
			}
			
			CBCGPOutlookWnd* pOutlookBar = (CBCGPOutlookWnd*) GetUnderlinedWindow ();
			if (pOutlookBar != NULL)
			{
				ar << pOutlookBar->GetVisiblePageButtons ();
			}
			else
			{
				ar << -1;
			}

			ar.Flush ();
		}

		UINT uiDataSize = (UINT) file.GetLength ();
		LPBYTE lpbData = file.Detach ();

		if (lpbData != NULL)
		{
			CBCGPRegistrySP regSP;
			CBCGPRegistry& reg = regSP.Create (FALSE, FALSE);

			if (reg.CreateKey (strSection))
			{
				reg.Write (strRegCustomPages, lpbData, uiDataSize);
			}

			free (lpbData);
		}
	}
	catch (CMemoryException* pEx)
	{
		pEx->Delete ();
		TRACE(_T("Memory exception in CBCGPOutlookBar::SaveState ()!\n"));
	}
	catch (CArchiveException* pEx)
	{
		pEx->Delete ();
		TRACE(_T("Archive exception in CBCGPOutlookBar::SaveState ()!\n"));
	}

	return TRUE;
}
Exemplo n.º 24
0
DWORD CALLBACK CFTPProtocolOutput::ProtocolStreamInCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
   CMemFile* pMf = reinterpret_cast<CMemFile*>(dwCookie);
   *pcb = pMf->Read(pbBuff, cb);
   return 0;
}
Exemplo n.º 25
0
DWORD SupFileSubtitleProvider::ThreadProc()
{
    CFile f;
    if (!f.Open(m_fname, CFile::modeRead|CFile::typeBinary|CFile::shareDenyNone)) {
        return 1;
    }

    f.SeekToBegin();

    CMemFile sub;
    sub.SetLength(f.GetLength());
    sub.SeekToBegin();

    int len;
    BYTE buff[65536];
    while ((len = f.Read(buff, sizeof(buff))) > 0) {
        sub.Write(buff, len);
    }
    sub.SeekToBegin();

    WORD sync              = 0;
    USHORT size            = 0;
    REFERENCE_TIME rtStart = 0;

    CAutoLock cAutoLock(&m_csCritSec);
    while (sub.GetPosition() < (sub.GetLength() - 10)) {
        sync = (WORD)ReadByte(&sub, 2);
        if (sync == 'PG') {
            rtStart = UINT64(ReadByte(&sub, 4) * (1000 / 9));
            sub.Seek(4 + 1, CFile::current); // rtStop + Segment type
            size = ReadByte(&sub, 2) + 3;    // Segment size
            sub.Seek(-3, CFile::current);
            sub.Read(buff, size);
            m_pSub->ParseSample(buff, size, rtStart, 0);
        } else {
            break;
        }
    }

    sub.Close();

    return 0;
}
Exemplo n.º 26
0
int main()
{
    CMapStringToString map;

    if( !map.IsEmpty() ) _fail;
    if( map.GetCount() != 0 ) _fail;
    if( map.GetSize() != 0 ) _fail;

    map.SetAt( _T("0"), _T(" ") );
    map.SetAt( _T("1"), _T("A") );
    map.SetAt( _T("2"), _T("B") );

    CString value;
    if( !map.Lookup( _T("0"), value ) ) _fail;
    if( value != _T(" ") ) _fail;
    if( !map.Lookup( _T("1"), value ) ) _fail;
    if( value != _T("A") ) _fail;
    if( !map.Lookup( _T("2"), value ) ) _fail;
    if( value != _T("B") ) _fail;
    if( map.Lookup( _T("3"), value ) ) _fail;

    POSITION    position = map.GetStartPosition();
    CString     key;
    BOOL        bFound0 = FALSE;
    BOOL        bFound1 = FALSE;
    BOOL        bFound2 = FALSE;
    while( position != NULL ) {
        map.GetNextAssoc( position, key, value );
        if( key == _T("0") ) {
            if( bFound0 ) _fail;
            if( value != _T(" ") ) _fail;
            bFound0 = TRUE;
        } else if( key == _T("1") ) {
            if( bFound1 ) _fail;
            if( value != _T("A") ) _fail;
            bFound1 = TRUE;
        } else if( key == _T("2") ) {
            if( bFound2 ) _fail;
            if( value != _T("B") ) _fail;
            bFound2 = TRUE;
        } else {
            _fail;
        }
    }
    if( !bFound0 ) _fail;
    if( !bFound1 ) _fail;
    if( !bFound2 ) _fail;

    map.RemoveKey( _T("0") );
    if( map.Lookup( _T("0"), value ) ) _fail;

    CMapStringToString smap1;
    CMapStringToString smap2;
    smap1[_T("0")] = _T(" ");
    smap1[_T("1")] = _T("A");
    smap1[_T("2")] = _T("B");
    
    CMemFile file;
    CArchive ar( &file, CArchive::store );
    smap1.Serialize( ar );
    ar.Close();

    file.Seek( 0, CFile::begin );
    CArchive ar2( &file, CArchive::load );
    smap2.Serialize( ar2 );
    ar2.Close();

    if( smap2[_T("0")] != _T(" ") ) _fail;
    if( smap2[_T("1")] != _T("A") ) _fail;
    if( smap2[_T("2")] != _T("B") ) _fail;

    _PASS;
}
Exemplo n.º 27
0
void CGenPropertyPage::OnCopyItem() 
{

char * p = NULL;

try
  {
  CMemFile f;      // open memory file for writing
  CArchive ar(&f, CArchive::store);

  // in case we do more than one (one day) the header comes before the batch
  if (m_strObjectType == "alias")
    m_doc->Save_Header_XML (ar, "aliases", false);
  else
    m_doc->Save_Header_XML (ar, m_strObjectType + "s", false);   // timers, triggers etc.

  for (int nItem = -1;
        (nItem = m_ctlList->GetNextItem(nItem, LVNI_SELECTED)) != -1;)
    {

    // get the lower-case name of this item's object
    CString * pstrObjectName = (CString *) m_ctlList->GetItemData (nItem);
    ASSERT (pstrObjectName != NULL);

    CObject * pItem;

    // check object is still there (it might have gone while we looked at the list box)
    if (!m_ObjectMap->Lookup (*pstrObjectName, pItem))
      {
      CString strMsg;

      m_ctlList->DeleteItem (nItem);    // it's gone, so delete it from the list view
      m_ctlList->RedrawItems (0, m_ctlList->GetItemCount () - 1);    // redraw the list

      // in the case of one-shot timers, unnamed items might be removed from the list
      if (pstrObjectName->Left (1) == "*")
        strMsg = TFormat ("The %s you selected is no longer in the %s list",
                      (LPCTSTR) m_strObjectType,
                      (LPCTSTR) m_strObjectType);
      else
        strMsg = TFormat ("The %s named \"%s\" is no longer in the %s list",
                      (LPCTSTR) m_strObjectType,
                      (LPCTSTR) *pstrObjectName,
                      (LPCTSTR) m_strObjectType);

      ::UMessageBox (strMsg);

      delete pstrObjectName;                 // and get rid of its name string
      continue;
      }

    ASSERT_VALID (pItem);
    ASSERT( pItem->IsKindOf( RUNTIME_CLASS( CObject ) ) );

    // turn into XML

    if (m_strObjectType == "trigger")
      m_doc->Save_One_Trigger_XML (ar, (CTrigger *) pItem);
    else if (m_strObjectType == "alias")
      m_doc->Save_One_Alias_XML (ar, (CAlias *) pItem);
    else if (m_strObjectType == "timer")
      m_doc->Save_One_Timer_XML (ar, (CTimer *) pItem);
    else if (m_strObjectType == "variable")
      m_doc->Save_One_Variable_XML (ar, (CVariable *) pItem);

    }   // end of dealing with each selected item

  if (m_strObjectType == "alias")
    m_doc->Save_Footer_XML (ar, "aliases");
  else
    m_doc->Save_Footer_XML (ar, m_strObjectType + "s");   // timers, triggers etc.

  ar.Close();

  int nLength = f.GetLength ();
  p = (char *) f.Detach ();

  CString strXML (p, nLength);

  free (p);   // remove memory allocated in CMemFile
  p = NULL;

  putontoclipboard (strXML, m_doc->m_bUTF_8);

  }   // end of try block

catch (CException* e)
	{
  if (p)
    free (p);   // remove memory allocated in CMemFile
	e->ReportError();
	e->Delete();
	}

}   // end of CGenPropertyPage::OnCopyItem
Exemplo n.º 28
0
int main()
{
    CMemFile file;
    CArchive ar( &file, CArchive::store );
    ar << TEST_BYTE;
    ar << TEST_WORD;
    ar << TEST_LONG;
    ar << TEST_DWORD;
    ar << TEST_FLOAT;
    ar << TEST_DOUBLE;
    ar << TEST_INT;
    ar << TEST_SHORT;
    ar << TEST_CHAR;
    ar << TEST_WCHAR_T;
    ar << TEST_UNSIGNED;
    ar << TEST_BOOL;
    ar << TEST_ULONGLONG;
    ar << TEST_LONGLONG;
    ar.Close();

    file.Seek( 0, CFile::begin );
    CArchive ar2( &file, CArchive::load );

    BYTE by;
    ar2 >> by;
    if( by != TEST_BYTE ) _fail;

    WORD w;
    ar2 >> w;
    if( w != TEST_WORD ) _fail;

    LONG l;
    ar2 >> l;
    if( l != TEST_LONG ) _fail;

    DWORD dw;
    ar2 >> dw;
    if( dw != TEST_DWORD ) _fail;

    float f;
    ar2 >> f;
    if( f != TEST_FLOAT ) _fail;

    double d;
    ar2 >> d;
    if( d != TEST_DOUBLE ) _fail;

    int i;
    ar2 >> i;
    if( i != TEST_INT ) _fail;

    short s;
    ar2 >> s;
    if( s != TEST_SHORT ) _fail;

    char ch;
    ar2 >> ch;
    if( ch != TEST_CHAR ) _fail;

    wchar_t wc;
    ar2 >> wc;
    if( wc != TEST_WCHAR_T ) _fail;

    unsigned u;
    ar2 >> u;
    if( u != TEST_UNSIGNED ) _fail;

    bool b;
    ar2 >> b;
    if( b != TEST_BOOL ) _fail;

    ULONGLONG ull;
    ar2 >> ull;
    if( ull != TEST_ULONGLONG ) _fail;

    LONGLONG ll;
    ar2 >> ll;
    if( ll != TEST_LONGLONG ) _fail;

    ar2.Close();
    
    _PASS;
}
Exemplo n.º 29
0
void CAICHHashSet::DbgTest()
{
#ifdef _DEBUG
	//define TESTSIZE 4294567295
	uint8 maxLevel = 0;
	uint32 cHash = 1;
	uint8 curLevel = 0;
	//uint32 cParts = 0;
	maxLevel = 0;
/*	CAICHHashTree* pTest = new CAICHHashTree(TESTSIZE, true, 9728000);
	for (uint64 i = 0; i+9728000 < TESTSIZE; i += 9728000) {
		CAICHHashTree* pTest2 = new CAICHHashTree(9728000, true, EMBLOCKSIZE);
		pTest->ReplaceHashTree(i, 9728000, &pTest2);
		cParts++;
	}
	CAICHHashTree* pTest2 = new CAICHHashTree(TESTSIZE-i, true, EMBLOCKSIZE);
	pTest->ReplaceHashTree(i, (TESTSIZE-i), &pTest2);
	cParts++;
*/
#define TESTSIZE m_pHashTree.m_nDataSize
	if (m_pHashTree.m_nDataSize <= EMBLOCKSIZE) {
		return;
	}
	CAICHHashSet TestHashSet(m_pOwner);
	TestHashSet.SetFileSize(m_pOwner->GetFileSize());
	TestHashSet.SetMasterHash(GetMasterHash(), AICH_VERIFIED);
	CMemFile file;
	uint64 i;
	for (i = 0; i+9728000 < TESTSIZE; i += 9728000) {
		VERIFY( CreatePartRecoveryData(i, &file) );
		
		/*uint32 nRandomCorruption = (rand() * rand()) % (file.GetLength()-4);
		file.Seek(nRandomCorruption, CFile::begin);
		file.Write(&nRandomCorruption, 4);*/

		file.Seek(0,wxFromStart);
		VERIFY( TestHashSet.ReadRecoveryData(i, &file) );
		file.Seek(0,wxFromStart);
		TestHashSet.FreeHashSet();
		uint32 j;
		for (j = 0; j+EMBLOCKSIZE < 9728000; j += EMBLOCKSIZE) {
			VERIFY( m_pHashTree.FindHash(i+j, EMBLOCKSIZE, &curLevel) );
			//TRACE(wxT("%u - %s\r\n"), cHash, m_pHashTree.FindHash(i+j, EMBLOCKSIZE, &curLevel)->m_Hash.GetString());
			maxLevel = max(curLevel, maxLevel);
			curLevel = 0;
			cHash++;
		}
		VERIFY( m_pHashTree.FindHash(i+j, 9728000-j, &curLevel) );
		//TRACE(wxT("%u - %s\r\n"), cHash, m_pHashTree.FindHash(i+j, 9728000-j, &curLevel)->m_Hash.GetString());
		maxLevel = max(curLevel, maxLevel);
		curLevel = 0;
		cHash++;

	}
	VERIFY( CreatePartRecoveryData(i, &file) );
	file.Seek(0,wxFromStart);
	VERIFY( TestHashSet.ReadRecoveryData(i, &file) );
	file.Seek(0,wxFromStart);
	TestHashSet.FreeHashSet();
	for (uint64 j = 0; j+EMBLOCKSIZE < TESTSIZE-i; j += EMBLOCKSIZE) {
		VERIFY( m_pHashTree.FindHash(i+j, EMBLOCKSIZE, &curLevel) );
		//TRACE(wxT("%u - %s\r\n"), cHash,m_pHashTree.FindHash(i+j, EMBLOCKSIZE, &curLevel)->m_Hash.GetString());
		maxLevel = max(curLevel, maxLevel);
		curLevel = 0;
		cHash++;
	}
	//VERIFY( m_pHashTree.FindHash(i+j, (TESTSIZE-i)-j, &curLevel) );
	//TRACE(wxT("%u - %s\r\n"), cHash,m_pHashTree.FindHash(i+j, (TESTSIZE-i)-j, &curLevel)->m_Hash.GetString());
	maxLevel = max(curLevel, maxLevel);
#endif
}
Exemplo n.º 30
-1
// serializing structures must follow serializing a common data type,
// because structures are serialized using CArchive::Read function
// which doesn't throw CArchiveException on end-of-file
bool CRegistrySerialize::Save()
{
	if (!Check())
		return false;

	CMemFile mf;
	try
	{
	
		CArchive ar(&mf, CArchive::store);
		m_pObject->Serialize(ar);
		ar.Close();
	}
	catch(CException* e)
	{
		e->Delete();
		return false;
	}

	DWORD iSize = (DWORD)mf.GetLength();
	BYTE* pData = mf.Detach();
	bool ret = RegSetValueEx(m_Key, m_szValue, 0, REG_BINARY, pData, iSize) == ERROR_SUCCESS;
	free(pData);
	return ret;
}