// 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 -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