Clone
ixen <ixen@copyhandler.com>
committed
on 23 Nov 16
Made reader and writer threads responsible for waiting for on-the-fly buffers (CH-307).
ParallelizeReaderWriter + 3 more
src/ch/MainWnd.cpp (+44 -37)
445 445                 {
446 446                         // wait state handling section
447 447                         m_tasks.ResumeWaitingTasks((size_t)GetPropValue<PP_CMLIMITMAXOPERATIONS>(GetConfig()));
448 448                         break;
449 449                 }
450 450         }
451 451
452 452         CWnd::OnTimer(nIDEvent);
453 453 }
454 454
455 455 void CMainWnd::OnPopupShowOptions()
456 456 {
457 457         COptionsDlg *pDlg=new COptionsDlg(this);
458 458         pDlg->m_bAutoDelete=true;
459 459         pDlg->m_bLockInstance=true;
460 460         pDlg->Create();
461 461 }
462 462
463 463 BOOL CMainWnd::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
464 464 {
  465         if(!pCopyDataStruct)
  466                 return CWnd::OnCopyData(pWnd, pCopyDataStruct);
  467
  468         switch(pCopyDataStruct->dwData)
  469         {
  470         case eCDType_TaskDefinitionContentSpecial:
  471         case eCDType_TaskDefinitionContent:
  472                 {
465 473                         // load task from buffer
466 474                         wchar_t* pszBuffer = static_cast<wchar_t*>(pCopyDataStruct->lpData);
467 475                         unsigned long ulLen = pCopyDataStruct->cbData / sizeof(wchar_t);
468 476
469 477                         // check if the string ends with '\0', so we can safely use it without length checks
470 478                         if(!pszBuffer || ulLen == 0 || pszBuffer[ulLen - 1] != L'\0')
471 479                                 return FALSE;
472 480
473 481                         chcore::TWStringData wstrData(pszBuffer);
474 482                         //AfxMessageBox(wstrData.GetData());            // TEMP = to remove before commit
475 483
476 484                         chcore::TTaskDefinition tTaskDefinition;
477 485                         tTaskDefinition.LoadFromString(wstrData);
478 486
479 487                         // apply current options from global config; in the future we might want to merge the incoming options with global ones instead of overwriting...
480 488                         chcore::TConfig& rConfig = GetConfig();
481 489                         rConfig.ExtractSubConfig(BRANCH_TASK_SETTINGS, tTaskDefinition.GetConfiguration());
482 490
483 491                         // special operation - modify stuff
484           switch(pCopyDataStruct->dwData & CSharedConfigStruct::OPERATION_MASK)
  492                         if(pCopyDataStruct->dwData == eCDType_TaskDefinitionContentSpecial)
485 493                         {
486           case CSharedConfigStruct::DD_COPYMOVESPECIAL_FLAG:
487           case CSharedConfigStruct::EC_PASTESPECIAL_FLAG:
488           case CSharedConfigStruct::EC_COPYMOVETOSPECIAL_FLAG:
489 494                                 CCustomCopyDlg dlg(tTaskDefinition);
490 495
491 496                                 GetPropValue<PP_RECENTPATHS>(rConfig, dlg.m_vRecent);
492 497
493 498                                 INT_PTR iModalResult;
494 499                                 if((iModalResult = dlg.DoModal()) == IDCANCEL)
495 500                                         return CWnd::OnCopyData(pWnd, pCopyDataStruct);
496 501                                 else if(iModalResult == -1)     // windows has been closed by a parent
497 502                                         return TRUE;
498 503
499 504                                 dlg.m_vRecent.push_back(dlg.m_tTaskDefinition.GetDestinationPath().ToString());
500 505
501 506                                 SetPropValue<PP_RECENTPATHS>(rConfig, dlg.m_vRecent);
502 507
503 508                                 tTaskDefinition = dlg.m_tTaskDefinition;
504 509                         }
505 510
506 511                         // load resource strings
507 512                         SetTaskPropValue<eTO_AlternateFilenameFormatString_First>(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_FIRSTCOPY_STRING));
508 513                         SetTaskPropValue<eTO_AlternateFilenameFormatString_AfterFirst>(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_NEXTCOPY_STRING));
509 514
510 515                         // create task with the above definition
511 516                         CTaskPtr spTask = m_tasks.CreateTask(tTaskDefinition);
512 517
513 518                         // add to task list and start processing
514 519                         spTask->BeginProcessing();
  520                 }
  521         }
515 522
516 523         return CWnd::OnCopyData(pWnd, pCopyDataStruct);
517 524 }
518 525
519 526 void CMainWnd::OnShowMiniView()
520 527 {
521 528         m_pdlgMiniView=new CMiniViewDlg(&m_tasks, &CStatusDlg::m_bLock, this);  // self-deleting
522 529         m_pdlgMiniView->m_bAutoDelete=true;
523 530         m_pdlgMiniView->m_bLockInstance=true;
524 531         m_pdlgMiniView->Create();
525 532 }
526 533
527 534 void CMainWnd::OnPopupCustomCopy()
528 535 {
529 536         chcore::TConfig& rConfig = GetConfig();
530 537
531 538         CCustomCopyDlg dlg;
532 539
533 540         GetPropValue<PP_RECENTPATHS>(rConfig, dlg.m_vRecent);
534 541