?? dspfile.cpp
字號:
// DSPFile.cpp: implementation of the DSPFile class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "PPQTEST.h"
#include "DSPFile.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
DSPFile::DSPFile()
{
this->m_pifs =NULL;
this->m_pofs =NULL;
}
DSPFile::~DSPFile()
{
if(this->m_pifs!=NULL)
delete this->m_pifs;
if(this->m_pofs!=NULL)
delete this->m_pofs;
}
bool DSPFile::Serialize(BYTE byClassLevels,BYTE byAttrNo,DSP::_DSPPACKET &dsp)
{
switch(byAttrNo)
{
case 1:
dsp.Write(this->m_nFileSize);
return false;
case 2:
dsp.Write(this->m_strFileName);
return false;
case 3: //序列化最后一個屬性
if(this->m_pifs==NULL)
{
//打開文件準備讀
this->m_pifs =new ifstream();
if(DSP::OpenIfstreamForRead(*this->m_pifs,this->m_strPathName.c_str())==FALSE)
{
//如果打開文件失敗
dsp.Write(NULL,0,true);
return true;
}
}
else
{
//關閉文件
delete this->m_pifs;
this->m_pifs =NULL;
}
dsp.Write(this->m_buff,0xFFF,false);
}
return true;
}
bool DSPFile::UnSerialize(BYTE byClassLevels,BYTE byAttrNo,DSP::_DSPPACKET &dsp,DWORD dwLen)
{
//反序列化對象
switch(byAttrNo)
{
case 1:
dsp.Read(this->m_nFileSize);
return false;
case 2:
dsp.Read(this->m_strFileName,dwLen);
return false;
case 3: //序列化最后一個屬性
if(this->m_pofs==NULL)
{
//傳送文件名和尺寸,并且打開文件輸出流,準備寫
::SendMessage(this->m_hwnd,MSG_SETFILENAMESIZE,(WPARAM)&this->m_strFileName,(LPARAM)this->m_nFileSize);
//打開對話框,選擇被保存的文件名
CFileDialog fileDialog(FALSE,NULL,this->m_strFileName.c_str(),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT);
if(fileDialog.DoModal()==IDOK)
{
//得到被選擇的文件名
CString strPath =fileDialog.GetPathName();
this->m_strPathName =strPath;
//傳送文件名和尺寸
::SendMessage(this->m_hwnd,MSG_SETFILENAMESIZE,(WPARAM)&this->m_strPathName,(LPARAM)this->m_nFileSize);
this->m_pofs =new ofstream();
if(DSP::OpenOfstreamForWrite(*this->m_pofs,strPath)==FALSE)
{
//如果找開文件失敗
dsp.Read(NULL,0);
return true;
}
}
}
else
{
//屬性值已反序列化完畢,刪除文件輸出流對象
delete this->m_pofs;
this->m_pofs =NULL;
}
dsp.Read(this->m_buff,dwLen);
}
return true;
}
bool DSPFile::AttrSectRecv(BYTE byClassLevels,BYTE byAttrNo,const char* const lpBuff,DWORD dwLen,bool bLast)
{
switch(byAttrNo)
{
case 3:
this->m_pofs->write(lpBuff,dwLen);
if(*this->m_lpbRun==false)
{
//如果放棄傳送
return false;
}
::PostMessage(this->m_hwnd,MSG_RECVSECT,dwLen,0);
if(bLast)
{
//如果是最后一個段,則文件輸出流關閉
this->m_pofs->flush();
this->m_pofs->close();
}
}
return true;
}
bool DSPFile::AttrSectSend(BYTE byClassLevels,BYTE byAttrNo,char** const lpBuff,DWORD& dwLen,bool& bContinue)
{
switch(byAttrNo)
{
case 3:
this->m_pifs->read(*lpBuff,dwLen);
bContinue =*this->m_lpbRun;
if(this->m_pifs->eof())
{
//如果文件已經結束
//得到文件的大小
int size =this->m_pifs->tellg();
//得到最后讀取的文件尺寸,設定最后接收的字節數
dwLen =size%dwLen;
//設定不需要再繼續接收
bContinue =false;
//關閉文件
this->m_pifs->close();
}
::PostMessage(this->m_hwnd,MSG_SENDSECT,dwLen,0);
}
return true;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -