Clone
ixen <ixen@copyhandler.com>
committed
on 30 Jan 15
Bugfix: CH crashes when shell ext version mismatch occurs (CH-129).
LoggerImprovements + 5 more
src/ch/MainWnd.cpp (+30 -2)
434 434 {
435 435         if(!pCopyDataStruct)
436 436                 return CWnd::OnCopyData(pWnd, pCopyDataStruct);
437 437
438 438         switch(pCopyDataStruct->dwData)
439 439         {
440 440         case eCDType_TaskDefinitionContentSpecial:
441 441         case eCDType_TaskDefinitionContent:
442 442                 {
443 443                         // load task from buffer
444 444                         wchar_t* pszBuffer = static_cast<wchar_t*>(pCopyDataStruct->lpData);
445 445                         unsigned long ulLen = pCopyDataStruct->cbData / sizeof(wchar_t);
446 446
447 447                         // check if the string ends with '\0', so we can safely use it without length checks
448 448                         if(!pszBuffer || ulLen == 0 || pszBuffer[ulLen - 1] != L'\0')
449 449                                 return FALSE;
450 450
451 451                         chcore::TString wstrData(pszBuffer);
452 452
453 453                         chcore::TTaskDefinition tTaskDefinition;
  454                         CString strError;
  455                         try
  456                         {
454 457                                 tTaskDefinition.LoadFromString(wstrData, true);
  458                         }
  459                         catch(const chcore::TCoreException& e)
  460                         {
  461                                 strError.Format(_T("Error code: %ld"), e.GetErrorCode());
  462                         }
  463                         catch(const std::exception& e)
  464                         {
  465                                 strError.Format(_T("Error message: %s"), e.what());
  466                         }
455 467
  468                         if(!strError.IsEmpty())
  469                         {
  470                                 ictranslate::CFormat fmt;
  471                                 fmt.SetFormat(_T("Cannot import shell extension xml in WM_COPYDATA. Xml: '%xml'. Error: %err."));
  472                                 fmt.SetParam(_T("%xml"), wstrData.c_str());
  473                                 fmt.SetParam(_T("%err"), (PCTSTR)strError);
  474
  475                                 LOG_ERROR(fmt);
  476
  477                                 fmt.SetFormat(GetResManager().LoadString(IDS_SHELLEXT_XML_IMPORT_FAILED));
  478                                 fmt.SetParam(_T("%err"), (PCTSTR)strError);
  479                                 AfxMessageBox(fmt, MB_OK | MB_ICONERROR);
  480
  481                                 break;
  482                         }
  483
456 484                         // apply current options from global config; in the future we might want to merge the incoming options with global ones instead of overwriting...
457 485                         chcore::TConfig& rConfig = GetConfig();
458 486                         rConfig.ExtractSubConfig(BRANCH_TASK_SETTINGS, tTaskDefinition.GetConfiguration());
459 487
460 488                         // special operation - modify stuff
461 489                         if(pCopyDataStruct->dwData == eCDType_TaskDefinitionContentSpecial)
462 490                         {
463 491                                 CCustomCopyDlg dlg(tTaskDefinition);
464 492
465 493                                 GetPropValue<PP_RECENTPATHS>(rConfig, dlg.m_vRecent);
466 494
467 495                                 INT_PTR iModalResult;
468 496                                 if((iModalResult = dlg.DoModal()) == IDCANCEL)
469 497                                         return CWnd::OnCopyData(pWnd, pCopyDataStruct);
470 498                                 else if(iModalResult == -1)     // windows has been closed by a parent
471 499                                         return TRUE;
472 500
473 501                                 TRecentPathsTools::AddNewPath(dlg.m_vRecent, dlg.m_tTaskDefinition.GetDestinationPath().ToString());
474 502
475 503                                 SetPropValue<PP_RECENTPATHS>(rConfig, dlg.m_vRecent);
 
542 570                                 if(spTask)
543 571                                         spTask->Store();
544 572                                 bImported = true;
545 573                         }
546 574                         catch(icpf::exception& e)
547 575                         {
548 576                                 bImported = false;
549 577                                 e.get_info(szBuffer.get(), stBufferSize);
550 578                         }
551 579                         catch(...)
552 580                         {
553 581                                 bImported = false;
554 582                                 szBuffer.get()[0] = _T('\0');
555 583                         }
556 584
557 585                         if(!bImported)
558 586                         {
559 587                                 ictranslate::CFormat fmt;
560 588                                 fmt.SetFormat(_T("Error encountered while importing task from path '%path'. Error: %err."));
561 589                                 fmt.SetParam(_T("%path"), strPath.ToString());
562                                   fmt.SetParam(_T("%error"), szBuffer.get());
  590                                 fmt.SetParam(_T("%err"), szBuffer.get());
563 591
564 592                                 LOG_ERROR(fmt);
565 593
566 594                                 fmt.SetFormat(GetResManager().LoadString(IDS_TASK_IMPORT_FAILED));
567 595                                 fmt.SetParam(_T("%path"), strPath.ToString());
568 596                                 AfxMessageBox(fmt, MB_OK | MB_ICONERROR);
569 597                         }
570 598                 }
571 599         }
572 600 }
573 601
574 602 void CMainWnd::OnShowMiniView()
575 603 {
576 604         m_pdlgMiniView=new CMiniViewDlg(m_spTasks.get(), &CStatusDlg::m_bLock, this);   // self-deleting
577 605         m_pdlgMiniView->m_bAutoDelete=true;
578 606         m_pdlgMiniView->m_bLockInstance=true;
579 607         m_pdlgMiniView->Create();
580 608 }
581 609
582 610 void CMainWnd::OnPopupCustomCopy()