// TFTP_PACKDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TFTP_PACK.h"
#include "TFTP_PACKDlg.h"
#include "FDownGress.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
/////////////////////////////////////////////////////////////////////////////
// CTFTP_PACKDlg dialog
CTFTP_PACKDlg::CTFTP_PACKDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTFTP_PACKDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTFTP_PACKDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTFTP_PACKDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTFTP_PACKDlg)
DDX_Control(pDX, IDC_COMMSG, m_ComMsg);
DDX_Control(pDX, IDC_CMDLST, m_CmdLst);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTFTP_PACKDlg, CDialog)
//{{AFX_MSG_MAP(CTFTP_PACKDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ADDFILE, OnAddfile)
ON_BN_CLICKED(IDC_DOWNLOAD, OnDownload)
ON_WM_SIZE()
ON_BN_CLICKED(IDCLEAR_TERMINAL, OnTerminal)
ON_BN_CLICKED(IDCLOSE_TERMINAL, OnCloseTerminal)
ON_BN_CLICKED(IDCLEAR, OnClear)
ON_WM_SYSCOMMAND()
ON_BN_CLICKED(IDPING, OnPing)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTFTP_PACKDlg message handlers
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTFTP_PACKDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTFTP_PACKDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTFTP_PACKDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
/*
if ( m_CmdLst.m_hWnd)
m_CmdLst.MoveWindow(0,69,cx-(0*2),140);
if ( m_ComMsg.m_hWnd)
m_ComMsg.MoveWindow(0,138+69,cx-(0*2),cy-138-69-0);
*/
}
/************************************************************************/
/************************************************************************/
/************************************************************************/
#define MaxFile 10
CStdioFile pInitFile;
CString srcFileName[MaxFile];
CFDownGress mFDnGrs(512);
bool connect();
bool makereq();
bool makedata(char *pSour , int dwAddr , int dwLen ,int dwPackIndex);
BOOL clrFlg=true;
bool Autorun=false;
BOOL HexToCString(BYTE *rev, CString &Str,int revlen);
struct{
unsigned char pFilename[16];
unsigned char pVerifyPin[4];
unsigned short wFileCnt;
unsigned short wFileIndex;
unsigned int dwAddr;
unsigned int dwLen;
unsigned char pRevByte[512-16-4-2-2-4-4];
}gCDataFile;
int find(char c1,char c2 ,char *sour,char *dest)
{
char *p1=0,*p2=0,*p3=sour;
*dest=0;
while(*p3 != '\0' && *p3 != c1) p3++;
if(*p3 == c1) p1 = ++p3;
while(*p3 != '\0' && *p3 != c2) p3++;
if(*p3 == c2) p2 = p3;
if(p1>=p2) return -1;
strncat(dest,p1,p2-p1);
return p2-sour;
}
/************************************************************************/
/************************************************************************/
/************************************************************************/
CString GetAppPath()//取程序自身路径
{
CString strRet;
TCHAR szBuff[_MAX_PATH];
VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, szBuff, _MAX_PATH));
strRet=szBuff;
int pos=strRet.ReverseFind('\\');
strRet=strRet.Left(pos);
return strRet;
}
BOOL CTFTP_PACKDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
Topsion = 18;
ComOpen(1);
m_CmdLst.InsertColumn(0,"内嵌文件名",LVCFMT_LEFT,85);
m_CmdLst.InsertColumn(1,"文件大小",LVCFMT_LEFT,200);
m_CmdLst.InsertColumn(2,"文件数",LVCFMT_LEFT,70);
m_CmdLst.InsertColumn(3,"下载地址",LVCFMT_LEFT,85);
m_CmdLst.InsertColumn(4,"下载进度",LVCFMT_LEFT,185);
m_CmdLst.SetExtendedStyle(LVS_EX_FULLROWSELECT);
WriteCnt = 0;
memset(&gCDataFile,0,sizeof(gCDataFile));
//*******************************************************************************
if(pInitFile.Open(GetAppPath() + "\\tftp.ini",CFile::modeRead))
{
for(int i=0;i<MaxFile;i++)
{
CString onestring;
char temp[100],out[100];
memset(temp,0,sizeof(temp));
if(!pInitFile.ReadString(onestring)) break;
strcpy(temp,onestring);
if(find('"','"',temp,out)>0)
srcFileName[i] = out;
else
break;
AddFile(srcFileName[i]);
}
pInitFile.Close();
}
AfxGetMainWnd()->SetWindowText("VCM-L600 生产下载工具 V1.1/2007-08-31 by lcg");
//*******************************************************************************
return TRUE; // return TRUE unless you set the focus to a control
}
/************************************************************************/
/************************************************************************/
/************************************************************************/
/************************************************************************/
/************************************************************************/
/************************************************************************/
CString GetSelFile()
{
CFile mfile;
CString m_filepath;
CFileDialog dlg(TRUE, NULL, NULL,OFN_HIDEREADONLY,
"Data Files (*.bin;*.ram;)|*.bin; *.ram;",
NULL );
dlg.m_ofn.lStructSize=88;
if(dlg.DoModal()==IDCANCEL) return "";
m_filepath = dlg.GetPathName();
return m_filepath;
}
/************************************************************************/
/************************************************************************/
/************************************************************************/
/************************************************************************/
/************************************************************************/
/************************************************************************/
/************************************************************************/
/************************************************************************/
void CTFTP_PACKDlg::OnAddfile()
{
AddFile("");
}
void CTFTP_PACKDlg::AddFile(CString mpathstr)
{
CString mfilename,maddstr,mnumstr,mlenstr;
char name[1024];
int TopPosition;
DWORD filelen;
CFile mfile;
BOOL errFlg = false;
if(mpathstr=="") {
errFlg = true;
if((mpathstr