⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftpsetup.cpp

📁 s3c2410 wince bootload update tools
💻 CPP
字号:
// FtpSetup.cpp : implementation file
//

#include "stdafx.h"
#include "ARMUpdate.h"
#include "FtpSetup.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFtpSetup dialog


CFtpSetup::CFtpSetup(CWnd* pParent /*=NULL*/)
	: CDialog(CFtpSetup::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFtpSetup)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CFtpSetup::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFtpSetup)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFtpSetup, CDialog)
	//{{AFX_MSG_MAP(CFtpSetup)
	ON_COMMAND(ID_MENU_FTPSETUP, OnMenuFtpsetup)
	ON_BN_CLICKED(IDC_BOOTPATHBT, OnBootpathbt)
	ON_BN_CLICKED(IDC_NKPATHBT, OnNkpathbt)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFtpSetup message handlers

void CFtpSetup::OnMenuFtpsetup() 
{
	// TODO: Add your command handler code here
	
}

void CFtpSetup::OnBootpathbt() 
{
	char szFilters[]="BIN Files (*.bin)|*.bin|All Files (*.*)|*.*||";
	
	// Create an Open dialog; the default file name extension is ".my".
	CFileDialog fdlg (TRUE, "BIN", "*.bin",OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);

	if(fdlg.DoModal()==IDOK)
	{
		SetDlgItemText(IDC_BOOTLOADPATH,fdlg.GetPathName());
	}
}

void CFtpSetup::OnNkpathbt() 
{
	char szFilters[]="BIN Files (*.bin)|*.bin|All Files (*.*)|*.*||";
	
	// Create an Open dialog; the default file name extension is ".my".
	CFileDialog fdlg (TRUE, "BIN", "*.bin",OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);

	if(fdlg.DoModal()==IDOK)
	{
		SetDlgItemText(IDC_NKPATH,fdlg.GetPathName());
	}
}
const char ftpRegName[][20]={"HostIP","HostPort","NKPath","BootLoadPath","RemoteFileName"};
const long ftpItem[]={IDC_HOSTNAME,IDC_HOSTPORT,IDC_NKPATH,IDC_BOOTLOADPATH,IDC_HOSTFILENAME};
const CHAR ftpActiveKey[]="SoftWare\\LanBo\\";

BOOL CFtpSetup::GetCOMRegSetup(void)
{
	DWORD status;
	CRegKey RegKey;
	DWORD pCount=1024;
	char szValue[1024];

	status=RegKey.Open(HKEY_CURRENT_USER,ftpActiveKey,KEY_ALL_ACCESS);
	if(status!=ERROR_SUCCESS)
	{
		status=RegKey.Create(HKEY_CURRENT_USER,ftpActiveKey,0,NULL,REG_OPTION_NON_VOLATILE);
		if(status!=ERROR_SUCCESS)
		{
			return false;
		}
		RegKey.Open(HKEY_CURRENT_USER,ftpActiveKey,KEY_ALL_ACCESS);
		RegKey.SetValue("192.168.0.30",ftpRegName[0]);
		RegKey.SetValue("69",ftpRegName[1]);
		RegKey.SetValue("c:\\",ftpRegName[2]);
		RegKey.SetValue("c:\\",ftpRegName[3]);
		RegKey.SetValue("boot.bin",ftpRegName[4]);
	}
	else
	{
		memset(szValue,0,sizeof(szValue));
		pCount=1024;
		RegKey.QueryValue(szValue,ftpRegName[0],&pCount);
		if(strlen(szValue)==0)RegKey.SetValue("192.168.0.30",ftpRegName[0]);

		memset(szValue,0,sizeof(szValue));
		pCount=1024;
		RegKey.QueryValue(szValue,ftpRegName[1],&pCount);
		if(strlen(szValue)==0)RegKey.SetValue("69",ftpRegName[1]);

		memset(szValue,0,sizeof(szValue));
		pCount=1024;
		RegKey.QueryValue(szValue,ftpRegName[2],&pCount);
		if(strlen(szValue)==0)RegKey.SetValue("c:\\",ftpRegName[2]);

		memset(szValue,0,sizeof(szValue));
		pCount=1024;
		RegKey.QueryValue(szValue,ftpRegName[3],&pCount);
		if(strlen(szValue)==0)RegKey.SetValue("c:\\",ftpRegName[3]);

		memset(szValue,0,sizeof(szValue));
		pCount=1024;
		RegKey.QueryValue(szValue,ftpRegName[4],&pCount);
		if(strlen(szValue)==0)RegKey.SetValue("boot.bin",ftpRegName[4]);
	}
	for(int i=0;i<sizeof(ftpItem)/4;i++)
	{
		memset(szValue,0,sizeof(szValue));
		pCount=1024;
		RegKey.QueryValue(szValue,ftpRegName[i],&pCount);
		switch(i)
		{
		case 0:
			m_szHostIP.Format("%s",szValue);
			memset(tftp.DestHost,0,sizeof(tftp.DestHost));
			memcpy(tftp.DestHost,m_szHostIP.GetBuffer(m_szHostIP.GetLength()),m_szHostIP.GetLength());
			break;
		case 1:
			m_szHostPort.Format("%s",szValue);
			break;
		case 2:
			m_szNKPath.Format("%s",szValue);
			break;
		case 3:
			m_szBootLoadPath.Format("%s",szValue);
			break;
		case 4:
			m_szRemoteFileName.Format("%s",szValue);
			break;
		}
	}
	return true;
}

BOOL CFtpSetup::SetCOMRegSetup(void)
{
	DWORD status;
	CRegKey RegKey;
	DWORD pCount=1024;
	char szValue[1024];
	CComboBox *p;

	status=RegKey.Open(HKEY_CURRENT_USER,ftpActiveKey,KEY_ALL_ACCESS);
	for(int i=0;i<sizeof(ftpItem)/4;i++)
	{
		p=(CComboBox*)GetDlgItem(ftpItem[i]);
		p->GetWindowText(szValue,1024);
		RegKey.SetValue(szValue,ftpRegName[i]);
	}
	RegKey.Close();
	return true;
}

void CFtpSetup::OnOK() 
{
	SetCOMRegSetup();
	CDialog::OnOK();
}

BOOL CFtpSetup::OnInitDialog() 
{
	CEdit *p;
	CDialog::OnInitDialog();
	GetCOMRegSetup();
	const long ftpItem[]={IDC_HOSTNAME,IDC_HOSTPORT,IDC_NKPATH,IDC_BOOTLOADPATH,IDC_HOSTFILENAME};

	p=(CEdit*)GetDlgItem(IDC_HOSTNAME);
	p->SetWindowText(m_szHostIP);

	p=(CEdit*)GetDlgItem(IDC_HOSTPORT);
	p->SetWindowText(m_szHostPort);
	
	p=(CEdit*)GetDlgItem(IDC_NKPATH);
	p->SetWindowText(m_szNKPath);
	
	p=(CEdit*)GetDlgItem(IDC_BOOTLOADPATH);
	p->SetWindowText(m_szBootLoadPath);
	
	p=(CEdit*)GetDlgItem(IDC_HOSTFILENAME);
	p->SetWindowText(m_szRemoteFileName);

	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
UINT CFtpSetup::TFTPGetFile(char * filename,CProgressCtrl *sb)
{
	GetCOMRegSetup();
	tftp.sb=sb;
	return tftp.GetFile(filename);
}
UINT CFtpSetup::TFTPPutNKFile(CProgressCtrl *sb)
{
	GetCOMRegSetup();
	tftp.sb=sb;
	return tftp.PutFile(m_szNKPath.GetBuffer(m_szNKPath.GetLength()),m_szRemoteFileName.GetBuffer(m_szRemoteFileName.GetLength()));
}
UINT CFtpSetup::TFTPPutBootLoadFile(CProgressCtrl *sb)
{
	GetCOMRegSetup();
	tftp.sb=sb;
	return tftp.PutFile(m_szBootLoadPath.GetBuffer(m_szBootLoadPath.GetLength()),m_szRemoteFileName.GetBuffer(m_szRemoteFileName.GetLength()));
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -