1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2020 - 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.
21 #include "TortoiseProc.h"
22 #include "SetMainPage.h"
24 #include "PathUtils.h"
25 #include "DirFileEnum.h"
26 #include "../version.h"
27 #include "I18NHelper.h"
29 #include "MessageBox.h"
30 #include "GitForWindows.h"
31 #include "Libraries.h"
32 #include "../../TGitCache/CacheInterface.h"
34 IMPLEMENT_DYNAMIC(CSetMainPage
, ISettingsPropPage
)
35 CSetMainPage::CSetMainPage()
36 : ISettingsPropPage(CSetMainPage::IDD
)
39 , m_dwMsysGitVersion(CRegDWORD(L
"Software\\TortoiseGit\\git_cached_version", 0))
41 m_regLanguage
= CRegDWORD(L
"Software\\TortoiseGit\\LanguageID", 1033);
43 m_regMsysGitPath
= CRegString(REG_MSYSGIT_PATH
);
44 m_regMsysGitExtranPath
=CRegString(REG_MSYSGIT_EXTRA_PATH
);
46 m_sMsysGitPath
= m_regMsysGitPath
;
47 m_sMsysGitExtranPath
= m_regMsysGitExtranPath
;
49 m_regCheckNewer
= CRegDWORD(L
"Software\\TortoiseGit\\VersionCheck", TRUE
);
52 CSetMainPage::~CSetMainPage()
56 void CSetMainPage::DoDataExchange(CDataExchange
* pDX
)
58 ISettingsPropPage::DoDataExchange(pDX
);
59 DDX_Control(pDX
, IDC_LANGUAGECOMBO
, m_LanguageCombo
);
60 m_dwLanguage
= static_cast<DWORD
>(m_LanguageCombo
.GetItemData(m_LanguageCombo
.GetCurSel()));
61 DDX_Text(pDX
, IDC_MSYSGIT_PATH
, m_sMsysGitPath
);
62 DDX_Text(pDX
, IDC_MSYSGIT_EXTERN_PATH
, m_sMsysGitExtranPath
);
63 DDX_Check(pDX
, IDC_CHECKNEWERVERSION
, m_bCheckNewer
);
67 BEGIN_MESSAGE_MAP(CSetMainPage
, ISettingsPropPage
)
68 ON_CBN_SELCHANGE(IDC_LANGUAGECOMBO
, OnModified
)
69 // ON_EN_CHANGE(IDC_TEMPEXTENSIONS, OnModified)
70 ON_BN_CLICKED(IDC_CHECKNEWERVERSION
, OnClickVersioncheck
)
71 ON_BN_CLICKED(IDC_CHECKNEWERBUTTON
, OnBnClickedChecknewerbutton
)
72 ON_BN_CLICKED(IDC_MSYSGIT_BROWSE
,OnBrowseDir
)
73 ON_BN_CLICKED(IDC_MSYSGIT_CHECK
,OnCheck
)
74 ON_EN_CHANGE(IDC_MSYSGIT_PATH
, OnMsysGitPathModify
)
75 ON_EN_CHANGE(IDC_MSYSGIT_EXTERN_PATH
, OnModified
)
76 ON_BN_CLICKED(IDC_BUTTON_SHOW_ENV
, &CSetMainPage::OnBnClickedButtonShowEnv
)
77 ON_BN_CLICKED(IDC_CREATELIB
, &CSetMainPage::OnBnClickedCreatelib
)
78 ON_BN_CLICKED(IDC_RUNFIRSTSTARTWIZARD
, &CSetMainPage::OnBnClickedRunfirststartwizard
)
81 BOOL
CSetMainPage::OnInitDialog()
83 ISettingsPropPage::OnInitDialog();
86 AdjustControlSize(IDC_CHECKNEWERVERSION
);
88 m_dwLanguage
= m_regLanguage
;
89 m_bCheckNewer
= m_regCheckNewer
;
91 m_tooltips
.AddTool(IDC_MSYSGIT_PATH
,IDS_MSYSGIT_PATH_TT
);
92 m_tooltips
.AddTool(IDC_MSYSGIT_EXTERN_PATH
, IDS_EXTRAPATH_TT
);
93 m_tooltips
.AddTool(IDC_CHECKNEWERVERSION
, IDS_SETTINGS_CHECKNEWER_TT
);
94 m_tooltips
.AddTool(IDC_CREATELIB
, IDS_SETTINGS_CREATELIB_TT
);
96 SHAutoComplete(GetDlgItem(IDC_MSYSGIT_PATH
)->m_hWnd
, SHACF_FILESYSTEM
);
98 // set up the language selecting combobox
99 TCHAR buf
[MAX_PATH
] = {0};
100 GetLocaleInfo(1033, LOCALE_SNATIVELANGNAME
, buf
, _countof(buf
));
101 m_LanguageCombo
.AddString(buf
);
102 m_LanguageCombo
.SetItemData(0, 1033);
103 CString path
= CPathUtils::GetAppParentDirectory();
104 path
= path
+ L
"Languages\\";
105 CSimpleFileFind
finder(path
, L
"*.dll");
107 while (finder
.FindNextFileNoDirectories())
109 CString file
= finder
.GetFilePath();
110 CString filename
= finder
.GetFileName();
111 if (CStringUtils::StartsWithI(filename
, L
"TortoiseProc"))
113 if (!CI18NHelper::DoVersionStringsMatch(CPathUtils::GetVersionFromFile(file
), _T(STRPRODUCTVER
)))
115 CString sLoc
= filename
.Mid(static_cast<int>(wcslen(L
"TortoiseProc")));
116 sLoc
= sLoc
.Left(sLoc
.GetLength() - static_cast<int>(wcslen(L
".dll"))); // cut off ".dll"
117 if (CStringUtils::StartsWith(sLoc
, L
"32") && (sLoc
.GetLength() > 5))
119 DWORD loc
= _wtoi(filename
.Mid(static_cast<int>(wcslen(L
"TortoiseProc"))));
123 GetLocaleInfo(loc
, LOCALE_SNATIVELANGNAME
, buf
, _countof(buf
));
126 GetLocaleInfo(loc
, LOCALE_SNATIVECTRYNAME
, buf
, _countof(buf
));
133 m_LanguageCombo
.AddString(sLang
);
134 m_LanguageCombo
.SetItemData(langcount
++, loc
);
138 for (int i
=0; i
<m_LanguageCombo
.GetCount(); i
++)
140 if (m_LanguageCombo
.GetItemData(i
) == m_dwLanguage
)
141 m_LanguageCombo
.SetCurSel(i
);
148 void CSetMainPage::OnClickVersioncheck()
150 if (m_bCheckNewer
&& CMessageBox::Show(GetSafeHwnd(), IDS_DISABLEUPDATECHECKS
, IDS_APPNAME
, 2, IDI_QUESTION
, IDS_DISABLEUPDATECHECKSBUTTON
, IDS_ABORTBUTTON
) != 1)
152 m_bCheckNewer
= !m_bCheckNewer
;
157 void CSetMainPage::OnModified()
162 void CSetMainPage::OnMsysGitPathModify()
165 if (GuessExtraPath(m_sMsysGitPath
, m_sMsysGitExtranPath
))
170 BOOL
CSetMainPage::OnApply()
174 PerformCommonGitPathCleanup(m_sMsysGitPath
);
177 Store(m_dwLanguage
, m_regLanguage
);
178 bool gitChanged
= false;
179 if (m_sMsysGitPath
.Compare(CString(m_regMsysGitPath
)) ||
180 this->m_sMsysGitExtranPath
.Compare(CString(m_regMsysGitExtranPath
)))
182 Store(m_sMsysGitPath
, m_regMsysGitPath
);
183 Store(m_sMsysGitExtranPath
, m_regMsysGitExtranPath
);
186 Store(m_bCheckNewer
, m_regCheckNewer
);
188 // only complete if the msysgit directory is ok
189 if (!CheckGitExe(GetSafeHwnd(), m_sMsysGitPath
, m_sMsysGitExtranPath
, IDC_MSYSGIT_VER
, [&](UINT helpid
) { HtmlHelp(0x20000 + helpid
); }))
192 if (gitChanged
|| g_Git
.ms_LastMsysGitVersion
!= static_cast<int>(m_dwMsysGitVersion
))
194 if (HWND hWnd
= ::FindWindow(TGIT_CACHE_WINDOW_NAME
, TGIT_CACHE_WINDOW_NAME
); hWnd
)
195 ::PostMessage(hWnd
, WM_CLOSE
, reinterpret_cast<WPARAM
>(nullptr), reinterpret_cast<LPARAM
>(nullptr));
196 CMessageBox::Show(GetSafeHwnd(), IDS_GITCHANGED_NEEDRESTART
, IDS_APPNAME
, MB_ICONINFORMATION
);
200 return ISettingsPropPage::OnApply();
203 void CSetMainPage::OnBnClickedChecknewerbutton()
205 CAppUtils::RunTortoiseGitProc(L
"/command:updatecheck /visible", false, false);
208 void CSetMainPage::OnBrowseDir()
212 if (!SelectFolder(GetSafeHwnd(), m_sMsysGitPath
, m_sMsysGitExtranPath
))
219 void CSetMainPage::OnCheck()
223 CheckGitExe(GetSafeHwnd(), m_sMsysGitPath
, m_sMsysGitExtranPath
, IDC_MSYSGIT_VER
, [&](UINT helpid
) { HtmlHelp(0x20000 + helpid
); });
228 void CSetMainPage::OnBnClickedButtonShowEnv()
231 CString tempfile
=::GetTempFile();
233 CString cmd
= L
"cmd /c set";
234 if (g_Git
.RunLogFile(cmd
, tempfile
, &err
))
236 CMessageBox::Show(GetSafeHwnd(), L
"Could not get environment variables:\n" + err
, L
"TortoiseGit", MB_OK
);
239 ::SetFileAttributes(tempfile
, FILE_ATTRIBUTE_READONLY
);
240 CAppUtils::LaunchAlternativeEditor(tempfile
);
243 void CSetMainPage::OnBnClickedCreatelib()
245 CoInitialize(nullptr);
250 void CSetMainPage::OnBnClickedRunfirststartwizard()
252 CAppUtils::RunTortoiseGitProc(L
"/command:firststart", false, false);