project64/Source/Project64/UserInterface/SupportEnterCode.cpp

262 lines
9.2 KiB
C++
Raw Normal View History

2016-08-11 10:38:45 +00:00
#include "stdafx.h"
2022-09-21 05:16:07 +00:00
2016-08-11 10:38:45 +00:00
#include "SupportEnterCode.h"
#include "resource.h"
2022-09-21 05:16:07 +00:00
#include <Project64-core/Settings/SettingType/SettingsType-Application.h>
2016-08-11 10:38:45 +00:00
2020-10-22 02:11:19 +00:00
class CRequestCode :
public CDialogImpl<CRequestCode>
{
public:
BEGIN_MSG_MAP_EX(CRequestCode)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground)
COMMAND_ID_HANDLER(IDOK, OnOkCmd)
COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd)
END_MSG_MAP()
enum { IDD = IDD_Support_RequestCode };
CRequestCode(CProjectSupport & Support);
2020-12-30 00:47:25 +00:00
void ShowOldCodeMsg();
2020-10-22 02:11:19 +00:00
private:
CRequestCode(void);
CRequestCode(const CRequestCode&);
CRequestCode& operator=(const CRequestCode&);
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled);
LRESULT OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
CProjectSupport & m_Support;
2020-12-30 00:47:25 +00:00
bool m_ShowOldCodeMsg;
2020-10-22 02:11:19 +00:00
};
CSupportEnterCode::CSupportEnterCode(CProjectSupport & Support) :
m_Support(Support)
{
}
2016-08-11 10:38:45 +00:00
LRESULT CSupportEnterCode::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
2020-10-22 02:11:19 +00:00
SetWindowText(wGS(MSG_SUPPORT_ENTER_CODE_TITLE).c_str());
CWindow hDescription = GetDlgItem(IDC_DESCRIPTION);
CWindow MachineId = GetDlgItem(IDC_MACHINE_ID);
CWindow OkBtn = GetDlgItem(IDOK);
CWindow CancelBtn = GetDlgItem(IDCANCEL);
std::wstring DescriptionText = wGS(MSG_SUPPORT_ENTER_CODE_DESC);
hDescription.SetWindowText(DescriptionText.c_str());
MachineId.SetWindowText(stdstr(m_Support.MachineID()).ToUTF16().c_str());
OkBtn.SetWindowText(wGS(MSG_SUPPORT_OK).c_str());
CancelBtn.SetWindowText(wGS(MSG_SUPPORT_CANCEL).c_str());
m_RequestLink.SubclassWindow(GetDlgItem(IDC_REQUEST_LINK));
m_RequestLink.SetHyperLinkExtendedStyle(HLINK_COMMANDBUTTON, HLINK_COMMANDBUTTON);
CRect rcWin = { 0 };
hDescription.GetClientRect(&rcWin);
CDC hDC = hDescription.GetDC();
HFONT hFont = hDescription.GetFont();
if (hFont == nullptr)
{
hFont = (HFONT)::GetStockObject(SYSTEM_FONT);
}
hDC.SelectFont(hFont);
if (hDC.DrawText(DescriptionText.c_str(), DescriptionText.length(), &rcWin, DT_LEFT | DT_CALCRECT | DT_WORDBREAK | DT_NOCLIP) > 0)
{
2021-04-12 11:35:39 +00:00
hDescription.SetWindowPos(nullptr, 0, 0, rcWin.right, rcWin.bottom, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER);
2020-10-22 02:11:19 +00:00
}
hDescription.GetWindowRect(&rcWin);
2021-04-12 11:35:39 +00:00
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&rcWin, 2);
2020-10-22 02:11:19 +00:00
2021-04-12 11:35:39 +00:00
MachineId.SetWindowPos(nullptr, rcWin.left, rcWin.bottom + 4, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
2020-10-22 02:11:19 +00:00
MachineId.GetWindowRect(&rcWin);
2021-04-12 11:35:39 +00:00
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&rcWin, 2);
2020-10-22 02:11:19 +00:00
CWindow Code = GetDlgItem(IDC_CODE);
2021-04-12 11:35:39 +00:00
Code.SetWindowPos(nullptr, rcWin.left, rcWin.bottom + 4, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
2020-10-22 02:11:19 +00:00
Code.GetWindowRect(&rcWin);
2021-04-12 11:35:39 +00:00
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&rcWin, 2);
2020-10-22 02:11:19 +00:00
CWindow RequestDescption = GetDlgItem(IDC_REQUEST_DESCPTION);
RequestDescption.ShowWindow(SWP_HIDEWINDOW);
2021-04-12 11:35:39 +00:00
RequestDescption.SetWindowPos(nullptr, rcWin.left, rcWin.bottom + 10, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
2020-10-22 02:11:19 +00:00
RequestDescption.GetWindowRect(&rcWin);
2021-04-12 11:35:39 +00:00
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&rcWin, 2);
2020-10-22 02:11:19 +00:00
CWindow RequestLink = GetDlgItem(IDC_REQUEST_LINK);
RequestLink.ShowWindow(SWP_HIDEWINDOW);
2021-04-12 11:35:39 +00:00
RequestLink.SetWindowPos(nullptr, rcWin.left, rcWin.bottom + 4, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
2020-10-22 02:11:19 +00:00
RequestLink.GetWindowRect(&rcWin);
2021-04-12 11:35:39 +00:00
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&rcWin, 2);
2020-10-22 02:11:19 +00:00
RECT CancelBtnWin = { 0 };
CancelBtn.GetWindowRect(&CancelBtnWin);
2021-04-12 11:35:39 +00:00
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&CancelBtnWin, 2);
CancelBtn.SetWindowPos(nullptr, CancelBtnWin.left, rcWin.bottom + 40, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
2020-10-22 02:11:19 +00:00
RECT OkBtnWin = { 0 };
OkBtn.GetWindowRect(&OkBtnWin);
2021-04-12 11:35:39 +00:00
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&OkBtnWin, 2);
OkBtn.SetWindowPos(nullptr, OkBtnWin.left, rcWin.bottom + 40, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
2020-10-22 02:11:19 +00:00
OkBtn.GetWindowRect(&OkBtnWin);
2021-04-12 11:35:39 +00:00
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&OkBtnWin, 2);
2020-10-22 02:11:19 +00:00
GetWindowRect(&rcWin);
SetRect(&rcWin, 0, 0, rcWin.Width(), OkBtnWin.bottom + 30);
2021-04-12 11:35:39 +00:00
AdjustWindowRectEx(&rcWin, GetStyle(), GetMenu() != nullptr, GetExStyle());
2020-10-22 02:11:19 +00:00
int32_t Left = (GetSystemMetrics(SM_CXSCREEN) - rcWin.Width()) / 2;
int32_t Top = (GetSystemMetrics(SM_CYSCREEN) - rcWin.Height()) / 2;
MoveWindow(Left, Top, rcWin.Width(), rcWin.Height(), TRUE);
2016-08-11 10:38:45 +00:00
return TRUE;
}
LRESULT CSupportEnterCode::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
2020-10-22 02:11:19 +00:00
CDCHandle hdcStatic = (HDC)wParam;
hdcStatic.SetTextColor(RGB(0, 0, 0));
hdcStatic.SetBkMode(TRANSPARENT);
2016-08-11 10:38:45 +00:00
return (LONG)(LRESULT)((HBRUSH)GetStockObject(NULL_BRUSH));
}
LRESULT CSupportEnterCode::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
2020-10-22 02:11:19 +00:00
static HPEN Outline = CreatePen(PS_SOLID, 1, 0x00FFFFFF);
static HBRUSH Fill = CreateSolidBrush(0x00FFFFFF);
CDCHandle hdc = (HDC)wParam;
hdc.SelectPen(Outline);
hdc.SelectBrush(Fill);
2016-08-11 10:38:45 +00:00
RECT rect;
GetClientRect(&rect);
2020-10-22 02:11:19 +00:00
hdc.Rectangle(&rect);
2016-08-11 10:38:45 +00:00
return TRUE;
}
LRESULT CSupportEnterCode::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
EndDialog(wID);
return TRUE;
}
LRESULT CSupportEnterCode::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
2020-05-12 12:19:05 +00:00
wchar_t code[50];
if (!GetDlgItemText(IDC_CODE,code,sizeof(code) /sizeof(code[0])))
2016-08-11 10:38:45 +00:00
{
2020-05-12 12:19:05 +00:00
MessageBox(wGS(MSG_SUPPORT_ENTER_SUPPORT_CODE).c_str(), wGS(MSG_SUPPORT_PROJECT64).c_str(), MB_OK);
2016-08-11 10:38:45 +00:00
return false;
}
2020-10-22 02:11:19 +00:00
GetDlgItem(IDOK).EnableWindow(false);
GetDlgItem(IDCANCEL).EnableWindow(false);
bool ValidCode = false;
if (_wcsicmp(code,L"thank you from project64") == 0)
{
2020-12-30 00:47:25 +00:00
SetDlgItemText(IDC_CODE, L"");
CRequestCode RequestWindow(m_Support);
RequestWindow.ShowOldCodeMsg();
RequestWindow.DoModal(m_hWnd);
GetDlgItem(IDOK).EnableWindow(TRUE);
GetDlgItem(IDCANCEL).EnableWindow(TRUE);
return TRUE;
2020-10-22 02:11:19 +00:00
}
else if (m_Support.ValidateCode(stdstr().FromUTF16(code).c_str()))
{
ValidCode = true;
}
if (ValidCode)
{
MessageBox(wGS(MSG_SUPPORT_COMPLETE).c_str(), wGS(MSG_SUPPORT_PROJECT64).c_str(), MB_OK);
EndDialog(wID);
}
else
2016-08-11 10:38:45 +00:00
{
2020-05-12 12:19:05 +00:00
MessageBox(wGS(MSG_SUPPORT_INCORRECT_CODE).c_str(), wGS(MSG_SUPPORT_PROJECT64).c_str(), MB_OK);
2020-10-22 02:11:19 +00:00
GetDlgItem(IDOK).EnableWindow(TRUE);
GetDlgItem(IDCANCEL).EnableWindow(TRUE);
2016-08-11 10:38:45 +00:00
}
2020-10-22 02:11:19 +00:00
return TRUE;
}
CRequestCode::CRequestCode(CProjectSupport & Support) :
2020-12-30 00:47:25 +00:00
m_Support(Support),
m_ShowOldCodeMsg(false)
2020-10-22 02:11:19 +00:00
{
}
2020-12-30 00:47:25 +00:00
void CRequestCode::ShowOldCodeMsg()
{
m_ShowOldCodeMsg = true;
}
2020-10-22 02:11:19 +00:00
LRESULT CSupportEnterCode::OnRequestCode(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CRequestCode RequestWindow(m_Support);
RequestWindow.DoModal(m_hWnd);
return 0;
}
LRESULT CRequestCode::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
2020-12-30 00:47:25 +00:00
if (m_ShowOldCodeMsg)
{
SetDlgItemText(IDC_DESCRIPTION, L"We have changed the code to be unique to a machine, please enter the email you used to support Project64 with.");
}
2020-10-22 02:11:19 +00:00
return TRUE;
}
LRESULT CRequestCode::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CDCHandle hdcStatic = (HDC)wParam;
hdcStatic.SetTextColor(RGB(0, 0, 0));
hdcStatic.SetBkMode(TRANSPARENT);
return (LONG)(LRESULT)((HBRUSH)GetStockObject(NULL_BRUSH));
}
LRESULT CRequestCode::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
static HPEN Outline = CreatePen(PS_SOLID, 1, 0x00FFFFFF);
static HBRUSH Fill = CreateSolidBrush(0x00FFFFFF);
CDCHandle hdc = (HDC)wParam;
hdc.SelectPen(Outline);
hdc.SelectBrush(Fill);
RECT rect;
GetClientRect(&rect);
hdc.Rectangle(&rect);
return TRUE;
}
LRESULT CRequestCode::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
GetDlgItem(IDOK).EnableWindow(false);
GetDlgItem(IDCANCEL).EnableWindow(false);
if (m_Support.RequestCode(GetCWindowText(GetDlgItem(IDC_EMAIL)).c_str()))
2020-10-22 02:11:19 +00:00
{
MessageBox(wGS(MSG_SUPPORT_REQUESTCODE_SUCCESS).c_str(), wGS(MSG_SUPPORT_REQUESTCODE_TITLE).c_str(), MB_OK);
EndDialog(wID);
}
else
{
MessageBox(wGS(MSG_SUPPORT_REQUESTCODE_FAIL).c_str(), wGS(MSG_SUPPORT_REQUESTCODE_TITLE).c_str(), MB_OK);
GetDlgItem(IDOK).EnableWindow(true);
GetDlgItem(IDCANCEL).EnableWindow(true);
}
return TRUE;
}
LRESULT CRequestCode::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
2016-08-11 10:38:45 +00:00
EndDialog(wID);
return TRUE;
2020-10-22 02:11:19 +00:00
}