1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016-2017, 2019-2021 - 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 "FirstStartWizardUser.h"
26 IMPLEMENT_DYNAMIC(CFirstStartWizardUser
, CFirstStartWizardBasePage
)
28 CFirstStartWizardUser::CFirstStartWizardUser() : CFirstStartWizardBasePage(CFirstStartWizardUser::IDD
)
31 m_psp
.dwFlags
|= PSP_DEFAULT
| PSP_USEHEADERTITLE
;
32 m_psp
.dwFlags
&= ~PSP_HASHELP
;
33 m_psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_FIRSTSTART_USERTITLE
);
36 CFirstStartWizardUser::~CFirstStartWizardUser()
40 void CFirstStartWizardUser::DoDataExchange(CDataExchange
* pDX
)
42 CFirstStartWizardBasePage::DoDataExchange(pDX
);
43 DDX_Check(pDX
, IDC_DONTSAVE
, m_bNoSave
);
44 DDX_Text(pDX
, IDC_GIT_USERNAME
, m_sUsername
);
45 DDX_Text(pDX
, IDC_GIT_USEREMAIL
, m_sUseremail
);
48 BEGIN_MESSAGE_MAP(CFirstStartWizardUser
, CFirstStartWizardBasePage
)
49 ON_BN_CLICKED(IDC_DONTSAVE
, OnClickedNoSave
)
52 void CFirstStartWizardUser::OnClickedNoSave()
55 GetDlgItem(IDC_GIT_USERNAME
)->EnableWindow(!m_bNoSave
);
56 GetDlgItem(IDC_GIT_USEREMAIL
)->EnableWindow(!m_bNoSave
);
59 LRESULT
CFirstStartWizardUser::OnWizardNext()
65 if (m_sUsername
.Trim().IsEmpty() || m_sUseremail
.Trim().IsEmpty())
67 MessageBox(L
"Username and email must not be empty.", L
"TortoiseGit", MB_ICONERROR
);
71 CAutoConfig
config(true);
72 int err
= git_config_add_file_ondisk(config
, CGit::GetGitPathStringA(g_Git
.GetGitGlobalXDGConfig()), GIT_CONFIG_LEVEL_XDG
, nullptr, FALSE
);
73 if (!err
&& (PathFileExists(g_Git
.GetGitGlobalConfig()) || !PathFileExists(g_Git
.GetGitGlobalXDGConfig())))
74 err
= git_config_add_file_ondisk(config
, CGit::GetGitPathStringA(g_Git
.GetGitGlobalConfig()), GIT_CONFIG_LEVEL_GLOBAL
, nullptr, FALSE
);
77 MessageBox(g_Git
.GetLibGit2LastErr(), L
"TortoiseGit", MB_ICONEXCLAMATION
);
80 if (git_config_set_string(config
, "user.name", CUnicodeUtils::GetUTF8(m_sUsername
)))
82 MessageBox(g_Git
.GetLibGit2LastErr(), L
"TortoiseGit", MB_ICONEXCLAMATION
);
85 if (git_config_set_string(config
, "user.email", CUnicodeUtils::GetUTF8(m_sUseremail
)))
87 MessageBox(g_Git
.GetLibGit2LastErr(), L
"TortoiseGit", MB_ICONEXCLAMATION
);
92 return __super::OnWizardNext();
95 BOOL
CFirstStartWizardUser::OnInitDialog()
97 CFirstStartWizardBasePage::OnInitDialog();
99 AdjustControlSize(IDC_DONTSAVE
);
101 CAutoConfig
config(true);
102 if (git_config_add_file_ondisk(config
, CGit::GetGitPathStringA(g_Git
.GetGitGlobalConfig()), GIT_CONFIG_LEVEL_GLOBAL
, nullptr, FALSE
))
103 MessageBox(g_Git
.GetLibGit2LastErr(), L
"TortoiseGit", MB_ICONEXCLAMATION
);
106 if (git_config_add_file_ondisk(config
, CGit::GetGitPathStringA(g_Git
.GetGitGlobalXDGConfig()), GIT_CONFIG_LEVEL_XDG
, nullptr, FALSE
))
107 MessageBox(g_Git
.GetLibGit2LastErr(), L
"TortoiseGit", MB_ICONEXCLAMATION
);
109 if (git_config_add_file_ondisk(config
, CGit::GetGitPathStringA(g_Git
.GetGitSystemConfig()), GIT_CONFIG_LEVEL_SYSTEM
, nullptr, FALSE
))
110 MessageBox(g_Git
.GetLibGit2LastErr(), L
"TortoiseGit", MB_ICONEXCLAMATION
);
112 config
.GetString(L
"user.name", m_sUsername
);
113 config
.GetString(L
"user.email", m_sUseremail
);
117 CTheme::Instance().SetThemeForDialog(GetSafeHwnd(), CTheme::Instance().IsDarkTheme());
122 BOOL
CFirstStartWizardUser::OnSetActive()
124 auto wiz
= static_cast<CFirstStartWizard
*>(GetParent());
126 wiz
->SetWizardButtons(PSWIZB_NEXT
| PSWIZB_BACK
);
128 return CFirstStartWizardBasePage::OnSetActive();