|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
#include "FileMgr.h"
|
|
|
|
|
#include "LogMgr.h"
|
|
|
|
|
#include "GlobalDefine.h"
|
|
|
|
|
|
|
|
|
|
CFileMgr::CFileMgr(void)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
CFileMgr::~CFileMgr(void)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
//<2F>Ե<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>Ŀ¼Ϊ<C2BC><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>(<28><><EFBFBD><EFBFBD>FilePath <20><>)
|
|
|
|
|
void CFileMgr::GetFullFilePath(char *FilePath,CString FileName)
|
|
|
|
|
{
|
|
|
|
|
CString str;
|
|
|
|
|
GetFullFilePath(str,FileName);
|
|
|
|
|
strcpy(FilePath,(LPSTR)(LPCTSTR)str);
|
|
|
|
|
}
|
|
|
|
|
//<2F>Ե<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>Ŀ¼Ϊ<C2BC><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>(FileName <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\Debug.txt)
|
|
|
|
|
void CFileMgr::GetFullFilePath(CString &FilePath,CString FileName)
|
|
|
|
|
{
|
|
|
|
|
CString sPath;
|
|
|
|
|
GetModuleFileName(NULL,sPath.GetBufferSetLength(1023),1024);
|
|
|
|
|
sPath.ReleaseBuffer();
|
|
|
|
|
int nPos;
|
|
|
|
|
nPos = sPath.ReverseFind('\\');
|
|
|
|
|
sPath = sPath.Left(nPos);
|
|
|
|
|
FilePath = sPath + FileName;
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>Ŀ¼
|
|
|
|
|
CString CFileMgr::GetWorkPath()
|
|
|
|
|
{
|
|
|
|
|
CString sPath;
|
|
|
|
|
GetModuleFileName(NULL,sPath.GetBufferSetLength(1023),1024);
|
|
|
|
|
sPath.ReleaseBuffer();
|
|
|
|
|
int nPos;
|
|
|
|
|
nPos = sPath.ReverseFind('\\');
|
|
|
|
|
sPath = sPath.Left(nPos);
|
|
|
|
|
return sPath;
|
|
|
|
|
}
|
|
|
|
|
#if 1
|
|
|
|
|
//<2F><><EFBFBD>ж<EFBFBD>ȡFilePath ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>浽vec <20><>(FilePath <20>dz<EFBFBD><C7B3><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF>µ<EFBFBD><C2B5>ļ<EFBFBD>·<EFBFBD><C2B7>)
|
|
|
|
|
void CFileMgr::ReadFileToStringVec(const CString &FilePath,vector<CString> &vec)
|
|
|
|
|
{
|
|
|
|
|
CStdioFile file;
|
|
|
|
|
if(file.Open(FilePath,CFile::modeRead,NULL))
|
|
|
|
|
{
|
|
|
|
|
CString str;
|
|
|
|
|
while(file.ReadString(str))
|
|
|
|
|
{
|
|
|
|
|
vec.push_back(str);
|
|
|
|
|
}
|
|
|
|
|
file.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ÿһ<C3BF><D2BB>,<2C>Զ<EFBFBD><D4B6>ŷ<EFBFBD><C5B7><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
void CFileMgr::ReadFileToDoubleVec(const CString &FilePath,vector<vector<double>> &Vec)
|
|
|
|
|
{
|
|
|
|
|
//<2F><>ȡÿһ<C3BF><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
vector<CString> StrVec;
|
|
|
|
|
ReadFileToStringVec(FilePath,StrVec);
|
|
|
|
|
vector<CString>::iterator iter = StrVec.begin();
|
|
|
|
|
vector<CString>::iterator iter_end = StrVec.end();
|
|
|
|
|
for(;iter!=iter_end;iter++)
|
|
|
|
|
{
|
|
|
|
|
vector<double> VecTmp;
|
|
|
|
|
//<2F><>str <20><><EFBFBD><EFBFBD>ȡdouble <20><>ֵ,<2C>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>
|
|
|
|
|
GetDoubleVal((*iter),VecTmp);
|
|
|
|
|
if(VecTmp.empty()==false)
|
|
|
|
|
Vec.push_back(VecTmp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><>str <20><><EFBFBD><EFBFBD>ȡdouble <20><>ֵ,<2C>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>
|
|
|
|
|
void CFileMgr::GetDoubleVal(CString Str,vector<double> &Vec)
|
|
|
|
|
{
|
|
|
|
|
int CommaPosPer;//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
CommaPosPer = Str.Find(",",0);
|
|
|
|
|
if(CommaPosPer == -1)//û<>ҵ<EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
char *recvBuf = Str.GetBuffer();
|
|
|
|
|
//<2F><>һ<EFBFBD><D2BB>ֵ
|
|
|
|
|
double val = 0;
|
|
|
|
|
CString Str1(recvBuf,CommaPosPer);
|
|
|
|
|
val= atof(Str1);
|
|
|
|
|
Vec.push_back(val);
|
|
|
|
|
|
|
|
|
|
int idx = 0;
|
|
|
|
|
int CommaPosNext = CommaPosPer;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
CommaPosNext = Str.Find(",",CommaPosPer+1);//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
if(CommaPosNext==-1)//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
{
|
|
|
|
|
CString Str1(recvBuf+CommaPosPer+1);
|
|
|
|
|
val= atof(Str1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CString Str1(recvBuf+CommaPosPer+1,CommaPosNext-CommaPosPer);
|
|
|
|
|
val= atof(Str1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vec.push_back(val);
|
|
|
|
|
|
|
|
|
|
CommaPosPer = CommaPosNext;
|
|
|
|
|
idx++;
|
|
|
|
|
}while(CommaPosNext!=-1);
|
|
|
|
|
}
|
|
|
|
|
//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>뵽<EFBFBD>ı<EFBFBD><C4B1>ļ<EFBFBD>
|
|
|
|
|
void CFileMgr::WriteDbxyVecToFile(vector<Dbxy> &vec,ofstream *file)
|
|
|
|
|
{
|
|
|
|
|
vector<Dbxy>::iterator iter = vec.begin();
|
|
|
|
|
vector<Dbxy>::iterator iter_end = vec.end();
|
|
|
|
|
for(;iter!=iter_end;iter++)
|
|
|
|
|
{
|
|
|
|
|
(*file)<<(*iter).x<<","<<(*iter).y<<endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>)
|
|
|
|
|
bool CFileMgr::IsFileExist(CString FilePath)
|
|
|
|
|
{
|
|
|
|
|
CFileFind finder;
|
|
|
|
|
bool bResult = finder.FindFile(FilePath);
|
|
|
|
|
finder.Close();
|
|
|
|
|
return bResult;
|
|
|
|
|
}
|
|
|
|
|
//Ŀ¼<C4BF>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
bool CFileMgr::IsDirectoryExists(CString const& path)
|
|
|
|
|
{
|
|
|
|
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(!PathFileExists(path))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD>ΪĿ¼
|
|
|
|
|
DWORD attributes = ::GetFileAttributes(path);
|
|
|
|
|
attributes &= FILE_ATTRIBUTE_DIRECTORY;
|
|
|
|
|
return attributes == FILE_ATTRIBUTE_DIRECTORY;
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>/<2F><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>(Suffix Ϊָ<CEAA><D6B8><EFBFBD>ĺ<EFBFBD><EFBFBD><D7BA>)
|
|
|
|
|
void CFileMgr::GetChildFileOrDirName(bool bDir,CString strPath,vector <CString>& Vec,CString Suffix)
|
|
|
|
|
{
|
|
|
|
|
CString strFilePath;
|
|
|
|
|
int dwDirSize = 0;
|
|
|
|
|
strFilePath += strPath;
|
|
|
|
|
strFilePath += "//*.*";
|
|
|
|
|
CFileFind finder;
|
|
|
|
|
BOOL bFind = finder.FindFile(strFilePath);
|
|
|
|
|
while (bFind)
|
|
|
|
|
{
|
|
|
|
|
bFind = finder.FindNextFile();
|
|
|
|
|
if (!finder.IsDots())
|
|
|
|
|
{
|
|
|
|
|
CString strTempPath = finder.GetFilePath();
|
|
|
|
|
if(bDir && finder.IsDirectory())
|
|
|
|
|
{
|
|
|
|
|
Vec.push_back(strTempPath);
|
|
|
|
|
}
|
|
|
|
|
else if(!bDir)
|
|
|
|
|
{
|
|
|
|
|
if(Suffix != "")//ָ<><D6B8><EFBFBD>˺<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
if(strTempPath.Find(Suffix)!=-1)
|
|
|
|
|
Vec.push_back(strTempPath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Vec.push_back(strTempPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finder.Close();
|
|
|
|
|
}
|
|
|
|
|
//ɾ<><C9BE>ָ<EFBFBD><D6B8>Ŀ¼<C4BF>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
void CFileMgr::DeleteDirFile(CString FilePath)
|
|
|
|
|
{
|
|
|
|
|
CString DelStr("del /s/q ");
|
|
|
|
|
DelStr += FilePath;
|
|
|
|
|
system(DelStr);
|
|
|
|
|
}
|
|
|
|
|
//ɾ<><C9BE>Ŀ¼
|
|
|
|
|
void CFileMgr::DeleteDir(CString DirPath)
|
|
|
|
|
{
|
|
|
|
|
CString DelStr("rmdir ");
|
|
|
|
|
DelStr += DirPath;
|
|
|
|
|
system(DelStr);
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ŀ¼
|
|
|
|
|
void CFileMgr::CreatDir(CString DirPath)
|
|
|
|
|
{
|
|
|
|
|
CString MkdirCmd("mkdir ");
|
|
|
|
|
MkdirCmd += DirPath;
|
|
|
|
|
system(MkdirCmd);
|
|
|
|
|
}
|
|
|
|
|
//<2F><>Path1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>copy <20><>Path2
|
|
|
|
|
void CFileMgr::CopyFile(CString Path1,CString Path2)
|
|
|
|
|
{
|
|
|
|
|
CString MoveFileCmd("copy ");
|
|
|
|
|
MoveFileCmd += Path1+" "+Path2;
|
|
|
|
|
system(MoveFileCmd);
|
|
|
|
|
}
|
|
|
|
|
//<2F><>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>(bDelSuffix ȥ<><C8A5><EFBFBD><EFBFBD>)
|
|
|
|
|
CString CFileMgr::GetFileNameFromPath(CString Path,bool bDelSuffix)
|
|
|
|
|
{
|
|
|
|
|
CString name = Path;
|
|
|
|
|
int idx = name.ReverseFind('\\');
|
|
|
|
|
if(idx != -1)
|
|
|
|
|
{
|
|
|
|
|
int len = name.GetLength();
|
|
|
|
|
name = name.Right(len - idx -1);
|
|
|
|
|
}
|
|
|
|
|
if(bDelSuffix)
|
|
|
|
|
{
|
|
|
|
|
idx = name.ReverseFind('.');
|
|
|
|
|
if(idx != -1)
|
|
|
|
|
{
|
|
|
|
|
int len = name.GetLength();
|
|
|
|
|
name = name.Left(len - (len-idx));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return name;
|
|
|
|
|
}
|