Merge branch 'vs2012'
[TortoiseGit.git] / src / TortoiseMerge / WorkingFile.cpp
blobcfa0dc070d3f26a49f22987960fb1ce69d8da09f
1 // TortoiseMerge - a Diff/Patch program
3 // Copyright (C) 2006-2007,2011 - 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.
19 #include "stdafx.h"
20 #include "Workingfile.h"
21 #include "AppUtils.h"
22 #include "PathUtils.h"
23 #include "resource.h"
24 #include "SmartHandle.h"
26 CWorkingFile::CWorkingFile(void)
30 CWorkingFile::~CWorkingFile(void)
34 void CWorkingFile::SetFileName(const CString& newFilename)
36 m_sFilename = newFilename;
37 m_sFilename.Replace('/', '\\');
38 m_sDescriptiveName.Empty();
41 void CWorkingFile::SetDescriptiveName(const CString& newDescName)
43 m_sDescriptiveName = newDescName;
46 CString CWorkingFile::GetDescriptiveName()
48 if (m_sDescriptiveName.IsEmpty())
50 CString sDescriptiveName = CPathUtils::GetFileNameFromPath(m_sFilename);
51 if (sDescriptiveName.GetLength() < 20)
52 return sDescriptiveName;
54 return m_sDescriptiveName;
57 // Make an empty file with this name
58 void CWorkingFile::CreateEmptyFile()
60 CAutoFile hFile = CreateFile(m_sFilename, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
63 // Move the details of the specified file to the current one, and then mark the specified file
64 // as out of use
65 void CWorkingFile::TransferDetailsFrom(CWorkingFile& rightHandFile)
67 // We don't do this to files which are already in use
68 ASSERT(!InUse());
70 m_sFilename = rightHandFile.m_sFilename;
71 m_sDescriptiveName = rightHandFile.m_sDescriptiveName;
72 rightHandFile.SetOutOfUse();
75 CString CWorkingFile::GetWindowName() const
77 CString sErrMsg = _T("");
78 // TortoiseMerge allows non-existing files to be used in a merge
79 // Inform the user (in a non-intrusive way) if a file is absent
80 if (! this->Exists())
82 sErrMsg = CString(MAKEINTRESOURCE(IDS_NOTFOUNDVIEWTITLEINDICATOR));
85 if(m_sDescriptiveName.IsEmpty())
87 // We don't have a proper name - use the filename part of the path
88 // return the filename part of the path.
89 return CPathUtils::GetFileNameFromPath(m_sFilename) + _T(" ") + sErrMsg;
91 else if (sErrMsg.IsEmpty())
93 return m_sDescriptiveName;
95 return m_sDescriptiveName + _T(" ") + sErrMsg;
98 bool CWorkingFile::Exists() const
100 return (!!PathFileExists(m_sFilename));