本文整理汇总了C++中CFile::SeekToBegin方法的典型用法代码示例。如果您正苦于以下问题:C++ CFile::SeekToBegin方法的具体用法?C++ CFile::SeekToBegin怎么用?C++ CFile::SeekToBegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFile
的用法示例。
在下文中一共展示了CFile::SeekToBegin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SaveUserInfo
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();
}
示例2: EncryptFile
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;
}
示例3: OnSendFile
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"));
}
}
示例4: SaveChessManual
//保存棋谱
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;
}
示例5: ClearMappingsAtEnd
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();
}
}
示例6: WriteHtmFile
//把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;
}
示例7: ComputeInfohash
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();
}
}
示例8: Save
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;
}
示例9: Open
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;
}
示例10: Serialize
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();
}
示例11: CFile
// 写入到*.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;
}
示例12: OnPreserve
//保存按钮
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;
}
示例13: SetDefServer
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);
}
示例14: ThreadProc
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;
}
示例15: Save
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;
}