Exemple #1
0
void CRegsterDialog::SaveUserInfo()
{
	UpdateData(TRUE);
	char Userstr[_MAX_PATH] = {0};
	sprintf_s(Userstr,  _MAX_PATH, "%s\\system\\userinfo.bin", CurrentPath);
	CFile cf;
	if(!cf.Open(Userstr, CFile::modeCreate|CFile::modeReadWrite))
		return;
	char username[32] = {0};
	strcpy_s(username, 32, m_username);
	int usernum = cf.GetLength()/sizeof(UserInfo);
	if(usernum != 0){
		UserInfo* Info = (UserInfo*)malloc(usernum*sizeof(UserInfo));
		ZeroMemory(Info, usernum*sizeof(UserInfo));
		cf.Read(Info, usernum*sizeof(UserInfo));
		int hasno = -1;
		for(int i=0; i<usernum; i++){
			UserInfo* tmp = Info+i;
			if(strcmp(tmp->UserName, username) == 0)
				hasno = i;
		}
		if(hasno == -1){
			if(usernum > 9){	//只能存9个
				cf.SeekToBegin();
				cf.Write(Info+1, (usernum-1)*sizeof(UserInfo));
			}
			else
				cf.SeekToEnd();
		}
		else{
			cf.SeekToBegin();
			for(int i=0; i<usernum; i++){
				UserInfo* tmp = Info+i;
				if(i != hasno)
					cf.Write(tmp,sizeof(UserInfo));
			}
			cf.Seek(-(long)sizeof(UserInfo), CFile::end);
		}
		if(Info)
			free(Info);
	}
	UserInfo info = {0};
	strcpy_s(info.UserName, 32, username);
	info.RememberPw = m_remember;
	if(m_remember){
		strcpy_s((char*)info.Pasword, 20, m_password);
		GetDisorString((char*)(info.Pasword), 19);
	}
	srand((unsigned)time(NULL));
	for(int i = 0; i < 4; i++){
		info.Puzzle[i] = rand();
	}
	cf.Write(&info, sizeof(UserInfo));
	cf.Close();
}
Exemple #2
0
BOOL CEncryptFile::EncryptFile(CString strKey, CString strSrcFile, CString strDstFile)
{
	if (strSrcFile != strDstFile) {
		if (!CopyFile(strSrcFile, strDstFile, FALSE))
			return  FALSE;
	}
	char *data = NULL;
	CFile *file;
	DWORD dwFileLen = 0;

	file = new CFile;
	if (!file->Open(strDstFile, CFile::shareDenyNone | CFile::modeReadWrite))
	{
		delete file;
		file = NULL;
		return FALSE;
	}

	dwFileLen = file->GetLength();
	data = new char[(int)dwFileLen];
	memset(data, 0, dwFileLen);

	//读取数据
	file->SeekToBegin();
	file->Read(data, dwFileLen);

	//加密
	int iAesLen = m_aes.aes_getsize(dwFileLen);
	char *AesData = new char[iAesLen];
	memset(AesData, 0, iAesLen);

	int iKeyLen = strKey.GetLength();
	char * pkey = new char[iKeyLen];
	memcpy_s(pkey, iKeyLen, strKey, iKeyLen);

	m_aes.aes_encrypt(pkey, data, dwFileLen, AesData, iAesLen);
	delete pkey;

	//写入数据
	file->SeekToBegin();
	file->Write(AesData, iAesLen);
	file->Flush();
	delete[] data;
	delete[] AesData;

	file->Close();
	
	delete file;

	return TRUE;
}
Exemple #3
0
void CMainFrame::OnSendFile() 
{
	// TODO: Add your command handler code here
	CMyCommDoc   *Doc   =  (CMyCommDoc   *)GetActiveDocument();
	if (!Doc->m_ComAction) {
		AfxMessageBox(_T("串口没有打开!"));
		return;
	}
	
	CSendFileByXModem dlg;
	dlg.m_ModemType = 0;
	if (dlg.DoModal()==IDOK)
	{
		//发送文件
		CFile fp;
		if(!(fp.Open((LPCTSTR)dlg.m_SendFileName ,CFile::modeRead))) 
		{
			AfxMessageBox(_T("打开文件出错!"));
			return;
		}
		fp.SeekToEnd();
		unsigned long fplength=fp.GetLength();
		char* fpBuff;
		fpBuff=new char[fplength];
		fp.SeekToBegin();
		if(fp.Read(fpBuff,fplength)<1)
		{
			fp.Close();
			return;
		}
		fp.Close();

		//send
		CMyCommView * myview = (CMyCommView *)GetActiveView();
		myview->m_EditLogger.AddText(_T("发送文件....\r\n"));
		BOOL mySendOk;
        
		switch(dlg.m_ModemType) {
			case 0:  //xModem
				mySendOk = Doc->SendByXmodem(fpBuff,fplength,0);
				break;
			case 1: //yModem
				break;
			case 2: //zModem
				
				break;
			case 3: //1k xmodem 
				
				break;
			default:
				return;
		}

		if(mySendOk)
			myview->m_EditLogger.AddText(_T("完成发送。\r\n"));
		else
			myview->m_EditLogger.AddText(_T("发送失败!!!\n\r"));

	}
}
//保存棋谱
bool CGameClientDlg::SaveChessManual(LPCTSTR pszFileName)
{
	//打开文件
	CFile FileManual;
	if (FileManual.Open(pszFileName,CFile::modeWrite|CFile::modeCreate)==FALSE) return false;

	//文件头
	tagChessManualHead ChessManualHead;
	ChessManualHead.wVersion=VER_MANUAL;
	ChessManualHead.dwManualDate=(DWORD)time(NULL);
	ChessManualHead.dwManualCount=(DWORD)m_GameLogic.m_ChessManualInfo.GetCount();

	//写入文件头
	FileManual.SeekToBegin();
	FileManual.Write(&ChessManualHead,sizeof(ChessManualHead));

	//棋谱数据
	tagChessManual * pChessManual=NULL;
	for (DWORD i=0;i<ChessManualHead.dwManualCount;i++)
	{
		pChessManual=&m_GameLogic.m_ChessManualInfo[i];
		FileManual.Write(pChessManual,sizeof(tagChessManual));
	}

	//关闭文件
	FileManual.SetLength(sizeof(ChessManualHead)+ChessManualHead.dwManualCount*sizeof(tagChessManual));
	FileManual.Close();

	return true;
}
void CFirewallOpener::ClearMappingsAtEnd() {
    m_bClearMappings = true;
    CICSRuleInfo mapping, search;

    //Add all mappings to the ICF.dat file
    CFile fICFdat;
    if(fICFdat.Open(GetICFdatFileName(), CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite|CFile::typeBinary)) {
        for(int i = 0; i < m_liAddedRules.GetCount(); i++) {
            mapping = m_liAddedRules.GetAt(i);

            //Search for the item on ICF.dat
            fICFdat.SeekToBegin();
            bool found = false;
            while(!found && ReadFromICFdat(fICFdat, search)) {
                if(search.m_nPortNumber == mapping.m_nPortNumber &&
                        search.m_byProtocol == mapping.m_byProtocol &&
                        search.m_strRuleName == mapping.m_strRuleName)
                {
                    found = true;
                }
            }

            if(!found) {
                fICFdat.SeekToEnd();
                AddToICFdat(fICFdat, mapping);
            }
        }
        fICFdat.Close();
    }
}
Exemple #6
0
//把htm的几个段都写到文件
BOOL CGenerateHtm::WriteHtmFile(const CString & filePath,const ePaperViewType & type)
{
	CFile file;
	if(file.Open(filePath,CFile::modeCreate | CFile::modeReadWrite))
	{
		CString s;
		file.SeekToBegin();
		file.Write(m_head,m_head.GetLength());
		s = "\r\n";
		file.Write(s,s.GetLength());
		file.Write(m_css,m_css.GetLength());
		s = "</style>\r\n";
		file.Write(s,s.GetLength());
		file.Write(m_js,m_js.GetLength());
		s = "</script>\r\n";
		file.Write(s,s.GetLength());
		s = "</head>\r\n";
		file.Write(s,s.GetLength());
		file.Write(m_body,m_body.GetLength());
		s = "";
		if(type != ePaperViewTypeScore)			//frame不能有body
			s = "</body>";
		s += "\r\n</html>";
		file.Write(s,s.GetLength());
		file.Close();
	}
	else
		return FALSE;//Open failed
	return TRUE;
}
Hash20Byte ComputeInfohash(const char *pFilename)
{
	if( pFilename == NULL )
		return Hash20Byte();

	CFile file;
	if( file.Open( pFilename, CFile::modeRead | CFile::typeBinary | CFile::shareDenyWrite ) )
	{
		UINT nFileSize = (UINT)file.GetLength();
		file.SeekToBegin();

		if( nFileSize < 128 )
			return Hash20Byte();

		unsigned char *pFileBuf = new unsigned char[ nFileSize ];
		file.Read( pFileBuf, nFileSize );
		file.Close();

		UINT nOffset = 0;
		bool nFound = false;
		for( /* nothing */; nOffset < ( nFileSize - 6 ); nOffset++ )
		{
			if( memcmp( pFileBuf + nOffset, "4:info", 6 ) == 0 )
			{
				nFound = true;
				break;
			}
		}

		if( !nFound )
		{
			delete pFileBuf;
			return Hash20Byte();
		}

		SHA1 sha1;
		sha1.Update( pFileBuf + nOffset + 6, nFileSize - ( nOffset + 6 + 1 ) );
		sha1.Final();

		unsigned char aSHA1Hash[20];
		sha1.GetHash( aSHA1Hash );

		Hash20Byte hash;
		hash = aSHA1Hash;

		delete pFileBuf;
		return hash;
	}
	else
	{
		return Hash20Byte();
	}
}
Exemple #8
0
BOOL CSetting::Save()
{
	CFile file;
	if(file.Open("Setting.set",CFile::modeWrite|CFile::modeCreate))
	{
		file.SeekToBegin();
		file.Write(this,sizeof(CSetting));
		file.Close();
		return TRUE;
	}
	else return FALSE;	
}
Exemple #9
0
BOOL CFace::Open(LPCSTR filename)
{
	CFile file;
	if(file.Open( filename,CFile::modeRead))
	{
		file.SeekToBegin();
		file.Read(this,sizeof(CFace));
		file.Close();
		return TRUE;
	}
	return FALSE;
}
Exemple #10
0
BOOL CFace::Save(LPCSTR filename)
{
	CFile file;
	if(file.Open(filename,CFile::modeWrite|CFile::modeCreate))
	{
		file.SeekToBegin();
		file.Write(this,sizeof(CFace));
		file.Close();
		return TRUE;
	}
	else return FALSE;	
}
void CmdwEditorDoc::Serialize(CArchive& ar)
{
	POSITION pos = this->GetFirstViewPosition();
	CView* cv = NULL;
	CEditView* pEv = NULL;
	
	do {
		cv = this->GetNextView(pos);
		if( cv != NULL && cv->IsKindOf(RUNTIME_CLASS(CEditView))) {
			pEv = (CEditView*)cv;  
			break;
		}
	} while(cv != NULL);

	if(pEv == NULL) return;

	//CString htmlpath;
	CFile *pCF = ar.GetFile();
	//if(pCF != NULL)
	//	htmlpath = pCF->GetFilePath() + _T(".html");

	if (ar.IsStoring())
	{
		// TODO: add storing code here
		/**
			unicode data 修改後儲存時轉換回 utf-8
			再由sundown 轉換成 html,通知 HtmlView 顯示
		*/
		LPCTSTR lpszText = pEv->LockBuffer();
		ASSERT(lpszText != NULL);
		UINT nLen = pEv->GetBufferLength();
		TRY
		{
			//ar.Write(lpszText, nLen*sizeof(TCHAR));
			getEditText(lpszText, nLen);

			pCF->SeekToBegin();
			pCF->Write(mib_utf8->data, mib_utf8->size);

			m_bHtmlExisted = convMd2Html((LPCTSTR)m_htmlPath, m_cssPath);
			this->UpdateAllViews(NULL, (LPARAM)(LPCTSTR)m_htmlPath, NULL);
		}
		CATCH_ALL(e)
		{
			pEv->UnlockBuffer();
			THROW_LAST();
		}
		END_CATCH_ALL

		pEv->UnlockBuffer();
	}
// 写入到*.pal文件
BOOL CRGB2YUVView::WriteYUV(byte *Video_Field0, byte *Video_Field1, int size)
{
	char strFileName[MAX_PATH]="720bmp.pal";
	CFile* f;
	f = new CFile();
	f->Open(strFileName, CFile::modeCreate |CFile::modeWrite);
	f->SeekToBegin();
	f->Write(Video_Field0, size);
	f->Write(Video_Field1, size);
	f->Close();
	
	char buffer[80];
	sprintf(buffer,"PAL图像保存为文件:%s ", strFileName);
	MessageBox(buffer, "提示信息", MB_OK | MB_ICONINFORMATION);

	return TRUE;
}
Exemple #13
0
//保存按钮
void CChessManual::OnPreserve()
{
	//获取目录
	TCHAR szPath[MAX_PATH]=TEXT("");
	GetCurrentDirectory(sizeof(szPath),szPath);

	//选择文件
	LPCTSTR pszFilter=TEXT("国际象棋棋谱文件 (*.CHM)|*.CHM||");
	CFileDialog DlgSaveManual(FALSE,TEXT("CHM"),NULL,OFN_NOCHANGEDIR|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,pszFilter);
	DlgSaveManual.m_pOFN->lpstrInitialDir=szPath;
	if (DlgSaveManual.DoModal()!=IDOK) return;

	//打开文件
	CFile FileManual;
	if (FileManual.Open(DlgSaveManual.GetPathName(),CFile::modeWrite|CFile::modeCreate)==FALSE)
	{
		AfxMessageBox(TEXT("无法创建文件,棋谱保存失败!"),MB_ICONSTOP);
		return;
	}

	//文件头
	tagChessManualHead ChessManualHead;
	ChessManualHead.wVersion=VER_MANUAL;
	ChessManualHead.dwManualDate=(DWORD)time(NULL);
	ChessManualHead.dwManualCount=(DWORD)m_GameLogic.m_ChessManualInfo.GetCount();

	//写入文件头
	FileManual.SeekToBegin();
	FileManual.Write(&ChessManualHead,sizeof(ChessManualHead));

	//棋谱数据
	tagChessManual * pChessManual=NULL;
	for (DWORD i=0;i<ChessManualHead.dwManualCount;i++)
	{
		pChessManual=&m_GameLogic.m_ChessManualInfo[i];
		FileManual.Write(pChessManual,sizeof(tagChessManual));
	}

	//关闭文件
	FileManual.SetLength(sizeof(ChessManualHead)+ChessManualHead.dwManualCount*sizeof(tagChessManual));
	FileManual.Close();

	return;
}
Exemple #14
0
void CRegsterDialog::SetDefServer(char *FileName, char *serverip)
{
	if(!serverip || strlen(serverip) == 0)
		return;

	CFile cf;
	if(!cf.Open(FileName, CFile::modeReadWrite|CFile::modeCreate))
		return;

	int servernum = cf.GetLength()/sizeof(DOWNLOADSERVERS);
	if(servernum == 0){
		cf.Close();
		return;
	}
	
	DOWNLOADSERVERS* server = (DOWNLOADSERVERS*)malloc(servernum*sizeof(DOWNLOADSERVERS));
	ZeroMemory(server, servernum*sizeof(DOWNLOADSERVERS));
	cf.Read(server, sizeof(DOWNLOADSERVERS)*servernum);
	int item = 0;
	for(item = 0; item< servernum; item++){
		if(strcmp(serverip, server[item].ServerIP) == 0)
			break;
	}
	int item1 = 0;
	for(item1=0; item1<servernum; item1++){
		if(server[item1].DefState == 1)
			break;
	}
	if(item != servernum){
		if(item1 != servernum){
			server[item1].DefState = 0;
		}
		server[item].DefState = 1;
	}
	else{
		if(item1 == servernum){
			server[0].DefState = 1;
		}
	}
	cf.SeekToBegin();
	cf.Write(server, sizeof(DOWNLOADSERVERS)*servernum);
	cf.Close();
	free(server);
}
Exemple #15
0
UINT CSupSubFile::ThreadProc()
{
	CFile f;
	if (!f.Open(m_fname, CFile::modeRead | CFile::typeBinary | CFile::shareDenyNone)) {
		return 1;
	}

	CAutoLock cAutoLock(&m_csCritSec);

	f.SeekToBegin();

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

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

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

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

	m_sub.Close();

	return 0;
}
Exemple #16
0
bool CIdentify::Save(CString filename)
{
	CString image;
	long i=0;
	for(i=0;i<m_nGestures;i++)
	{
		switch(m_Gestures[i].m_GroupStatus)
		{
			case 0:
				if(!m_Gestures[i].m_Description.IsEmpty())
					image+=_T("description[")+ToSafe(m_Gestures[i].m_Description)+_T("]\n");
				image+=_T("name[")+ToSafe(m_Gestures[i].m_Name)+_T("]\n");
				image+=_T("commands[")+(CString)m_Gestures[i].m_Commands+_T("]\n");
				if(m_Gestures[i].m_Compatibility.m_Type!=0)
					image+=_T("compatibility[")+(CString)m_Gestures[i].m_Compatibility+_T("]\n");// no convert!
				if(m_Gestures[i].m_Disable==true)
					image+=_T("disable[]\n");
				image+=_T("symbols[")+(CString)m_Gestures[i].m_Symbols+_T("]\n");
			break;
			case 1:
				if(!m_Gestures[i].m_Description.IsEmpty())
					image+=_T("description[")+ToSafe(m_Gestures[i].m_Description)+_T("]\n");
				image+=_T("opengroup[")+ToSafe(m_Gestures[i].m_Name)+_T("]\n");
			break;
			case 2:
				if(!m_Gestures[i].m_Description.IsEmpty())
					image+=_T("description[")+ToSafe(m_Gestures[i].m_Description)+_T("]\n");
				image+=_T("closegroup[")+ToSafe(m_Gestures[i].m_Name)+_T("]\n");
			break;
		}
		image+=_T("\n");
	}
	long length=image.GetLength();

	CFile file;
	if(!file.Open(filename,CFile::modeWrite|CFile::modeCreate))
		return false;
	file.SeekToBegin();
	file.Write(image.GetBuffer(length),length);
	file.Close();

	return true;
}
//将指定的文件内容转换为字节流,保存在 nDest 中
BOOL CXmlBase::ConvertFile2Variant(CComVariant& nDest, const CString& strPathfilename)
{
	nDest = _T("");
	//
	if (strPathfilename.IsEmpty()) return FALSE;
	
	//打开文件
	CFile file;
	if (!file.Open((LPCTSTR)strPathfilename
		, CFile::modeRead | CFile::shareDenyNone)) return FALSE;
	if (file.m_hFile == CFile::hFileNull) return FALSE;

	UINT nSize = (UINT)file.GetLength();
	char *pBuf = new char[nSize + 2];
	memset(pBuf, NULL, nSize + 2);
	file.SeekToBegin();
	char *p = pBuf;
	DWORD nNumberOfBytesRead = 0;
	UINT nTotalRead = 0;
	while (ReadFile(file.m_hFile, p, 1024 * 4, &nNumberOfBytesRead, NULL) && nNumberOfBytesRead > 0)
	{
		p += nNumberOfBytesRead;
		nTotalRead += nNumberOfBytesRead;
	}
	file.Close();

	if (nTotalRead == 0 || p == NULL) return FALSE;

	//base64
	int nEncodeLen = nTotalRead * 2;
	char * pEecode = new char[nEncodeLen];
	memset(pEecode, NULL, nEncodeLen);
	BOOL bEocode = ATL::Base64Encode((BYTE*)pBuf, nTotalRead, pEecode, &nEncodeLen);
	if (bEocode)
	{
		nDest = pEecode;
	}

	delete[] pEecode;
	delete[] pBuf;
	return TRUE;
}
void CSingleView::OnLButtonDown(UINT nFlags, CPoint point)
{
    // step 1) 파일 객체 생성
    CFile* pFile = new CFile();
    ASSERT (pFile != NULL);
    if ( !pFile->Open("foo.dat", CFile::modeWrite|CFile::modeCreate) )
    {
        // Handle error
        return;
    }

    // step 2: CArchive 객체 생성
    bool bReading = false;  // ... for writing
    CArchive* pArchive = NULL;
    try
    {
        pFile->SeekToBegin();
        UINT uMode = (bReading ? CArchive::load : CArchive::store);
        pArchive = new CArchive(pFile, uMode);
        ASSERT (pArchive != NULL);
    }
    catch (CException* pException)
    {
        // Handle error
        return;
    }

    // step 3: 직렬화 맴버 함수 호출
    CFoo*   pFoo = new CFoo();
    pFoo->Serialize( *pArchive );
    delete pFoo;


    // step 4: 다리 객체와 파일 객체 파괴
    pArchive->Close();
    delete pArchive;
    pFile->Close();
    delete pFile;

    CView::OnLButtonDown(nFlags, point);
}
Exemple #19
0
int YpFile::ReadSmallFile(BYTE* data, UINT max_len)
{
	ULONGLONG size;
	int ret;
	if (GetFileSize(size))
	{
		if (size > 1048000)
		{
			return -1;
		}
		CFile file;
		if (file.Open(path, CFile::modeRead))
		{
			file.SeekToBegin();
			ret = file.Read(data, max_len);
			file.Close();
			return ret;
		}
	}
	return -1;
}
// 读第7,8个字符,00为Normal,02为扩展,04为扩展线性
HEXFILE_FORMAT	CHexFileParser::GetHexFileType(CFile& hexFile)
{
	int nRet = 0;
	char chBuf[64] = {0};
	hexFile.Read(chBuf, 12);
	if (chBuf[8] == '0')
	{		
	}
	else if (chBuf[8] == '2')
	{
		nRet = 1;
	}
	else if (chBuf[8] == '4')
	{
		nRet = 2;
	}

	// reset file pointer
	hexFile.SeekToBegin();
	return (HEXFILE_FORMAT)nRet;		
}
Exemple #21
0
BOOL CSetting::Load()
{
	CFile file;
	if(file.Open( "Setting.set",CFile::modeRead))
	{
		file.SeekToBegin();
		file.Read(this,sizeof(CSetting));
		file.Close();

		if(IsNormal())return TRUE;
		else
		{
			Reset();
			Save();
			return FALSE;
		}		
	}
	MessageBox(NULL, "没找到 Setting.set 文件\n\n这个文件并不是必需的,但它记录了你的设置内容,\n\n请不要删掉\n\n你现在可以通过菜单 \"文件\" -> \"设置\" 重新设定.","提醒",MB_OK|MB_ICONINFORMATION);
	Reset();
	Save();
	return FALSE;
}
// 隔行显示BMP
void CRGB2YUVView::OnReadBmp() 
{
	// TODO: Add your command handler code here
	CDC *pDC = GetDC();
	
	CRect rect;
	CBrush brush(RGB(128,128,128));
	GetClientRect(&rect);
	pDC->FillRect(&rect, &brush);

	BITMAPFILEHEADER bmfh;
	BITMAPINFOHEADER bmih;

    char strFileName[MAX_PATH]="720bmp.bmp";
	CFile* f;
	f = new CFile();
	f->Open(strFileName, CFile::modeRead);
	f->SeekToBegin();
	f->Read(&bmfh, sizeof(bmfh));
	f->Read(&bmih, sizeof(bmih));
  
    // 分配图片像素内存
    RGBTRIPLE *rgb;
	rgb = new RGBTRIPLE[bmih.biWidth*bmih.biHeight];

	f->SeekToBegin();
	f->Seek(54,CFile::begin); // BMP 54个字节之后的是像素数据
	f->Read(rgb, bmih.biWidth * bmih.biHeight * 3);	 // 这里只读24位RGB(r,g,b)图像
	
	// 显示上场 (奇数行组成的奇数场)
	for (int i = 0; i<bmih.biHeight; i++) {
		for (int j = 0; j<bmih.biWidth; j++) {
			if(!(i%2))
				pDC->SetPixel(j, bmih.biHeight-i, RGB(rgb[i*bmih.biWidth+j].rgbtRed,rgb[i*bmih.biWidth+j].rgbtGreen,rgb[i*bmih.biWidth+j].rgbtBlue));
			for (int k=0; k<1000; k++) ;  //延时
		}
	}

    Sleep(500);

    // 显示下场 (偶数行组成的偶数场)
	for (int i_ = 0; i_<bmih.biHeight; i_++) {
		for (int j_ = 0; j_<bmih.biWidth; j_++) {
			if(i_%2)
				pDC->SetPixel(j_, bmih.biHeight-i_, RGB(rgb[i_*bmih.biWidth+j_].rgbtRed,rgb[i_*bmih.biWidth+j_].rgbtGreen,rgb[i_*bmih.biWidth+j_].rgbtBlue));
			for (int k=0; k<1000; k++) ;  //延时
		}
	}

	// 显示24位BMP信息
	LONG dwWidth = bmih.biWidth;
	LONG dwHeight = bmih.biHeight;
	WORD wBitCount = bmih.biBitCount;
	char buffer[80];
	sprintf(buffer,"图像宽为:%ld 高为:%ld 像数位数:%d", dwWidth, dwHeight, wBitCount);
	MessageBox(buffer, "每个像素的位数", MB_OK | MB_ICONINFORMATION);
	
	f->Close();
	delete f;
	delete rgb;
}
// 读取PAL文件转换为RGB并显示
void CRGB2YUVView::OnReadPAL() 
{
	// TODO: Add your command handler code here
	CDC *pDC = GetDC();
	CRect rect;
	CBrush brush(RGB(128,128,128));
	GetClientRect(&rect);
	pDC->FillRect(&rect, &brush);

	// PAL 720x576 : 中国的电视标准为PAL制	
	int CurrentXRes = 720;
	int CurrentYRes = 576;
	int size        = CurrentXRes * CurrentYRes;
    
	// 分配内存
	byte *Video_Field0 = (byte*)malloc(CurrentXRes*CurrentYRes);  
	byte *Video_Field1 = (byte*)malloc(CurrentXRes*CurrentYRes);

	// 保存内存指针
	byte *Video_Field0_ = Video_Field0;
	byte *Video_Field1_ = Video_Field1;

	// 初始化内存
	ZeroMemory(Video_Field0, CurrentXRes*CurrentYRes);
	ZeroMemory(Video_Field1, CurrentXRes*CurrentYRes);

	byte yuv_y0, yuv_u0, yuv_v0; // yuv_v1;  // {y0, u0, v0, v1};
	byte r, g, b;
	byte bufRGB[3];  // 临时保存{R,G,B}
	byte bufYUV[3];  // 临时保存{Y,U,V}
	
	// 初始化数组空间
	memset(bufRGB,0, sizeof(byte)*3); 
	memset(bufYUV,0, sizeof(byte)*3); 
    
    char strFileName[MAX_PATH]="720bmp.pal";
 
    // 分配图片像素内存
    RGBTRIPLE *rgb;
	rgb = new RGBTRIPLE[CurrentXRes*CurrentYRes];

	memset(rgb,0, sizeof(RGBTRIPLE)*CurrentXRes*CurrentYRes); // 初始化内存空间

	CFile* f;
	f = new CFile();
	f->Open(strFileName, CFile::modeRead);
	f->SeekToBegin();
	f->Read(Video_Field0, CurrentXRes*CurrentYRes);
	f->Read(Video_Field1, CurrentXRes*CurrentYRes);

	// 上场  (1,3,5,7...行)
	for ( int i = CurrentYRes-1; i>=0; i--) {
		for ( int j = 0; j<CurrentXRes; j++) {
			if(!(i%2)==0) 
			{
				// UYVY标准  [U0 Y0 V0 Y1] [U1 Y2 V1 Y3] [U2 Y4 V2 Y5] 每像素点两个字节,[内]为四个字节 
				if ((j%2)==0) 
				{
					yuv_u0 = *Video_Field0;  
					Video_Field0++;
				} 
				else
				{
					yuv_v0 = *Video_Field0;  
					Video_Field0++;
				}
				yuv_y0 = *Video_Field0;      
				Video_Field0++;

				bufYUV[0] = yuv_y0;  //	Y
				bufYUV[1] = yuv_u0;  // U
				bufYUV[2] = yuv_v0;  // V

				// RGB转换为YUV
				YUV2RGB(bufRGB,bufYUV);
				r = bufRGB[0];   // y
				g = bufRGB[1];   // u
				b = bufRGB[2];   // v
				if (r>255) r=255; if (r<0) r=0;
				if (g>255) g=255; if (g<0) g=0;
				if (b>255) b=255; if (b<0) b=0;

				for (int k=0; k<1000; k++) ;  //延时
				// 视图中显示
				pDC->SetPixel(j, CurrentYRes-1-i, RGB(r, g, b));

			}// end if i%2
		}
	}

    // 下场 (2,4,6,8...行)
	for ( int i_ = CurrentYRes-1; i_>=0; i_--) {
		for ( int j_ = 0; j_<CurrentXRes; j_++) {
			if((i_%2)==0) 
			{
				// UYVY标准  [U0 Y0 V0 Y1] [U1 Y2 V1 Y3] [U2 Y4 V2 Y5] 每像素点两个字节,[内]为四个字节 
				if ((j_%2)==0) 
				{
					yuv_u0 = *Video_Field1;  
					Video_Field1++;
				} 
				else
				{
					yuv_v0 = *Video_Field1;  
					Video_Field1++;
				}
				yuv_y0 = *Video_Field1;      
				Video_Field1++;

				bufYUV[0] = yuv_y0;  //	Y
				bufYUV[1] = yuv_u0;  // U
				bufYUV[2] = yuv_v0;  // V

				// RGB转换为YUV
				YUV2RGB(bufRGB,bufYUV);
				r = bufRGB[0];   // y
				g = bufRGB[1];   // u
				b = bufRGB[2];   // v
				if (r>255) r=255; if (r<0) r=0;
				if (g>255) g=255; if (g<0) g=0;
				if (b>255) b=255; if (b<0) b=0;

				for (int k=0; k<1000; k++) ;  //延时
				// 视图中显示
				pDC->SetPixel(j_, CurrentYRes-1-i_, RGB(r, g, b));
			}
		}
	}
	
	// 提示完成
	char buffer[80];
	sprintf(buffer,"完成读取PAL文件:%s ", strFileName);
	MessageBox(buffer, "提示信息", MB_OK | MB_ICONINFORMATION);

    // 关闭PAL电视场文件
	f->Close();
	// WriteYUV(Video_Field0_, Video_Field1_, size);
	
	// 释放内存
	free( Video_Field0_ ); 
	free( Video_Field1_ );
	delete f;
	delete rgb;
}
// 转换RGB
void CRGB2YUVView::OnConvertPAL() 
{
	CDC *pDC = GetDC();
	CRect rect;
	CBrush brush(RGB(128,128,128));
	GetClientRect(&rect);
	pDC->FillRect(&rect, &brush);

	// PAL 720x576 : 中国的电视标准为PAL制	
	int CurrentXRes = 720;
	int CurrentYRes = 576;
	int size        = CurrentXRes * CurrentYRes;
    
	// 分配内存
	byte *Video_Field0 = (byte*)malloc(CurrentXRes*CurrentYRes);  
	byte *Video_Field1 = (byte*)malloc(CurrentXRes*CurrentYRes);
	
	// 保存内存指针
	byte *Video_Field0_ = Video_Field0;
	byte *Video_Field1_ = Video_Field1;

	byte yuv_y0, yuv_u0, yuv_v0, yuv_v1;  // {y0, u0, v0, v1};
	byte bufRGB[3];  // 临时保存{R,G,B}
	byte bufYUV[3];  // 临时保存{Y,U,V}

	// 初始化数组空间
    ZeroMemory(bufRGB, sizeof(byte)*3);
	ZeroMemory(bufYUV, sizeof(byte)*3);

	// 初始化内存
	ZeroMemory(Video_Field0, CurrentXRes*CurrentYRes);
	ZeroMemory(Video_Field1, CurrentXRes*CurrentYRes);
	
	// BMP 位图操作
	BITMAPFILEHEADER bmfh;
	BITMAPINFOHEADER bmih;

    char strFileName[MAX_PATH]="720bmp.bmp";
	CFile* f;
	f = new CFile();
	f->Open(strFileName, CFile::modeRead);
	f->SeekToBegin();
	f->Read(&bmfh, sizeof(bmfh));
	f->Read(&bmih, sizeof(bmih));
 
    // 分配图片像素内存
    RGBTRIPLE *rgb;
	rgb = new RGBTRIPLE[bmih.biWidth*bmih.biHeight];

	f->SeekToBegin();
	f->Seek(54,CFile::begin);  // BMP 54个字节之后的是位像素数据
	f->Read(rgb, bmih.biWidth * bmih.biHeight * 3);	 // 这里只读24位RGB(r,g,b)图像
	
	// 上场  (1,3,5,7...行)
	for (int i = bmih.biHeight-1; i>=0; i--) {
		for (int j = 0; j<bmih.biWidth; j++) {
			if(!(i%2)==0) 
			{
				bufRGB[0] = rgb[i*bmih.biWidth+j].rgbtRed;   //	R
				bufRGB[1] = rgb[i*bmih.biWidth+j].rgbtGreen; // G
				bufRGB[2] = rgb[i*bmih.biWidth+j].rgbtBlue;  // B

				// RGB转换为YUV
				RGB2YUV(bufRGB,bufYUV);
				yuv_y0 = bufYUV[0];   // y
				yuv_u0 = bufYUV[1];   // u
				yuv_v0 = bufYUV[2];   // v
				
				for (int k=0; k<1000; k++) ;  //延时
				// 视图中显示
				pDC->SetPixel(j, (bmih.biHeight-1)-i, RGB(bufRGB[0], bufRGB[1], bufRGB[2]));
				
				// UYVY标准  [U0 Y0 V0 Y1] [U1 Y2 V1 Y3] [U2 Y4 V2 Y5] 每像素点两个字节,[内]为四个字节 
				if ((j%2)==0) 
				{
					*Video_Field0 = yuv_u0;  
					Video_Field0++;
					yuv_v1 = yuv_v0;   // v保存起来供下一字节使用
				} 
				else
				{
					*Video_Field0 = yuv_v1;  
					Video_Field0++;
				}
				*Video_Field0 = yuv_y0;      
				Video_Field0++;
			}// end if i%2
		}
	}

    // 下场 (2,4,6,8...行)
	for (int i_ = bmih.biHeight-1; i_>=0; i_--) {
		for (int j_ = 0; j_<bmih.biWidth; j_++) {
			if((i_%2)==0) 
			{
				bufRGB[0] = rgb[i_*bmih.biWidth+j_].rgbtRed;   //	R
				bufRGB[1] = rgb[i_*bmih.biWidth+j_].rgbtGreen; // G
				bufRGB[2] = rgb[i_*bmih.biWidth+j_].rgbtBlue;  // B

				// RGB转换为YUV
				RGB2YUV(bufRGB,bufYUV);
				yuv_y0 = bufYUV[0];   // y
				yuv_u0 = bufYUV[1];   // u
				yuv_v0 = bufYUV[2];   // v

				for (int k=0; k<1000; k++) ;  //延时
				// 视图中显示
				pDC->SetPixel(j_, (bmih.biHeight-1)-i_, RGB(bufRGB[0], bufRGB[1], bufRGB[2]));

				// UYVY标准  [U0 Y0 V0 Y1] [U1 Y2 V1 Y3] [U2 Y4 V2 Y5] 每像素点两个字节,[内]为四个字节 
				if ((j_%2)==0) 
				{
					*Video_Field1 = yuv_u0;  
					Video_Field1++;
					yuv_v1 = yuv_v0;   // v保存起来供下一字节使用
				} 
				else
				{
					*Video_Field1 = yuv_v1;  
					Video_Field1++;
				}
				*Video_Field1 = yuv_y0;      
				Video_Field1++;
			}
		}
	}

    // 关闭BMP位图文件
	f->Close();
	WriteYUV(Video_Field0_, Video_Field1_, size);
	
	// 释放内存
	free( Video_Field0_ ); 
	free( Video_Field1_ );
	delete f;
	delete rgb;
}
Exemple #25
0
void CWaveIn::SaveFile(LPCSTR strFileName, bool bCreate, char *pszData, DWORD dwLen)
{
    if (bCreate)
    {
        CFile file;
        if (file.Open(strFileName, CFile::modeCreate | CFile::modeReadWrite))
        {
            RIFF_HEADER riff_header = {0};
            FMT_BLOCK   fmt_block   = {0};
            DATA_BLOCK  data_block  = {0};

            memcpy(riff_header.szRiffID, "RIFF", 4);
            memcpy(riff_header.szRiffFormat, "WAVE", 4);
            riff_header.dwRiffSize = sizeof(RIFF_HEADER) + sizeof(FMT_BLOCK) + sizeof(DATA_BLOCK) + dwLen - 8;

            memcpy(fmt_block.szFmtID, "fmt ", 4);
            fmt_block.dwFmtSize = sizeof(WAVE_FORMAT);
            fmt_block.wavFormat.wFormatTag = WAVE_FORMAT_PCM;
            fmt_block.wavFormat.wChannels = m_wChannel;
            fmt_block.wavFormat.dwSamplesPerSec = m_dwSample;
            fmt_block.wavFormat.dwAvgBytesPerSec = m_wChannel * m_dwSample * m_wBit / 8;
            fmt_block.wavFormat.wBlockAlign = m_wBit * m_wChannel / 8;
            fmt_block.wavFormat.wBitsPerSample = m_wBit;

            memcpy(data_block.szDataID, "data", 4);
            data_block.dwDataSize = dwLen;

            file.Write(&riff_header, sizeof(RIFF_HEADER));
            file.Write(&fmt_block, sizeof(FMT_BLOCK));
            file.Write(&data_block, sizeof(DATA_BLOCK));
            file.Write(pszData, dwLen);
            file.Close();
        }
    }
    else
    {
        CFile file;
        if (file.Open(strFileName, CFile::modeReadWrite))
        {
            RIFF_HEADER riff_header = {0};
            FMT_BLOCK   fmt_block   = {0};
            DATA_BLOCK  data_block  = {0};
			FACT_BLOCK  fat_block   = {0};
			WORD		wData		= 0;
			BOOL		bHaveFact	= FALSE;

            file.Read(&riff_header, sizeof(RIFF_HEADER));
            file.Read(&fmt_block, sizeof(FMT_BLOCK));

			if (18 == fmt_block.dwFmtSize)	// 18 多2个字节的扩展数据
				file.Read(&wData, 2);

			file.Read(&fat_block, sizeof(FACT_BLOCK));

			if (0 != strncmp(fat_block.szFactID, "fact", 4))	// FACT_BLOCK是可选的
				file.Seek(-12, CFile::current);
			else
				bHaveFact = TRUE;

			file.Read(&data_block, sizeof(DATA_BLOCK));

            riff_header.dwRiffSize += dwLen;
            fat_block.dwDataSize += dwLen;
			data_block.dwDataSize += dwLen;

            file.SeekToBegin();
            file.Write(&riff_header, sizeof(RIFF_HEADER));
            file.Write(&fmt_block, sizeof(FMT_BLOCK));
			if (18 == fmt_block.dwFmtSize) file.Seek(2, CFile::current);
			if (bHaveFact) file.Write(&fmt_block, sizeof(FMT_BLOCK));
            file.Write(&data_block, sizeof(DATA_BLOCK));
            file.SeekToEnd();
            file.Write(pszData, dwLen);
            file.Close();
        }
    }
}
Exemple #26
0
void ModEncrypt::VerifyEncryptFile(/*CString& strPassWord*/)
{
	char *szPassWord=NULL;
	char *MP=NULL;
	char *EP=NULL;
	char *EP1=NULL;
	try
	{
		long i=0,iPos=0;
		char tmp;
		// a$
		// bTmp  String * 1
		CFile f;
		DWORD lngEP,lngMP;
		if(!f.Open(user::gstrWinDir+FilejmBASE1,CFile::modeRead))
			return;
		//开始字符串长度
		f.SeekToBegin();
		f.Read(&lngMP,sizeof(lngMP));
		MP=new char[lngMP+1];
		f.Read(MP,lngMP);
		MP[lngMP]='\0';
		//然后是密码长度
		f.Read(& lngEP,sizeof(lngEP));
		f.Read(& glngLimitedDemoVersionDays,sizeof(DWORD));
		f.Read(& gLngSavedMicroDogID,sizeof(DWORD));
		f.Read(& gLngVersionID,sizeof(DWORD));
		f.Read(& glngVersion,sizeof(glngVersion));
		EP=new char[lngEP+1];
		f.Read(EP,lngEP);
		EP[lngEP]='\0';
		f.Close();
		
		//if(strPassWord=="")
		{
			if(!f.Open(user::gstrWinDir + FilePsw,CFile::modeRead))
				goto FunOut;
			int len=f.GetLength();
			len-=16;
			f.Seek(16,CFile::begin);
			szPassWord=new char[len+1];
			f.Read(szPassWord,len);
			szPassWord[len]='\0';
			f.Close();
		}
		//MP.ReleaseBuffer();
		//EP.ReleaseBuffer();
		//strPassWord.ReleaseBuffer();
		int passlen=strlen(szPassWord);
		EP1=new char [passlen+1];
		for( i = 0 ; i<passlen;i++)
		{
			tmp=szPassWord[i];
			
			if( '0' <= tmp && tmp <='9' ){
				iPos = tmp - '0' + 2;
			}else if( 'A' <= tmp && tmp <= 'Z' ){
				iPos = tmp - 'A' + 12;
			}
			else if('a' <= tmp && tmp <= 'z' ){
				iPos = tmp - 'a' + 12;
			}
			EP1[i]=(char)MP[iPos-1];
			//MsgBox EP1
		}
		EP1[i]='\0';
		if( strcmp(EP1, EP)==0 )
		{
			EncryptCompanyName(szPassWord, true);
			//EncryptCompanyName(strPassWord, false);
			/*#if DebugMode = -1 ){
			//MsgBox "你是合法用户!"
      #endif*/
			if( gLngVersionID == 1236 && glngVersion == glngAppVersion ){
				//标准版标志
				gbLegalUser = true;
			}else{
				gbLegalUser = false;
			}
			if( FileExists(user::gstrWinDir + FileOutDate) ) 
				::DeleteFile( user::gstrWinDir + FileOutDate);
			if( FileExists(user::gstrWinDir + FileFlag) )
				::DeleteFile( user::gstrWinDir + FileFlag);
			if(!f.Open(user::gstrWinDir+FileFlag,CFile::modeWrite|CFile::modeCreate))
				goto FunOut;
			lngEP = 1234;
			f.Write(&lngEP,sizeof(DWORD));
			f.Close();
			SetFileTime(user::gstrWinDir + FileWinCom, user::gstrWinDir + FileFlag);
		}
		else
		{
			//MsgBox "你是非法用户!"
			gstrLegalCompanyName = GetResStr(IDS_YouAreIllegalUser);
			gLngVersionID=0;
			gbLegalUser = false;
		}
	}
	catch(CFileException * e)
	{
		e->ReportError();
		e->Delete();
	}
FunOut:
	delete [] szPassWord;
	delete [] MP;
	delete [] EP;
	delete [] EP1;
}
BOOL CPreviewThread::Run()
{
	//Xman
	// BEGINSLUGFILLER: SafeHash
	CReadWriteLock lock(&theApp.m_threadlock);
	if (!lock.ReadLock(0))
		return 0;
	// END SLUGFILLER: SafeHash

	ASSERT (m_pPartfile) ;
	CFile destFile;
	CFile srcFile;
	if (!srcFile.Open(m_pPartfile->GetFilePath(), CFile::modeRead | CFile::shareDenyNone))
		return FALSE;
	try{
		uint64 nSize = m_pPartfile->GetFileSize();
		CString strExtension = CString(_tcsrchr(m_pPartfile->GetFileName(), _T('.')));
		CString strPreviewName = m_pPartfile->GetTempPath() + m_pPartfile->GetFileName().Mid(0, 5) + _T("_preview") + strExtension;
		bool bFullSized = true;
		if (!strExtension.CompareNoCase(_T(".mpg")) || !strExtension.CompareNoCase(_T(".mpeg")))
			bFullSized = false;
		if (!destFile.Open(strPreviewName, CFile::modeWrite | CFile::shareDenyWrite | CFile::modeCreate))
			return FALSE;
		srcFile.SeekToBegin();
		if (bFullSized)
			destFile.SetLength(nSize);
		destFile.SeekToBegin();
		BYTE abyBuffer[4096];
		uint32 nRead;
		while (destFile.GetPosition()+4096 < PARTSIZE*2){
			nRead = srcFile.Read(abyBuffer,4096);
			destFile.Write(abyBuffer,nRead);
		}
		srcFile.Seek(-(LONGLONG)(PARTSIZE*2), CFile::end);
		uint32 nToGo = PARTSIZE*2;
		if (bFullSized)
			destFile.Seek(-(LONGLONG)(PARTSIZE*2), CFile::end);
		do{
			nRead = (nToGo - 4096 < 1)? nToGo:4096;
			nToGo -= nRead;
			nRead = srcFile.Read(abyBuffer,4096);
			destFile.Write(abyBuffer,nRead);
		}
		while (nToGo);
		destFile.Close();
		srcFile.Close();
		m_pPartfile->m_bPreviewing = false;

		SHELLEXECUTEINFO SE = {0};
		SE.fMask = SEE_MASK_NOCLOSEPROCESS;

		CString strCommand;
		CString strArgs;
		CString strCommandDir;
		if (!m_strCommand.IsEmpty())
		{
			SE.lpVerb = _T("open");	// "open" the specified video player

			// get directory of video player application
			strCommandDir = m_strCommand;
			int iPos = strCommandDir.ReverseFind(_T('\\'));
			if (iPos == -1)
				strCommandDir.Empty();
			else
				strCommandDir = strCommandDir.Left(iPos + 1);
			PathRemoveBackslash(strCommandDir.GetBuffer());
			strCommandDir.ReleaseBuffer();

			strArgs = m_strCommandArgs;
			if (!strArgs.IsEmpty())
				strArgs += _T(' ');
			if (strPreviewName.Find(_T(' ')) != -1)
				strArgs += _T('\"') + strPreviewName + _T('\"');
			else
				strArgs += strPreviewName;

			strCommand = m_strCommand;
			ExpandEnvironmentStrings(strCommand);
			ExpandEnvironmentStrings(strArgs);
			ExpandEnvironmentStrings(strCommandDir);
			SE.lpFile = strCommand;
			SE.lpParameters = strArgs;
			SE.lpDirectory = strCommandDir;
		}
		else
		{
			SE.lpVerb = NULL;	// use the default verb or the open verb for the document
			SE.lpFile = strPreviewName;
		}
		SE.nShow = SW_SHOW;
		SE.cbSize = sizeof(SE);
		ShellExecuteEx(&SE);
		if (SE.hProcess){
			WaitForSingleObject(SE.hProcess, INFINITE);
			CloseHandle(SE.hProcess);
		}
		CFile::Remove(strPreviewName);
	}
	catch(CFileException* error){
		m_pPartfile->m_bPreviewing = false;
		error->Delete();
	}
	return TRUE;
}
Exemple #28
0
HRESULT CGif::LoadFromFile(LPCTSTR lpstrFileName)
{
	DebugPrintf("道具GIF 头=%s ",lpstrFileName);
	if (NULL != m_pImage)
	{
		delete m_pImage;
		m_pImage = NULL;
		
	}

#ifndef BZ_ZLIB
	CFile	TempFile;
	if (! TempFile.Open(lpstrFileName, CFile::modeRead))
	{
		CString	 str(lpstrFileName);
		str.Format(_TEXT("LoadFromFile() failed , reason : open file \" %s \"Failed"), lpstrFileName);
		//WriteToFile(ErrorFileName, str);
		return E_FAIL;
	}


	LONGLONG  llFileSize = TempFile.GetLength();
	HGLOBAL		hGlobalMem = GlobalAlloc(GPTR, static_cast<SIZE_T>(llFileSize));
	if (NULL == hGlobalMem)
	{
		CString	 str("LoadFromFile() failed , reason : malloc memory failed");
		WriteToFile(ErrorFileName, str);

		AfxMessageBox(str);
		TempFile.Close();
		return E_OUTOFMEMORY;
	}

	TempFile.SeekToBegin();
	void	*pBuf = GlobalLock(hGlobalMem);
	int		iReadSize = TempFile.Read(pBuf, static_cast<UINT>(llFileSize));
	GlobalUnlock(hGlobalMem);
	TempFile.Close();
#endif

#ifdef BZ_ZLIB


	TCHAR pchar[MAX_PATH];
	ZeroMemory(pchar,MAX_PATH);
	memcpy(pchar,lpstrFileName,strlen(lpstrFileName));
	CUnZipRes unZipRes;

	int		iReadSize;
	void	*pBuf = unZipRes.LoadFileBufferFromZip(pchar, iReadSize);

	//DebugPrintf("道具GIF pchar=%s",pchar);
	//DebugPrintf("道具GIF pIStream=%d",pIStream);

	if (NULL == pBuf)
	{
		CString	 str("LoadFromFile() failed , reason : Stream = NULL ");
		WriteToFile(ErrorFileName, str);
		return E_FAIL;
	}

#endif

	//从内存中加载动画文件
	m_animator.OpenAnimatorFromMemory((BYTE *)pBuf, iReadSize);

	//获取帧数量 
	m_uiFrameCount = m_animator.GetFrameCount();

	//加载每个帧图片到帧列表
	LoadImageListFromAnimator();

	//设置每个帧的延时
	m_pFrameDelay = new UINT[m_uiFrameCount];	//new帧延时
	if (NULL == m_pFrameDelay)
	{
		//OutputDebugString("zhtout:NULL == m_pFrameDelay");
		return E_FAIL;
	}

	for(int i = 0; i < m_uiFrameCount; i++)
	{
		m_pFrameDelay[i] = m_animator.GetSpeed();
	}

	m_uiCurSelFrameID =  0;
	m_LastTimeSwitchFrame = GetTickCount();  //获取第一次计时值

	//设置第一张图片
	m_pImage = GetFrameData(0); 

	CString str;

	m_animator.GetWidthAndHeight(&m_nWidth, &m_nHeight);

	return NOERROR;
}
BOOL CPreviewThread::Run()
{
	ASSERT (m_pPartfile) ;
	CFile destFile;
	CFile srcFile;
	if (!srcFile.Open(m_pPartfile->GetFilePath(), CFile::modeRead | CFile::shareDenyNone))
		return FALSE;
	try{
		uint32 nSize = m_pPartfile->GetFileSize();
		CString strExtension = CString(_tcsrchr(m_pPartfile->GetFileName(), _T('.')));
		CString strPreviewName = m_pPartfile->GetTempPath() + _T("\\") + m_pPartfile->GetFileName().Mid(0, 5) + _T("_preview") + strExtension;
		bool bFullSized = true;
		if (!strExtension.CompareNoCase(_T(".mpg")) || !strExtension.CompareNoCase(_T(".mpeg")))
			bFullSized = false;
		if (!destFile.Open(strPreviewName, CFile::modeWrite | CFile::shareDenyWrite | CFile::modeCreate))
			return FALSE;
		srcFile.SeekToBegin();
		if (bFullSized)
			destFile.SetLength(nSize);
		destFile.SeekToBegin();
		BYTE abyBuffer[4096];
		uint32 nRead;
		while (destFile.GetPosition()+4096 < PARTSIZE*2){
			nRead = srcFile.Read(abyBuffer,4096);
			destFile.Write(abyBuffer,nRead);
		}
		srcFile.Seek(-(PARTSIZE*2),CFile::end);
		uint32 nToGo =PARTSIZE*2;
		if (bFullSized)
			destFile.Seek(-(PARTSIZE*2),CFile::end);
		do{
			nRead = (nToGo - 4096 < 1)? nToGo:4096;
			nToGo -= nRead;
			nRead = srcFile.Read(abyBuffer,4096);
			destFile.Write(abyBuffer,nRead);
		}
		while (nToGo);
		destFile.Close();
		srcFile.Close();
		m_pPartfile->m_bPreviewing = false;

		SHELLEXECUTEINFO SE;
		MEMSET(&SE,0,sizeof(SE));
		SE.fMask = SEE_MASK_NOCLOSEPROCESS ;
		SE.lpVerb = _T("open");
		
		CString path;
		if (!m_player.IsEmpty())
		{
			TCHAR shortPath[512]; //Cax2 short path for vlc
			GetShortPathName(strPreviewName, shortPath, ARRSIZE(shortPath));

			path=thePrefs.GetVideoPlayer();
			int pos = path.ReverseFind(_T('\\'));
			if (pos == -1)
				path.Empty();
			else
				path = path.Left(pos + 1);
			SE.lpFile = m_player.GetBuffer();
			SE.lpParameters=shortPath;
			SE.lpDirectory=path.GetBuffer();
		}
		else
			SE.lpFile = strPreviewName.GetBuffer();
		SE.nShow = SW_SHOW;
		SE.cbSize = sizeof(SE);
		ShellExecuteEx(&SE);
		if (SE.hProcess){
			WaitForSingleObject(SE.hProcess, INFINITE);
			CloseHandle(SE.hProcess);
		}
		CFile::Remove(strPreviewName);
	}	
	catch(CFileException* error){
		m_pPartfile->m_bPreviewing = false;
		error->Delete();
	}
	return TRUE;
}
Exemple #30
0
BOOL CSelectdiaryDlg::OnInitDialog()
{
    CETApplicationView *prev = (CETApplicationView*) this->GetParent();
    CDialogEx::OnInitDialog();
    CRect rect;

    HINSTANCE hinst = ::AfxGetInstanceHandle();
    if(hResourceHandle != NULL)
        hinst = hResourceHandle;

    LoadString(hinst,IDS_STR_TIME,m_bufftime,8);

    ploadiary = (CListCtrl*)GetDlgItem(IDC_LIST_DY);

    ploadiary->GetClientRect(rect);
    ploadiary->ModifyStyle(0,LVS_SINGLESEL);
    ploadiary->SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES|LVS_EX_AUTOCHECKSELECT);
    ploadiary->InsertColumn(0,_T("NO."));
    ploadiary->InsertColumn(1,m_bufftime);
    ploadiary->SetColumnWidth(0,rect.Width()*2/5);
    ploadiary->SetColumnWidth(1,rect.Width()*3/5);
    //--------------------------------------------------------------------
    BOOL fret = FALSE, result = TRUE;
    CFile freadiary;
    CString strdtime;
    CString strbeforetime = _T("");
    char *pbuff = NULL;
    char *psession = NULL;
    char *phead = NULL;
    char *psinglerow = NULL;
    char buffhead[256];
    char onerecordbuff[128];
    int headsize = 0;
    int rowlen = 0;
    int timenodenum = 0;
    std::string strday ,stroldday;
    std::wstring strwday;

    std::string absoluteFilename;
    std::wstring absolutewFilename;

    CString strpath;
    int count = 0;

    //m_d_TimeList.RemoveAll();

    memset(buffhead,0,256*sizeof(char));
    memset(onerecordbuff,0,128*sizeof(char));

    strpath = m_strpath;

    if(result)
    {
        fret = freadiary.Open(strpath,CFile::modeRead);   //CFile::modeReadWrite);
        if(fret == 0)
        {
            MessageBox(_T("No diary founded!"));
            return -1;
        }
    }

    ASSERT(freadiary);

    int  len = freadiary.GetLength();
    int s=0;

    pbuff = new char[len];
    memset(pbuff,0,len * sizeof(char));

    if(len)
    {
        freadiary.SeekToBegin();
        s = freadiary.Read(pbuff,len);
    }

    while(psession = strstr(pbuff,"AMPSTART"))
    {
        CString strid;
        CString retstr;
        pbuff = psession;
        pbuff += 8;

        phead = strstr(pbuff,"DIARYSTART");
        headsize = phead - pbuff;
        strncpy(buffhead,pbuff,headsize);
        //retstr = _T("");
        retstr = prev->GetDiaryHead(buffhead,FALSE);
        memset(buffhead,0,256*sizeof(char));
        strid.Format(_T("%d"),count);
        ploadiary->InsertItem(count,strid);
        ploadiary->SetItemText(count,1,retstr);
        count++;
    }

    ploadiary->SetCheck(count - 1);

    freadiary.Close();

    //--------------------------------------------------------------------

    return TRUE;
}