206 lines
4.3 KiB
C++
206 lines
4.3 KiB
C++
// TkwFile.cpp: implementation of the CTkwFile class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "TkwFile.h"
|
|
#include "XFilePathName.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
CTkwFile::CTkwFile()
|
|
{
|
|
|
|
}
|
|
|
|
CTkwFile::~CTkwFile()
|
|
{
|
|
|
|
}
|
|
|
|
CTkwFile::CTkwFile(const TCHAR* szTKWName)
|
|
{
|
|
ReadFile(szTKWName);
|
|
}
|
|
|
|
void CTkwFile::SetTKList(XStringList &lstTk)
|
|
{
|
|
m_lstTK.Reset();
|
|
for(int i=0; i<lstTk.Length();i++){
|
|
CString csTK = lstTk[i];
|
|
m_lstTK.Append(tstrnew(csTK));
|
|
}
|
|
}
|
|
|
|
void CTkwFile::GetTKList(XStringList &lstTk)
|
|
{
|
|
lstTk.Reset();
|
|
for(int i=0; i<m_lstTK.Length();i++)
|
|
{
|
|
CString csTK = m_lstTK[i];
|
|
lstTk.Append(tstrnew(csTK));
|
|
}
|
|
}
|
|
|
|
|
|
BOOL CTkwFile::ReadFile(const TCHAR* szTKWName)
|
|
{
|
|
m_lstTK.Reset();
|
|
CFileFind find;
|
|
if(!find.FindFile(szTKWName))
|
|
{
|
|
return FALSE;
|
|
}
|
|
FILE *fp=_tfopen(szTKWName, _T("r"));
|
|
if(!fp)
|
|
return FALSE;
|
|
CString csBuf;
|
|
BOOL bIsTKW = FALSE;
|
|
BOOL bIsDescription = FALSE;
|
|
BOOL bIsTKList = FALSE;
|
|
BOOL bIsShowType = FALSE;
|
|
BOOL bIsVersion = FALSE;
|
|
BOOL bIsFirstRow = FALSE;
|
|
BOOL bIsType = FALSE;
|
|
while(!feof(fp))
|
|
{
|
|
TCHAR sBuf[256]=_T("");
|
|
_fgetts(sBuf, 255, fp);
|
|
csBuf = sBuf;
|
|
csBuf.TrimLeft();
|
|
csBuf.TrimRight();
|
|
if(csBuf == _T("") && !bIsFirstRow)
|
|
continue;
|
|
else if(csBuf != _T("") && !bIsFirstRow)
|
|
{
|
|
bIsFirstRow = TRUE;
|
|
int pos = csBuf.Find(_T("Tangent TKW System"), 0);
|
|
if(pos > -1)
|
|
{
|
|
int len = csBuf.GetLength();
|
|
m_csVersion = csBuf.Right(len - 18);
|
|
m_csVersion.TrimLeft();
|
|
m_csVersion.TrimRight();
|
|
if(m_csVersion != _T("1.0"))
|
|
break;
|
|
bIsVersion = TRUE;
|
|
bIsTKW = TRUE;
|
|
continue;
|
|
}
|
|
break;
|
|
}
|
|
//add by cwk on 060828
|
|
if (csBuf.Find(_T("[Type]"),0) > -1 && bIsTKW)
|
|
{
|
|
bIsType = TRUE;
|
|
continue;
|
|
}
|
|
|
|
if(csBuf == _T("[Description]") && bIsTKW && !bIsTKList)
|
|
{
|
|
bIsDescription = TRUE;
|
|
continue;
|
|
}
|
|
else if(csBuf == _T("[TK LIST]") && bIsTKW && bIsDescription)
|
|
{
|
|
bIsTKList = TRUE;
|
|
bIsDescription = FALSE;
|
|
continue;
|
|
}
|
|
else if(csBuf.Find(_T("[Show Type]"), 0) > -1 && bIsTKW)
|
|
{
|
|
bIsShowType = TRUE;
|
|
int pos = csBuf.Find(_T("[Show Type]"), 0);
|
|
int len = csBuf.GetLength();
|
|
CString csTmp;
|
|
csTmp = csBuf.Right(len - 11);
|
|
csTmp.TrimLeft();
|
|
csTmp.TrimRight();
|
|
if(_tcsicmp(csTmp, _T("JPG")) == 0)
|
|
m_bIsJpg = TRUE;
|
|
else if(_tcsicmp(csTmp, _T("SLD")) == 0)
|
|
m_bIsJpg = FALSE;
|
|
else
|
|
{
|
|
bIsShowType = FALSE;//非法
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
if (bIsType)
|
|
{
|
|
m_csDxfCode = csBuf;
|
|
bIsType = FALSE;
|
|
}
|
|
if(bIsDescription)
|
|
{
|
|
TCHAR strtemp = 13;
|
|
TCHAR strtemp2 = 10;
|
|
m_csDescription += csBuf;
|
|
m_csDescription += strtemp;
|
|
m_csDescription += strtemp2;
|
|
}
|
|
if(bIsTKList)
|
|
{
|
|
CString csTKfile = csBuf;
|
|
XFilePathName FilePath1(csBuf);
|
|
XFilePathName FilePath2(szTKWName);
|
|
if(FilePath1.getDriver() == _T("") && FilePath1.getDir() == _T(""))
|
|
{
|
|
csTKfile = FilePath2.getDriver() + FilePath2.getDir() + csBuf;
|
|
}
|
|
XString fullFile;
|
|
if(FindFile(csTKfile, fullFile))
|
|
{
|
|
m_lstTK.Append(tstrnew(fullFile));
|
|
}
|
|
}
|
|
}
|
|
if(!bIsTKW || !bIsShowType || !bIsVersion)
|
|
{
|
|
AfxMessageBox(_T("不是标准TKW文件!"));
|
|
}
|
|
fclose(fp);
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CTkwFile::WriteFile(const TCHAR* szTKWName)
|
|
{
|
|
FILE *fp=_tfopen(szTKWName, _T("w"));
|
|
if(!fp)
|
|
return FALSE;
|
|
CString csVersion = _T("Tangent TKW System ") + m_csVersion + _T("\n");
|
|
_fputts(csVersion, fp);
|
|
if(m_bIsJpg)
|
|
m_csType = _T("[Show Type] JPG\n");
|
|
else
|
|
m_csType = _T("[Show Type] SLD\n");
|
|
_fputts(m_csType, fp);
|
|
_fputts(_T("[Description]\n"), fp);
|
|
_fputts(m_csDescription, fp);
|
|
_fputts(_T("[TK LIST]\n"), fp);
|
|
for(int i=0;i<m_lstTK.Length();i++)
|
|
{
|
|
CString csNewFile = (const TCHAR*)m_lstTK[i];
|
|
XFilePathName XFilePath1(csNewFile);
|
|
XFilePathName XFilePath2(szTKWName);
|
|
if((_tcsicmp(XFilePath1.getDriver(), XFilePath2.getDriver()) == 0) &&
|
|
(_tcsicmp(XFilePath1.getDir(), XFilePath2.getDir()) == 0))
|
|
csNewFile = XFilePath1.getFileName()+ XFilePath1.getFileExt();
|
|
csNewFile += _T("\n");
|
|
_fputts(csNewFile, fp);
|
|
}
|
|
_fputts(_T("[Type]\n"), fp);
|
|
_fputts(m_csDxfCode, fp);
|
|
fclose(fp);
|
|
return TRUE;
|
|
}
|