-rw-r--r-- | PumpKINDlg.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/PumpKINDlg.cpp b/PumpKINDlg.cpp index 0b3bf41..fc24596 100644 --- a/PumpKINDlg.cpp +++ b/PumpKINDlg.cpp | |||
@@ -234,192 +234,193 @@ CRect rc, drc; | |||
234 | } | 234 | } |
235 | return TRUE; // return TRUE unless you set the focus to a control | 235 | return TRUE; // return TRUE unless you set the focus to a control |
236 | } | 236 | } |
237 | 237 | ||
238 | void CPumpKINDlg::OnSysCommand(UINT nID, LPARAM lParam) | 238 | void CPumpKINDlg::OnSysCommand(UINT nID, LPARAM lParam) |
239 | { | 239 | { |
240 | if ((nID & 0xFFF0) == IDM_ABOUTBOX) | 240 | if ((nID & 0xFFF0) == IDM_ABOUTBOX) |
241 | { | 241 | { |
242 | CAboutDlg dlgAbout; | 242 | CAboutDlg dlgAbout; |
243 | dlgAbout.DoModal(); | 243 | dlgAbout.DoModal(); |
244 | } | 244 | } |
245 | else | 245 | else |
246 | { | 246 | { |
247 | CDialog::OnSysCommand(nID, lParam); | 247 | CDialog::OnSysCommand(nID, lParam); |
248 | } | 248 | } |
249 | } | 249 | } |
250 | 250 | ||
251 | void CPumpKINDlg::OnDestroy() | 251 | void CPumpKINDlg::OnDestroy() |
252 | { | 252 | { |
253 | SaveSettings(); | 253 | SaveSettings(); |
254 | 254 | ||
255 | NOTIFYICONDATA nid; | 255 | NOTIFYICONDATA nid; |
256 | memset(&nid,0,sizeof(nid)); | 256 | memset(&nid,0,sizeof(nid)); |
257 | nid.cbSize=sizeof(nid); | 257 | nid.cbSize=sizeof(nid); |
258 | nid.hWnd=m_Trayer->m_hWnd; | 258 | nid.hWnd=m_Trayer->m_hWnd; |
259 | nid.uID=IDC_TRAYICON; | 259 | nid.uID=IDC_TRAYICON; |
260 | nid.uFlags=0; | 260 | nid.uFlags=0; |
261 | VERIFY(Shell_NotifyIcon(NIM_DELETE,&nid)); | 261 | VERIFY(Shell_NotifyIcon(NIM_DELETE,&nid)); |
262 | 262 | ||
263 | WinHelp(0L, HELP_QUIT); | 263 | WinHelp(0L, HELP_QUIT); |
264 | CDialog::OnDestroy(); | 264 | CDialog::OnDestroy(); |
265 | POSITION p = m_LogTimes.GetStartPosition(); | 265 | POSITION p = m_LogTimes.GetStartPosition(); |
266 | while(p){ | 266 | while(p){ |
267 | CTime *t,*tt; | 267 | CTime *t,*tt; |
268 | m_LogTimes.GetNextAssoc(p,t,tt); | 268 | m_LogTimes.GetNextAssoc(p,t,tt); |
269 | ASSERT(t && tt && t==tt); | 269 | ASSERT(t && tt && t==tt); |
270 | delete t; | 270 | delete t; |
271 | } | 271 | } |
272 | // *** Abort and cleanup transfers | 272 | // *** Abort and cleanup transfers |
273 | m_LogTimes.RemoveAll(); | 273 | m_LogTimes.RemoveAll(); |
274 | } | 274 | } |
275 | 275 | ||
276 | // If you add a minimize button to your dialog, you will need the code below | 276 | // If you add a minimize button to your dialog, you will need the code below |
277 | // to draw the icon. For MFC applications using the document/view model, | 277 | // to draw the icon. For MFC applications using the document/view model, |
278 | // this is automatically done for you by the framework. | 278 | // this is automatically done for you by the framework. |
279 | 279 | ||
280 | void CPumpKINDlg::OnPaint() | 280 | void CPumpKINDlg::OnPaint() |
281 | { | 281 | { |
282 | if (IsIconic()) | 282 | if (IsIconic()) |
283 | { | 283 | { |
284 | CPaintDC dc(this); // device context for painting | 284 | CPaintDC dc(this); // device context for painting |
285 | 285 | ||
286 | SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); | 286 | SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); |
287 | 287 | ||
288 | // Center icon in client rectangle | 288 | // Center icon in client rectangle |
289 | int cxIcon = GetSystemMetrics(SM_CXICON); | 289 | int cxIcon = GetSystemMetrics(SM_CXICON); |
290 | int cyIcon = GetSystemMetrics(SM_CYICON); | 290 | int cyIcon = GetSystemMetrics(SM_CYICON); |
291 | CRect rect; | 291 | CRect rect; |
292 | GetClientRect(&rect); | 292 | GetClientRect(&rect); |
293 | int x = (rect.Width() - cxIcon + 1) / 2; | 293 | int x = (rect.Width() - cxIcon + 1) / 2; |
294 | int y = (rect.Height() - cyIcon + 1) / 2; | 294 | int y = (rect.Height() - cyIcon + 1) / 2; |
295 | 295 | ||
296 | // Draw the icon | 296 | // Draw the icon |
297 | dc.DrawIcon(x, y, m_hIcon); | 297 | dc.DrawIcon(x, y, m_hIcon); |
298 | } | 298 | } |
299 | else | 299 | else |
300 | { | 300 | { |
301 | CPaintDC pDC(this); | 301 | CPaintDC pDC(this); |
302 | CDC bmpDC; | 302 | CDC bmpDC; |
303 | bmpDC.CreateCompatibleDC(&pDC); | 303 | bmpDC.CreateCompatibleDC(&pDC); |
304 | bmpDC.SelectObject(&m_bmpBack); | 304 | bmpDC.SelectObject(&m_bmpBack); |
305 | CRect rc; | 305 | CRect rc; |
306 | GetClientRect(&rc); | 306 | GetClientRect(&rc); |
307 | for(int x=-m_bitmapBack.bmWidth*2/4;x<rc.Width();x+=m_bitmapBack.bmWidth) | 307 | for(int x=-m_bitmapBack.bmWidth*2/4;x<rc.Width();x+=m_bitmapBack.bmWidth) |
308 | for(int y=-m_bitmapBack.bmHeight*2/4;y<rc.Height();y+=m_bitmapBack.bmHeight) | 308 | for(int y=-m_bitmapBack.bmHeight*2/4;y<rc.Height();y+=m_bitmapBack.bmHeight) |
309 | pDC.BitBlt(x,y,m_bitmapBack.bmWidth,m_bitmapBack.bmHeight,&bmpDC,0,0,SRCCOPY); | 309 | pDC.BitBlt(x,y,m_bitmapBack.bmWidth,m_bitmapBack.bmHeight,&bmpDC,0,0,SRCCOPY); |
310 | bmpDC.DeleteDC(); | 310 | bmpDC.DeleteDC(); |
311 | CDialog::OnPaint(); | 311 | CDialog::OnPaint(); |
312 | } | 312 | } |
313 | } | 313 | } |
314 | 314 | ||
315 | // The system calls this to obtain the cursor to display while the user drags | 315 | // The system calls this to obtain the cursor to display while the user drags |
316 | // the minimized window. | 316 | // the minimized window. |
317 | HCURSOR CPumpKINDlg::OnQueryDragIcon() | 317 | HCURSOR CPumpKINDlg::OnQueryDragIcon() |
318 | { | 318 | { |
319 | return (HCURSOR) m_hIcon; | 319 | return (HCURSOR) m_hIcon; |
320 | } | 320 | } |
321 | 321 | ||
322 | int CPumpKINDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) | 322 | int CPumpKINDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) |
323 | { | 323 | { |
324 | if (CDialog::OnCreate(lpCreateStruct) == -1) | 324 | if (CDialog::OnCreate(lpCreateStruct) == -1) |
325 | return -1; | 325 | return -1; |
326 | 326 | ||
327 | m_Listener.m_Daddy=this; | 327 | m_Listener.m_Daddy=this; |
328 | if(!m_Listener.Create(m_ListenPort,SOCK_DGRAM)){ | 328 | if(!m_Listener.Create(m_ListenPort,SOCK_DGRAM)){ |
329 | TRACE0("Failed to create socket\n"); | 329 | TRACE0("Failed to create socket\n"); |
330 | AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION); | ||
330 | return -1; | 331 | return -1; |
331 | } | 332 | } |
332 | 333 | ||
333 | if(!m_Trayer->Create(NULL,"PumpKIN TrayIcon",WS_CHILD,CRect(0,0,0,0),this,0)){ | 334 | if(!m_Trayer->Create(NULL,"PumpKIN TrayIcon",WS_CHILD,CRect(0,0,0,0),this,0)){ |
334 | TRACE0("Failed to create trayer\n"); | 335 | TRACE0("Failed to create trayer\n"); |
335 | return -1; | 336 | return -1; |
336 | } | 337 | } |
337 | 338 | ||
338 | NOTIFYICONDATA nid; | 339 | NOTIFYICONDATA nid; |
339 | memset(&nid,0,sizeof(nid)); | 340 | memset(&nid,0,sizeof(nid)); |
340 | nid.cbSize=sizeof(nid); | 341 | nid.cbSize=sizeof(nid); |
341 | nid.hWnd=m_Trayer->m_hWnd; | 342 | nid.hWnd=m_Trayer->m_hWnd; |
342 | nid.uID=IDC_TRAYICON; | 343 | nid.uID=IDC_TRAYICON; |
343 | nid.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP; | 344 | nid.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP; |
344 | nid.uCallbackMessage=WM_TRAYICON; | 345 | nid.uCallbackMessage=WM_TRAYICON; |
345 | nid.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME); | 346 | nid.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME); |
346 | // *** Load from resource | 347 | // *** Load from resource |
347 | strcpy(nid.szTip,"PumpKIN"); | 348 | strcpy(nid.szTip,"PumpKIN"); |
348 | VERIFY(Shell_NotifyIcon(NIM_ADD,&nid)); | 349 | VERIFY(Shell_NotifyIcon(NIM_ADD,&nid)); |
349 | 350 | ||
350 | return 0; | 351 | return 0; |
351 | } | 352 | } |
352 | 353 | ||
353 | void CListenSocket::OnReceive(int nErrorCode) | 354 | void CListenSocket::OnReceive(int nErrorCode) |
354 | { | 355 | { |
355 | ASSERT(m_Daddy); | 356 | ASSERT(m_Daddy); |
356 | if(nErrorCode){ | 357 | if(nErrorCode){ |
357 | m_Daddy->LogLine(IDS_LOG_LISTENRECEIVEERROR); | 358 | m_Daddy->LogLine(IDS_LOG_LISTENRECEIVEERROR); |
358 | return; | 359 | return; |
359 | } | 360 | } |
360 | DWORD fionread = 0; | 361 | DWORD fionread = 0; |
361 | VERIFY(IOCtl(FIONREAD,&fionread));// *** Do some checking on the value acquired | 362 | VERIFY(IOCtl(FIONREAD,&fionread));// *** Do some checking on the value acquired |
362 | tftp *tftpRQ = tftp::Allocate(fionread); | 363 | tftp *tftpRQ = tftp::Allocate(fionread); |
363 | ASSERT(tftpRQ); | 364 | ASSERT(tftpRQ); |
364 | SOCKADDR_IN sin; | 365 | SOCKADDR_IN sin; |
365 | if(!tftpRQ->Receive(this,fionread,&sin)){ | 366 | if(!tftpRQ->Receive(this,fionread,&sin)){ |
366 | m_Daddy->LogLine(IDS_LOG_LISTENACCEPTERROR); | 367 | m_Daddy->LogLine(IDS_LOG_LISTENACCEPTERROR); |
367 | delete tftpRQ; | 368 | delete tftpRQ; |
368 | return; | 369 | return; |
369 | } | 370 | } |
370 | #ifndefNDEBUG | 371 | #ifndefNDEBUG |
371 | CString tmp; | 372 | CString tmp; |
372 | tmp.Format("%u - %s - %u\n",tftpRQ->Opcode(),inet_ntoa(sin.sin_addr),sin.sin_port); | 373 | tmp.Format("%u - %s - %u\n",tftpRQ->Opcode(),inet_ntoa(sin.sin_addr),sin.sin_port); |
373 | TRACE0(tmp); | 374 | TRACE0(tmp); |
374 | #endif | 375 | #endif |
375 | POSITION p = m_Daddy->m_Xfers.GetStartPosition(); | 376 | POSITION p = m_Daddy->m_Xfers.GetStartPosition(); |
376 | while(p){ | 377 | while(p){ |
377 | SOCKET key; | 378 | SOCKET key; |
378 | CXferSocket *sock; | 379 | CXferSocket *sock; |
379 | m_Daddy->m_Xfers.GetNextAssoc(p,key,sock); | 380 | m_Daddy->m_Xfers.GetNextAssoc(p,key,sock); |
380 | ASSERT(sock); | 381 | ASSERT(sock); |
381 | if(sock->m_Peer.sin_addr.s_addr==sin.sin_addr.s_addr && sock->m_Peer.sin_port==sin.sin_port){ | 382 | if(sock->m_Peer.sin_addr.s_addr==sin.sin_addr.s_addr && sock->m_Peer.sin_port==sin.sin_port){ |
382 | TRACE0("Ignoring request which we are already processing\n"); | 383 | TRACE0("Ignoring request which we are already processing\n"); |
383 | delete tftpRQ; | 384 | delete tftpRQ; |
384 | return; | 385 | return; |
385 | } | 386 | } |
386 | } | 387 | } |
387 | switch(tftpRQ->Opcode()){ | 388 | switch(tftpRQ->Opcode()){ |
388 | case tftp::opRRQ: | 389 | case tftp::opRRQ: |
389 | // Read Request | 390 | // Read Request |
390 | { | 391 | { |
391 | CString tmp; | 392 | CString tmp; |
392 | tmp.Format(IDS_LOG_RRQSERVE,tftpRQ->rqFileName(),tftpRQ->rqType(),inet_ntoa(sin.sin_addr)); | 393 | tmp.Format(IDS_LOG_RRQSERVE,tftpRQ->rqFileName(),tftpRQ->rqType(),inet_ntoa(sin.sin_addr)); |
393 | m_Daddy->LogLine(tmp); | 394 | m_Daddy->LogLine(tmp); |
394 | CRRQSocket *s = new CRRQSocket(m_Daddy,tftpRQ->rqFileName(),tftpRQ->rqType(),&sin); | 395 | CRRQSocket *s = new CRRQSocket(m_Daddy,tftpRQ->rqFileName(),tftpRQ->rqType(),&sin); |
395 | ASSERT(s); | 396 | ASSERT(s); |
396 | tftpRQ->GetOptions(&s->m_Options); | 397 | tftpRQ->GetOptions(&s->m_Options); |
397 | if(!s->Create()) | 398 | if(!s->Create()) |
398 | s->Destroy(FALSE); | 399 | s->Destroy(FALSE); |
399 | } | 400 | } |
400 | break; | 401 | break; |
401 | case tftp::opWRQ: | 402 | case tftp::opWRQ: |
402 | // Write Request | 403 | // Write Request |
403 | { | 404 | { |
404 | CString tmp; | 405 | CString tmp; |
405 | tmp.Format(IDS_LOG_WRQSERVE,tftpRQ->rqFileName(),tftpRQ->rqType(),inet_ntoa(sin.sin_addr)); | 406 | tmp.Format(IDS_LOG_WRQSERVE,tftpRQ->rqFileName(),tftpRQ->rqType(),inet_ntoa(sin.sin_addr)); |
406 | m_Daddy->LogLine(tmp); | 407 | m_Daddy->LogLine(tmp); |
407 | CWRQSocket *s = new CWRQSocket(m_Daddy,tftpRQ->rqFileName(),tftpRQ->rqType(),&sin); | 408 | CWRQSocket *s = new CWRQSocket(m_Daddy,tftpRQ->rqFileName(),tftpRQ->rqType(),&sin); |
408 | ASSERT(s); | 409 | ASSERT(s); |
409 | tftpRQ->GetOptions(&s->m_Options); | 410 | tftpRQ->GetOptions(&s->m_Options); |
410 | if(!s->Create(NULL,NULL)) | 411 | if(!s->Create(NULL,NULL)) |
411 | s->Destroy(FALSE); | 412 | s->Destroy(FALSE); |
412 | } | 413 | } |
413 | break; | 414 | break; |
414 | default: | 415 | default: |
415 | m_Daddy->LogLine(IDS_LOG_LISTENOPCODE); | 416 | m_Daddy->LogLine(IDS_LOG_LISTENOPCODE); |
416 | delete tftpRQ; | 417 | delete tftpRQ; |
417 | return; | 418 | return; |
418 | } | 419 | } |
419 | delete tftpRQ; | 420 | delete tftpRQ; |
420 | } | 421 | } |
421 | 422 | ||
422 | BOOL tftp::Receive(CAsyncSocket* socket,UINT maxLength,SOCKADDR_IN *sin) | 423 | BOOL tftp::Receive(CAsyncSocket* socket,UINT maxLength,SOCKADDR_IN *sin) |
423 | { | 424 | { |
424 | ASSERT(socket); | 425 | ASSERT(socket); |
425 | int saddrLen = sizeof(SOCKADDR_IN); | 426 | int saddrLen = sizeof(SOCKADDR_IN); |