1 /////////////////////////////////////////////////////////////////////////////
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or (at
6 // your option) any later version.
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 /////////////////////////////////////////////////////////////////////////////
18 * @file ProjectFile.cpp
20 * @brief Implementation file for ProjectFile class
22 // RCS ID line follows -- this is updated by CVS
26 #include "ProjectFile.h"
28 ProjectFile::ProjectFile()
34 * @brief Open given path-file and read data from it to member variables.
36 BOOL ProjectFile::Read(LPCTSTR path, CString *sError)
38 ASSERT(sError != NULL);
42 if (!file.Open(path, CFile::modeRead, &e))
45 e.GetErrorMessage(szError, 1024);
51 TCHAR buf2[4096] = {0};
52 TCHAR tmpPath[MAX_PATH] = {0};
53 UINT bytesRead = file.Read(buf, 4095);
56 _tcsncpy(buf2, A2T(buf), 4096);
58 if (_tcsstr(buf2, _T("<?xml")) && _tcsstr(buf2, _T("?>")))
60 TCHAR *pProject = _tcsstr(buf2, _T("<project>"));
64 TCHAR *pPaths = _tcsstr(buf2, _T("<paths>"));
65 TCHAR *pLeft = _tcsstr(buf2, _T("<left>"));
66 TCHAR *pRight = _tcsstr(buf2, _T("<right>"));
67 TCHAR *pFilter = _tcsstr(buf2, _T("<filter>"));
68 TCHAR *pSubs = _tcsstr(buf2, _T("<subfolders>"));
71 GetVal(pPaths, pLeft, &m_leftFile, _T("<left>"), _T("</left>"), buf2);
72 GetVal(pPaths, pRight, &m_rightFile, _T("<right>"), _T("</right>"), buf2);
73 GetVal(pPaths, pFilter, &m_filter, _T("<filter>"), _T("</filter>"), buf2);
74 if (GetVal(pPaths, pSubs, &subs, _T("<subfolders>"), _T("</subfolders>"), buf2))
75 m_subfolders = _ttoi(subs);
85 * @brief Save data from member variables to path-file.
87 BOOL ProjectFile::Save(LPCTSTR path)
89 UINT flags = CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite;
95 * @brief Returns if left path is defined.
97 BOOL ProjectFile::HasLeft() const
99 return !m_leftFile.IsEmpty();
103 * @brief Returns if right path is defined.
105 BOOL ProjectFile::HasRight() const
107 return !m_rightFile.IsEmpty();
111 * @brief Returns if filter is defined.
113 BOOL ProjectFile::HasFilter() const
115 return !m_filter.IsEmpty();
119 * @brief Returns if subfolder is included.
121 BOOL ProjectFile::HasSubfolders() const
123 return (m_subfolders != -1);
127 * @brief Returns left path.
129 CString ProjectFile::GetLeft() const
135 * @brief Returns right path.
137 CString ProjectFile::GetRight() const
143 * @brief Returns filter.
145 CString ProjectFile::GetFilter() const
151 * @brief Returns subfolder included -setting.
153 int ProjectFile::GetSubfolders() const
159 * @brief Reads one value from XML data.
161 BOOL ProjectFile::GetVal(TCHAR *pPaths, TCHAR *pVal, CString * sval,
162 TCHAR *ptag1, TCHAR *ptag2, TCHAR *pbuf)
164 if (pPaths && pVal && pVal > pPaths)
166 TCHAR tmpPath[MAX_PATH] = {0};
167 TCHAR *pTagEnd = _tcsstr(pbuf, ptag2);
168 if ((pTagEnd - pVal) < (MAX_PATH * sizeof(TCHAR)))
170 pVal += _tcslen(ptag1);
171 _tcsncpy(tmpPath, pVal, pTagEnd - pVal);
180 * @brief Returns left and right paths and recursive from project file
182 * @param [out] sLeft Left path
183 * @param [out] sRight Right path
184 * @param [out] bSubFolders If TRUE subfolders included (recursive compare)
186 void ProjectFile::GetPaths(CString & sLeft, CString & sRight,
187 BOOL & bSubfolders) const
194 bSubfolders = (GetSubfolders() == 1);