1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2012 - TortoiseGit
4 // Copyright (C) 2010-2012 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "SysProgressDlg.h"
35 * Does a dry run of the patching, fills in all the arrays.
36 * Call this function first.
37 * The progress dialog is used to show progress info if the initialization takes a long time.
38 * \return the number of files affected by the patchfile, 0 in case of an error
40 int Init(const CString
& patchfile
, const CString
& targetpath
, CSysProgressDlg
*pPprogDlg
);
43 * Sets the target path. Use this after getting a new path from CheckPatchPath()
45 void SetTargetPath(const CString
& targetpath
) { m_targetpath
= targetpath
; m_targetpath
.Replace('\\', '/'); }
46 CString
GetTargetPath() { return m_targetpath
; }
49 * Finds the best path to apply the patch file. Starting from the targetpath
50 * specified in Init() first upwards, then downwards.
51 * \remark this function shows a progress dialog and also shows a dialog asking
52 * the user to accept a possible better target path.
53 * \return the best path to apply the patch to.
55 CString
CheckPatchPath(const CString
& path
);
58 * Applies the patch for the given \c path, including property changes if necessary.
60 bool PatchPath(const CString
& path
);
63 * Returns the paths of the patch result for the \c sPath.
64 * The patch is applied in the Init() method.
65 * \return the number of failed hunks, 0 if everything was applied successfully, -1 on error
67 int GetPatchResult(const CString
& sPath
, CString
& sSavePath
, CString
& sRejectPath
) const;
70 * returns the number of files that are affected by the patchfile.
72 int GetNumberOfFiles() const { return (int)m_filePaths
.size(); }
75 * Returns the path of the affected file
77 CString
GetFilePath(int index
) const { return m_filePaths
[index
].path
; }
80 * Returns the number of failed hunks for the affected file
82 int GetFailedHunks(int index
) const { return m_filePaths
[index
].rejects
; }
85 * Returns true if there are content modifications for the path
87 bool GetContentMods(int index
) const { return m_filePaths
[index
].content
; }
90 * Returns true if there are property modifications for the path
92 bool GetPropMods(int index
) const { return m_filePaths
[index
].props
; }
95 * Returns the path of the affected file, stripped by m_nStrip.
97 CString
GetStrippedPath(int nIndex
) const;
100 * Returns a string containing the last error message.
102 CString
GetErrorMessage() const { return m_errorStr
; }
105 * Removes the file from version control
107 bool RemoveFile(const CString
& path
);
109 CString
GetPatchRejects(int nIndex
) const;
112 int CountMatches(const CString
& path
) const;
113 int CountDirMatches(const CString
& path
) const;
115 * Strips the filename by removing m_nStrip prefixes.
117 CString
Strip(const CString
& filename
) const;
119 typedef struct PathRejects
128 std::vector
<PathRejects
> m_filePaths
;
130 bool m_bSuccessfullyPatched
;
133 CString m_targetpath
;
135 CString m_filetopatch
;
137 CSysProgressDlg
* m_pProgDlg
;
141 bool PatchFile(int nIndex
, CString
&datapath
);