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"
29 ProjectFile::ProjectFile()
35 * @brief Get message from exception into sError, or else throw it.
37 * If this successfully extracts the error description into the string, it simply returns FALSE
38 * If it fails to extract the error description, it rethrows the exception
40 static BOOL NTAPI False(CException *e, CString *sError)
45 e->GetErrorMessage(szError, 1024);
52 * @brief Open given path-file and read data from it to member variables.
54 BOOL ProjectFile::Read(LPCTSTR path, CString *sError)
56 return Serialize(false, path, sError);
60 * @brief Save data from member variables to path-file.
61 * @note paths are converted to UTF-8
63 BOOL ProjectFile::Save(LPCTSTR path, CString *sError)
65 return Serialize(true, path, sError);
70 * @brief Read or write project file
72 BOOL ProjectFile::Serialize(bool writing, LPCTSTR path, CString *sError)
76 XmlDoc::XML_LOADSAVE loadSave = (writing ? XmlDoc::XML_SAVE : XmlDoc::XML_LOAD);
78 XmlDoc doc(path, loadSave, _T("UTF-8"));
81 XmlElement project(doc, _T("project"));
83 XmlElement paths(doc, _T("paths"));
85 XmlElement(doc, _T("left"), m_leftFile);
87 XmlElement(doc, _T("right"), m_rightFile);
89 XmlElement(doc, _T("filter"), m_filter);
91 XmlElement(doc, _T("subfolders"), m_subfolders);
100 return False(e, sError);
106 * @brief Returns if left path is defined.
108 BOOL ProjectFile::HasLeft() const
110 return !m_leftFile.IsEmpty();
114 * @brief Returns if right path is defined.
116 BOOL ProjectFile::HasRight() const
118 return !m_rightFile.IsEmpty();
122 * @brief Returns if filter is defined.
124 BOOL ProjectFile::HasFilter() const
126 return !m_filter.IsEmpty();
130 * @brief Returns if subfolder is included.
132 BOOL ProjectFile::HasSubfolders() const
134 return (m_subfolders != -1);
138 * @brief Returns left path.
140 CString ProjectFile::GetLeft() const
146 * @brief Set left path, returns old left path.
148 CString ProjectFile::SetLeft(const CString& sLeft)
150 CString sLeftOld = GetLeft();
157 * @brief Returns right path.
159 CString ProjectFile::GetRight() const
165 * @brief Set right path, returns old right path.
167 CString ProjectFile::SetRight(const CString& sRight)
169 CString sRightOld = GetRight();
170 m_rightFile = sRight;
176 * @brief Returns filter.
178 CString ProjectFile::GetFilter() const
184 * @brief Set filter, returns old filter.
186 CString ProjectFile::SetFilter(const CString& sFilter)
188 CString sFilterOld = GetFilter();
195 * @brief Returns subfolder included -setting.
197 int ProjectFile::GetSubfolders() const
203 * @brief set subfolder, returns old subfolder value.
205 int ProjectFile::SetSubfolders(const int iSubfolder)
207 int iSubfoldersOld = GetSubfolders();
208 m_subfolders = iSubfolder ? 1 : 0;
210 return iSubfoldersOld;
214 * @brief Reads one value from XML data.
216 BOOL ProjectFile::GetVal(TCHAR *pPaths, TCHAR *pVal, CString * sval,
217 TCHAR *ptag1, TCHAR *ptag2, TCHAR *pbuf)
219 if (pPaths && pVal && pVal > pPaths)
221 TCHAR tmpPath[MAX_PATH] = {0};
222 TCHAR *pTagEnd = _tcsstr(pbuf, ptag2);
223 if ((pTagEnd - pVal) < (MAX_PATH * sizeof(TCHAR)))
225 pVal += _tcslen(ptag1);
226 _tcsncpy(tmpPath, pVal, pTagEnd - pVal);
235 * @brief Returns left and right paths and recursive from project file
237 * @param [out] sLeft Left path
238 * @param [out] sRight Right path
239 * @param [out] bSubFolders If TRUE subfolders included (recursive compare)
241 void ProjectFile::GetPaths(CString & sLeft, CString & sRight,
242 BOOL & bSubfolders) const
249 bSubfolders = (GetSubfolders() == 1);