1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016 - 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 CFirstStartWizardGit::CFirstStartWizardGit() : CFirstStartWizardBasePage(CFirstStartWizardGit::IDD
)
32 m_psp
.dwFlags
|= PSP_DEFAULT
| PSP_USEHEADERTITLE
;
33 m_psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_FIRSTSTART_GITTITLE
);
35 g_Git
.CheckMsysGitDir(TRUE
);
36 m_regMsysGitPath
= CRegString(REG_MSYSGIT_PATH
);
38 m_regMsysGitExtranPath
= CRegString(REG_MSYSGIT_EXTRA_PATH
);
40 m_sMsysGitPath
= m_regMsysGitPath
;
41 m_sMsysGitExtranPath
= m_regMsysGitExtranPath
;
43 m_bEnableHacks
= (CGit::ms_bCygwinGit
|| CGit::ms_bMsys2Git
);
46 CFirstStartWizardGit::~CFirstStartWizardGit()
50 void CFirstStartWizardGit::DoDataExchange(CDataExchange
* pDX
)
52 CFirstStartWizardBasePage::DoDataExchange(pDX
);
53 DDX_Text(pDX
, IDC_MSYSGIT_PATH
, m_sMsysGitPath
);
54 DDX_Text(pDX
, IDC_MSYSGIT_EXTERN_PATH
, m_sMsysGitExtranPath
);
55 DDX_Control(pDX
, IDC_LINK
, m_link
);
56 DDX_Check(pDX
, IDC_WORKAROUNDS
, m_bEnableHacks
);
59 BEGIN_MESSAGE_MAP(CFirstStartWizardGit
, CFirstStartWizardBasePage
)
60 ON_BN_CLICKED(IDC_MSYSGIT_BROWSE
, OnBrowseDir
)
61 ON_BN_CLICKED(IDC_MSYSGIT_CHECK
, OnCheck
)
62 ON_BN_CLICKED(IDC_WORKAROUNDS
, OnClickedWorkarounds
)
65 LRESULT
CFirstStartWizardGit::OnWizardNext()
69 PerformCommonGitPathCleanup(m_sMsysGitPath
);
74 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
))
76 StoreSetting(GetSafeHwnd(), m_sMsysGitPath
, m_regMsysGitPath
);
77 StoreSetting(GetSafeHwnd(), m_sMsysGitExtranPath
, m_regMsysGitExtranPath
);
78 StoreSetting(GetSafeHwnd(), CGit::ms_bCygwinGit
, m_regCygwinHack
);
79 StoreSetting(GetSafeHwnd(), CGit::ms_bMsys2Git
, m_regMsys2Hack
);
80 SendCacheCommand(TGITCACHECOMMAND_END
);
83 // only complete if the msysgit directory is ok
84 bool needWorkarounds
= (GetDlgItem(IDC_WORKAROUNDS
)->IsWindowVisible() == TRUE
);
85 if (!CheckGitExe(GetSafeHwnd(), m_sMsysGitPath
, m_sMsysGitExtranPath
, IDC_MSYSGIT_VER
, [&](UINT helpid
) { HtmlHelp(0x20000 + helpid
); }, &needWorkarounds
))
88 ShowWorkarounds(true);
92 return __super::OnWizardNext();
95 void CFirstStartWizardGit::ShowWorkarounds(bool show
)
97 if (!(CGit::ms_bCygwinGit
|| CGit::ms_bMsys2Git
|| show
))
100 GetDlgItem(IDC_WORKAROUNDS
)->ShowWindow(SW_SHOW
);
102 GetDlgItem(IDC_GITHACKS1
)->ShowWindow(m_bEnableHacks
? SW_SHOW
: SW_HIDE
);
103 GetDlgItem(IDC_GITHACKS2
)->ShowWindow(m_bEnableHacks
? SW_SHOW
: SW_HIDE
);
105 if (CGit::ms_bCygwinGit
)
106 CheckRadioButton(IDC_GITHACKS1
, IDC_GITHACKS2
, IDC_GITHACKS1
);
107 else if (CGit::ms_bMsys2Git
)
108 CheckRadioButton(IDC_GITHACKS1
, IDC_GITHACKS2
, IDC_GITHACKS2
);
111 BOOL
CFirstStartWizardGit::OnInitDialog()
113 CFirstStartWizardBasePage::OnInitDialog();
115 SHAutoComplete(GetDlgItem(IDC_MSYSGIT_PATH
)->m_hWnd
, SHACF_FILESYSTEM
);
117 m_tooltips
.Create(this);
118 m_tooltips
.AddTool(IDC_MSYSGIT_EXTERN_PATH
, IDS_EXTRAPATH_TT
);
120 GetDlgItem(IDC_LINK
)->SetWindowText(GIT_FOR_WINDOWS_URL
);
121 m_link
.SetURL(GIT_FOR_WINDOWS_URL
);
123 AdjustControlSize(IDC_LINK
, false);
124 AdjustControlSize(IDC_WORKAROUNDS
);
125 AdjustControlSize(IDC_GITHACKS1
);
126 AdjustControlSize(IDC_GITHACKS2
);
128 CheckRadioButton(IDC_GITHACKS1
, IDC_GITHACKS2
, IDC_GITHACKS1
);
134 BOOL
CFirstStartWizardGit::OnSetActive()
136 CFirstStartWizard
* wiz
= (CFirstStartWizard
*)GetParent();
138 wiz
->SetWizardButtons(PSWIZB_NEXT
| PSWIZB_BACK
);
140 return CFirstStartWizardBasePage::OnSetActive();
143 void CFirstStartWizardGit::OnMsysGitPathModify()
146 if (GuessExtraPath(m_sMsysGitPath
, m_sMsysGitExtranPath
))
150 void CFirstStartWizardGit::OnBrowseDir()
154 if (!SelectFolder(GetSafeHwnd(), m_sMsysGitPath
, m_sMsysGitExtranPath
))
160 void CFirstStartWizardGit::SetGitHacks()
162 CGit::ms_bCygwinGit
= false;
163 CGit::ms_bMsys2Git
= false;
166 int id
= GetCheckedRadioButton(IDC_GITHACKS1
, IDC_GITHACKS2
);
167 CGit::ms_bCygwinGit
= (id
== IDC_GITHACKS1
);
168 CGit::ms_bMsys2Git
= (id
== IDC_GITHACKS2
);
172 void CFirstStartWizardGit::OnCheck()
175 bool oldCygwinGit
= CGit::ms_bCygwinGit
;
176 bool oldMsys2Git
= CGit::ms_bMsys2Git
;
179 CGit::ms_bCygwinGit
= oldCygwinGit
;
180 CGit::ms_bMsys2Git
= oldMsys2Git
;
185 bool needWorkarounds
= (GetDlgItem(IDC_WORKAROUNDS
)->IsWindowVisible() == TRUE
);
186 CheckGitExe(GetSafeHwnd(), m_sMsysGitPath
, m_sMsysGitExtranPath
, IDC_MSYSGIT_VER
, [&](UINT helpid
) { HtmlHelp(0x20000 + helpid
); }, &needWorkarounds
);
188 ShowWorkarounds(true);
191 BOOL
CFirstStartWizardGit::PreTranslateMessage(MSG
* pMsg
)
193 m_tooltips
.RelayEvent(pMsg
);
194 return __super::PreTranslateMessage(pMsg
);
197 void CFirstStartWizardGit::OnClickedWorkarounds()
200 ShowWorkarounds(true);