You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
273 lines
5.6 KiB
C++
273 lines
5.6 KiB
C++
// testAppDlg.cpp : Implementierungsdatei
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "testApp.h"
|
|
#include "testAppDlg.h"
|
|
#include "DlgEnterFilename.h"
|
|
|
|
/*
|
|
* Call Back
|
|
*/
|
|
int FtpTransfer(char * curFilename, int totalbytes, int totalfiles, int percentcomplete, void *userPtr )
|
|
{
|
|
|
|
DebugOutLn("FTP Transfer: %s, %d %%percent complete", curFilename, percentcomplete);
|
|
|
|
// llirq_Sleep(100);
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
int CFTPThread::Main()
|
|
{
|
|
int size = 0;
|
|
DebugOutLn("CFTPThread::Main");
|
|
llfile_current_stream = m_ftp_stream;
|
|
|
|
void * ftpfile = llfile_LoadToMem(m_file,&size);
|
|
|
|
if( ftpfile && size != 0 ){
|
|
CString savefilename;
|
|
|
|
char * P = strrchr(m_file,'/');
|
|
if( P == 0 ){
|
|
P = strrchr(m_file,'\\');
|
|
}
|
|
if( P != 0 )
|
|
savefilename = P+1;
|
|
else
|
|
savefilename = m_file;
|
|
|
|
CStdioFile logfile( savefilename, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary );
|
|
logfile.Write(ftpfile,size);
|
|
logfile.Close();
|
|
DebugOutLn("Written %d bytes to file %s",size,savefilename);
|
|
}
|
|
|
|
ftpfile = llfile_LoadToMem(m_file,&size);
|
|
DebugOutLn("file 2 %x",ftpfile);
|
|
if( ftpfile && size != 0 ){
|
|
CString savefilename;
|
|
|
|
char * P = strrchr(m_file,'/');
|
|
if( P == 0 ){
|
|
P = strrchr(m_file,'\\');
|
|
}
|
|
if( P != 0 )
|
|
savefilename = P+1;
|
|
else
|
|
savefilename = m_file;
|
|
|
|
CStdioFile logfile( savefilename, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary );
|
|
logfile.Write(ftpfile,size);
|
|
logfile.Close();
|
|
DebugOutLn("Written %d bytes to file %s",size,savefilename);
|
|
}
|
|
//Close FTP
|
|
llfile_CloseStream(m_ftp_stream);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CTestAppDlg Dialogfeld
|
|
|
|
CTestAppDlg::CTestAppDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CTestAppDlg::IDD, pParent)
|
|
{
|
|
m_filepos = 0;
|
|
m_inifile.LoadVars("ftpdat.ini");
|
|
DebugOutLn("ftpdat.ini loaded");
|
|
|
|
//{{AFX_DATA_INIT(CTestAppDlg)
|
|
m_ftp_passwd = m_inifile.GetVarS("ftppasswd","");
|
|
m_ftp_server = m_inifile.GetVarS("ftpserver","");
|
|
m_ftp_user = m_inifile.GetVarS("ftpuser","");
|
|
m_getfile = _T("");
|
|
//}}AFX_DATA_INIT
|
|
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
|
}
|
|
|
|
CTestAppDlg::~CTestAppDlg()
|
|
{
|
|
}
|
|
|
|
void CTestAppDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CTestAppDlg)
|
|
DDX_Control(pDX, IDC_LIST1, m_list);
|
|
DDX_Text(pDX, IDC_EDIT_FTPPASSWD, m_ftp_passwd);
|
|
DDX_Text(pDX, IDC_EDIT_FTPSERVER, m_ftp_server);
|
|
DDX_Text(pDX, IDC_EDIT_FTPUSER, m_ftp_user);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CTestAppDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CTestAppDlg)
|
|
ON_WM_PAINT()
|
|
ON_WM_QUERYDRAGICON()
|
|
ON_WM_TIMER()
|
|
ON_BN_CLICKED(IDC_BUTTON1, OnConnect)
|
|
ON_BN_CLICKED(IDC_BUTTON3, OnOK)
|
|
ON_BN_CLICKED(IDC_BUTTON2, OnGetFile)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CTestAppDlg Nachrichten-Handler
|
|
|
|
BOOL CTestAppDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
unlink( CDebug::m_filename );
|
|
|
|
SetIcon(m_hIcon, TRUE);
|
|
SetIcon(m_hIcon, FALSE);
|
|
|
|
SetTimer(0, 50, 0 );
|
|
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CTestAppDlg::OnPaint()
|
|
{
|
|
CDialog::OnPaint();
|
|
}
|
|
|
|
|
|
HCURSOR CTestAppDlg::OnQueryDragIcon()
|
|
{
|
|
return (HCURSOR) m_hIcon;
|
|
}
|
|
|
|
|
|
void CTestAppDlg::OnOK()
|
|
{
|
|
m_inifile.SetVarS("ftppasswd",m_ftp_passwd);
|
|
|
|
m_inifile.SetVarS("ftpuser",m_ftp_user);
|
|
|
|
m_inifile.SetVarS("ftpserver",m_ftp_server);
|
|
|
|
m_inifile.SaveVars("ftpdat.ini");
|
|
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
void CTestAppDlg::OnCancel()
|
|
{
|
|
UpdateData();
|
|
CDialog::OnCancel();
|
|
}
|
|
|
|
|
|
void CTestAppDlg::OnTimer(UINT nIDEvent)
|
|
{
|
|
try
|
|
{
|
|
CStdioFile logfile( CDebug::m_filename, CFile::modeRead );
|
|
|
|
DWORD currentfilepos = (DWORD)logfile.GetLength();
|
|
|
|
// Anything changed?
|
|
if( currentfilepos != m_filepos )
|
|
{
|
|
logfile.Seek( m_filepos, CFile::begin );
|
|
|
|
CString logfile_line;
|
|
while( NULL != logfile.ReadString(logfile_line) )
|
|
{
|
|
logfile_line.Replace("\r"," ");
|
|
m_list.AddString(logfile_line);
|
|
}
|
|
m_filepos = (DWORD)logfile.GetLength();
|
|
m_list.SetCurSel(m_list.GetCount()-1);
|
|
}
|
|
|
|
logfile.Close();
|
|
}
|
|
catch (CFileException* e)
|
|
{
|
|
}
|
|
CDialog::OnTimer(nIDEvent);
|
|
}
|
|
|
|
|
|
/*
|
|
* Connect, Open a Stream
|
|
*/
|
|
void CTestAppDlg::OnConnect()
|
|
{
|
|
UpdateData();
|
|
|
|
// Open FTP Stream
|
|
CString connectstring;
|
|
connectstring = m_ftp_server + ":" + m_ftp_user + ":" + m_ftp_passwd;
|
|
|
|
llfile_eSTREAM ftpstream = llfile_OpenStream(
|
|
LLFILE_STREAM_FTP, // Stream Type
|
|
connectstring // ip:user:pw
|
|
);
|
|
|
|
DebugOutLn("llfile_OpenStream(LLFILE_STREAM_FTP,%s)",connectstring);
|
|
|
|
if( ftpstream == (llfile_eSTREAM)0 ){
|
|
DebugOutLn("Connect Test failed");
|
|
}
|
|
else {
|
|
DebugOutLn("Connection success");
|
|
llfile_PushModule(ftpstream, new CReadHookModule(81920,FtpTransfer,0), HEAD);
|
|
char listbuf[2048];
|
|
memset(listbuf,0,sizeof(listbuf));
|
|
strcpy(listbuf,"/"); // directory list
|
|
llfile_IoCtlStream(ftpstream,"LIST",listbuf);
|
|
DebugOutLn("%s",listbuf);
|
|
llfile_CloseStream(ftpstream);
|
|
}
|
|
|
|
}
|
|
|
|
void CTestAppDlg::OnGetFile()
|
|
{
|
|
DlgEnterFilename dlg;
|
|
|
|
dlg.m_filename = m_inifile.GetVarS("getfile","");
|
|
if( IDOK == dlg.DoModal() ){
|
|
m_inifile.SetVarS("getfile",dlg.m_filename);
|
|
|
|
// Open FTP Stream
|
|
CString connectstring;
|
|
connectstring = m_ftp_server + ":" + m_ftp_user + ":" + m_ftp_passwd;
|
|
llfile_eSTREAM ftpstream = llfile_OpenStream(
|
|
LLFILE_STREAM_FTP, // Stream Type
|
|
connectstring // ip:user:pw
|
|
);
|
|
|
|
DebugOutLn("llfile_OpenStream(LLFILE_STREAM_FTP,%s)",connectstring);
|
|
|
|
if( ftpstream == (llfile_eSTREAM)0 ){
|
|
DebugOutLn("Connect failed");
|
|
}
|
|
else {
|
|
DebugOutLn("Connection success");
|
|
llfile_PushModule(ftpstream, new CReadHookModule(8192,FtpTransfer,0), HEAD);
|
|
|
|
CFTPThread *ftpt = new CFTPThread();
|
|
|
|
ftpt->m_ftp_stream = ftpstream;
|
|
ftpt->m_file = dlg.m_filename;
|
|
|
|
ftpt->Resume();
|
|
DebugOutLn("FTP Thread started");
|
|
}
|
|
|
|
}//
|
|
}
|