ciderpress/app/CassImpTargetDialog.cpp

153 lines
4.0 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.
*/
/*
* Choose file name and characteristics for a file imported from an audio
* cassette tape.
*/
#include "StdAfx.h"
#include "CassImpTargetDialog.h"
#include "GenericArchive.h" // just want kFileTypeXXX
2007-03-27 17:47:10 +00:00
BEGIN_MESSAGE_MAP(CassImpTargetDialog, CDialog)
ON_BN_CLICKED(IDC_CASSIMPTARG_BAS, OnTypeChange)
ON_BN_CLICKED(IDC_CASSIMPTARG_INT, OnTypeChange)
ON_BN_CLICKED(IDC_CASSIMPTARG_BIN, OnTypeChange)
ON_EN_CHANGE(IDC_CASSIMPTARG_BINADDR, OnAddrChange)
2007-03-27 17:47:10 +00:00
END_MESSAGE_MAP()
BOOL CassImpTargetDialog::OnInitDialog(void)
2007-03-27 17:47:10 +00:00
{
/* substitute our replacement edit control */
fAddrEdit.ReplaceDlgCtrl(this, IDC_CASSIMPTARG_BINADDR);
fAddrEdit.SetProperties(MyEdit::kCapsOnly | MyEdit::kHexOnly);
2007-03-27 17:47:10 +00:00
//CWnd* pWnd;
CEdit* pEdit;
2007-03-27 17:47:10 +00:00
pEdit = (CEdit*) GetDlgItem(IDC_CASSIMPTARG_BINADDR);
pEdit->SetLimitText(4); // 4-digit hex value
2007-03-27 17:47:10 +00:00
/* do the DDX thing, then update computed fields */
CDialog::OnInitDialog();
OnTypeChange();
OnAddrChange();
2007-03-27 17:47:10 +00:00
pEdit = (CEdit*) GetDlgItem(IDC_CASSIMPTARG_FILENAME);
pEdit->SetSel(0, -1);
pEdit->SetFocus();
return FALSE; // don't change the focus
2007-03-27 17:47:10 +00:00
}
void CassImpTargetDialog::DoDataExchange(CDataExchange* pDX)
2007-03-27 17:47:10 +00:00
{
DDX_Radio(pDX, IDC_CASSIMPTARG_BAS, fFileTypeIndex);
DDX_Text(pDX, IDC_CASSIMPTARG_FILENAME, fFileName);
if (pDX->m_bSaveAndValidate) {
CString appName;
CheckedLoadString(&appName, IDS_MB_APP_NAME);
if (fFileTypeIndex == kTypeBIN) {
if (GetStartAddr() < 0) {
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
MessageBox(L"The address field must be a valid 4-digit "
L" hexadecimal number.",
appName, MB_OK);
pDX->Fail();
return;
}
fStartAddr = (unsigned short) GetStartAddr();
}
if (fFileName.IsEmpty()) {
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
MessageBox(L"You must enter a filename.", appName, MB_OK);
pDX->Fail();
return;
}
} else {
CWnd* pWnd;
CString tmpStr;
pWnd = GetDlgItem(IDC_CASSIMPTARG_BINADDR);
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
tmpStr.Format(L"%04X", fStartAddr);
pWnd->SetWindowText(tmpStr);
}
2007-03-27 17:47:10 +00:00
}
void CassImpTargetDialog::OnTypeChange(void)
2007-03-27 17:47:10 +00:00
{
CButton* pButton;
CWnd* pWnd;
2007-03-27 17:47:10 +00:00
pButton = (CButton*) GetDlgItem(IDC_CASSIMPTARG_BIN);
pWnd = GetDlgItem(IDC_CASSIMPTARG_BINADDR);
2007-03-27 17:47:10 +00:00
pWnd->EnableWindow(pButton->GetCheck() == BST_CHECKED);
2007-03-27 17:47:10 +00:00
}
void CassImpTargetDialog::OnAddrChange(void)
2007-03-27 17:47:10 +00:00
{
CWnd* pWnd;
CString tmpStr;
long val;
2007-03-27 17:47:10 +00:00
val = GetStartAddr();
if (val < 0)
val = 0;
2007-03-27 17:47:10 +00:00
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
tmpStr.Format(L".%04X", val + fFileLength-1);
2007-03-27 17:47:10 +00:00
pWnd = GetDlgItem(IDC_CASSIMPTARG_RANGE);
pWnd->SetWindowText(tmpStr);
2007-03-27 17:47:10 +00:00
}
long CassImpTargetDialog::GetStartAddr(void) const
2007-03-27 17:47:10 +00:00
{
CWnd* pWnd = GetDlgItem(IDC_CASSIMPTARG_BINADDR);
2014-11-18 05:13:13 +00:00
ASSERT(pWnd != NULL);
CString aux;
pWnd->GetWindowText(aux);
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
const WCHAR* str = aux;
WCHAR* end;
long val;
if (str[0] == '\0') {
LOGI(" HEY: blank addr, returning -1");
return -1;
}
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
val = wcstoul(aux, &end, 16);
if (end != str + wcslen(str)) {
LOGI(" HEY: found some garbage in addr '%ls', returning -1",
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
(LPCWSTR) aux);
return -1;
}
return val;
2007-03-27 17:47:10 +00:00
}
long CassImpTargetDialog::GetFileType(void) const
2007-03-27 17:47:10 +00:00
{
switch (fFileTypeIndex) {
case kTypeBIN: return kFileTypeBIN;
case kTypeINT: return kFileTypeINT;
case kTypeBAS: return kFileTypeBAS;
default:
assert(false);
return -1;
}
2007-03-27 17:47:10 +00:00
}
void CassImpTargetDialog::SetFileType(long type)
2007-03-27 17:47:10 +00:00
{
switch (type) {
case kFileTypeBIN: fFileTypeIndex = kTypeBIN; break;
case kFileTypeINT: fFileTypeIndex = kTypeINT; break;
case kFileTypeBAS: fFileTypeIndex = kTypeBAS; break;
default:
assert(false);
break;
}
2007-03-27 17:47:10 +00:00
}