1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016-2017 - TortoiseGit
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.
20 #include "TortoiseProc.h"
21 #include "FirstStartWizard.h"
22 #include "FirstStartWizardGit.h"
24 #include "MessageBox.h"
25 #include "GitForWindows.h"
26 #include "../../TGitCache/CacheInterface.h"
28 IMPLEMENT_DYNAMIC(CFirstStartWizardGit
, CFirstStartWizardBasePage
)
30 #define CHECK_NEWGIT_TIMER 100
32 CFirstStartWizardGit::CFirstStartWizardGit() : CFirstStartWizardBasePage(CFirstStartWizardGit::IDD
)
34 m_psp
.dwFlags
|= PSP_DEFAULT
| PSP_USEHEADERTITLE
;
35 m_psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_FIRSTSTART_GITTITLE
);
37 g_Git
.CheckMsysGitDir(TRUE
);
38 m_regMsysGitPath
= CRegString(REG_MSYSGIT_PATH
);
40 m_regMsysGitExtranPath
= CRegString(REG_MSYSGIT_EXTRA_PATH
);
42 m_sMsysGitPath
= m_regMsysGitPath
;
43 m_sMsysGitExtranPath
= m_regMsysGitExtranPath
;
45 m_bEnableHacks
= (CGit::ms_bCygwinGit
|| CGit::ms_bMsys2Git
);
48 CFirstStartWizardGit::~CFirstStartWizardGit()
52 void CFirstStartWizardGit::DoDataExchange(CDataExchange
* pDX
)
54 CFirstStartWizardBasePage::DoDataExchange(pDX
);
55 DDX_Text(pDX
, IDC_MSYSGIT_PATH
, m_sMsysGitPath
);
56 DDX_Text(pDX
, IDC_MSYSGIT_EXTERN_PATH
, m_sMsysGitExtranPath
);
57 DDX_Control(pDX
, IDC_LINK
, m_link
);
58 DDX_Check(pDX
, IDC_WORKAROUNDS
, m_bEnableHacks
);
61 BEGIN_MESSAGE_MAP(CFirstStartWizardGit
, CFirstStartWizardBasePage
)
62 ON_BN_CLICKED(IDC_MSYSGIT_BROWSE
, OnBrowseDir
)
63 ON_BN_CLICKED(IDC_MSYSGIT_CHECK
, OnCheck
)
64 ON_BN_CLICKED(IDC_WORKAROUNDS
, OnClickedWorkarounds
)
68 LRESULT
CFirstStartWizardGit::OnWizardNext()
72 PerformCommonGitPathCleanup(m_sMsysGitPath
);
77 if (m_sMsysGitPath
.Compare(CString(m_regMsysGitPath
)) || m_sMsysGitExtranPath
.Compare(CString(m_regMsysGitExtranPath
)) || CGit::ms_bCygwinGit
!= (m_regCygwinHack
== TRUE
) || CGit::ms_bMsys2Git
!= (m_regMsys2Hack
== TRUE
))
79 StoreSetting(GetSafeHwnd(), m_sMsysGitPath
, m_regMsysGitPath
);
80 StoreSetting(GetSafeHwnd(), m_sMsysGitExtranPath
, m_regMsysGitExtranPath
);
81 StoreSetting(GetSafeHwnd(), CGit::ms_bCygwinGit
, m_regCygwinHack
);
82 StoreSetting(GetSafeHwnd(), CGit::ms_bMsys2Git
, m_regMsys2Hack
);
83 SendCacheCommand(TGITCACHECOMMAND_END
);
86 // only complete if the msysgit directory is ok
87 bool needWorkarounds
= (GetDlgItem(IDC_WORKAROUNDS
)->IsWindowVisible() == TRUE
);
88 if (!CheckGitExe(GetSafeHwnd(), m_sMsysGitPath
, m_sMsysGitExtranPath
, IDC_MSYSGIT_VER
, [&](UINT helpid
) { HtmlHelp(0x20000 + helpid
); }, &needWorkarounds
))
91 ShowWorkarounds(true);
95 return __super::OnWizardNext();
98 void CFirstStartWizardGit::ShowWorkarounds(bool show
)
100 if (!(CGit::ms_bCygwinGit
|| CGit::ms_bMsys2Git
|| show
))
103 GetDlgItem(IDC_WORKAROUNDS
)->ShowWindow(SW_SHOW
);
105 GetDlgItem(IDC_GITHACKS1
)->ShowWindow(m_bEnableHacks
? SW_SHOW
: SW_HIDE
);
106 GetDlgItem(IDC_GITHACKS2
)->ShowWindow(m_bEnableHacks
? SW_SHOW
: SW_HIDE
);
108 if (CGit::ms_bCygwinGit
)
109 CheckRadioButton(IDC_GITHACKS1
, IDC_GITHACKS2
, IDC_GITHACKS1
);
110 else if (CGit::ms_bMsys2Git
)
111 CheckRadioButton(IDC_GITHACKS1
, IDC_GITHACKS2
, IDC_GITHACKS2
);
114 BOOL
CFirstStartWizardGit::OnInitDialog()
116 CFirstStartWizardBasePage::OnInitDialog();
118 SHAutoComplete(GetDlgItem(IDC_MSYSGIT_PATH
)->m_hWnd
, SHACF_FILESYSTEM
);
120 m_tooltips
.Create(this);
121 m_tooltips
.AddTool(IDC_MSYSGIT_EXTERN_PATH
, IDS_EXTRAPATH_TT
);
123 GetDlgItem(IDC_LINK
)->SetWindowText(GIT_FOR_WINDOWS_URL
);
124 m_link
.SetURL(GIT_FOR_WINDOWS_URL
);
126 AdjustControlSize(IDC_LINK
, false);
127 AdjustControlSize(IDC_WORKAROUNDS
);
128 AdjustControlSize(IDC_GITHACKS1
);
129 AdjustControlSize(IDC_GITHACKS2
);
131 CheckRadioButton(IDC_GITHACKS1
, IDC_GITHACKS2
, IDC_GITHACKS1
);
134 if (m_sMsysGitPath
.IsEmpty())
135 SetTimer(CHECK_NEWGIT_TIMER
, 1000, nullptr);
140 void CFirstStartWizardGit::OnTimer(UINT_PTR nIDEvent
)
142 if (nIDEvent
== CHECK_NEWGIT_TIMER
)
144 KillTimer(CHECK_NEWGIT_TIMER
);
146 if (m_sMsysGitPath
.IsEmpty())
148 if (FindGitForWindows(m_sMsysGitPath
))
153 SetTimer(CHECK_NEWGIT_TIMER
, 1000, nullptr);
157 __super::OnTimer(nIDEvent
);
160 BOOL
CFirstStartWizardGit::OnSetActive()
162 CFirstStartWizard
* wiz
= (CFirstStartWizard
*)GetParent();
164 wiz
->SetWizardButtons(PSWIZB_NEXT
| PSWIZB_BACK
);
166 return CFirstStartWizardBasePage::OnSetActive();
169 void CFirstStartWizardGit::OnMsysGitPathModify()
172 if (GuessExtraPath(m_sMsysGitPath
, m_sMsysGitExtranPath
))
176 void CFirstStartWizardGit::OnBrowseDir()
180 if (!SelectFolder(GetSafeHwnd(), m_sMsysGitPath
, m_sMsysGitExtranPath
))
186 void CFirstStartWizardGit::SetGitHacks()
188 CGit::ms_bCygwinGit
= false;
189 CGit::ms_bMsys2Git
= false;
192 int id
= GetCheckedRadioButton(IDC_GITHACKS1
, IDC_GITHACKS2
);
193 CGit::ms_bCygwinGit
= (id
== IDC_GITHACKS1
);
194 CGit::ms_bMsys2Git
= (id
== IDC_GITHACKS2
);
198 void CFirstStartWizardGit::OnCheck()
201 bool oldCygwinGit
= CGit::ms_bCygwinGit
;
202 bool oldMsys2Git
= CGit::ms_bMsys2Git
;
205 CGit::ms_bCygwinGit
= oldCygwinGit
;
206 CGit::ms_bMsys2Git
= oldMsys2Git
;
211 bool needWorkarounds
= (GetDlgItem(IDC_WORKAROUNDS
)->IsWindowVisible() == TRUE
);
212 CheckGitExe(GetSafeHwnd(), m_sMsysGitPath
, m_sMsysGitExtranPath
, IDC_MSYSGIT_VER
, [&](UINT helpid
) { HtmlHelp(0x20000 + helpid
); }, &needWorkarounds
);
214 ShowWorkarounds(true);
217 BOOL
CFirstStartWizardGit::PreTranslateMessage(MSG
* pMsg
)
219 m_tooltips
.RelayEvent(pMsg
);
220 return __super::PreTranslateMessage(pMsg
);
223 void CFirstStartWizardGit::OnClickedWorkarounds()
226 ShowWorkarounds(true);