1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2007 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include "LogFile.h"
\r
21 #include "PathUtils.h"
\r
23 CLogFile::CLogFile(void)
\r
25 m_maxlines = CRegStdWORD(_T("Software\\TortoiseGit\\MaxLinesInLogfile"), 4000);
\r
28 CLogFile::~CLogFile(void)
\r
32 bool CLogFile::Open()
\r
34 CTSVNPath logfile = CTSVNPath(CPathUtils::GetAppDataDirectory() + _T("\\logfile.txt"));
\r
35 return Open(logfile);
\r
38 bool CLogFile::Open(const CTSVNPath& logfile)
\r
41 m_logfile = logfile;
\r
42 if (!logfile.Exists())
\r
44 CPathUtils::MakeSureDirectoryPathExists(logfile.GetContainingDirectory().GetWinPath());
\r
52 int retrycounter = 10;
\r
53 // try to open the file for about two seconds - some other TSVN process might be
\r
54 // writing to the file and we just wait a little for this to finish
\r
55 while (!file.Open(logfile.GetWinPath(), CFile::typeText | CFile::modeRead | CFile::shareDenyWrite) && retrycounter)
\r
60 if (retrycounter == 0)
\r
63 while (file.ReadString(strLine))
\r
65 m_lines.push_back(strLine);
\r
69 catch (CFileException* pE)
\r
71 TRACE("CFileException loading autolist regex file\n");
\r
78 bool CLogFile::AddLine(const CString& line)
\r
80 m_lines.push_back(line);
\r
84 bool CLogFile::Close()
\r
92 int retrycounter = 10;
\r
93 // try to open the file for about two seconds - some other TSVN process might be
\r
94 // writing to the file and we just wait a little for this to finish
\r
95 while (!file.Open(m_logfile.GetWinPath(), CFile::typeText | CFile::modeWrite | CFile::modeCreate) && retrycounter)
\r
100 if (retrycounter == 0)
\r
103 for (std::list<CString>::const_iterator it = m_lines.begin(); it != m_lines.end(); ++it)
\r
105 file.WriteString(*it);
\r
106 file.WriteString(_T("\n"));
\r
110 catch (CFileException* pE)
\r
112 TRACE("CFileException loading autolist regex file\n");
\r
119 bool CLogFile::AddTimeLine()
\r
122 // first add an empty line as a separator
\r
123 m_lines.push_back(sLine);
\r
124 // now add the time string
\r
125 TCHAR datebuf[4096] = {0};
\r
126 GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, datebuf, 4096);
\r
128 GetTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL, datebuf, 4096);
\r
129 sLine += _T(" - ");
\r
131 m_lines.push_back(sLine);
\r
135 void CLogFile::AdjustSize()
\r
137 DWORD maxlines = m_maxlines;
\r
139 while (m_lines.size() > maxlines)
\r
141 m_lines.pop_front();
\r