// CardIO.cpp : implementation file // #include "stdafx.h" #include "RawDisk.h" #include "CardIO.h" #include ".\cardio.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CWriteCard dialog CWriteCard::CWriteCard(CWnd* pParent /*=NULL*/) : CDialog(CWriteCard::IDD, pParent) { //{{AFX_DATA_INIT(CWriteCard) m_bBootloader = FALSE; m_bHeader = FALSE; m_bWinCE = FALSE; m_bDiag = FALSE; m_sBootloader = _T(""); m_sWinCE = _T(""); m_sDiag = _T(""); m_iHeaderType = -1; //}}AFX_DATA_INIT } void CWriteCard::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CWriteCard) DDX_Check(pDX, IDC_DO_BOOTLOADER, m_bBootloader); DDX_Check(pDX, IDC_DO_HEADER, m_bHeader); DDX_Check(pDX, IDC_DO_WINCE, m_bWinCE); DDX_Check(pDX, IDC_DO_DIAG, m_bDiag); DDX_Text(pDX, IDC_BOOTLOADER_FILE, m_sBootloader); DDX_Text(pDX, IDC_WINCE_FILE, m_sWinCE); DDX_Text(pDX, IDC_DIAG_FILE, m_sDiag); DDX_Radio(pDX, IDC_HEADER_1K, m_iHeaderType); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CWriteCard, CDialog) //{{AFX_MSG_MAP(CWriteCard) ON_BN_CLICKED(IDC_WINCE_BROWSE, OnWinceBrowse) ON_BN_CLICKED(IDC_BOOTLOADER_BROWSE, OnBootloaderBrowse) ON_BN_CLICKED(IDC_DIAG_BROWSE, OnDiagBrowse) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CWriteCard message handlers void CWriteCard::OnWinceBrowse() { UpdateData( true ); CFileDialog cd( true, NULL, NULL, OFN_FILEMUSTEXIST|OFN_ENABLESIZING, "Windows CE (*.nb1)|*.nb1|ROM update files (*.nbf)|*.nbf|SD card images (*.img)|*.img|All files (*.*)|*.*||" ); TCHAR szCurDir[1024]; szCurDir[0]=0; if (GetCurrentDirectory(1024, szCurDir)) { cd.m_pOFN->lpstrInitialDir= szCurDir; } if( cd.DoModal()==IDOK ) { m_sWinCE= cd.GetPathName(); if( m_sBootloader=="" ) { m_sBootloader= m_sWinCE; if( m_sBootloader.Right(1)=="1" ) { m_sBootloader= m_sBootloader.Left( m_sBootloader.GetLength()-1 )+"0"; } } UpdateData( false ); } } void CWriteCard::OnBootloaderBrowse() { UpdateData( true ); CFileDialog cd( true, NULL, NULL, OFN_FILEMUSTEXIST|OFN_ENABLESIZING, "Bootloader (*.nb0)|*.nb0|ROM update files (*.nbf)|*.nbf|SD card images (*.img)|*.img|All files (*.*)|*.*||" ); if( cd.DoModal()==IDOK ) { m_sBootloader= cd.GetPathName(); if( m_sWinCE=="" ) { m_sWinCE= m_sBootloader; if( m_sWinCE.Right(1)=="0" ) { m_sWinCE= m_sWinCE.Left( m_sWinCE.GetLength()-1 )+"1"; } } UpdateData( false ); } } void CWriteCard::OnDiagBrowse() { UpdateData( true ); CFileDialog cd( true, NULL, NULL, OFN_FILEMUSTEXIST|OFN_ENABLESIZING, "Diagnostics (*.nb2)|*.nb2|SD card images (*.img)|*.img|All files (*.*)|*.*||" ); if( cd.DoModal()==IDOK ) { m_sDiag= cd.GetPathName(); m_sWinCE= m_sBootloader= ""; m_bWinCE= m_bBootloader= false; UpdateData( false ); } } void CWriteCard::OnOK() { UpdateData( true ); if( m_bBootloader && m_sBootloader=="" ) { AfxMessageBox( "You must specify the bootloader image if you want to include it.", MB_ICONHAND ); return; } if( m_bWinCE && m_sWinCE=="" ) { AfxMessageBox( "You must specify the Windows CE image if you want to include it.", MB_ICONHAND ); return; } if( m_bDiag && m_sDiag=="" ) { AfxMessageBox( "You must specify the diagnostics image if you want to include it.", MB_ICONHAND ); return; } CDialog::OnOK(); } ///////////////////////////////////////////////////////////////////////////// // CReadCard dialog CReadCard::CReadCard(CWnd* pParent /*=NULL*/) : CDialog(CReadCard::IDD, pParent) { //{{AFX_DATA_INIT(CReadCard) m_bBootloader = FALSE; m_bWinCE = FALSE; m_sBootloader = _T(""); m_sWinCE = _T(""); //}}AFX_DATA_INIT } void CReadCard::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CReadCard) DDX_Check(pDX, IDC_DO_BOOTLOADER, m_bBootloader); DDX_Check(pDX, IDC_DO_WINCE, m_bWinCE); DDX_Text(pDX, IDC_BOOTLOADER_FILE, m_sBootloader); DDX_Text(pDX, IDC_WINCE_FILE, m_sWinCE); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CReadCard, CDialog) //{{AFX_MSG_MAP(CReadCard) ON_BN_CLICKED(IDC_BOOTLOADER_BROWSE, OnBootloaderBrowse) ON_BN_CLICKED(IDC_WINCE_BROWSE, OnWinceBrowse) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CReadCard message handlers void CReadCard::OnBootloaderBrowse() { UpdateData( true ); CFileDialog cd( false, "nb0", NULL, OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST|OFN_ENABLESIZING, "Bootloader (*.nb0)|*.nb0|SD card images (*.img)|*.img|All files (*.*)|*.*||" ); if( cd.DoModal()==IDOK ) { m_sBootloader= cd.GetPathName(); if( m_sWinCE=="" ) { m_sWinCE= m_sBootloader; if( m_sWinCE.Right(1)=="0" ) { m_sWinCE= m_sWinCE.Left( m_sWinCE.GetLength()-1 )+"1"; } } UpdateData( false ); } } void CReadCard::OnWinceBrowse() { UpdateData( true ); CFileDialog cd( false, "nb1", NULL, OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST|OFN_ENABLESIZING, "Windows CE (*.nb1)|*.nb1|SD card images (*.img)|*.img|All files (*.*)|*.*||" ); if( cd.DoModal()==IDOK ) { m_sWinCE= cd.GetPathName(); if( m_sBootloader=="" ) { m_sBootloader= m_sWinCE; if( m_sBootloader.Right(1)=="1" ) { m_sBootloader= m_sBootloader.Left( m_sBootloader.GetLength()-1 )+"0"; } } UpdateData( false ); } } void CReadCard::OnOK() { UpdateData( true ); if( m_bBootloader && m_sBootloader=="" ) { AfxMessageBox( "You must specify the bootloader image if you want to save it.", MB_ICONHAND ); return; } if( m_bWinCE && m_sWinCE=="" ) { AfxMessageBox( "You must specify the Windows CE image if you want to save it.", MB_ICONHAND ); return; } CDialog::OnOK(); } ///////////////////////////////////////////////////////////////////////////// // CProgress dialog CProgress::CProgress(CWnd* pParent /*=NULL*/) : CDialog(CProgress::IDD, pParent) , m_bCancelled(false) { //{{AFX_DATA_INIT(CProgress) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CProgress::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CProgress) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP DDX_Control(pDX, IDC_PROGRESS1, m_cProgress); DDX_Control(pDX, IDC_SPEED, m_cSpeed); DDX_Control(pDX, IDC_TIME_REMAINING, m_cCountdown); } BEGIN_MESSAGE_MAP(CProgress, CDialog) //{{AFX_MSG_MAP(CProgress) // NOTE: the ClassWizard will add message map macros here //}}AFX_MSG_MAP ON_NOTIFY(NM_CUSTOMDRAW, IDC_PROGRESS1, OnNMCustomdrawProgress1) ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CProgress message handlers BOOL CProgress::Create() { BOOL bRes= CDialog::Create( IDD_PROGRESS, NULL ); CenterWindow(); CWnd *pParent= GetParent(); pParent->EnableWindow( false ); m_cProgress.SetRange(0, 100); return bRes; } BOOL CProgress::DestroyWindow() { CWnd *pParent= GetParent(); pParent->EnableWindow( true ); return CDialog::DestroyWindow(); } void CProgress::OnNMCustomdrawProgress1(NMHDR *pNMHDR, LRESULT *pResult) { LPNMCUSTOMDRAW pNMCD = reinterpret_cast(pNMHDR); // TODO: Add your control notification handler code here *pResult = 0; } void CProgress::SetPercentage(double percentage) { m_cProgress.SetPos((int)percentage); } void CProgress::SetSpeed(double speed) { CString str; str.Format("%8.1f", speed/1024); m_cSpeed.SetWindowText(str); } void CProgress::OnBnClickedCancel() { // TODO: Add your control notification handler code here m_bCancelled= true; OnCancel(); } void CProgress::SetRemainingTime(long dwRemainingSeconds) { CString str; str.Format("%2d:%02d", dwRemainingSeconds/60, dwRemainingSeconds%60); m_cCountdown.SetWindowText(str); }