📄 fileoperaton.cpp
字号:
#include "StdAfx.h"
#include "FileOperation.h"
FileOperation::FileOperation()
{
}
FileOperation::~FileOperation()
{
}
BOOL FileOperation::setFileName( CString csFN )
{
m_csFileName = csFN;
return TRUE;
}
BOOL FileOperation::readFile( CString& csFile )
{
DWORD dwLength = 0;
CFileException e;
CString szCause;
CString strFormatted;
int nErr = 0;
try
{
nErr = Open( m_csFileName, CFile::modeRead, &e );
}
catch ( CFileException* e )
{
e->GetErrorMessage( (LPTSTR)&szCause, 255);
strFormatted = _T("The data file could not be opened because of this error: ");
strFormatted += szCause;
AfxMessageBox(strFormatted);
throw;
}
if( ! nErr ){
// CString csErr = m_csFileName + " file can`t find or can`t open";
// AfxMessageBox( csErr );
return FALSE;
}
dwLength = GetLength();
char* pData;
pData = new char[dwLength+1];
memset( pData, 0x00, dwLength+1 );
Read( pData, dwLength );
csFile = pData;
delete []pData;
Close( );
return TRUE;
}
BOOL FileOperation::writeFile( CString& csFile )
{
CFileException e;
CString szCause;
CString strFormatted;
int nErr = 0;
try
{
nErr = Open( m_csFileName, CFile::modeReadWrite | CFile::modeCreate |
CFile::modeNoTruncate, &e );
}
catch (CFileException* e)
{
e->GetErrorMessage( (LPTSTR)&szCause, 255);
strFormatted = _T("The data file could not be opened because of this error: ");
strFormatted += szCause;
AfxMessageBox(strFormatted);
throw;
}
if( ! nErr ){
CString csErr = m_csFileName + " file can`t find or can`t open";
AfxMessageBox( csErr );
return FALSE;
}
int nCsLen = csFile.GetLength();
LPTSTR lpBuffer = csFile.GetBuffer(0);
char* contxt = new char[nCsLen*2];
memset( contxt, 0x00, sizeof( char ) );
int nlen= WideCharToMultiByte(CP_ACP,0,lpBuffer,nCsLen,0,0,0,0);
WideCharToMultiByte(CP_ACP, 0, lpBuffer, nCsLen, contxt, nlen, NULL, NULL);
SeekToEnd( );
Write( contxt, nlen );
delete []contxt;
Close( );
return TRUE;
}
BOOL FileOperation::deleteFile()
{
CFile::Remove( m_csFileName );
return TRUE;
}
BOOL FileOperation::getFileNameForDelete()
{
return TRUE;
}
BOOL FileOperation::getList( CStringList* cArrayNameList, CString& sNameString, CString& theFlg )
{
int position_1 = 0;
int position_2 = 0;
int position_3 = 0;
CString sBuffer;
BOOL flg;
position_2 = sNameString.Find( theFlg, position_1 );
if( position_2 == -1 ){
flg = FALSE;
return flg;
}
int nPOS = 0;
for( ; ; )
{
position_2 = sNameString.Find( theFlg, position_1 );
if( position_2 == -1 ){
position_3 = sNameString.GetLength();
// deleteSpace( position_1, position_3, sNameString );
if( position_1 == position_3 ){
flg = FALSE;
return flg;
}else{
sBuffer = sNameString.Mid( position_1, (nPOS) );
cArrayNameList->AddTail( sBuffer );
}
break;
}else{
position_3 = position_2;
// deleteSpace( position_1, position_3, sNameString );
}
if( position_1 == position_3 ){
flg = FALSE;
return flg;
}else{
if ( theFlg == "\n" )
nPOS = position_3 - position_1-1;
else
nPOS = position_3 - position_1;
sBuffer = sNameString.Mid( position_1, (nPOS) );
cArrayNameList->AddTail( sBuffer );
}
position_1 = position_2 + theFlg.GetLength();
}
flg = TRUE;
return flg;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -