Index: src/ch/ClipboardMonitor.cpp =================================================================== diff -u -r92410cc8f6de1e1696774cb25cb37464c4e74cbd -r8068e0c351055554340ac9755d1bc846893bf2b8 --- src/ch/ClipboardMonitor.cpp (.../ClipboardMonitor.cpp) (revision 92410cc8f6de1e1696774cb25cb37464c4e74cbd) +++ src/ch/ClipboardMonitor.cpp (.../ClipboardMonitor.cpp) (revision 8068e0c351055554340ac9755d1bc846893bf2b8) @@ -20,16 +20,20 @@ /// @brief Contains the implementation of clipboard monitor package. //****************************************************************************** #include "stdafx.h" -#include "TWorkerThreadController.h" +#include "../libchcore/TWorkerThreadController.h" #include "ClipboardMonitor.h" #include "ch.h" -#include "task.h" +#include "../libchcore/TTaskManager.h" +#include "../libchcore/TTask.h" #include "CfgProperties.h" -#include "charvect.h" #include "FolderDialog.h" -#include "task.h" #include "ShutdownDlg.h" +#include "DirectoryChooser.h" +#include "TTaskManagerWrapper.h" +#include "resource.h" +using namespace chcore; + CClipboardMonitor CClipboardMonitor::S_ClipboardMonitor; CClipboardMonitor::CClipboardMonitor() @@ -41,19 +45,19 @@ Stop(); } -void CClipboardMonitor::StartMonitor(CTaskArray* pTasks) +void CClipboardMonitor::StartMonitor(chcore::TTaskManagerPtr spTasks) { - CClipboardMonitor::S_ClipboardMonitor.Start(pTasks); + CClipboardMonitor::S_ClipboardMonitor.Start(spTasks); } void CClipboardMonitor::StopMonitor() { return CClipboardMonitor::S_ClipboardMonitor.Stop(); } -void CClipboardMonitor::Start(CTaskArray* pTasks) +void CClipboardMonitor::Start(chcore::TTaskManagerPtr spTasks) { - m_pTasks = pTasks; + m_spTasks = spTasks; m_threadWorker.StartThread(&CClipboardMonitor::ClipboardMonitorProc, this); } @@ -69,204 +73,114 @@ // bufor TCHAR path[_MAX_PATH]; - // UINT i; // counter - CTaskPtr spTask; // ptr to a task - CClipboardEntryPtr spEntry; // register clipboard format UINT nFormat=RegisterClipboardFormat(_T("Preferred DropEffect")); UINT uiCounter=0, uiShutCounter=0; - icpf::config& rConfig = GetConfig(); + chcore::TConfig& rConfig = GetConfig(); for(;;) { - if (uiCounter == 0 && rConfig.get_bool(PP_PCLIPBOARDMONITORING) && IsClipboardFormatAvailable(CF_HDROP)) + if (uiCounter == 0 && GetPropValue(rConfig) && IsClipboardFormatAvailable(CF_HDROP)) { // get data from clipboard - OpenClipboard(NULL); + OpenClipboard(nullptr); HANDLE handle=GetClipboardData(CF_HDROP); - UINT nCount=DragQueryFile(static_cast(handle), 0xffffffff, NULL, 0); + UINT nCount=DragQueryFile(static_cast(handle), 0xffffffff, nullptr, 0); - spTask = pData->m_pTasks->CreateTask(); + chcore::TTaskDefinition tTaskDefinition; - for (UINT i=0;i(handle), i, path, _MAX_PATH); - spEntry.reset(new CClipboardEntry); - spEntry->SetPath(path); - spTask->AddClipboardData(spEntry); + DragQueryFile(static_cast(handle), stIndex, path, _MAX_PATH); + + tTaskDefinition.AddSourcePath(chcore::PathFromString(path)); } - if (IsClipboardFormatAvailable(nFormat)) + // operation type + chcore::EOperationType eOperation = chcore::eOperation_Copy; + + if(IsClipboardFormatAvailable(nFormat)) { handle=GetClipboardData(nFormat); LPVOID addr=GlobalLock(handle); DWORD dwData=((DWORD*)addr)[0]; - if (dwData & DROPEFFECT_COPY) - spTask->SetStatus(ST_COPY, ST_OPERATION_MASK); // copy - else if (dwData & DROPEFFECT_MOVE) - spTask->SetStatus(ST_MOVE, ST_OPERATION_MASK); // move + if(dwData & DROPEFFECT_COPY) + eOperation = chcore::eOperation_Copy; // copy + else if(dwData & DROPEFFECT_MOVE) + eOperation = chcore::eOperation_Move; // move GlobalUnlock(handle); } else - spTask->SetStatus(ST_COPY, ST_OPERATION_MASK); // default - copy + eOperation = chcore::eOperation_Copy; // default - copy + tTaskDefinition.SetOperationType(eOperation); // copy + + // set the default options for task + GetConfig().ExtractSubConfig(BRANCH_TASK_SETTINGS, tTaskDefinition.GetConfiguration()); + EmptyClipboard(); CloseClipboard(); - BUFFERSIZES bs; - bs.m_bOnlyDefault=rConfig.get_bool(PP_BFUSEONLYDEFAULT); - bs.m_uiDefaultSize=(UINT)rConfig.get_signed_num(PP_BFDEFAULT); - bs.m_uiOneDiskSize=(UINT)rConfig.get_signed_num(PP_BFONEDISK); - bs.m_uiTwoDisksSize=(UINT)rConfig.get_signed_num(PP_BFTWODISKS); - bs.m_uiCDSize=(UINT)rConfig.get_signed_num(PP_BFCD); - bs.m_uiLANSize=(UINT)rConfig.get_signed_num(PP_BFLAN); - - spTask->SetBufferSizes(&bs); - spTask->SetPriority(boost::numeric_cast(rConfig.get_signed_num(PP_CMDEFAULTPRIORITY))); - - // get dest folder - CFolderDialog dlg; - - const tchar_t* pszPath = NULL; - dlg.m_bdData.cvShortcuts.clear(true); - size_t stCount = rConfig.get_value_count(PP_SHORTCUTS); - for(size_t stIndex = 0; stIndex < stCount; stIndex++) + TSmartPath pathSelected; + INT_PTR iResult = DirectoryChooser::ChooseDirectory(eOperation, tTaskDefinition.GetSourcePaths(), pathSelected); + if(iResult == IDOK) { - pszPath = rConfig.get_string(PP_SHORTCUTS, stIndex); - dlg.m_bdData.cvShortcuts.push_back(pszPath); - } - - dlg.m_bdData.cvRecent.clear(true); - stCount = rConfig.get_value_count(PP_RECENTPATHS); - for(size_t stIndex = 0; stIndex < stCount; stIndex++) - { - pszPath = rConfig.get_string(PP_RECENTPATHS, stIndex); - dlg.m_bdData.cvRecent.push_back(pszPath); - } - - dlg.m_bdData.bExtended=rConfig.get_bool(PP_FDEXTENDEDVIEW); - dlg.m_bdData.cx=boost::numeric_cast(rConfig.get_signed_num(PP_FDWIDTH)); - dlg.m_bdData.cy=boost::numeric_cast(rConfig.get_signed_num(PP_FDHEIGHT)); - dlg.m_bdData.iView=boost::numeric_cast(rConfig.get_signed_num(PP_FDSHORTCUTLISTSTYLE)); - dlg.m_bdData.bIgnoreDialogs=rConfig.get_bool(PP_FDIGNORESHELLDIALOGS); - - dlg.m_bdData.strInitialDir=(dlg.m_bdData.cvRecent.size() > 0) ? dlg.m_bdData.cvRecent.at(0) : _T(""); - - int iStatus=spTask->GetStatus(ST_OPERATION_MASK); - if (iStatus == ST_COPY) - dlg.m_bdData.strCaption=GetResManager().LoadString(IDS_TITLECOPY_STRING); - else if (iStatus == ST_MOVE) - dlg.m_bdData.strCaption=GetResManager().LoadString(IDS_TITLEMOVE_STRING); - else - dlg.m_bdData.strCaption=GetResManager().LoadString(IDS_TITLEUNKNOWNOPERATION_STRING); - dlg.m_bdData.strText=GetResManager().LoadString(IDS_MAINBROWSETEXT_STRING); - - // set count of data to display - size_t stClipboardSize = spTask->GetClipboardDataSize(); - size_t stEntries = (stClipboardSize > 3) ? 2 : stClipboardSize; - for(size_t i = 0; i < stEntries; i++) - { - dlg.m_bdData.strText += spTask->GetClipboardData(i)->GetPath() + _T("\n"); - } - - // add ... - if (stEntries < stClipboardSize) - dlg.m_bdData.strText+=_T("..."); - - // show window - INT_PTR iResult=dlg.DoModal(); - - // set data to config - rConfig.clear_array_values(PP_SHORTCUTS); - for(char_vector::iterator it = dlg.m_bdData.cvShortcuts.begin(); it != dlg.m_bdData.cvShortcuts.end(); it++) - { - rConfig.set_string(PP_SHORTCUTS, (*it), icpf::property::action_add); - } - - rConfig.clear_array_values(PP_RECENTPATHS); - for(char_vector::iterator it = dlg.m_bdData.cvRecent.begin(); it != dlg.m_bdData.cvRecent.end(); it++) - { - rConfig.set_string(PP_RECENTPATHS, (*it), icpf::property::action_add); - } - - rConfig.set_bool(PP_FDEXTENDEDVIEW, dlg.m_bdData.bExtended); - rConfig.set_signed_num(PP_FDWIDTH, dlg.m_bdData.cx); - rConfig.set_signed_num(PP_FDHEIGHT, dlg.m_bdData.cy); - rConfig.set_signed_num(PP_FDSHORTCUTLISTSTYLE, dlg.m_bdData.iView); - rConfig.set_bool(PP_FDIGNORESHELLDIALOGS, dlg.m_bdData.bIgnoreDialogs); - rConfig.write(NULL); - - if(iResult != IDOK) - spTask.reset(); - else - { // get dest path - CString strData; - dlg.GetPath(strData); - spTask->SetDestPath(strData); + tTaskDefinition.SetDestinationPath(pathSelected); - // get the relationship between src and dst paths - for (size_t stIndex = 0; stIndex < spTask->GetClipboard()->GetSize(); ++stIndex) - { - spTask->GetClipboard()->GetAt(stIndex)->CalcBufferIndex(spTask->GetDestPath()); - } + TTaskManagerWrapper tTaskManager(pData->m_spTasks); - // add task to a list of tasks and start - pData->m_pTasks->Add(spTask); - - // write spTask to a file - spTask->Store(true); - spTask->Store(false); - - // start processing - spTask->BeginProcessing(); + tTaskManager.CreateTask(tTaskDefinition); } } // do we need to check for turning computer off - if(uiShutCounter == 0 && GetConfig().get_bool(PP_PSHUTDOWNAFTREFINISHED)) + if(uiShutCounter == 0 && GetPropValue(GetConfig())) { - if(pData->m_pTasks->AreAllFinished()) + if(pData->m_spTasks->AreAllFinished()) { TRACE("Shut down windows\n"); bool bShutdown=true; - if (GetConfig().get_signed_num(PP_PTIMEBEFORESHUTDOWN) != 0) + if (GetPropValue(GetConfig()) != 0) { 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; + dlg.SetOverallTime(GetPropValue(GetConfig())); bShutdown=(dlg.DoModal() != IDCANCEL); } - GetConfig().set_bool(PP_PSHUTDOWNAFTREFINISHED, false); - GetConfig().write(NULL); - if (bShutdown) + SetPropValue(GetConfig(), false); + GetConfig().Write(); + if(bShutdown) { // adjust token privileges for NT - HANDLE hToken=NULL; - TOKEN_PRIVILEGES tp; + HANDLE hToken = nullptr; + TOKEN_PRIVILEGES tp = { 0 }; if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken) - && LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tp.Privileges[0].Luid)) + && LookupPrivilegeValue(nullptr, SE_SHUTDOWN_NAME, &tp.Privileges[0].Luid)) { tp.PrivilegeCount=1; tp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; - AdjustTokenPrivileges(hToken, FALSE, &tp, NULL, NULL, NULL); + AdjustTokenPrivileges(hToken, FALSE, &tp, 0, nullptr, nullptr); + } - BOOL bExit=ExitWindowsEx(EWX_POWEROFF | EWX_SHUTDOWN | (GetConfig().get_bool(PP_PFORCESHUTDOWN) ? EWX_FORCE : 0), 0); + if(hToken) + CloseHandle(hToken); + + BOOL bExit=ExitWindowsEx(EWX_POWEROFF | EWX_SHUTDOWN | (GetPropValue(GetConfig()) ? 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()); + fmt.SetParam(_T("%errno"), GetLastError()); AfxMessageBox(fmt, MB_ICONERROR | MB_OK | MB_SYSTEMMODAL); } } @@ -276,14 +190,14 @@ // sleep for some time const int iSleepCount=200; - if(pData->m_threadWorker.KillRequested()) + if(pData->m_threadWorker.KillRequested(iSleepCount)) break; uiCounter+=iSleepCount; uiShutCounter+=iSleepCount; - if (uiCounter >= (UINT)GetConfig().get_signed_num(PP_PMONITORSCANINTERVAL)) + if(uiCounter >= GetPropValue(GetConfig())) uiCounter=0; - if (uiShutCounter >= 800) + if(uiShutCounter >= 800) uiShutCounter=0; }