本文整理汇总了C++中CFileException类的典型用法代码示例。如果您正苦于以下问题:C++ CFileException类的具体用法?C++ CFileException怎么用?C++ CFileException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CFileException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Parse
/**
* \brief Start parsing.
* \param LogProc A Pointer to the logging procedure.
*/
void CAuxParser::Parse(PFNLOGPROC LogProc)
{
m_LogProc = LogProc;
m_Errors = 0;
m_BibData.Empty();
m_BibStyle.Empty();
CString str;
if (!m_AuxFile.IsEmpty()) {
CFile f;
CFileException ex;
if (f.Open(m_AuxFile, CFile::modeRead | CFile::shareDenyWrite, &ex)) {
str.Format(AfxLoadString(IDS_STRING_PARSING), m_AuxFile);
AddLog(str);
CBibReader reader(&f);
ParseFile(&reader);
f.Close();
} else {
m_Errors++;
TCHAR msg[MAX_PATH];
ex.GetErrorMessage(msg, MAX_PATH);
str.Format(AfxLoadString(IDS_STRING_ERROR), msg);
AddLog(str);
}
}
}
示例2: Load
//-----------------------------------------------------------------------------
// Does: Open a File And Load It Into IPicture (Interface)
// ~~~~ (.BMP .DIB .EMF .GIF .ICO .JPG .WMF)
//
// InPut: sFilePathName - Path And FileName Target To Save
// ~~~~~
//
// OutPut: TRUE If Succeeded...
// ~~~~~~
//-----------------------------------------------------------------------------
BOOL CPicViewer::Load(CString sFilePathName)
//=============================================================================
{
BOOL bResult = FALSE;
CFile PictureFile;
CFileException e;
int nSize = 0;
if(m_IPicture != NULL) FreePictureData(); // Important - Avoid Leaks...
if(PictureFile.Open(sFilePathName, CFile::modeRead | CFile::typeBinary, &e))
{
nSize = PictureFile.GetLength();
BYTE* pBuffer = new BYTE[nSize];
if(PictureFile.Read(pBuffer, nSize) > 0)
{
// 防止图像文件数据有错(目前的问题是无结束符),导致OleLoadPicture无响应 [6/22/2009 guowenpeng]
if ((pBuffer[nSize - 2] != 0xff)
|| (pBuffer[nSize - 1] != 0xd9)) // 0xffd9: jpeg文件结束标志
{
pBuffer[nSize - 2] = 0xff;
pBuffer[nSize - 1] = 0xd9;
}
if(LoadPictureData(pBuffer, nSize)) bResult = TRUE;
}
PictureFile.Close();
delete [] pBuffer;
}
else // Open Failed...
{
TCHAR szCause[255];
e.GetErrorMessage(szCause, 255, NULL);
TRACE( "%s\n", szCause );
// HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
// MessageBoxEx(hWnd, szCause, ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
bResult = FALSE;
}
m_Weight = nSize; // Update Picture Size Info...
if(m_IPicture != NULL) // Do Not Try To Read From Memory That Is Not Exist...
{
m_IPicture->get_Height(&m_Height);
m_IPicture->get_Width(&m_Width);
// Calculate Its Size On a "Standard" (96 DPI) Device Context
m_Height = MulDiv(m_Height, 96, HIMETRIC_INCH);
m_Width = MulDiv(m_Width, 96, HIMETRIC_INCH);
}
else // Picture Data Is Not a Known Picture Type
{
m_Height = 0;
m_Width = 0;
bResult = FALSE;
}
return(bResult);
}
示例3: Files
void CTextPadDlg::OnBnClickedLoadbtn()
{
// TODO: Add your control notification handler code here
char szFilter[] = "(*.txt) | All Files(*.*)|*.*||";
CFileDialog dlg(TRUE, "txt", "*.txt", OFN_HIDEREADONLY, szFilter);
if(IDOK == dlg.DoModal()){
CString strPathName = dlg.GetPathName();
CStdioFile fp;
CFileException e;
if(!fp.Open(strPathName, CFile::modeRead, &e)) {
e.ReportError();
return;
}
CString str = "";
CString tmp = "";
while(fp.ReadString(tmp)){
str += tmp;
str += "\r\n";
}
UpdateData(FALSE);
textpad.SetWindowText(str);
fp.Close();
}
}
示例4: Convert
void CKmlDlg::convert_all_file()
{
int i;
CString temp;
for(i=0;i<NumOfFile;i++)
{
CFileException ef;
try
{
if(!Fsource.Open(FilePath[i],CFile::modeRead,&ef))
{
ef.ReportError();
continue;
}
IsFSourceOpen = true;
kml_filename = FileName[i];
int find = kml_filename.Find(".");
kml_filename = kml_filename.Mid(0,find);
Convert();
temp.Format("%s OK",FileName[i]);
m_check[i].SetWindowText(temp);
m_check[i].SetCheck(BST_CHECKED);
}
catch(CFileException *fe)
{
fe->ReportError();
fe->Delete();
}
}
}
示例5: ASSERT
bool CCrossDlg::Save(int Sel)
{
ASSERT(Sel >= 0 && Sel < SELS);
CPathStr FileName;
GetName(Sel, FileName);
CFileDialog fd(FALSE, EXT_PATCH, FileName, OFN_OVERWRITEPROMPT, LDS(IDS_FILTER_PATCH));
if (fd.DoModal() != IDOK)
return(FALSE);
CStdioFile fp;
CFileException e;
if (!fp.Open(fd.GetPathName(), CFile::modeCreate | CFile::modeWrite, &e)) {
e.ReportError();
return(FALSE);
}
CPatch Patch;
Patch = m_Info[Sel]; // assign parm info
m_Frm->GetPatch(Patch); // get master and main info
if (!Patch.Write(fp))
return(FALSE);
m_Modified[Sel] = FALSE;
FileName = fd.GetFileName();
FileName.RemoveExtension();
SetName(Sel, FileName);
return(TRUE);
}
示例6: CheckMoves
RenJS::Result
RenJS::addGame(const CString& strFile)
{
CFileException e;
if (!mGameFile.Open(strFile, CFile::modeRead, &e))
{
mResult = OPEN_FILE_ERROR;
}
else
{
try
{
parseGame();
if (mMoves.size() == 0)
{
mResult = EMPTY_ERROR;
}
}
catch (Exception e)
{
mResult = e.getErrorCause();
}
mGameFile.Close();
}
if (mResult == VALID)
{
mResult = CheckMoves();
}
return mResult;
}
示例7: strError
bool CKnownFileList::LoadKnownFiles()
{
CString fullpath = thePrefs.GetMuleDirectory(EMULE_CONFIGDIR);
fullpath.Append(KNOWN_MET_FILENAME);
CSafeBufferedFile file;
CFileException fexp;
if (!file.Open(fullpath,CFile::modeRead|CFile::osSequentialScan|CFile::typeBinary|CFile::shareDenyWrite, &fexp)){
if (fexp.m_cause != CFileException::fileNotFound){
CString strError(_T("Failed to load ") KNOWN_MET_FILENAME _T(" file"));
TCHAR szError[MAX_CFEXP_ERRORMSG];
if (fexp.GetErrorMessage(szError, ARRSIZE(szError))){
strError += _T(" - ");
strError += szError;
}
LogError(LOG_STATUSBAR, _T("%s"), strError);
}
return false;
}
setvbuf(file.m_pStream, NULL, _IOFBF, 16384);
CKnownFile* pRecord = NULL;
try {
uint8 header = file.ReadUInt8();
if (header != MET_HEADER && header != MET_HEADER_I64TAGS){
file.Close();
LogError(LOG_STATUSBAR, GetResString(IDS_ERR_SERVERMET_BAD));
return false;
}
AddDebugLogLine(false, _T("Known.met file version is %u (%s support 64bit tags)"), header, (header == MET_HEADER) ? _T("doesn't") : _T("does"));
UINT RecordsNumber = file.ReadUInt32();
for (UINT i = 0; i < RecordsNumber; i++) {
pRecord = new CKnownFile();
if (!pRecord->LoadFromFile(&file)){
TRACE(_T("*** Failed to load entry %u (name=%s hash=%s size=%I64u parthashs=%u expected parthashs=%u) from known.met\n"), i,
pRecord->GetFileName(), md4str(pRecord->GetFileHash()), pRecord->GetFileSize(), pRecord->GetHashCount(), pRecord->GetED2KPartHashCount());
delete pRecord;
pRecord = NULL;
continue;
}
SafeAddKFile(pRecord);
pRecord = NULL;
}
file.Close();
}
catch(CFileException* error){
if (error->m_cause == CFileException::endOfFile)
LogError(LOG_STATUSBAR, GetResString(IDS_ERR_SERVERMET_BAD));
else{
TCHAR buffer[MAX_CFEXP_ERRORMSG];
error->GetErrorMessage(buffer, ARRSIZE(buffer));
LogError(LOG_STATUSBAR, GetResString(IDS_ERR_SERVERMET_UNKNOWN),buffer);
}
error->Delete();
delete pRecord;
return false;
}
return true;
}
示例8: GetTempFile
CString CGravador::GetTempFile(CString strSql)
{
// cria o arquivo .SQL no diretório temp
CString strFile;
CStdioFile cFile;
BOOL bResFile;
CFileException ex;
CString strPath;
// obtém o diretório temp do computador local.
// Get the executable file path
CString szFilePath;
szFilePath = CUtil::GetFilePath();
strFile = szFilePath + _T("\\temp.cfg");
bResFile = cFile.Open(strFile, CFile::modeCreate | CFile::modeWrite | CFile::typeText | CFile::shareExclusive, &ex);
if (!bResFile)
{
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
m_debugLog.Log(LOG_ERROR, _T("Não foi possível abrir o arquivo %s, erro = %s") , strFile, szError);
}
// escreve a string de script no arquivo.
if (cFile.m_hFile != CFile::hFileNull)
{
cFile.WriteString(strSql);
cFile.Close();
}
// devolve o nome do arquivo para ser deletado e também para usar o diretório temp na linha de comando.
m_debugLog.Log(LOG_INFO, strFile);
return strFile;
}
示例9: ClearError
BOOL CTextFile::ReadTextFile( CString& filename, CStringArray& contents )
/* ============================================================
Function : CTextFile::ReadTextFile
Description : Will read the contents of the file filename
into the CStringArray contents, one line
from the file at a time.
If filename is empty, the standard file
dialog will be displayed, and - if OK is
selected - filename will contain the
selected filename on return.
Return : BOOL - TRUE if OK.
GetErrorMessage
will contain errors.
Parameters : CString& filename - file to read from
CStringArray& contents - will be filled
with the contents
of the file
============================================================*/
{
ClearError();
BOOL result = TRUE;
if( filename.IsEmpty() )
result = GetFilename( FALSE, filename );
if( result )
{
CStdioFile file;
CFileException feError;
if( file.Open( filename, CFile::modeRead, &feError ) )
{
contents.RemoveAll();
CString line;
while( file.ReadString( line ) )
contents.Add( line );
file.Close();
}
else
{
TCHAR errBuff[256];
feError.GetErrorMessage( errBuff, 256 );
m_error = errBuff;
result = FALSE;
}
}
return result;
}
示例10: AddDebugLogLine
void CClientCreditsList::SaveList()
{
if (thePrefs.GetLogFileSaving())
AddDebugLogLine(false, _T("Saving clients credit list file \"%s\""), CLIENTS_MET_FILENAME);
m_nLastSaved = ::GetTickCount();
CString name = thePrefs.GetMuleDirectory(EMULE_CONFIGDIR) + CLIENTS_MET_FILENAME;
CFile file;// no buffering needed here since we swap out the entire array
CFileException fexp;
if (!file.Open(name, CFile::modeWrite|CFile::modeCreate|CFile::typeBinary|CFile::shareDenyWrite, &fexp)){
CString strError(GetResString(IDS_ERR_FAILED_CREDITSAVE));
TCHAR szError[MAX_CFEXP_ERRORMSG];
if (fexp.GetErrorMessage(szError, ARRSIZE(szError))){
strError += _T(" - ");
strError += szError;
}
LogError(LOG_STATUSBAR, _T("%s"), strError);
return;
}
uint32 count = m_mapClients.GetCount();
BYTE* pBuffer = new BYTE[count*sizeof(CreditStruct)];
CClientCredits* cur_credit;
CCKey tempkey(0);
POSITION pos = m_mapClients.GetStartPosition();
count = 0;
while (pos)
{
m_mapClients.GetNextAssoc(pos, tempkey, cur_credit);
if (cur_credit->GetUploadedTotal() || cur_credit->GetDownloadedTotal())
{
memcpy(pBuffer+(count*sizeof(CreditStruct)), cur_credit->GetDataStruct(), sizeof(CreditStruct));
count++;
}
}
try{
uint8 version = CREDITFILE_VERSION;
file.Write(&version, 1);
file.Write(&count, 4);
file.Write(pBuffer, count*sizeof(CreditStruct));
// Comment UI
//if (thePrefs.GetCommitFiles() >= 2 || (thePrefs.GetCommitFiles() >= 1 && !theApp.emuledlg->IsRunning()))
// file.Flush();
file.Close();
}
catch(CFileException* error){
CString strError(GetResString(IDS_ERR_FAILED_CREDITSAVE));
TCHAR szError[MAX_CFEXP_ERRORMSG];
if (error->GetErrorMessage(szError, ARRSIZE(szError))){
strError += _T(" - ");
strError += szError;
}
LogError(LOG_STATUSBAR, _T("%s"), strError);
error->Delete();
}
delete[] pBuffer;
}
示例11: OpenFile
bool CZipStorage::OpenFile(LPCTSTR lpszName, UINT uFlags, bool bThrow)
{
CFileException* e = new CFileException;
BOOL bRet = m_file.Open(lpszName, uFlags | CFile::shareDenyWrite, e);
if (!bRet && bThrow)
throw e;
e->Delete();
return bRet != 0;
}
示例12: AppendFile
BOOL CTextFile::AppendFile( CString& filename, const CStringArray& contents )
/* ============================================================
Function : CTextFile::AppendFile
Description : Appends contents to filename. Will create
the file if it doesn't already exist.
If filename is empty, the standard file
dialog will be displayed, and - if OK is
selected - filename will contain the
selected filename on return.
Return : BOOL - TRUE if OK.
GetErrorMessage
will return
errors
Parameters : CString& filename - file to write to
CStringArray contents - contents to write
============================================================*/
{
CStdioFile file;
CFileException feError;
BOOL result = TRUE;
if( filename.IsEmpty() )
result = GetFilename( TRUE, filename );
if( result )
{
// Write the file
if( file.Open( filename, CFile::modeWrite | CFile::modeCreate | CFile::modeNoTruncate, &feError ) )
{
file.SeekToEnd();
int max = contents.GetSize();
for( int t = 0 ; t < max ; t++ )
file.WriteString( contents[ t ] + m_eol );
file.Close();
}
else
{
// Set error message
TCHAR errBuff[256];
feError.GetErrorMessage( errBuff, 256 );
m_error = errBuff;
result = FALSE;
}
}
return result;
}
示例13: strError
bool CFriendList::AddEmfriendsMetToList(const CString& strFile)
{
CSafeBufferedFile file;
CFileException fexp;
if ( !file.Open(strFile, CFile::modeRead|CFile::osSequentialScan|CFile::typeBinary, &fexp) )
{
if ( fexp.m_cause != CFileException::fileNotFound )
{
CString strError(GetResString(IDS_ERR_READEMFRIENDS));
TCHAR szError[MAX_CFEXP_ERRORMSG];
if ( fexp.GetErrorMessage(szError,MAX_CFEXP_ERRORMSG) )
{
strError += _T(" - ");
strError += szError;
}
AddLogLine(true, _T("%s"), strError);
}
return false;
}
try
{
uint8 header = file.ReadUInt8();
if ( header != MET_HEADER )
{
file.Close();
return false;
}
UINT nRecordsNumber = file.ReadUInt32();
for (UINT i = 0; i < nRecordsNumber; i++)
{
CFriend* Record = new CFriend();
Record->LoadFromFile(&file);
if ( !IsAlreadyFriend(Record->m_abyUserhash) )
m_listFriends.AddTail(Record);
}
file.Close();
}
catch ( CFileException* error )
{
if ( error->m_cause == CFileException::endOfFile )
AddLogLine(true,GetResString(IDS_ERR_EMFRIENDSINVALID));
else
{
TCHAR buffer[MAX_CFEXP_ERRORMSG];
error->GetErrorMessage(buffer, MAX_CFEXP_ERRORMSG);
AddLogLine(true, GetResString(IDS_ERR_READEMFRIENDS), buffer);
}
error->Delete();
return false;
}
return true;
}// MORPH END - Added by Commander, Friendlinks [emulEspaña]
示例14: logError
BOOL CMFile::FOpen(LPCSTR filename,int opentype)
{
if (File == NULL) return false;
if(bDontClose) return false;//bDontClose true ise CFile dýþardan set edilmiþ demektir.
UINT openflag;
CFileStatus status;
if (FileOpen)
{
logError("Dosya zaten açýk");
return false;
}
switch (opentype)
{
case OT_READ : openflag = CFile::modeRead |CFile::typeBinary;break;
case OT_WRITE : openflag = CFile::modeCreate |CFile::modeWrite|CFile::typeBinary;break;
case OT_APPEND : openflag = CFile::modeWrite | CFile::modeNoTruncate|CFile::typeBinary;break;
case OT_READWRITE : openflag = CFile::modeReadWrite|CFile::typeBinary;break;
default: ASSERT(false);return false;break;
}
CFileException e;
if (File->Open(filename,openflag,&e))
{
if (File->GetStatus(status))
{
ReadOnly = ( (status.m_attribute & 1) != 0);
Hidden = ( (status.m_attribute & 2) != 0);
System = ( (status.m_attribute & 4) != 0);
Archive = ( (status.m_attribute & 0x20) != 0);
Normal = status.m_attribute == 0;
FileOpen = true;
OpenType = opentype;
if (opentype == OT_APPEND)
File->SeekToEnd();
return true;
}
else
{
CString temp;
temp.Format("(%s)Could not read File Status. Process Terminated.",filename);
logError(temp);
return false;
}
}
else
{
char error[200];
e.GetErrorMessage(error,200);
logError(error);
return false;
}
}
示例15: Convert2
void CKmlDlg::convert_all_file()
{
int i;
CString temp;
CKmlDlg::kmlDlg->PostMessage(UWM_PROGRESS, 1, 0); //Show progress
for(i = 0; i < NumOfFile; ++i)
{
CFileException ef;
CFile f;
try
{
if(KML_USE_CHECKLISTBOX)
{
m_fileList.SetCurSel(i);
}
if(!f.Open(FilePath[i], CFile::modeRead,&ef))
{
ef.ReportError();
continue;
}
kml_filename = FilePath[i];
int find = kml_filename.ReverseFind('.');
kml_filename = kml_filename.Mid(0,find);
//Convert(f);
Convert2(f);
f.Close();
temp.Format("%s OK", FileName[i]);
if(KML_USE_CHECKLISTBOX)
{
//m_fileList.SetCurSel(i);
m_fileList.DeleteString(i);
m_fileList.InsertString(i, temp);
m_fileList.SetCheck(i, BST_CHECKED);
}
else
{
m_check[i].SetWindowText(temp);
m_check[i].SetCheck(BST_CHECKED);
}
}
catch(CFileException *fe)
{
fe->ReportError();
fe->Delete();
}
}
CKmlDlg::kmlDlg->PostMessage(UWM_PROGRESS, 0, 1000); //Hide progress
}