52 lines
1.0 KiB
C++
52 lines
1.0 KiB
C++
|
|
#include "stdafx.h"
|
|||
|
|
#include "File.h"
|
|||
|
|
|
|||
|
|
bool Files::ReadFile(const CString& _fileName, CString& _content) {
|
|||
|
|
_content.Empty();
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
CFile f(_fileName, CFile::modeRead);
|
|||
|
|
|
|||
|
|
size_t nBytes = (UINT)f.GetLength();
|
|||
|
|
size_t nChars = nBytes / sizeof(TCHAR);
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ȡƵ<C8A1><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
nBytes = f.Read(_content.GetBuffer(nChars), nBytes);
|
|||
|
|
|
|||
|
|
_content.ReleaseBuffer(nChars);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
catch (CFileException* e) {
|
|||
|
|
e->ReportError();
|
|||
|
|
e->Delete();
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Files::WriteFile(const CString& _fileName, CString& _content) {
|
|||
|
|
try {
|
|||
|
|
CFile f(_fileName, CFile::modeWrite | CFile::modeCreate);
|
|||
|
|
f.Write(_content, _content.GetLength()*sizeof(TCHAR));
|
|||
|
|
}
|
|||
|
|
catch (CFileException* e) {
|
|||
|
|
e->ReportError();
|
|||
|
|
e->Delete();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool Files::WriteAllBytes(const CString& _name, const void* _b, size_t _len, CString* _path) {
|
|||
|
|
try {
|
|||
|
|
CFile f(_name, CFile::modeCreate | CFile::modeWrite);
|
|||
|
|
f.Write(_b, _len);
|
|||
|
|
|
|||
|
|
if (_path != nullptr)
|
|||
|
|
*_path = f.GetFilePath();
|
|||
|
|
} catch (CException* e) {
|
|||
|
|
e->ReportError();
|
|||
|
|
e->Delete();
|
|||
|
|
}
|
|||
|
|
return true;
|
|||
|
|
}
|