Index: src/ch/ClipboardMonitor.cpp =================================================================== diff -u -rf703b71b8c856e2538283555e9fdbc84918677c3 -rb55cf150df571c279536a2b4e33bcecedef17305 --- src/ch/ClipboardMonitor.cpp (.../ClipboardMonitor.cpp) (revision f703b71b8c856e2538283555e9fdbc84918677c3) +++ src/ch/ClipboardMonitor.cpp (.../ClipboardMonitor.cpp) (revision b55cf150df571c279536a2b4e33bcecedef17305) @@ -102,8 +102,6 @@ // register clipboard format UINT nFormat=RegisterClipboardFormat(_T("Preferred DropEffect")); UINT uiCounter=0, uiShutCounter=0; - LONG lFinished=0; - bool bEnd=false; icpf::config& rConfig = GetConfig(); for(;;) @@ -256,64 +254,50 @@ } // do we need to check for turning computer off - if (GetConfig().get_bool(PP_PSHUTDOWNAFTREFINISHED)) + if(uiShutCounter == 0 && GetConfig().get_bool(PP_PSHUTDOWNAFTREFINISHED)) { - if (uiShutCounter == 0) + if(pData->m_pTasks->AreAllFinished()) { - if (lFinished != pData->m_pTasks->m_lFinished) + TRACE("Shut down windows\n"); + bool bShutdown=true; + if (GetConfig().get_signed_num(PP_PTIMEBEFORESHUTDOWN) != 0) { - bEnd=true; - lFinished=pData->m_pTasks->m_lFinished; + CShutdownDlg dlg; + dlg.m_iOverallTime = boost::numeric_cast(GetConfig().get_signed_num(PP_PTIMEBEFORESHUTDOWN)); + if (dlg.m_iOverallTime < 0) + dlg.m_iOverallTime=-dlg.m_iOverallTime; + bShutdown=(dlg.DoModal() != IDCANCEL); } - if (bEnd && pData->m_pTasks->IsFinished()) + GetConfig().set_bool(PP_PSHUTDOWNAFTREFINISHED, false); + GetConfig().write(NULL); + if (bShutdown) { - TRACE("Shut down windows\n"); - bool bShutdown=true; - if (GetConfig().get_signed_num(PP_PTIMEBEFORESHUTDOWN) != 0) + // adjust token privileges for NT + HANDLE hToken=NULL; + TOKEN_PRIVILEGES tp; + if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken) + && LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tp.Privileges[0].Luid)) { - CShutdownDlg dlg; - dlg.m_iOverallTime = boost::numeric_cast(GetConfig().get_signed_num(PP_PTIMEBEFORESHUTDOWN)); - if (dlg.m_iOverallTime < 0) - dlg.m_iOverallTime=-dlg.m_iOverallTime; - bShutdown=(dlg.DoModal() != IDCANCEL); + tp.PrivilegeCount=1; + tp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; + + AdjustTokenPrivileges(hToken, FALSE, &tp, NULL, NULL, NULL); } - GetConfig().set_bool(PP_PSHUTDOWNAFTREFINISHED, false); - GetConfig().write(NULL); - if (bShutdown) + BOOL bExit=ExitWindowsEx(EWX_POWEROFF | EWX_SHUTDOWN | (GetConfig().get_bool(PP_PFORCESHUTDOWN) ? EWX_FORCE : 0), 0); + if (bExit) + return 1; + else { - // adjust token privileges for NT - HANDLE hToken=NULL; - TOKEN_PRIVILEGES tp; - if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken) - && LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tp.Privileges[0].Luid)) - { - tp.PrivilegeCount=1; - tp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; - - AdjustTokenPrivileges(hToken, FALSE, &tp, NULL, NULL, NULL); - } - - BOOL bExit=ExitWindowsEx(EWX_POWEROFF | EWX_SHUTDOWN | (GetConfig().get_bool(PP_PFORCESHUTDOWN) ? EWX_FORCE : 0), 0); - if (bExit) - return 1; - else - { - // some kind of error - ictranslate::CFormat fmt(GetResManager().LoadString(IDS_SHUTDOWNERROR_STRING)); - fmt.SetParam(_t("%errno"), GetLastError()); - AfxMessageBox(fmt, MB_ICONERROR | MB_OK | MB_SYSTEMMODAL); - } + // some kind of error + ictranslate::CFormat fmt(GetResManager().LoadString(IDS_SHUTDOWNERROR_STRING)); + fmt.SetParam(_t("%errno"), GetLastError()); + AfxMessageBox(fmt, MB_ICONERROR | MB_OK | MB_SYSTEMMODAL); } } } } - else - { - bEnd=false; - lFinished=pData->m_pTasks->m_lFinished; - } // sleep for some time const int iSleepCount=200; Index: src/ch/task.cpp =================================================================== diff -u -rcf2edb7c2fd0a5561d730449efa73b0f634cf3b0 -rb55cf150df571c279536a2b4e33bcecedef17305 --- src/ch/task.cpp (.../task.cpp) (revision cf2edb7c2fd0a5561d730449efa73b0f634cf3b0) +++ src/ch/task.cpp (.../task.cpp) (revision b55cf150df571c279536a2b4e33bcecedef17305) @@ -63,7 +63,7 @@ //////////////////////////////////////////////////////////////////////////// // CTask members -CTask::CTask(chcore::IFeedbackHandler* piFeedbackHandler, const TASK_CREATE_DATA *pCreateData, size_t stSessionUniqueID, TTasksGlobalStats& tGlobalStats) : +CTask::CTask(chcore::IFeedbackHandler* piFeedbackHandler, size_t stSessionUniqueID, TTasksGlobalStats& tGlobalStats) : m_log(), m_piFeedbackHandler(piFeedbackHandler), m_files(m_clipboard), @@ -82,7 +82,6 @@ m_ucCopies(1), m_ucCurrentCopy(0), m_uiResumeInterval(0), - m_plFinished(pCreateData->plFinished), m_bForce(false), m_bContinue(false), m_bSaved(false), @@ -2302,15 +2301,11 @@ pTask->m_log.logi(fmt); // we have been killed - the last operation - InterlockedIncrement(pTask->m_plFinished); pTask->CleanupAfterKill(); pTask->SetKilledFlag(); } catch(CProcessingException* e) { - // increment count of beginnings - InterlockedIncrement(pTask->m_plFinished); - // refresh time pTask->UpdateTime(); @@ -2481,7 +2476,6 @@ //////////////////////////////////////////////////////////////////////////////// // CTaskArray members CTaskArray::CTaskArray() : - m_lFinished(0), m_piFeedbackFactory(NULL), m_stNextSessionUniqueID(0) { @@ -2496,8 +2490,6 @@ { BOOST_ASSERT(piFeedbackHandlerFactory); - m_tcd.pLock=&m_lock; - m_tcd.plFinished=&m_lFinished; m_piFeedbackFactory = piFeedbackHandlerFactory; } @@ -2511,7 +2503,7 @@ if(!piHandler) return CTaskPtr(); - CTaskPtr spTask(new CTask(piHandler, &m_tcd, m_stNextSessionUniqueID++, m_globalStats)); + CTaskPtr spTask(new CTask(piHandler, m_stNextSessionUniqueID++, m_globalStats)); return spTask; } @@ -2806,22 +2798,25 @@ return m_globalStats.GetProgressPercents(); } -bool CTaskArray::IsFinished() +bool CTaskArray::AreAllFinished() { bool bFlag=true; UINT uiStatus; - boost::shared_lock lock(m_lock); if(m_globalStats.GetRunningTasksCount() != 0) bFlag = false; else { + boost::shared_lock lock(m_lock); BOOST_FOREACH(CTaskPtr& spTask, m_vTasks) { uiStatus = spTask->GetStatus(); bFlag = ((uiStatus & ST_STEP_MASK) == ST_FINISHED || (uiStatus & ST_STEP_MASK) == ST_CANCELLED || (uiStatus & ST_WORKING_MASK) == ST_PAUSED || ((uiStatus & ST_WORKING_MASK) == ST_ERROR && !GetConfig().get_bool(PP_CMAUTORETRYONERROR))); + + if(!bFlag) + break; } } Index: src/ch/task.h =================================================================== diff -u -rcf2edb7c2fd0a5561d730449efa73b0f634cf3b0 -rb55cf150df571c279536a2b4e33bcecedef17305 --- src/ch/task.h (.../task.h) (revision cf2edb7c2fd0a5561d730449efa73b0f634cf3b0) +++ src/ch/task.h (.../task.h) (revision b55cf150df571c279536a2b4e33bcecedef17305) @@ -69,18 +69,6 @@ #define E_CANCEL 0x02 #define E_PAUSE 0x03 -///////////////////////////////////////////////////////////////////// -// CTask - -class CTask; - -struct TASK_CREATE_DATA -{ - LONG *plFinished; - - boost::shared_mutex* pLock; -}; - // structure for gettings status of a task struct TASK_DISPLAY_DATA { @@ -228,7 +216,7 @@ class CTask { public: - CTask(chcore::IFeedbackHandler* piFeedbackHandler, const TASK_CREATE_DATA *pCreateData, size_t stSessionUniqueID, TTasksGlobalStats& tGlobalStats); + CTask(chcore::IFeedbackHandler* piFeedbackHandler, size_t stSessionUniqueID, TTasksGlobalStats& tGlobalStats); ~CTask(); // m_clipboard @@ -420,7 +408,6 @@ chcore::IFeedbackHandler* m_piFeedbackHandler; // ptr to count of currently started tasks - LONG* m_plFinished; bool m_bForce; // if the continuation of tasks should be independent of limitation bool m_bContinue; // used by ClipboardMonitorProc @@ -568,7 +555,7 @@ ull_t GetRange(); int GetPercent(); - bool IsFinished(); + bool AreAllFinished(); void SetTasksDir(const tchar_t* pszPath); @@ -578,9 +565,7 @@ public: tstring_t m_strTasksDir; - LONG m_lFinished; // count of finished tasks mutable boost::shared_mutex m_lock; - TASK_CREATE_DATA m_tcd; private: std::vector m_vTasks; // vector with tasks objects