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