ciderpress/app/EnterRegDialog.cpp

211 lines
5.4 KiB
C++
Raw Normal View History

2007-03-27 17:47:10 +00:00
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
#if 0
/*
* Support for entering registration data.
*/
#include "stdafx.h"
#include "EnterRegDialog.h"
#include "MyApp.h"
#include "HelpTopics.h"
BEGIN_MESSAGE_MAP(EnterRegDialog, CDialog)
ON_EN_CHANGE(IDC_REGENTER_USER, OnUserChange)
ON_EN_CHANGE(IDC_REGENTER_COMPANY, OnCompanyChange)
ON_EN_CHANGE(IDC_REGENTER_REG, OnRegChange)
ON_COMMAND(IDHELP, OnHelp)
2007-03-27 17:47:10 +00:00
END_MESSAGE_MAP()
/*
* Disable the "OK" button initially.
*/
BOOL
EnterRegDialog::OnInitDialog(void)
{
//CWnd* pWnd = GetDlgItem(IDOK);
//ASSERT(pWnd != nil);
//pWnd->EnableWindow(false);
fMyEdit.ReplaceDlgCtrl(this, IDC_REGENTER_REG);
fMyEdit.SetProperties(MyEdit::kCapsOnly | MyEdit::kNoWhiteSpace);
/* place a reasonable cap on the field lengths, since these go
straight into the registry */
CEdit* pEdit;
pEdit = (CEdit*) GetDlgItem(IDC_REGENTER_USER);
ASSERT(pEdit != nil);
pEdit->SetLimitText(120);
pEdit = (CEdit*) GetDlgItem(IDC_REGENTER_COMPANY);
ASSERT(pEdit != nil);
pEdit->SetLimitText(120);
pEdit = (CEdit*) GetDlgItem(IDC_REGENTER_REG);
ASSERT(pEdit != nil);
pEdit->SetLimitText(40);
return CDialog::OnInitDialog();
2007-03-27 17:47:10 +00:00
}
/*
* Shuffle data in and out of the edit fields. We do an extra validation
* step on the registration key before accepting it.
*/
void
EnterRegDialog::DoDataExchange(CDataExchange* pDX)
{
DDX_Text(pDX, IDC_REGENTER_USER, fUserName);
DDX_Text(pDX, IDC_REGENTER_COMPANY, fCompanyName);
DDX_Text(pDX, IDC_REGENTER_REG, fRegKey);
/* validate the reg field */
if (pDX->m_bSaveAndValidate) {
ASSERT(!fUserName.IsEmpty());
ASSERT(!fRegKey.IsEmpty());
if (gMyApp.fRegistry.IsValidRegistrationKey(fUserName, fCompanyName,
fRegKey))
{
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
WMSG3("Correct key entered: '%ls' '%ls' '%ls'\n",
(LPCTSTR)fUserName, (LPCTSTR)fCompanyName, (LPCTSTR)fRegKey);
} else {
WMSG0("Incorrect key entered, rejecting\n");
CString appName, msg;
appName.LoadString(IDS_MB_APP_NAME);
msg.LoadString(IDS_REG_BAD_ENTRY);
MessageBox(msg, appName, MB_ICONWARNING|MB_OK);
pDX->Fail();
}
} else {
OnUserChange();
OnCompanyChange();
OnRegChange();
}
2007-03-27 17:47:10 +00:00
}
/*
* Call this when the text in an edit field has changed.
*
* If there's nothing in the "user name" or "reg key" fields, dim the OK
* button.
*/
void
EnterRegDialog::HandleEditChange(int editID, int crcID)
{
CString userStr, regStr;
CEdit* pEdit;
CWnd* pWnd;
/*
* Update the CRC for the modified control.
*/
pEdit = (CEdit*) GetDlgItem(editID);
ASSERT(pEdit != nil);
pEdit->GetWindowText(userStr);
unsigned short crc;
crc = gMyApp.fRegistry.ComputeStringCRC(userStr);
userStr.Format("%04X", crc);
pWnd = GetDlgItem(crcID);
ASSERT(pWnd != nil);
pWnd->SetWindowText(userStr);
/*
* Update the OK button.
*/
pEdit = (CEdit*) GetDlgItem(IDC_REGENTER_USER);
ASSERT(pEdit != nil);
pEdit->GetWindowText(userStr);
pEdit = (CEdit*) GetDlgItem(IDC_REGENTER_REG);
ASSERT(pEdit != nil);
pEdit->GetWindowText(regStr);
pWnd = GetDlgItem(IDOK);
ASSERT(pWnd != nil);
pWnd->EnableWindow(!userStr.IsEmpty() && !regStr.IsEmpty());
2007-03-27 17:47:10 +00:00
}
/*
* Handle changes in the three edit fields.
*/
void
EnterRegDialog::OnUserChange(void)
{
HandleEditChange(IDC_REGENTER_USER, IDC_REGENTER_USERCRC);
2007-03-27 17:47:10 +00:00
}
void
EnterRegDialog::OnCompanyChange(void)
{
HandleEditChange(IDC_REGENTER_COMPANY, IDC_REGENTER_COMPCRC);
2007-03-27 17:47:10 +00:00
}
void
EnterRegDialog::OnRegChange(void)
{
HandleEditChange(IDC_REGENTER_REG, IDC_REGENTER_REGCRC);
2007-03-27 17:47:10 +00:00
}
/*
* User pressed the "Help" button.
*/
void
EnterRegDialog::OnHelp(void)
{
WinHelp(HELP_TOPIC_ENTER_REG_DATA, HELP_CONTEXT);
2007-03-27 17:47:10 +00:00
}
/*
* Get registration info from the user. This is a static utility function
* that can be called from elsewhere in the app.
*
* Returns 0 on successful registration, nonzero on failure or if the user
* cancels out of the dialog.
*/
/*static*/ int
EnterRegDialog::GetRegInfo(CWnd* pWnd)
{
CString user, company, reg, versions, expire;
/*
* Get current data (if any). This call only fails if the registry itself
* appears to be generally inaccessible.
*/
if (gMyApp.fRegistry.GetRegistration(&user, &company, &reg, &versions,
&expire) != 0)
{
CString msg;
msg.LoadString(IDS_REG_FAILURE);
ShowFailureMsg(pWnd, msg, IDS_FAILED);
return -1;
}
/*
* Post the dialog.
*/
EnterRegDialog dlg(pWnd);
int result = -1;
if (dlg.DoModal() == IDOK) {
user = dlg.fUserName;
company = dlg.fCompanyName;
reg = dlg.fRegKey;
/* data was validated by EnterRegDialog, so just save it to registry */
if (gMyApp.fRegistry.SetRegistration(user, company, reg, versions,
expire) != 0)
{
CString msg;
msg.LoadString(IDS_REG_FAILURE);
ShowFailureMsg(pWnd, msg, IDS_FAILED);
} else {
result = 0;
}
}
return result;
2007-03-27 17:47:10 +00:00
}
#endif /*0*/