1 // TortoiseMerge - a Diff/Patch program
\r
3 // Copyright (C) 2006-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 "Workingfile.h"
\r
21 #include "AppUtils.h"
\r
22 #include "PathUtils.h"
\r
23 #include "resource.h"
\r
25 CWorkingFile::CWorkingFile(void)
\r
29 CWorkingFile::~CWorkingFile(void)
\r
33 void CWorkingFile::SetFileName(const CString& newFilename)
\r
35 m_sFilename = newFilename;
\r
36 m_sFilename.Replace('/', '\\');
\r
37 m_sDescriptiveName.Empty();
\r
40 void CWorkingFile::SetDescriptiveName(const CString& newDescName)
\r
42 m_sDescriptiveName = newDescName;
\r
45 CString CWorkingFile::GetDescriptiveName()
\r
47 if (m_sDescriptiveName.IsEmpty())
\r
49 CString sDescriptiveName = CPathUtils::GetFileNameFromPath(m_sFilename);
\r
50 if (sDescriptiveName.GetLength() < 20)
\r
51 return sDescriptiveName;
\r
53 return m_sDescriptiveName;
\r
56 // Make an empty file with this name
\r
57 void CWorkingFile::CreateEmptyFile()
\r
59 HANDLE hFile = CreateFile(m_sFilename, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
\r
63 // Move the details of the specified file to the current one, and then mark the specified file
\r
65 void CWorkingFile::TransferDetailsFrom(CWorkingFile& rightHandFile)
\r
67 // We don't do this to files which are already in use
\r
70 m_sFilename = rightHandFile.m_sFilename;
\r
71 m_sDescriptiveName = rightHandFile.m_sDescriptiveName;
\r
72 rightHandFile.SetOutOfUse();
\r
75 CString CWorkingFile::GetWindowName() const
\r
77 CString sErrMsg = _T("");
\r
78 // TortoiseMerge allows non-existing files to be used in a merge
\r
79 // Inform the user (in a non-intrusive way) if a file is absent
\r
80 if (! this->Exists())
\r
82 sErrMsg = CString(MAKEINTRESOURCE(IDS_NOTFOUNDVIEWTITLEINDICATOR));
\r
85 if(m_sDescriptiveName.IsEmpty())
\r
87 // We don't have a proper name - use the filename part of the path
\r
88 // return the filename part of the path.
\r
89 return CPathUtils::GetFileNameFromPath(m_sFilename) + _T(" ") + sErrMsg;
\r
91 else if (sErrMsg.IsEmpty())
\r
93 return m_sDescriptiveName;
\r
95 return m_sDescriptiveName + _T(" ") + sErrMsg;
\r
98 bool CWorkingFile::Exists() const
\r
100 return (!!PathFileExists(m_sFilename));
\r