Index: src/ch/MainWnd.cpp =================================================================== diff -u -r8f15ad1d2f65340f4f5a30bc95f40a12b0b7dd66 -r4fe995b304ea342b50293f92d3c1992b43b820f7 --- src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 8f15ad1d2f65340f4f5a30bc95f40a12b0b7dd66) +++ src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 4fe995b304ea342b50293f92d3c1992b43b820f7) @@ -44,6 +44,11 @@ #include "TRecentPathsTools.h" #include "DirectoryChooser.h" #include "FeedbackHandlerFactory.h" +#include "../libchcore/TTask.h" +#include "TTaskManagerWrapper.h" +#include "shortcuts.h" +#include "CfgProperties.h" +#include "resource.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -196,7 +201,7 @@ // start clipboard monitoring LOG_INFO(_T("Starting clipboard monitor...")); - CClipboardMonitor::StartMonitor(m_spTasks.get()); + CClipboardMonitor::StartMonitor(m_spTasks); CheckForUpdates(); @@ -380,7 +385,35 @@ void CMainWnd::OnClose() { - PrepareToExit(); + CString strMessage; + try + { + PrepareToExit(); + } + catch(const chcore::TBaseException& e) + { + const size_t stMaxError = 1024; + wchar_t szError[ stMaxError ]; + e.GetErrorInfo(szError, stMaxError); + + strMessage = szError; + } + catch(const std::exception& e) + { + strMessage = e.what(); + } + + if(!strMessage.IsEmpty()) + { + LOG_ERROR(L"Failed to finalize tasks before exiting Copy Handler. Error: " + strMessage); + + ictranslate::CFormat fmt; + + fmt.SetFormat(GetResManager().LoadString(IDS_FINALIZE_CH_ERROR)); + fmt.SetParam(_T("%reason"), strMessage); + AfxMessageBox(fmt, MB_OK | MB_ICONERROR); + } + CWnd::OnClose(); } @@ -389,12 +422,27 @@ switch (nIDEvent) { case 1023: - // autosave timer - KillTimer(1023); - m_spTasks->Store(false); - SetTimer(1023, GetPropValue(GetConfig()), NULL); - break; + { + // autosave timer + KillTimer(1023); + try + { + m_spTasks->Store(false); + } + catch(const std::exception& e) + { + CString strError = e.what(); + ictranslate::CFormat fmt; + fmt.SetFormat(_T("Failed to autosave task. Error: %err.")); + fmt.SetParam(_T("%err"), (PCTSTR)strError); + + LOG_ERROR(fmt); + } + + SetTimer(1023, GetPropValue(GetConfig()), NULL); + break; + } case 3245: // auto-delete finished tasks timer KillTimer(3245); @@ -511,16 +559,9 @@ break; } - // load resource strings - chcore::SetTaskPropValue(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_FIRSTCOPY_STRING)); - chcore::SetTaskPropValue(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_NEXTCOPY_STRING)); + TTaskManagerWrapper tTaskManager(m_spTasks); + tTaskManager.CreateTask(tTaskDefinition); - // create task with the above definition - chcore::TTaskPtr spTask = m_spTasks->CreateTask(tTaskDefinition); - - // add to task list and start processing - spTask->BeginProcessing(); - break; } case eCDType_CommandLineArguments: @@ -621,15 +662,8 @@ chcore::TTaskDefinition tTaskDefinition = dlg.m_tTaskDefinition; - // load resource strings - chcore::SetTaskPropValue(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_FIRSTCOPY_STRING)); - chcore::SetTaskPropValue(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_NEXTCOPY_STRING)); - - // new task - chcore::TTaskPtr spTask = m_spTasks->CreateTask(tTaskDefinition); - - // start - spTask->BeginProcessing(); + TTaskManagerWrapper tTaskManager(m_spTasks); + tTaskManager.CreateTask(tTaskDefinition); } } @@ -647,7 +681,7 @@ { OnShowMiniView(); return static_cast(0); - break; + } case WM_CONFIGNOTIFY: @@ -687,7 +721,7 @@ bool bAddedAnyOption = false; if(GetPropValue(rConfig)) { - spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUCOPY_STRING), rResManager.LoadString(IDS_MENUTIPCOPY_STRING), + spRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUCOPY_STRING), rResManager.LoadString(IDS_MENUTIPCOPY_STRING), TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), false, chcore::eOperation_Copy)); @@ -696,7 +730,7 @@ if(GetPropValue(rConfig)) { - spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUMOVE_STRING), rResManager.LoadString(IDS_MENUTIPMOVE_STRING), + spRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUMOVE_STRING), rResManager.LoadString(IDS_MENUTIPMOVE_STRING), TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move), TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), false, chcore::eOperation_Move)); @@ -705,7 +739,7 @@ if(GetPropValue(rConfig)) { - spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUCOPYMOVESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPCOPYMOVESPECIAL_STRING), + spRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUCOPYMOVESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPCOPYMOVESPECIAL_STRING), TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), true)); @@ -715,7 +749,7 @@ if(bAddedAnyOption) { // insert separator as an addition to other items - spRootItem->AddChild(boost::make_shared()); + spRootItem->AddChild(std::make_shared()); } break; } @@ -724,15 +758,15 @@ { if(GetPropValue(rConfig)) { - spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUPASTE_STRING), rResManager.LoadString(IDS_MENUTIPPASTE_STRING), + spRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUPASTE_STRING), rResManager.LoadString(IDS_MENUTIPPASTE_STRING), TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), TSourcePathsInfo(TSourcePathsInfo::eSrcType_Clipboard), TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializeAuto, chcore::TSmartPath()), false)); } if(GetPropValue(rConfig)) { - spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUPASTESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPPASTESPECIAL_STRING), + spRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUPASTESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPPASTESPECIAL_STRING), TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), TSourcePathsInfo(TSourcePathsInfo::eSrcType_Clipboard), TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializeAuto, chcore::TSmartPath()), true)); @@ -772,10 +806,10 @@ if(GetPropValue(rConfig)) { - boost::shared_ptr menuItem(boost::make_shared(rResManager.LoadString(IDS_MENUCOPYTO_STRING), rResManager.LoadString(IDS_MENUTIPCOPYTO_STRING))); + std::shared_ptr menuItem(std::make_shared(rResManager.LoadString(IDS_MENUCOPYTO_STRING), rResManager.LoadString(IDS_MENUTIPCOPYTO_STRING))); BOOST_FOREACH(const CShortcut& tShortcut, vShortcuts) { - menuItem->AddChild(boost::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, + menuItem->AddChild(std::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), false)); @@ -785,21 +819,21 @@ // optionally separator if(!vShortcuts.empty()) - menuItem->AddChild(boost::make_shared()); + menuItem->AddChild(std::make_shared()); // "Choose" menu option - menuItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), + menuItem->AddChild(std::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), false)); } if(GetPropValue(rConfig)) { - boost::shared_ptr menuItem(boost::make_shared(rResManager.LoadString(IDS_MENUMOVETO_STRING), rResManager.LoadString(IDS_MENUTIPMOVETO_STRING))); + std::shared_ptr menuItem(std::make_shared(rResManager.LoadString(IDS_MENUMOVETO_STRING), rResManager.LoadString(IDS_MENUTIPMOVETO_STRING))); BOOST_FOREACH(const CShortcut& tShortcut, vShortcuts) { - menuItem->AddChild(boost::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, + menuItem->AddChild(std::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move), TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), false)); @@ -809,21 +843,21 @@ // optionally separator if(!vShortcuts.empty()) - menuItem->AddChild(boost::make_shared()); + menuItem->AddChild(std::make_shared()); // "Choose" menu option - menuItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), + menuItem->AddChild(std::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move), TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), false)); } if(GetPropValue(rConfig)) { - boost::shared_ptr menuItem(boost::make_shared(rResManager.LoadString(IDS_MENUCOPYMOVETOSPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPCOPYMOVETOSPECIAL_STRING))); + std::shared_ptr menuItem(std::make_shared(rResManager.LoadString(IDS_MENUCOPYMOVETOSPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPCOPYMOVETOSPECIAL_STRING))); BOOST_FOREACH(const CShortcut& tShortcut, vShortcuts) { - menuItem->AddChild(boost::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, + menuItem->AddChild(std::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), true)); @@ -833,10 +867,10 @@ // optionally separator if(!vShortcuts.empty()) - menuItem->AddChild(boost::make_shared()); + menuItem->AddChild(std::make_shared()); // "Choose" menu option - menuItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), + menuItem->AddChild(std::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), true)); @@ -912,7 +946,6 @@ case WM_TRAYNOTIFY: { return OnTrayNotification(wParam, lParam); - break; } }