1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016-2020 - 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"
29 IMPLEMENT_DYNAMIC(CFirstStartWizardGit
, CFirstStartWizardBasePage
)
31 #define CHECK_NEWGIT_TIMER 100
33 CFirstStartWizardGit::CFirstStartWizardGit() : CFirstStartWizardBasePage(CFirstStartWizardGit::IDD
)
34 , m_dwMsysGitVersion(CRegDWORD(L
"Software\\TortoiseGit\\git_cached_version", 0))
36 m_psp
.dwFlags
|= PSP_DEFAULT
| PSP_USEHEADERTITLE
;
37 m_psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_FIRSTSTART_GITTITLE
);
39 g_Git
.CheckMsysGitDir(TRUE
);
40 m_regMsysGitPath
= CRegString(REG_MSYSGIT_PATH
);
42 m_regMsysGitExtranPath
= CRegString(REG_MSYSGIT_EXTRA_PATH
);
44 m_sMsysGitPath
= m_regMsysGitPath
;
45 m_sMsysGitExtranPath
= m_regMsysGitExtranPath
;
47 m_bEnableHacks
= (CGit::ms_bCygwinGit
|| CGit::ms_bMsys2Git
);
50 CFirstStartWizardGit::~CFirstStartWizardGit()
54 void CFirstStartWizardGit::DoDataExchange(CDataExchange
* pDX
)
56 CFirstStartWizardBasePage::DoDataExchange(pDX
);
57 DDX_Text(pDX
, IDC_MSYSGIT_PATH
, m_sMsysGitPath
);
58 DDX_Text(pDX
, IDC_MSYSGIT_EXTERN_PATH
, m_sMsysGitExtranPath
);
59 DDX_Control(pDX
, IDC_LINK
, m_link
);
60 DDX_Check(pDX
, IDC_WORKAROUNDS
, m_bEnableHacks
);
63 BEGIN_MESSAGE_MAP(CFirstStartWizardGit
, CFirstStartWizardBasePage
)
64 ON_BN_CLICKED(IDC_MSYSGIT_BROWSE
, OnBrowseDir
)
65 ON_BN_CLICKED(IDC_MSYSGIT_CHECK
, OnCheck
)
66 ON_BN_CLICKED(IDC_WORKAROUNDS
, OnClickedWorkarounds
)
70 LRESULT
CFirstStartWizardGit::OnWizardNext()
74 PerformCommonGitPathCleanup(m_sMsysGitPath
);
79 bool needsRestart
= false;
80 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
))
82 StoreSetting(GetSafeHwnd(), m_sMsysGitPath
, m_regMsysGitPath
);
83 StoreSetting(GetSafeHwnd(), m_sMsysGitExtranPath
, m_regMsysGitExtranPath
);
84 StoreSetting(GetSafeHwnd(), CGit::ms_bCygwinGit
, m_regCygwinHack
);
85 StoreSetting(GetSafeHwnd(), CGit::ms_bMsys2Git
, m_regMsys2Hack
);
89 // only complete if the msysgit directory is ok
90 bool needWorkarounds
= (GetDlgItem(IDC_WORKAROUNDS
)->IsWindowVisible() == TRUE
);
91 if (!CheckGitExe(GetSafeHwnd(), m_sMsysGitPath
, m_sMsysGitExtranPath
, IDC_MSYSGIT_VER
, [&](UINT helpid
) { HtmlHelp(0x20000 + helpid
); }, &needWorkarounds
))
94 ShowWorkarounds(true);
98 if (needsRestart
|| g_Git
.ms_LastMsysGitVersion
!= static_cast<int>(m_dwMsysGitVersion
))
100 if (HWND hWnd
= ::FindWindow(TGIT_CACHE_WINDOW_NAME
, TGIT_CACHE_WINDOW_NAME
); hWnd
)
101 ::PostMessage(hWnd
, WM_CLOSE
, reinterpret_cast<WPARAM
>(nullptr), reinterpret_cast<LPARAM
>(nullptr));
103 CAppUtils::RunTortoiseGitProc(L
"/command:firststart /page:3", false, false);
110 return __super::OnWizardNext();
113 void CFirstStartWizardGit::ShowWorkarounds(bool show
)
115 if (!(CGit::ms_bCygwinGit
|| CGit::ms_bMsys2Git
|| show
))
118 GetDlgItem(IDC_WORKAROUNDS
)->EnableWindow(TRUE
);
119 GetDlgItem(IDC_WORKAROUNDS
)->ShowWindow(SW_SHOW
);
121 GetDlgItem(IDC_GITHACKS1
)->EnableWindow(m_bEnableHacks
);
122 GetDlgItem(IDC_GITHACKS1
)->ShowWindow(m_bEnableHacks
? SW_SHOW
: SW_HIDE
);
123 GetDlgItem(IDC_GITHACKS2
)->EnableWindow(m_bEnableHacks
);
124 GetDlgItem(IDC_GITHACKS2
)->ShowWindow(m_bEnableHacks
? SW_SHOW
: SW_HIDE
);
126 if (CGit::ms_bCygwinGit
)
127 CheckRadioButton(IDC_GITHACKS1
, IDC_GITHACKS2
, IDC_GITHACKS1
);
128 else if (CGit::ms_bMsys2Git
)
129 CheckRadioButton(IDC_GITHACKS1
, IDC_GITHACKS2
, IDC_GITHACKS2
);
132 BOOL
CFirstStartWizardGit::OnInitDialog()
134 CFirstStartWizardBasePage::OnInitDialog();
136 SHAutoComplete(GetDlgItem(IDC_MSYSGIT_PATH
)->m_hWnd
, SHACF_FILESYSTEM
);
138 m_tooltips
.Create(this);
139 m_tooltips
.AddTool(IDC_MSYSGIT_EXTERN_PATH
, IDS_EXTRAPATH_TT
);
141 GetDlgItem(IDC_LINK
)->SetWindowText(GIT_FOR_WINDOWS_URL
);
142 m_link
.SetURL(GIT_FOR_WINDOWS_URL
);
144 CTheme::Instance().SetThemeForDialog(GetSafeHwnd(), CTheme::Instance().IsDarkTheme());
146 AdjustControlSize(IDC_LINK
, false);
147 AdjustControlSize(IDC_WORKAROUNDS
);
148 AdjustControlSize(IDC_GITHACKS1
);
149 AdjustControlSize(IDC_GITHACKS2
);
151 CheckRadioButton(IDC_GITHACKS1
, IDC_GITHACKS2
, IDC_GITHACKS1
);
154 if (m_sMsysGitPath
.IsEmpty())
155 SetTimer(CHECK_NEWGIT_TIMER
, 1000, nullptr);
160 void CFirstStartWizardGit::OnTimer(UINT_PTR nIDEvent
)
162 if (nIDEvent
== CHECK_NEWGIT_TIMER
)
164 KillTimer(CHECK_NEWGIT_TIMER
);
166 if (m_sMsysGitPath
.IsEmpty())
168 if (FindGitForWindows(m_sMsysGitPath
))
173 SetTimer(CHECK_NEWGIT_TIMER
, 1000, nullptr);
177 __super::OnTimer(nIDEvent
);
180 BOOL
CFirstStartWizardGit::OnSetActive()
182 auto wiz
= static_cast<CFirstStartWizard
*>(GetParent());
184 wiz
->SetWizardButtons(PSWIZB_NEXT
| PSWIZB_BACK
);
186 return CFirstStartWizardBasePage::OnSetActive();
189 void CFirstStartWizardGit::OnMsysGitPathModify()
192 if (GuessExtraPath(m_sMsysGitPath
, m_sMsysGitExtranPath
))
196 void CFirstStartWizardGit::OnBrowseDir()
200 if (!SelectFolder(GetSafeHwnd(), m_sMsysGitPath
, m_sMsysGitExtranPath
))
206 void CFirstStartWizardGit::SetGitHacks()
208 CGit::ms_bCygwinGit
= false;
209 CGit::ms_bMsys2Git
= false;
212 int id
= GetCheckedRadioButton(IDC_GITHACKS1
, IDC_GITHACKS2
);
213 CGit::ms_bCygwinGit
= (id
== IDC_GITHACKS1
);
214 CGit::ms_bMsys2Git
= (id
== IDC_GITHACKS2
);
218 void CFirstStartWizardGit::OnCheck()
221 bool oldCygwinGit
= CGit::ms_bCygwinGit
;
222 bool oldMsys2Git
= CGit::ms_bMsys2Git
;
225 CGit::ms_bCygwinGit
= oldCygwinGit
;
226 CGit::ms_bMsys2Git
= oldMsys2Git
;
231 bool needWorkarounds
= (GetDlgItem(IDC_WORKAROUNDS
)->IsWindowVisible() == TRUE
);
232 CheckGitExe(GetSafeHwnd(), m_sMsysGitPath
, m_sMsysGitExtranPath
, IDC_MSYSGIT_VER
, [&](UINT helpid
) { HtmlHelp(0x20000 + helpid
); }, &needWorkarounds
);
234 ShowWorkarounds(true);
237 BOOL
CFirstStartWizardGit::PreTranslateMessage(MSG
* pMsg
)
239 m_tooltips
.RelayEvent(pMsg
);
240 return __super::PreTranslateMessage(pMsg
);
243 void CFirstStartWizardGit::OnClickedWorkarounds()
246 ShowWorkarounds(true);