Clone
ixen <ixen@copyhandler.com>
committed
on 24 Nov 09
Changed e-mail contact in about-box to a contact form on www.copyhandler.com, where user can read when he shouldn't write.
LoggerImprovements + 5 more
src/ch/ch.cpp (+5 -10)
19 19 #include "stdafx.h"
20 20 #include "ch.h"
21 21
22 22 #include "CfgProperties.h"
23 23 #include "MainWnd.h"
24 24 #include "../common/ipcstructs.h"
25 25 #include <Dbghelp.h>
26 26 #include "CrashDlg.h"
27 27 #include "../common/version.h"
28 28 #include "TCommandLineParser.h"
29 29 #include "../libchcore/TStringSet.h"
30 30 #include "../libchcore/TSimpleTimer.h"
31 31 #include "../libchcore/SerializerTrace.h"
32 32 #include <boost/container/flat_map.hpp>
33 33 #include "../libchcore/TSQLiteTaskSchema.h"
34 34 #include "../libchcore/TSQLiteSerializer.h"
35 35 #include "../libchcore/ISerializerContainer.h"
36 36 #include "../libchcore/ISerializerRowData.h"
37 37 #include "../libchcore/TFileInfo.h"
38 38 #include "TMsgBox.h"
  39 #include "../libchcore/TWin32ErrorFormatter.h"
39 40
40 41 #ifdef _DEBUG
41 42 #define new DEBUG_NEW
42 43 #endif
43 44
44 45 #ifdef _DEBUG
45 46 #define new DEBUG_NEW
46 47 #undef THIS_FILE
47 48 static char THIS_FILE[] = __FILE__;
48 49 #endif
49 50
50 51 /////////////////////////////////////////////////////////////////////////////
51 52 // CCopyHandlerApp
52 53
53 54 BEGIN_MESSAGE_MAP(CCopyHandlerApp, CWinApp)
54 55 END_MESSAGE_MAP()
55 56
56 57 int iCount=98;
57 58 unsigned short msg[]={  0x40d1, 0x4dcd, 0x8327, 0x6cdf, 0xb912, 0x017b, 0xac78, 0x1e04, 0x5637,
58 59                                                 0x1822, 0x0a69, 0x1b40, 0x4169, 0x504d, 0x80ff, 0x6c2f, 0xa612, 0x017e,
 
560 561 }
561 562
562 563 void CCopyHandlerApp::RegisterShellExtension()
563 564 {
564 565         CString strPath = CString(GetProgramPath()) + _T("\\");
565 566
566 567 #ifdef _WIN64
567 568         strPath += _T("chext64.dll");
568 569 #else
569 570         strPath += _T("chext.dll");
570 571 #endif
571 572
572 573         long lExtensionVersion = 0;
573 574         CString strExtensionVersion;
574 575
575 576         HRESULT hResult = m_tShellExtClient.RegisterShellExtDll(strPath, PRODUCT_VERSION1 << 24 | PRODUCT_VERSION2 << 16 | PRODUCT_VERSION3 << 8 | PRODUCT_VERSION4,
576 577                                                                                                                         lExtensionVersion, strExtensionVersion);
577 578         if(FAILED(hResult))
578 579         {
579 580                 // normal failure
580                   TCHAR szStr[256];
581                   FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hResult, 0, szStr, 256, NULL);
582                   while(szStr[_tcslen(szStr) - 1] == _T('\n') || szStr[_tcslen(szStr) - 1] == _T('\r') || szStr[_tcslen(szStr) - 1] == _T('.'))
583                           szStr[_tcslen(szStr)-1] = _T('\0');
  581                 chcore::TString strError = chcore::TWin32ErrorFormatter::FormatWin32ErrorCode(hResult, true);
584 582
585 583                 ictranslate::CFormat fmt(GetResManager().LoadString(IDS_REGISTERERR_STRING));
586 584                 fmt.SetParam(_T("%errno"), (ulong_t)hResult);
587                   fmt.SetParam(_T("%errdesc"), szStr);
  585                 fmt.SetParam(_T("%errdesc"), strError.c_str());
588 586                 AfxMessageBox(fmt, MB_ICONERROR | MB_OK);
589 587         }
590 588         else if(hResult == S_FALSE)
591 589         {
592 590                 // registered ok, but incompatible versions - probably restart required
593 591                 CString strMsg;
594 592                 strMsg.Format(_T("Registration succeeded, but still the shell extension has different version (0x%lx) than Copy Handler (0x%lx)."), lExtensionVersion, PRODUCT_VERSION1 << 24 | PRODUCT_VERSION2 << 16 | PRODUCT_VERSION3 << 8 | PRODUCT_VERSION4);
595 593                 LOG_WARNING(strMsg);
596 594
597 595                 MsgBox(IDS_SHELL_EXTENSION_REGISTERED_MISMATCH_STRING, MB_ICONWARNING | MB_OK);
598 596         }
599 597         else if(hResult == S_OK)
600 598                 MsgBox(IDS_REGISTEROK_STRING, MB_ICONINFORMATION | MB_OK);
601 599 }
602 600
603 601 void CCopyHandlerApp::UnregisterShellExtension()
604 602 {
605 603         CString strPath = CString(GetProgramPath()) + _T("\\");
606 604
607 605 #ifdef _WIN64
608 606         strPath += _T("chext64.dll");
609 607 #else
610 608         strPath += _T("chext.dll");
611 609 #endif
612 610
613 611         HRESULT hResult = m_tShellExtClient.UnRegisterShellExtDll(strPath);
614 612         if(hResult == TYPE_E_REGISTRYACCESS)
615 613         {
616 614                 MsgBox(IDS_CHEXT_ALREADY_UNREGISTERED, MB_ICONINFORMATION | MB_OK);
617 615         }
618 616         else if(FAILED(hResult))
619 617         {
620                   TCHAR szStr[256];
621                   FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hResult, 0, szStr, 256, NULL);
622                   while (szStr[_tcslen(szStr)-1] == _T('\n') || szStr[_tcslen(szStr)-1] == _T('\r') || szStr[_tcslen(szStr)-1] == _T('.'))
623                           szStr[_tcslen(szStr)-1] = _T('\0');
  618                 chcore::TString strError = chcore::TWin32ErrorFormatter::FormatWin32ErrorCode(hResult, true);
624 619
625 620                 ictranslate::CFormat fmt(GetResManager().LoadString(IDS_UNREGISTERERR_STRING));
626 621                 fmt.SetParam(_T("%errno"), (ulong_t)hResult);
627                   fmt.SetParam(_T("%errdesc"), szStr);
  622                 fmt.SetParam(_T("%errdesc"), strError.c_str());
628 623
629 624                 AfxMessageBox(fmt, MB_ICONERROR | MB_OK);
630 625         }
631 626         else if(hResult == S_OK)
632 627                 MsgBox(IDS_UNREGISTEROK_STRING, MB_ICONINFORMATION | MB_OK);
633 628 }
634 629
635 630 void CCopyHandlerApp::OnConfigNotify(const chcore::TStringSet& setPropNames)
636 631 {
637 632         // is this language
638 633         if(setPropNames.HasValue(PropData<PP_PLANGUAGE>::GetPropertyName()))
639 634         {
640 635                 // update language in resource manager
641 636                 CString strPath;
642 637                 GetPropValue<PP_PLANGUAGE>(GetConfig(), strPath);
643 638                 GetResManager().SetLanguage(ExpandPath(strPath.GetBufferSetLength(_MAX_PATH)));
644 639                 strPath.ReleaseBuffer();
645 640         }
646 641
647 642         if(setPropNames.HasValue(PropData<PP_LOGENABLELOGGING>::GetPropertyName()))