Handle versioncheck.tortoisegit.org as official source
[TortoiseGit.git] / src / TortoiseProc / AppUtils.h
blob3458dcef9648dd5660b0229b12d8190198203358
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - TortoiseGit
4 // Copyright (C) 2003-2008 - 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.
20 #pragma once
21 #include "GitRev.h"
22 #include "CommonAppUtils.h"
24 class CTGitPath;
25 struct git_cred;
26 struct git_transfer_progress;
27 class CIgnoreFile;
29 /**
30 * \ingroup TortoiseProc
31 * An utility class with static functions.
33 class CAppUtils : public CCommonAppUtils
35 public:
36 /**
37 * Flags for StartExtDiff function.
39 struct DiffFlags
41 bool bWait;
42 bool bBlame;
43 bool bReadOnly;
44 bool bAlternativeTool; // If true, invert selection of TortoiseGitMerge vs. external diff tool
46 DiffFlags(): bWait(false), bBlame(false), bReadOnly(false), bAlternativeTool(false) {}
47 DiffFlags& Wait(bool b = true) { bWait = b; return *this; }
48 DiffFlags& Blame(bool b = true) { bBlame = b; return *this; }
49 DiffFlags& ReadOnly(bool b = true) { bReadOnly = b; return *this; }
50 DiffFlags& AlternativeTool(bool b = true) { bAlternativeTool = b; return *this; }
53 CAppUtils(void);
54 ~CAppUtils(void);
56 /**
57 * Launches the external merge program if there is one.
58 * \return TRUE if the program could be started
60 static BOOL StartExtMerge(
61 const CTGitPath& basefile, const CTGitPath& theirfile, const CTGitPath& yourfile, const CTGitPath& mergedfile,
62 const CString& basename = CString(), const CString& theirname = CString(), const CString& yourname = CString(),
63 const CString& mergedname = CString(), bool bReadOnly = false, HWND resolveMsgHwnd = nullptr, bool bDeleteBaseTheirsMineOnClose = false);
65 /**
66 * Starts the external patch program (currently always TortoiseGitMerge)
68 static BOOL StartExtPatch(const CTGitPath& patchfile, const CTGitPath& dir,
69 const CString& sOriginalDescription = CString(), const CString& sPatchedDescription = CString(),
70 BOOL bReversed = FALSE, BOOL bWait = FALSE);
72 /**
73 * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).
74 * If no app is associated with those file types, the default text editor is used.
76 static BOOL StartUnifiedDiffViewer(const CString& patchfile, const CString& title, BOOL bWait = FALSE);
78 /**
79 * Sets up all the default diff and merge scripts.
80 * \param force if true, overwrite all existing entries
81 * \param either "Diff", "Merge" or an empty string
83 static bool SetupDiffScripts(bool force, const CString& type);
85 /**
86 * Starts the external diff application
88 static bool StartExtDiff(
89 const CString& file1, const CString& file2,
90 const CString& sName1, const CString& sName2,
91 const CString& originalFile1, const CString& originalFile2,
92 const git_revnum_t& hash1, const git_revnum_t& hash2, const DiffFlags& flags, int jumpToLine = 0);
94 /**
95 * Launches the standard text viewer/editor application which is associated
96 * with txt files.
97 * \return TRUE if the program could be started.
99 static BOOL StartTextViewer(CString file);
102 * Checks if the given file has a size of less than four, which means
103 * an 'empty' file or just newlines, i.e. an empty diff.
105 static BOOL CheckForEmptyDiff(const CTGitPath& sDiffPath);
108 * Create a font which can is used for log messages, etc
110 static void CreateFontForLogs(CFont& fontToCreate);
113 * Launch the external blame viewer
115 static bool LaunchTortoiseBlame(
116 const CString& sBlameFile, const CString& Rev, const CString& sParams = CString());
119 * Launch alternative editor
121 static bool LaunchAlternativeEditor(const CString& filename, bool uac = false);
124 * Sets the title of a dialog
126 static void SetWindowTitle(HWND hWnd, const CString& urlorpath, const CString& dialogname);
129 * Formats text in a rich edit control (version 2).
130 * text in between * chars is formatted bold
131 * text in between ^ chars is formatted italic
132 * text in between _ chars is underlined
134 static bool FormatTextInRichEditControl(CWnd * pWnd);
135 static bool FindStyleChars(const CString& sText, TCHAR stylechar, int& start, int& end);
137 * implements URL searching with the same logic as CSciEdit::StyleURLs
139 static std::vector<CHARRANGE> FindURLMatches(const CString& msg);
140 static BOOL StyleURLs(const CString& msg, CWnd* pWnd);
143 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
145 static bool StartShowUnifiedDiff(HWND hWnd, const CTGitPath& url1, const git_revnum_t& rev1,
146 const CTGitPath & url2, const git_revnum_t& rev2,
148 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
149 bool bAlternateDiff = false,
150 bool bIgnoreAncestry = false,
151 bool blame = false,
152 bool bMerge = false,
153 bool bCompact = false);
155 static bool Export(const CString* BashHash = nullptr, const CTGitPath* orgPath = nullptr);
156 static bool CreateBranchTag(bool IsTag = TRUE, const CString* CommitHash = nullptr, bool switch_new_brach = false);
157 static bool Switch(const CString& initialRefName = CString());
158 static bool PerformSwitch(const CString& ref, bool bForce = false, const CString& sNewBranch = CString(), bool bBranchOverride = false, BOOL bTrack = 2, bool bMerge = false);
160 static bool IgnoreFile(const CTGitPathList& filelist, bool IsMask);
161 static bool GitReset(const CString* CommitHash, int type = 1);
162 static bool ConflictEdit(const CTGitPath& file, bool bAlternativeTool = false, bool revertTheirMy = false, HWND resolveMsgHwnd = nullptr);
164 static CString GetMergeTempFile(const CString& str, const CTGitPath& merge);
165 static bool StashSave(const CString& msg = CString(), bool showPull = false, bool pullShowPush = false, bool showMerge = false, const CString& mergeRev = CString());
166 static bool StashApply(CString ref, bool showChanges = true);
167 static bool StashPop(bool showChanges = true);
169 static bool IsSSHPutty();
171 static bool LaunchRemoteSetting();
173 static bool LaunchPAgent(const CString* keyfile = nullptr, const CString* pRemote = nullptr);
175 static bool ShellOpen(const CString& file, HWND hwnd = nullptr);
176 static bool ShowOpenWithDialog(const CString& file, HWND hwnd = nullptr);
178 static CString GetClipboardLink(const CString &skipGitPrefix = _T(""), int paramsCount = 0);
179 static CString ChooseRepository(const CString* path);
181 static bool SendPatchMail(CTGitPathList& pathlist, bool bIsMainWnd = false);
182 static bool SendPatchMail(const CString& cmd, const CString& formatpatchoutput, bool bIsMainWnd = false);
184 static int SaveCommitUnicodeFile(const CString& filename, CString& mesage);
186 static int GetLogOutputEncode(CGit *pGit=&g_Git);
188 static bool Pull(bool showPush = false, bool showStashPop = false);
189 static bool RebaseAfterFetch(const CString& upstream = _T(""));
190 static bool Fetch(const CString& remoteName = _T(""), bool allRemotes = false);
191 static bool Push(const CString& selectLocalBranch = CString());
192 static bool RequestPull(const CString& endrevision = _T(""), const CString& repositoryUrl = _T(""), bool bIsMainWnd = false);
194 static bool CreateMultipleDirectory(const CString &dir);
196 static void RemoveTrailSlash(CString &path);
198 static bool CheckUserData();
200 static BOOL Commit(const CString& bugid, BOOL bWholeProject, CString &sLogMsg,
201 CTGitPathList &pathList,
202 CTGitPathList &selectedList,
203 bool bSelectFilesForCommit);
205 static BOOL SVNDCommit();
206 static BOOL Merge(const CString* commit = nullptr, bool showStashPop = false);
207 static BOOL MergeAbort();
208 static void RemoveTempMergeFile(const CTGitPath& path);
209 static void EditNote(GitRev *hash);
210 static int GetMsysgitVersion();
211 static void MarkWindowAsUnpinnable(HWND hWnd);
213 static bool BisectStart(const CString& lastGood, const CString& firstBad, bool bIsMainWnd = false);
215 static int Git2GetUserPassword(git_cred **out, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload);
217 static int Git2CertificateCheck(git_cert *cert, int valid, const char* host, void *payload);
219 static void ExploreTo(HWND hwnd, CString path);
221 enum resolve_with {
222 RESOLVE_WITH_CURRENT,
223 RESOLVE_WITH_MINE,
224 RESOLVE_WITH_THEIRS,
227 static int ResolveConflict(CTGitPath& path, resolve_with resolveWith);
229 private:
230 static CString PickDiffTool(const CTGitPath& file1, const CTGitPath& file2);
232 static bool OpenIgnoreFile(CIgnoreFile &file, const CString& filename);
234 static void DescribeConflictFile(bool mode, bool base,CString &descript);