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 "FirstStartWizardStart.h"
23 #include "PathUtils.h"
24 #include "DirFileEnum.h"
25 #include "..\version.h"
26 #include "FirstStartWizardLanguage.h"
28 #define DOWNLOAD_URL L"https://tortoisegit.org/download/"
29 #define WM_SETPAGEFOCUS WM_APP+2
31 IMPLEMENT_DYNAMIC(CFirstStartWizardLanguage
, CFirstStartWizardBasePage
)
33 CFirstStartWizardLanguage::CFirstStartWizardLanguage() : CFirstStartWizardBasePage(CFirstStartWizardLanguage::IDD
)
35 , m_regLanguage(L
"Software\\TortoiseGit\\LanguageID", 1033)
37 m_psp
.dwFlags
|= PSP_DEFAULT
| PSP_USEHEADERTITLE
;
38 m_psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_FIRSTSTART_STARTTITLE
);
41 CFirstStartWizardLanguage::~CFirstStartWizardLanguage()
45 void CFirstStartWizardLanguage::DoDataExchange(CDataExchange
* pDX
)
47 CFirstStartWizardBasePage::DoDataExchange(pDX
);
48 DDX_Control(pDX
, IDC_LANGUAGECOMBO
, m_LanguageCombo
);
49 DDX_Control(pDX
, IDC_LINK
, m_link
);
50 if (m_LanguageCombo
.GetCurSel() >= 0)
51 m_dwLanguage
= (DWORD
)m_LanguageCombo
.GetItemData(m_LanguageCombo
.GetCurSel());
54 BEGIN_MESSAGE_MAP(CFirstStartWizardLanguage
, CFirstStartWizardBasePage
)
55 ON_MESSAGE(WM_SETPAGEFOCUS
, OnDialogDisplayed
)
56 ON_NOTIFY(NM_CLICK
, IDC_FIRSTSTART_HINT
, OnClickedLink
)
57 ON_BN_CLICKED(IDC_REFRESH
, &CFirstStartWizardLanguage::OnBnClickedRefresh
)
60 static void AppendStringResource(CString
& text
, UINT resouceID
)
63 temp
.LoadString(resouceID
);
64 text
.AppendChar(L
'\n');
65 text
.AppendChar(L
'\n');
69 BOOL
CFirstStartWizardLanguage::OnInitDialog()
71 CFirstStartWizardBasePage::OnInitDialog();
74 hinttext
.LoadString(IDS_FIRSTSTART_LANGUAGEHINT1
);
75 AppendStringResource(hinttext
, IDS_FIRSTSTART_LANGUAGEHINT2
);
76 AppendStringResource(hinttext
, IDS_FIRSTSTART_LANGUAGEHINT3
);
77 GetDlgItem(IDC_FIRSTSTART_HINT
)->SetWindowText(hinttext
);
79 GetDlgItem(IDC_LINK
)->SetWindowText(DOWNLOAD_URL
);
80 m_link
.SetURL(DOWNLOAD_URL
);
81 AdjustControlSize(IDC_LINK
, false);
88 BOOL
CFirstStartWizardLanguage::OnSetActive()
90 CFirstStartWizard
* wiz
= (CFirstStartWizard
*)GetParent();
92 wiz
->SetWizardButtons(PSWIZB_NEXT
);
94 PostMessage(WM_SETPAGEFOCUS
, 0, 0);
96 return CFirstStartWizardBasePage::OnSetActive();
99 LRESULT
CFirstStartWizardLanguage::OnDialogDisplayed(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
101 GetDlgItem(IDC_LANGUAGECOMBO
)->SetFocus();
106 LRESULT
CFirstStartWizardLanguage::OnWizardNext()
110 if (m_dwLanguage
!= m_regLanguage
)
112 m_regLanguage
= m_dwLanguage
;
114 CAppUtils::RunTortoiseGitProc(L
"/command:firststart /page:1", false, false);
121 return __super::OnWizardNext();
125 void CFirstStartWizardLanguage::OnClickedLink(NMHDR
* pNMHDR
, LRESULT
* pResult
)
127 ATLASSERT(pNMHDR
&& pResult
);
128 auto pNMLink
= reinterpret_cast<PNMLINK
>(pNMHDR
);
129 if (wcscmp(pNMLink
->item
.szID
, L
"download") == 0)
130 ShellExecute(GetSafeHwnd(), L
"open", DOWNLOAD_URL
, nullptr, nullptr, SW_SHOWNORMAL
);
135 void CFirstStartWizardLanguage::OnBnClickedRefresh()
138 m_LanguageCombo
.ResetContent();
140 // set up the language selecting combobox
141 TCHAR buf
[MAX_PATH
] = { 0 };
142 GetLocaleInfo(1033, LOCALE_SNATIVELANGNAME
, buf
, _countof(buf
));
143 m_LanguageCombo
.AddString(buf
);
144 m_LanguageCombo
.SetItemData(0, 1033);
145 CString path
= CPathUtils::GetAppParentDirectory();
146 path
= path
+ L
"Languages\\";
147 CSimpleFileFind
finder(path
, L
"*.dll");
149 while (finder
.FindNextFileNoDirectories())
151 CString file
= finder
.GetFilePath();
152 CString filename
= finder
.GetFileName();
153 if (CStringUtils::StartsWithI(filename
, L
"TortoiseProc"))
155 CString sVer
= _T(STRPRODUCTVER
);
156 sVer
= sVer
.Left(sVer
.ReverseFind('.'));
157 CString sFileVer
= CPathUtils::GetVersionFromFile(file
);
158 sFileVer
= sFileVer
.Left(sFileVer
.ReverseFind('.'));
159 if (sFileVer
.Compare(sVer
) != 0)
161 CString sLoc
= filename
.Mid(12);
162 sLoc
= sLoc
.Left(sLoc
.GetLength() - 4); // cut off ".dll"
163 if (CStringUtils::StartsWith(sLoc
, L
"32") && (sLoc
.GetLength() > 5))
165 DWORD loc
= _wtoi(filename
.Mid(12));
166 GetLocaleInfo(loc
, LOCALE_SNATIVELANGNAME
, buf
, _countof(buf
));
168 GetLocaleInfo(loc
, LOCALE_SNATIVECTRYNAME
, buf
, _countof(buf
));
175 m_LanguageCombo
.AddString(sLang
);
176 m_LanguageCombo
.SetItemData(++langcount
, loc
);
180 m_regLanguage
.read();
181 m_dwLanguage
= m_regLanguage
;
182 for (int i
= 0; i
< m_LanguageCombo
.GetCount(); ++i
)
184 if (m_LanguageCombo
.GetItemData(i
) == m_dwLanguage
)
185 m_LanguageCombo
.SetCurSel(i
);