| |
28 |
28 |
#include "..\common\ipcstructs.h" |
| |
29 |
29 |
#include "UpdateChecker.h" |
| |
30 |
30 |
#include "UpdaterDlg.h" |
| |
31 |
31 |
#include "FeedbackHandler.h" |
| |
32 |
32 |
#include "MiniviewDlg.h" |
| |
33 |
33 |
#include "StatusDlg.h" |
| |
34 |
34 |
#include "ClipboardMonitor.h" |
| |
35 |
35 |
#include <boost/make_shared.hpp> |
| |
36 |
36 |
#include <boost/shared_array.hpp> |
| |
37 |
37 |
#include "../common/TShellExtMenuConfig.h" |
| |
38 |
38 |
#include "../libchcore/TConfig.h" |
| |
39 |
39 |
#include "FileSupport.h" |
| |
40 |
40 |
#include "StringHelpers.h" |
| |
41 |
41 |
#include "../libchcore/TCoreException.h" |
| |
42 |
42 |
#include "../libchcore/TTaskManagerStatsSnapshot.h" |
| |
43 |
43 |
#include "../libchcore/TSQLiteSerializerFactory.h" |
| |
44 |
44 |
#include "TRecentPathsTools.h" |
| |
45 |
45 |
#include "DirectoryChooser.h" |
| |
46 |
46 |
#include "FeedbackHandlerFactory.h" |
| |
47 |
47 |
#include "../libchcore/TTask.h" |
| |
|
48 |
#include "TTaskManagerWrapper.h" |
| |
48 |
49 |
|
| |
49 |
50 |
#ifdef _DEBUG |
| |
50 |
51 |
#define new DEBUG_NEW |
| |
51 |
52 |
#undef THIS_FILE |
| |
52 |
53 |
static char THIS_FILE[] = __FILE__; |
| |
53 |
54 |
#endif |
| |
54 |
55 |
|
| |
55 |
56 |
#define CH_WNDCLASS_NAME _T("Copy Handler Wnd Class") |
| |
56 |
57 |
|
| |
57 |
58 |
#define WM_TRAYNOTIFY (WM_USER+0) |
| |
58 |
59 |
|
| |
59 |
60 |
#define WM_ICON_NOTIFY WM_USER+4 |
| |
60 |
61 |
#define WM_SHOWMINIVIEW WM_USER+3 |
| |
61 |
62 |
#define WM_IDENTIFY WM_USER+11 |
| |
62 |
63 |
|
| |
63 |
64 |
#define TM_AUTOREMOVE 1000 |
| |
64 |
65 |
#define TM_ACCEPTING 100 |
| |
65 |
66 |
|
| |
66 |
67 |
extern int iCount; |
| |
67 |
68 |
extern unsigned short msg[]; |
|
| |
180 |
181 |
m_uiTaskbarRestart = RegisterWindowMessage(_T("TaskbarCreated")); |
| |
181 |
182 |
|
| |
182 |
183 |
|
| |
183 |
184 |
ShowTrayIcon(); |
| |
184 |
185 |
|
| |
185 |
186 |
if(!LoadTaskManager()) |
| |
186 |
187 |
{ |
| |
187 |
188 |
LOG_ERROR(_T("Couldn't load task manager data. User did not allow re-creation of the database.")); |
| |
188 |
189 |
return -1; |
| |
189 |
190 |
} |
| |
190 |
191 |
|
| |
191 |
192 |
|
| |
192 |
193 |
const TCommandLineParser& cmdLine = GetApp().GetCommandLine(); |
| |
193 |
194 |
ProcessCommandLine(cmdLine); |
| |
194 |
195 |
|
| |
195 |
196 |
|
| |
196 |
197 |
m_spTasks->TasksRetryProcessing(); |
| |
197 |
198 |
|
| |
198 |
199 |
|
| |
199 |
200 |
LOG_INFO(_T("Starting clipboard monitor...")); |
| |
200 |
|
CClipboardMonitor::StartMonitor(m_spTasks.get()); |
| |
|
201 |
CClipboardMonitor::StartMonitor(m_spTasks); |
| |
201 |
202 |
|
| |
202 |
203 |
CheckForUpdates(); |
| |
203 |
204 |
|
| |
204 |
205 |
SetupTimers(); |
| |
205 |
206 |
|
| |
206 |
207 |
if (GetPropValue<PP_MVAUTOSHOWWHENRUN>(GetConfig())) |
| |
207 |
208 |
PostMessage(WM_SHOWMINIVIEW); |
| |
208 |
209 |
} |
| |
209 |
210 |
catch(chcore::TCoreException& e) |
| |
210 |
211 |
{ |
| |
211 |
212 |
bCaughtError = true; |
| |
212 |
213 |
e.GetErrorInfo(szErrInfo.get(), stMaxErrInfo); |
| |
213 |
214 |
} |
| |
214 |
215 |
catch(std::exception& e) |
| |
215 |
216 |
{ |
| |
216 |
217 |
bCaughtError = true; |
| |
217 |
218 |
_snwprintf_s(szErrInfo.get(), stMaxErrInfo, _TRUNCATE, _T("%S"), e.what()); |
| |
218 |
219 |
szErrInfo.get()[stMaxErrInfo - 1] = _T('\0'); |
| |
219 |
220 |
} |
| |
220 |
221 |
catch(...) |
|
| |
364 |
365 |
m_pdlgStatus->m_spInitialSelection = spSelect; |
| |
365 |
366 |
m_pdlgStatus->m_bLockInstance=true; |
| |
366 |
367 |
m_pdlgStatus->m_bAutoDelete=true; |
| |
367 |
368 |
m_pdlgStatus->Create(); |
| |
368 |
369 |
|
| |
369 |
370 |
|
| |
370 |
371 |
if (m_pdlgMiniView != NULL && m_pdlgMiniView->m_bLock) |
| |
371 |
372 |
{ |
| |
372 |
373 |
if (::IsWindow(m_pdlgMiniView->m_hWnd)) |
| |
373 |
374 |
m_pdlgMiniView->HideWindow(); |
| |
374 |
375 |
} |
| |
375 |
376 |
} |
| |
376 |
377 |
|
| |
377 |
378 |
void CMainWnd::OnPopupShowStatus() |
| |
378 |
379 |
{ |
| |
379 |
380 |
ShowStatusWindow(); |
| |
380 |
381 |
} |
| |
381 |
382 |
|
| |
382 |
383 |
void CMainWnd::OnClose() |
| |
383 |
384 |
{ |
| |
|
385 |
CString strMessage; |
| |
|
386 |
try |
| |
|
387 |
{ |
| |
384 |
388 |
PrepareToExit(); |
| |
|
389 |
} |
| |
|
390 |
catch(const chcore::TBaseException& e) |
| |
|
391 |
{ |
| |
|
392 |
const size_t stMaxError = 1024; |
| |
|
393 |
wchar_t szError[ stMaxError ]; |
| |
|
394 |
e.GetErrorInfo(szError, stMaxError); |
| |
|
395 |
|
| |
|
396 |
strMessage = szError; |
| |
|
397 |
} |
| |
|
398 |
catch(const std::exception& e) |
| |
|
399 |
{ |
| |
|
400 |
strMessage = e.what(); |
| |
|
401 |
} |
| |
|
402 |
|
| |
|
403 |
if(!strMessage.IsEmpty()) |
| |
|
404 |
{ |
| |
|
405 |
LOG_ERROR(L"Failed to finalize tasks before exiting Copy Handler. Error: " + strMessage); |
| |
|
406 |
|
| |
|
407 |
ictranslate::CFormat fmt; |
| |
|
408 |
|
| |
|
409 |
fmt.SetFormat(GetResManager().LoadString(IDS_FINALIZE_CH_ERROR)); |
| |
|
410 |
fmt.SetParam(_T("%reason"), strMessage); |
| |
|
411 |
AfxMessageBox(fmt, MB_OK | MB_ICONERROR); |
| |
|
412 |
} |
| |
|
413 |
|
| |
385 |
414 |
CWnd::OnClose(); |
| |
386 |
415 |
} |
| |
387 |
416 |
|
| |
388 |
417 |
void CMainWnd::OnTimer(UINT_PTR nIDEvent) |
| |
389 |
418 |
{ |
| |
390 |
419 |
switch (nIDEvent) |
| |
391 |
420 |
{ |
| |
392 |
421 |
case 1023: |
| |
|
422 |
{ |
| |
393 |
423 |
|
| |
394 |
424 |
KillTimer(1023); |
| |
|
425 |
try |
| |
|
426 |
{ |
| |
395 |
427 |
m_spTasks->Store(false); |
| |
|
428 |
} |
| |
|
429 |
catch(const std::exception& e) |
| |
|
430 |
{ |
| |
|
431 |
CString strError = e.what(); |
| |
|
432 |
|
| |
|
433 |
ictranslate::CFormat fmt; |
| |
|
434 |
fmt.SetFormat(_T("Failed to autosave task. Error: %err.")); |
| |
|
435 |
fmt.SetParam(_T("%err"), (PCTSTR)strError); |
| |
|
436 |
|
| |
|
437 |
LOG_ERROR(fmt); |
| |
|
438 |
} |
| |
|
439 |
|
| |
396 |
440 |
SetTimer(1023, GetPropValue<PP_PAUTOSAVEINTERVAL>(GetConfig()), NULL); |
| |
397 |
441 |
break; |
| |
398 |
|
|
| |
|
442 |
} |
| |
399 |
443 |
case 3245: |
| |
400 |
444 |
|
| |
401 |
445 |
KillTimer(3245); |
| |
402 |
446 |
if (GetPropValue<PP_STATUSAUTOREMOVEFINISHED>(GetConfig())) |
| |
403 |
447 |
{ |
| |
404 |
448 |
size_t stSize = m_spTasks->GetSize(); |
| |
405 |
449 |
m_spTasks->RemoveAllFinished(); |
| |
406 |
450 |
if(m_spTasks->GetSize() != stSize && m_pdlgStatus && m_pdlgStatus->m_bLock && IsWindow(m_pdlgStatus->m_hWnd)) |
| |
407 |
451 |
m_pdlgStatus->SendMessage(WM_UPDATESTATUS); |
| |
408 |
452 |
} |
| |
409 |
453 |
|
| |
410 |
454 |
SetTimer(3245, TM_AUTOREMOVE, NULL); |
| |
411 |
455 |
break; |
| |
412 |
456 |
|
| |
413 |
457 |
case 8743: |
| |
414 |
458 |
{ |
| |
415 |
459 |
|
| |
416 |
460 |
m_spTasks->ResumeWaitingTasks((size_t)GetPropValue<PP_CMLIMITMAXOPERATIONS>(GetConfig())); |
| |
417 |
461 |
break; |
| |
418 |
462 |
} |
|
| |
495 |
539 |
if((iModalResult = dlg.DoModal()) == IDCANCEL) |
| |
496 |
540 |
return CWnd::OnCopyData(pWnd, pCopyDataStruct); |
| |
497 |
541 |
else if(iModalResult == -1) |
| |
498 |
542 |
return TRUE; |
| |
499 |
543 |
|
| |
500 |
544 |
TRecentPathsTools::AddNewPath(dlg.m_vRecent, dlg.m_tTaskDefinition.GetDestinationPath().ToString()); |
| |
501 |
545 |
|
| |
502 |
546 |
SetPropValue<PP_RECENTPATHS>(rConfig, dlg.m_vRecent); |
| |
503 |
547 |
|
| |
504 |
548 |
tTaskDefinition = dlg.m_tTaskDefinition; |
| |
505 |
549 |
} |
| |
506 |
550 |
else if(tTaskDefinition.GetDestinationPath().IsEmpty()) |
| |
507 |
551 |
{ |
| |
508 |
552 |
chcore::TSmartPath pathSelected; |
| |
509 |
553 |
if(DirectoryChooser::ChooseDirectory(tTaskDefinition.GetOperationType(), tTaskDefinition.GetSourcePaths(), pathSelected) == IDOK) |
| |
510 |
554 |
tTaskDefinition.SetDestinationPath(pathSelected); |
| |
511 |
555 |
else |
| |
512 |
556 |
break; |
| |
513 |
557 |
} |
| |
514 |
558 |
|
| |
515 |
|
|
| |
516 |
|
chcore::SetTaskPropValue<chcore::eTO_AlternateFilenameFormatString_First>(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_FIRSTCOPY_STRING)); |
| |
517 |
|
chcore::SetTaskPropValue<chcore::eTO_AlternateFilenameFormatString_AfterFirst>(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_NEXTCOPY_STRING)); |
| |
|
559 |
TTaskManagerWrapper tTaskManager(m_spTasks); |
| |
|
560 |
tTaskManager.CreateTask(tTaskDefinition); |
| |
518 |
561 |
|
| |
519 |
|
|
| |
520 |
|
chcore::TTaskPtr spTask = m_spTasks->CreateTask(tTaskDefinition); |
| |
521 |
|
|
| |
522 |
|
|
| |
523 |
|
spTask->BeginProcessing(); |
| |
524 |
|
|
| |
525 |
562 |
break; |
| |
526 |
563 |
} |
| |
527 |
564 |
case eCDType_CommandLineArguments: |
| |
528 |
565 |
{ |
| |
529 |
566 |
|
| |
530 |
567 |
wchar_t* pszBuffer = static_cast<wchar_t*>(pCopyDataStruct->lpData); |
| |
531 |
568 |
unsigned long ulLen = pCopyDataStruct->cbData / sizeof(wchar_t); |
| |
532 |
569 |
|
| |
533 |
570 |
|
| |
534 |
571 |
if(!pszBuffer || ulLen == 0 || pszBuffer[ulLen - 1] != L'\0') |
| |
535 |
572 |
return FALSE; |
| |
536 |
573 |
|
| |
537 |
574 |
TCommandLineParser cmdLineParser; |
| |
538 |
575 |
cmdLineParser.ParseCommandLine(pszBuffer); |
| |
539 |
576 |
|
| |
540 |
577 |
ProcessCommandLine(cmdLineParser); |
| |
541 |
578 |
m_spTasks->TasksRetryProcessing(); |
| |
542 |
579 |
|
| |
543 |
580 |
return TRUE; |
| |
544 |
581 |
} |
|
| |
605 |
642 |
m_pdlgMiniView->m_bLockInstance=true; |
| |
606 |
643 |
m_pdlgMiniView->Create(); |
| |
607 |
644 |
} |
| |
608 |
645 |
|
| |
609 |
646 |
void CMainWnd::OnPopupCustomCopy() |
| |
610 |
647 |
{ |
| |
611 |
648 |
chcore::TConfig& rConfig = GetConfig(); |
| |
612 |
649 |
|
| |
613 |
650 |
CCustomCopyDlg dlg; |
| |
614 |
651 |
|
| |
615 |
652 |
GetPropValue<PP_RECENTPATHS>(rConfig, dlg.m_vRecent); |
| |
616 |
653 |
|
| |
617 |
654 |
if(dlg.DoModal() == IDOK) |
| |
618 |
655 |
{ |
| |
619 |
656 |
TRecentPathsTools::AddNewPath(dlg.m_vRecent, dlg.m_tTaskDefinition.GetDestinationPath().ToString()); |
| |
620 |
657 |
|
| |
621 |
658 |
SetPropValue<PP_RECENTPATHS>(rConfig, dlg.m_vRecent); |
| |
622 |
659 |
|
| |
623 |
660 |
chcore::TTaskDefinition tTaskDefinition = dlg.m_tTaskDefinition; |
| |
624 |
661 |
|
| |
625 |
|
|
| |
626 |
|
chcore::SetTaskPropValue<chcore::eTO_AlternateFilenameFormatString_First>(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_FIRSTCOPY_STRING)); |
| |
627 |
|
chcore::SetTaskPropValue<chcore::eTO_AlternateFilenameFormatString_AfterFirst>(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_NEXTCOPY_STRING)); |
| |
628 |
|
|
| |
629 |
|
|
| |
630 |
|
chcore::TTaskPtr spTask = m_spTasks->CreateTask(tTaskDefinition); |
| |
631 |
|
|
| |
632 |
|
|
| |
633 |
|
spTask->BeginProcessing(); |
| |
|
662 |
TTaskManagerWrapper tTaskManager(m_spTasks); |
| |
|
663 |
tTaskManager.CreateTask(tTaskDefinition); |
| |
634 |
664 |
} |
| |
635 |
665 |
} |
| |
636 |
666 |
|
| |
637 |
667 |
LRESULT CMainWnd::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) |
| |
638 |
668 |
{ |
| |
639 |
669 |
switch (message) |
| |
640 |
670 |
{ |
| |
641 |
671 |
case WM_MINIVIEWDBLCLK: |
| |
642 |
672 |
{ |
| |
643 |
673 |
chcore::TTaskPtr spTask = m_spTasks->GetTaskByTaskID(boost::numeric_cast<chcore::taskid_t>(lParam)); |
| |
644 |
674 |
ShowStatusWindow(spTask); |
| |
645 |
675 |
break; |
| |
646 |
676 |
} |
| |
647 |
677 |
case WM_SHOWMINIVIEW: |
| |
648 |
678 |
{ |
| |
649 |
679 |
OnShowMiniView(); |
| |
650 |
680 |
return static_cast<LRESULT>(0); |
| |
651 |
681 |
break; |
| |
652 |
682 |
} |
| |
653 |
683 |
|