-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDlgUpload.cpp
More file actions
421 lines (329 loc) · 9.35 KB
/
DlgUpload.cpp
File metadata and controls
421 lines (329 loc) · 9.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/*******************************************************************
// Copyright (c) 2002, 2003, 2004, 2005,
// Robert Umbehant
// mailto:rumbehant@wheresjames.com
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330,
// Boston, MA 02111-1307 USA
//
*******************************************************************/
// DlgUpload.cpp : implementation file
//
#include "stdafx.h"
#include "vp.h"
#include "DlgUpload.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WM_FTP ( WM_USER + 101 )
/////////////////////////////////////////////////////////////////////////////
// CDlgUpload dialog
CDlgUpload::CDlgUpload(CWnd* pParent /*=NULL*/)
: CDialog(CDlgUpload::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgUpload)
m_sStatus = _T("");
m_sStatusBox = _T("");
//}}AFX_DATA_INIT
m_hFind = NULL;
*m_szRoot = 0;
// *m_szTemp = 0;
m_ptr = 0;
m_buf = NULL;
m_size = NULL;
m_fname = NULL;
}
void CDlgUpload::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgUpload)
DDX_Control(pDX, IDC_PROGRESS, m_progress);
DDX_Text(pDX, IDC_STATUS, m_sStatus);
DDX_Text(pDX, IDC_STATUSBOX, m_sStatusBox);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgUpload, CDialog)
//{{AFX_MSG_MAP(CDlgUpload)
//}}AFX_MSG_MAP
ON_MESSAGE( WM_FTP, OnFtp )
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgUpload message handlers
BOOL CDlgUpload::OnInitDialog()
{
CDialog::OnInitDialog();
// Create temporary filename
// CWinFile::CreateTemp( m_szTemp );
// Setup progress bar
m_dwPos = 0;
m_progress.SetRange( 0, (short)m_dwFileCount );
m_progress.SetPos( 0 );
// Setup for message callbacks
m_ftp.SetMessageTarget( GetSafeHwnd(), WM_FTP );
char username[ CWF_STRSIZE ] = { 0 };
char password[ CWF_STRSIZE ] = { 0 };
if ( FTPSERVERS().GetValue( m_sFtp, "Username", username, sizeof( username ) ) )
{
FTPSERVERS().GetValue( m_sFtp, "Password", password, sizeof( password ) );
// Set username / password
m_ftp.SetUsernamePassword( username, password );
} // end if
// Attempt to connect to the domain
char domain[ CWF_STRSIZE ] = { 0 };
if ( FTPSERVERS().GetValue( m_sFtp, "Address", domain, sizeof( domain ) ) )
{
m_ftp.Connect( domain );
SetStatus( "Connecting ..." );
} // end if
// Lost cause
else
{ AfxMessageBox( "No FTP information" );
OnCancel();
} // end else
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CDlgUpload::Upload( LPCTSTR pPath, LPCTSTR pFtp, CWnd *pwnd, BOOL bModeless)
{
m_ptr = 0;
m_buf = NULL;
m_size = NULL;
m_fname = NULL;
// Sanity checks
if ( pPath == NULL || pFtp == NULL ) return FALSE;
if ( FTPSERVERS().FindGroup( pFtp ) == NULL ) return FALSE;
// Copy ftp server tag name
m_sFtp = pFtp;
// Is window
if ( ::IsWindow( GetSafeHwnd() ) )
{ ShowWindow( SW_SHOWNORMAL );
return FALSE;
} // end if
// How many files?
m_dwFileCount = CWinFile::GetFileCount( pPath );
if ( m_dwFileCount == 0 ) return FALSE;
char search[ MAX_PATH ];
// Verify file
DWORD fa = GetFileAttributes( pPath );
if ( fa == MAXDWORD ) return FALSE;
if ( ( fa & FILE_ATTRIBUTE_DIRECTORY ) != 0 )
{ CWinFile::BuildPath( search, pPath, "*.*" );
strcpy_sz( m_szRoot, pPath );
} // end if
else
{ strcpy_sz( search, pPath );
CWinFile::GetPathFromFileName( pPath, m_szRoot );
} // end else
// Find first file
m_hFind = FindFirstFile( search, &m_fd );
if ( m_hFind == INVALID_HANDLE_VALUE ) return FALSE;
if ( bModeless )
{
// Create the dialog box
if ( GetSafeHwnd() != NULL ) DestroyWindow();
Create( IDD, pwnd );
ShowWindow( SW_SHOWNORMAL );
CenterWindow();
} // end if
return TRUE;
}
BOOL CDlgUpload::UploadFile()
{
char path[ FTP_STRSIZE ];
char upload[ FTP_STRSIZE ] = { 0 };
char root[ FTP_STRSIZE ];
// Get the upload directory
FTPSERVERS().GetValue( m_sFtp, "Folder", root, sizeof( root ) );
do
{
// Any more files?
if ( m_hFind == NULL )
{ SendMessage( WM_CLOSE, 0, 0L );
return FALSE;
} // end if
// Get a real file
while ( !strcmp( m_fd.cFileName, "." ) ||
!strcmp( m_fd.cFileName, ".." ) ||
( m_fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) != 0 )
if ( !FindNextFile( m_hFind, &m_fd ) )
{ SendMessage( WM_CLOSE, 0, 0L );
return FALSE;
} // end if
// Build a full path to the file
CWinFile::BuildPath( path, m_szRoot, m_fd.cFileName );
// Build the upload path
CWinFile::WebBuildPath( upload, root, m_fd.cFileName );
/* LPCTSTR ext = CWinFile::GetExtension( m_fd.cFileName );
if ( !strcmpi( ext, "htm" ) || !strcmpi( ext, "html" ) )
{
// SubstituteStrings( path, m_szTemp );
// strcpy_sz( path, m_szTemp );
} // end if
*/
{ // Update display
m_sStatus = m_fd.cFileName;
m_progress.SetPos( ++m_dwPos );
UpdateData( FALSE );
CWnd *pWnd = GetDlgItem( IDC_STATUS );
if ( pWnd != NULL ) pWnd->RedrawWindow();
pWnd = GetDlgItem( IDC_PROGRESS );
if ( pWnd != NULL ) pWnd->RedrawWindow();
} // end update display
// Get the next file
if ( !FindNextFile( m_hFind, &m_fd ) )
{ FindClose( m_hFind ); m_hFind = NULL; }
// Upload it
} while ( !m_ftp.Upload( path, upload ) );
return TRUE;
}
BOOL CDlgUpload::SubstituteStrings(LPCTSTR pFile, LPCTSTR pSub)
{
CWinFile f1, f2;
// Open files
if ( !f1.OpenExisting( pFile ) || !f2.OpenNew( pSub ) )
return FALSE;
DWORD size = f1.Size();
if ( size == 0 ) return FALSE;
LPBYTE buf = new BYTE[ size + 1 ];
if ( buf == NULL ) return FALSE;
if ( !f1.Read( buf, size ) )
{ delete [] buf; return FALSE; }
// Sub strings
f2.Write( buf, size );
delete [] buf;
return TRUE;
}
/*
void CDlgUpload::OnNetFile(WPARAM wParam, LPARAM lParam)
{
if ( ( wParam & NETFILE_DS_INITIALIZING ) != 0 )
SetStatus( "Initializing ..." );
else if ( ( wParam & NETFILE_DS_CONNECTING ) != 0 )
SetStatus( "Connecting ..." );
else if ( ( wParam & NETFILE_DS_DOWNLOADING ) != 0 )
{
CNetFile *pnf = (CNetFile*)lParam;
if ( pnf != NULL )
{
char msg[ 256 ];
char num[ 256 ];
CWinFile::CreateSizeString( num, pnf->GetDataRead() );
strcpy( msg, "Downloading - " );
strcat( msg, num );
SetStatus( msg );
} // end if
else SetStatus( "Downloading ..." );
} // end if
else if ( ( wParam & NETFILE_DS_UPLOADING ) != 0 )
{
CNetFile *pnf = (CNetFile*)lParam;
if ( pnf != NULL )
{
char msg[ 256 ];
char num[ 256 ];
CWinFile::CreateSizeString( num, pnf->GetDataWritten() );
strcpy( msg, "Uploading - " );
strcat( msg, num );
SetStatus( msg );
} // end if
else SetStatus( "Uploading ..." );
} // end if
else if ( ( wParam & NETFILE_DS_DONE ) != 0 )
{
if ( ( wParam & NETFILE_DS_ERROR ) != 0 ) SetStatus( "Error" );
else SetStatus( "Success" );
// Call next file
if ( !UploadFile() )
{ CWinFile::Delete( m_szTemp );
DestroyWindow();
} // end if
} // end if
}
*/
void CDlgUpload::OnCancel()
{
// m_netfile.Destroy();
m_ftp.Destroy();
if ( m_hFind != NULL )
{ FindClose( m_hFind ); m_hFind = NULL; }
CDialog::OnCancel();
}
void CDlgUpload::SetStatus(LPCTSTR pStatus)
{
m_sStatusBox = pStatus;
CWnd *pSB = GetDlgItem( IDC_STATUSBOX );
if ( pSB != NULL )
{
pSB->SetWindowText( pStatus );
pSB->RedrawWindow();
} // end if
}
LRESULT CDlgUpload::OnFtp(WPARAM wParam, LPARAM lParam)
{
if ( wParam == FTPMSG_CMDCOMPLETE ||
( wParam == FTPMSG_STATUS && lParam == FTP_LOGGEDON ) )
{
m_sStatusBox = "Uploading...";
UpdateData( FALSE );
if ( m_buf == NULL ) UploadFile();
else if ( m_ptr >= m_dwFileCount )
SendMessage( WM_CLOSE, 0, 0L );
else
{
{ // Update display
m_sStatus = m_fname[ m_ptr ];
m_progress.SetPos( ++m_dwPos );
UpdateData( FALSE );
CWnd *pWnd = GetDlgItem( IDC_STATUS );
if ( pWnd != NULL ) pWnd->RedrawWindow();
pWnd = GetDlgItem( IDC_PROGRESS );
if ( pWnd != NULL ) pWnd->RedrawWindow();
} // end update display
// Upload FTP
m_ftp.Upload( (LPBYTE)m_buf[ m_ptr ], m_size[ m_ptr ], m_fname[ m_ptr ] );
// Next file
m_ptr++;
} // end else
} // end if
return 0;
}
BOOL CDlgUpload::Upload(char* *buf, LPDWORD size, char* *fname, CWnd * pwnd, BOOL bModeless)
{
if ( buf == NULL || size == NULL || fname == NULL )
return FALSE;
// Is window
if ( ::IsWindow( GetSafeHwnd() ) )
{ ShowWindow( SW_SHOWNORMAL );
return FALSE;
} // end if
m_dwFileCount = 0;
while ( buf[ m_dwFileCount ] != NULL ) m_dwFileCount++;
if ( m_dwFileCount == 0 ) return FALSE;
// Save data pointers
m_buf = buf;
m_size = size;
m_fname = fname;
// Start with first file
m_ptr = 0;
if ( bModeless )
{
// Create the dialog box
if ( GetSafeHwnd() != NULL ) DestroyWindow();
Create( IDD, pwnd );
ShowWindow( SW_SHOWNORMAL );
CenterWindow();
} // end if
return TRUE;
}