Index: src/ch/MainWnd.cpp =================================================================== diff -u -r8068e0c351055554340ac9755d1bc846893bf2b8 -r7eb1f74a4a5228a71a86f522d22056ff8f616050 --- src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 8068e0c351055554340ac9755d1bc846893bf2b8) +++ src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 7eb1f74a4a5228a71a86f522d22056ff8f616050) @@ -24,20 +24,15 @@ #include "FolderDialog.h" #include "CustomCopyDlg.h" #include "AboutDlg.h" -#include "ShutdownDlg.h" #include "..\common\ipcstructs.h" #include "UpdateChecker.h" #include "UpdaterDlg.h" -#include "FeedbackHandler.h" #include "MiniviewDlg.h" #include "StatusDlg.h" #include "ClipboardMonitor.h" -#include #include #include "../common/TShellExtMenuConfig.h" #include "../libchcore/TConfig.h" -#include "FileSupport.h" -#include "StringHelpers.h" #include "../libchcore/TCoreException.h" #include "../libchcore/TTaskManagerStatsSnapshot.h" #include "../libchcore/TSQLiteSerializerFactory.h" @@ -46,7 +41,6 @@ #include "FeedbackHandlerFactory.h" #include "../libchcore/TTask.h" #include "TTaskManagerWrapper.h" -#include "shortcuts.h" #include "CfgProperties.h" #include "resource.h" @@ -74,13 +68,20 @@ extern unsigned char off[]; extern unsigned short _hash[]; +enum ETimers +{ + eTimer_Autosave = 1023, + eTimer_AutoremoveFinished = 3245, + eTimer_ResumeWaitingTasks = 8743 +}; ///////////////////////////////////////////////////////////////////////////// // CMainWnd ///////////////////////////////////////////////////////////////////////////// // CMainWnd construction/destruction CMainWnd::CMainWnd() : - m_spTaskMgrStats(new chcore::TTaskManagerStatsSnapshot) + m_spTaskMgrStats(new chcore::TTaskManagerStatsSnapshot), + m_spLog(logger::MakeLogger(GetLogFileData(), L"MainWnd")) { } @@ -129,15 +130,10 @@ bool bRes=m_ctlTray.CreateIcon(m_hWnd, WM_TRAYNOTIFY, strText, hIcon, 0); if(!bRes) { -// GetLog()->Log(_T("[CMainWnd] ... creating tray icon failed.")); + LOG_ERROR(m_spLog) << L"Failed to create tray icon"; return -1; } -/* if (!m_ctlTray.ShowIcon()) - GetLog()->Log(_T("[CMainWnd] ... showing tray icon failed.")); - else - GetLog()->Log(_T("[CMainWnd] ... showing tray icon succeeded.")); -*/ return 0; } @@ -188,7 +184,7 @@ if(!LoadTaskManager()) { - LOG_ERROR(_T("Couldn't load task manager data. User did not allow re-creation of the database.")); + LOG_ERROR(m_spLog) << _T("Couldn't load task manager data. User did not allow re-creation of the database."); return -1; } @@ -200,7 +196,7 @@ m_spTasks->TasksRetryProcessing(); // start clipboard monitoring - LOG_INFO(_T("Starting clipboard monitor...")); + LOG_INFO(m_spLog) << _T("Starting clipboard monitor..."); CClipboardMonitor::StartMonitor(m_spTasks); CheckForUpdates(); @@ -229,7 +225,7 @@ if(bCaughtError) { - LOG_ERROR(szErrInfo.get()); + LOG_ERROR(m_spLog) << szErrInfo.get(); return -1; } return 0; @@ -246,7 +242,7 @@ try { - m_spTasks.reset(new chcore::TTaskManager(spSerializerFactory, spFeedbackFactory, PathFromString(strTasksDir))); + m_spTasks.reset(new chcore::TTaskManager(spSerializerFactory, spFeedbackFactory, PathFromString(strTasksDir), GetApp().GetEngineLoggerConfig())); } catch(const std::exception& e) { @@ -257,14 +253,14 @@ { if(MsgBox(IDS_TASKMANAGER_LOAD_FAILED, MB_ICONERROR | MB_OKCANCEL) == IDOK) { - m_spTasks.reset(new chcore::TTaskManager(spSerializerFactory, spFeedbackFactory, PathFromString(strTasksDir), true)); + m_spTasks.reset(new chcore::TTaskManager(spSerializerFactory, spFeedbackFactory, PathFromString(strTasksDir), GetApp().GetEngineLoggerConfig(), true)); } else return false; } // load last state - LOG_INFO(_T("Loading existing tasks...")); + LOG_INFO(m_spLog) << _T("Loading existing tasks..."); // load tasks m_spTasks->Load(); @@ -277,7 +273,6 @@ if (wParam != m_ctlTray.m_tnd.uID) return (LRESULT)FALSE; - TCHAR text[_MAX_PATH]; switch(LOWORD(lParam)) { case WM_LBUTTONDOWN: @@ -342,6 +337,7 @@ { m_spTasks->GetStatsSnapshot(m_spTaskMgrStats); + TCHAR text[ _MAX_PATH ]; _sntprintf(text, _MAX_PATH, _T("%s - %.0f %%"), GetApp().GetAppName(), m_spTaskMgrStats->GetCombinedProgress() * 100.0); m_ctlTray.SetTooltipText(text); } @@ -405,7 +401,7 @@ if(!strMessage.IsEmpty()) { - LOG_ERROR(L"Failed to finalize tasks before exiting Copy Handler. Error: " + strMessage); + LOG_ERROR(m_spLog) << L"Failed to finalize tasks before exiting Copy Handler. Error: " + strMessage; ictranslate::CFormat fmt; @@ -421,10 +417,10 @@ { switch (nIDEvent) { - case 1023: + case eTimer_Autosave: { // autosave timer - KillTimer(1023); + KillTimer(eTimer_Autosave); try { m_spTasks->Store(false); @@ -437,15 +433,15 @@ fmt.SetFormat(_T("Failed to autosave task. Error: %err.")); fmt.SetParam(_T("%err"), (PCTSTR)strError); - LOG_ERROR(fmt); + LOG_ERROR(m_spLog) << fmt; } - SetTimer(1023, GetPropValue(GetConfig()), nullptr); + SetTimer(eTimer_Autosave, GetPropValue(GetConfig()), nullptr); break; } - case 3245: + case eTimer_AutoremoveFinished: // auto-delete finished tasks timer - KillTimer(3245); + KillTimer(eTimer_AutoremoveFinished); if (GetPropValue(GetConfig())) { size_t stSize = m_spTasks->GetSize(); @@ -454,10 +450,10 @@ m_pdlgStatus->SendMessage(WM_UPDATESTATUS); } - SetTimer(3245, TM_AUTOREMOVE, nullptr); + SetTimer(eTimer_AutoremoveFinished, TM_AUTOREMOVE, nullptr); break; - case 8743: + case eTimer_ResumeWaitingTasks: { // wait state handling section m_spTasks->ResumeWaitingTasks((size_t)GetPropValue(GetConfig())); @@ -496,6 +492,8 @@ chcore::TString wstrData(pszBuffer); + LOG_DEBUG(m_spLog) << L"Received task definition to process: " << wstrData; + chcore::TTaskDefinition tTaskDefinition; CString strError; try @@ -504,7 +502,7 @@ } catch(const chcore::TCoreException& e) { - strError.Format(_T("Error code: %ld"), e.GetErrorCode()); + strError.Format(_T("Error code: %d"), e.GetErrorCode()); } catch(const std::exception& e) { @@ -518,7 +516,7 @@ fmt.SetParam(_T("%xml"), wstrData.c_str()); fmt.SetParam(_T("%err"), (PCTSTR)strError); - LOG_ERROR(fmt); + LOG_ERROR(m_spLog) << fmt; fmt.SetFormat(GetResManager().LoadString(IDS_SHELLEXT_XML_IMPORT_FAILED)); fmt.SetParam(_T("%err"), (PCTSTR)strError); @@ -628,7 +626,7 @@ fmt.SetParam(_T("%path"), strPath.ToString()); fmt.SetParam(_T("%err"), szBuffer.get()); - LOG_ERROR(fmt); + LOG_ERROR(m_spLog) << fmt; fmt.SetFormat(GetResManager().LoadString(IDS_TASK_IMPORT_FAILED)); fmt.SetParam(_T("%path"), strPath.ToString()); @@ -695,228 +693,15 @@ break; } - case WM_GETCONFIG: - { - try - { - chcore::TConfig& rConfig = GetConfig(); - ictranslate::CResourceManager& rResManager = GetResManager(); - - TShellExtMenuConfig cfgShellExt; - - // experimental - doesn't work on all systems - cfgShellExt.SetShowShortcutIcons(GetPropValue(rConfig)); - - cfgShellExt.SetInterceptDragAndDrop(GetPropValue(rConfig)); - cfgShellExt.SetInterceptKeyboardActions(GetPropValue(rConfig)); - cfgShellExt.SetInterceptCtxMenuActions(GetPropValue(rConfig)); - - TShellMenuItemPtr spRootItem = cfgShellExt.GetCommandRoot(); - - // what kind of menu ? - switch(wParam) - { - case eLocation_DragAndDropMenu: - { - bool bAddedAnyOption = false; - if(GetPropValue(rConfig)) - { - 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)); - bAddedAnyOption = true; - } - - if(GetPropValue(rConfig)) - { - 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)); - bAddedAnyOption = true; - } - - if(GetPropValue(rConfig)) - { - 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)); - bAddedAnyOption = true; - } - - if(bAddedAnyOption) - { - // insert separator as an addition to other items - spRootItem->AddChild(std::make_shared()); - } - break; - } - - case eLocation_ContextMenu: - { - if(GetPropValue(rConfig)) - { - 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(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)); - } - - if(GetPropValue(rConfig) || GetPropValue(rConfig) || GetPropValue(rConfig)) - { - // prepare shortcuts for all menu options - std::vector vShortcutStrings; - GetPropValue(rConfig, vShortcutStrings); - - bool bRetrieveFreeSpace = GetPropValue(rConfig); - - std::vector vShortcuts; - - BOOST_FOREACH(const CString& strShortcutString, vShortcutStrings) - { - CShortcut tShortcut; - if(tShortcut.FromString(strShortcutString)) - { - unsigned long long ullSize = 0; - - // retrieving free space might fail, but it's not critical - we just won't show the free space - if(bRetrieveFreeSpace && GetDynamicFreeSpace(tShortcut.m_strPath, &ullSize, nullptr)) - { - CString strNameFormat; - strNameFormat.Format(_T("%s (%s)"), tShortcut.m_strName, GetSizeString(ullSize)); - - tShortcut.m_strName = strNameFormat; - } - - vShortcuts.push_back(tShortcut); - } - else - BOOST_ASSERT(false); // non-critical, but not very nice - } - - if(GetPropValue(rConfig)) - { - 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(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)); - } - - spRootItem->AddChild(menuItem); - - // optionally separator - if(!vShortcuts.empty()) - menuItem->AddChild(std::make_shared()); - - // "Choose" menu option - 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)) - { - 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(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)); - } - - spRootItem->AddChild(menuItem); - - // optionally separator - if(!vShortcuts.empty()) - menuItem->AddChild(std::make_shared()); - - // "Choose" menu option - 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)) - { - 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(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)); - } - - spRootItem->AddChild(menuItem); - - // optionally separator - if(!vShortcuts.empty()) - menuItem->AddChild(std::make_shared()); - - // "Choose" menu option - 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)); - } - } - - break; - } - - default: - ASSERT(false); // unhandled case - } - - chcore::TConfig cfgStorage; - chcore::TString wstrData; - - cfgShellExt.StoreInConfig(cfgStorage, _T("ShellExtCfg")); - cfgStorage.WriteToString(wstrData); - - std::wstring strSHMName = IPCSupport::GenerateSHMName((unsigned long)lParam); - - m_tCHExtharedMemory.Create(strSHMName.c_str(), wstrData); - } - catch(const std::exception& e) - { - _ASSERTE(FALSE); - CString strMsg; - strMsg.Format(L"Encountered problem trying to retrieve shell ext configuration.\nReason: %S", e.what()); - LOG_ERROR(strMsg); - - return FALSE; - } - - return TRUE; - } - case WM_IDENTIFY: { //decode unsigned char *dec=new unsigned char[iCount+1]; dec[iCount]=0; - unsigned short sData; for (int i=0, j=0;i(msg[i] - _hash[j]); + unsigned short sData=static_cast(msg[i] - _hash[j]); sData >>= off[j]; dec[i]=static_cast(sData); @@ -1062,7 +847,7 @@ // perform checking for updates only when the minimal interval has passed if(ullCurrentStamp - ullTimestamp >= ullMinInterval) { - LOG_INFO(_T("Checking for updates...")); + LOG_INFO(m_spLog) << _T("Checking for updates..."); CUpdaterDlg* pDlg = new CUpdaterDlg(true); pDlg->m_bAutoDelete = true; @@ -1076,7 +861,7 @@ } catch(const std::exception& /*e*/) { - LOG_ERROR(_T("Storing last update check timestamp in configuration failed")); + LOG_ERROR(m_spLog) << _T("Storing last update check timestamp in configuration failed"); } } } @@ -1085,8 +870,8 @@ void CMainWnd::SetupTimers() { // start saving timer - SetTimer(1023, GetPropValue(GetConfig()), nullptr); + SetTimer(eTimer_Autosave, GetPropValue(GetConfig()), nullptr); - SetTimer(3245, TM_AUTOREMOVE, nullptr); - SetTimer(8743, TM_ACCEPTING, nullptr); // ends wait state in tasks + SetTimer(eTimer_AutoremoveFinished, TM_AUTOREMOVE, nullptr); + SetTimer(eTimer_ResumeWaitingTasks, TM_ACCEPTING, nullptr); // ends wait state in tasks }