Index: src/ch/MainWnd.cpp =================================================================== diff -u -r53cb62334fc09a404726d92af726eca6141ad177 -rd9982d1ee462dceb76298ef4216f0b6122d004a6 --- src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 53cb62334fc09a404726d92af726eca6141ad177) +++ src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision d9982d1ee462dceb76298ef4216f0b6122d004a6) @@ -2334,11 +2334,8 @@ void CMainWnd::OnPopupCheckForUpdates() { - CUpdateChecker uc; - CUpdateChecker::ECheckResult eResult = uc.CheckForUpdates(true); - - CString strVer; - uc.GetRemoteVersion(strVer); - CUpdaterDlg dlg(eResult, strVer, uc.GetLastError()); - dlg.DoModal(); + CUpdaterDlg* pDlg = new CUpdaterDlg; + pDlg->m_bAutoDelete = true; + + pDlg->Create(); } Index: src/ch/UpdateChecker.cpp =================================================================== diff -u -r53cb62334fc09a404726d92af726eca6141ad177 -rd9982d1ee462dceb76298ef4216f0b6122d004a6 --- src/ch/UpdateChecker.cpp (.../UpdateChecker.cpp) (revision 53cb62334fc09a404726d92af726eca6141ad177) +++ src/ch/UpdateChecker.cpp (.../UpdateChecker.cpp) (revision d9982d1ee462dceb76298ef4216f0b6122d004a6) @@ -3,72 +3,110 @@ #include #include #include "../common/version.h" +#include "../libicpf/cfg.h" +#include "../libicpf/exception.h" -CUpdateChecker::ECheckResult CUpdateChecker::CheckForUpdates(bool bCheckBeta) +CUpdateChecker::ECheckResult CUpdateChecker::CheckForUpdates(const tchar_t* pszSite, bool bCheckBeta) { try { + CString strSite(pszSite); + strSite.Replace(_T("http://"), _T("")); + CInternetSession inetSession; - CHttpConnection* pHttpConnection = inetSession.GetHttpConnection(_T("www.copyhandler.com"), INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, 80); + CHttpConnection* pHttpConnection = inetSession.GetHttpConnection(strSite, INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, 80); if(!pHttpConnection) - return eResult_Error; + { + m_eResult = eResult_Error; + return m_eResult; + } - CString strAddr = _T("chver.php?ver="); - strAddr += bCheckBeta ? _T("beta") : _T("stable"); + CString strAddr = _T("chver.ini"); CHttpFile* pHttpFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strAddr); if(!pHttpFile) - return eResult_Error; + { + m_eResult = eResult_Error; + return m_eResult; + } if(!pHttpFile->SendRequest()) - return eResult_Error; + { + m_eResult = eResult_Error; + return m_eResult; + } - char szBuf[512]; - UINT uiRD = pHttpFile->Read(szBuf, 511); + const size_t stBufferSize(65536); + tchar_t* pszBuf = new tchar_t[stBufferSize]; + UINT uiRD = pHttpFile->Read(pszBuf, stBufferSize - 1); if(uiRD > 0) - szBuf[uiRD] = _T('\0'); + pszBuf[uiRD] = _T('\0'); // convert text to unicode - CA2CT a2ct(szBuf); + icpf::config cfg(icpf::config::eIni); + const uint_t uiVersionNumeric = cfg.register_string(_t("Version/Numeric"), _t("")); + const uint_t uiVersionReadable = cfg.register_string(_t("Version/Human Readable"), _t("")); + const uint_t uiDownloadAddress = cfg.register_string(_t("Version/Download Address"), pszSite); + const uint_t uiBetaVersionNumeric = cfg.register_string(_t("Version/Numeric Beta"), _t("")); + const uint_t uiBetaVersionReadable = cfg.register_string(_t("Version/Human Readable Beta"), _t("")); + const uint_t uiBetaDownloadAddress = cfg.register_string(_t("Version/Download Address Beta"), pszSite); + try + { + cfg.read_from_buffer(pszBuf, uiRD); + } + catch(icpf::exception& e) + { + m_strLastError = e.get_desc(); - CString strVersion = a2ct; - CString strNumericVersion; - CString strReadableVersion; - int iPos = strVersion.Find(_t('|')); - if(iPos != -1) + delete [] pszBuf; + m_eResult = eResult_Error; + return m_eResult; + } + delete [] pszBuf; + + if(bCheckBeta) { - strNumericVersion = strVersion.Mid(0, iPos); - strReadableVersion = strVersion.Mid(iPos + 1); + m_strReadableVersion = cfg.get_string(uiBetaVersionReadable); + m_strNumericVersion = cfg.get_string(uiBetaVersionNumeric); + m_strDownloadAddress = cfg.get_string(uiBetaDownloadAddress); } - else - strNumericVersion = strVersion; - m_strRemoteVersion = strReadableVersion; + if(!bCheckBeta || m_strNumericVersion.IsEmpty()) + { + m_strNumericVersion = cfg.get_string(uiVersionNumeric); + m_strReadableVersion = cfg.get_string(uiVersionReadable); + m_strDownloadAddress = cfg.get_string(uiDownloadAddress); + } // and compare to current version ushort_t usVer[4]; - if(_stscanf(strNumericVersion, _t("%hu.%hu.%hu.%hu"), &usVer[0], &usVer[1], &usVer[2], &usVer[3]) != 4) + if(_stscanf(m_strNumericVersion, _t("%hu.%hu.%hu.%hu"), &usVer[0], &usVer[1], &usVer[2], &usVer[3]) != 4) { TRACE(_T("Error parsing retrieved version number.")); - return eResult_Error; + m_eResult = eResult_Error; + return m_eResult; } ull_t ullCurrentVersion = ((ull_t)PRODUCT_VERSION1) << 48 | ((ull_t)PRODUCT_VERSION2) << 32 | ((ull_t)PRODUCT_VERSION3) << 16 | ((ull_t)PRODUCT_VERSION4); ull_t ullSiteVersion = ((ull_t)usVer[0]) << 48 | ((ull_t)usVer[1]) << 32 | ((ull_t)usVer[2]) << 16 | ((ull_t)usVer[3]); if(ullCurrentVersion < ullSiteVersion) - return eResult_VersionNewer; + m_eResult = eResult_VersionNewer; else if(ullCurrentVersion == ullSiteVersion) - return eResult_VersionCurrent; + m_eResult = eResult_VersionCurrent; else - return eResult_VersionOlder; + m_eResult = eResult_VersionOlder; + + return m_eResult; } catch(CInternetException* e) { TCHAR* pszBuffer = m_strLastError.GetBufferSetLength(1024); e->GetErrorMessage(pszBuffer, 1023); pszBuffer[1023] = _T('\0'); m_strLastError.ReleaseBuffer(); + m_strLastError.TrimRight(); - return eResult_Error; + m_eResult = eResult_Error; + return m_eResult; } } Index: src/ch/UpdateChecker.h =================================================================== diff -u -r53cb62334fc09a404726d92af726eca6141ad177 -rd9982d1ee462dceb76298ef4216f0b6122d004a6 --- src/ch/UpdateChecker.h (.../UpdateChecker.h) (revision 53cb62334fc09a404726d92af726eca6141ad177) +++ src/ch/UpdateChecker.h (.../UpdateChecker.h) (revision d9982d1ee462dceb76298ef4216f0b6122d004a6) @@ -6,22 +6,32 @@ public: enum ECheckResult { + eResult_Undefined, eResult_VersionOlder, eResult_VersionCurrent, eResult_VersionNewer, eResult_Error }; public: - CUpdateChecker() { }; + CUpdateChecker() : m_eResult(eResult_Undefined) { }; ~CUpdateChecker() { }; - ECheckResult CheckForUpdates(bool bCheckBeta); - void GetRemoteVersion(CString& rVersion) { rVersion = m_strRemoteVersion; } + ECheckResult CheckForUpdates(const tchar_t* pszSite, bool bCheckBeta); + + const tchar_t* GetNumericVersion() const { return (const tchar_t*)m_strNumericVersion; } + const tchar_t* GetReadableVersion() const { return (const tchar_t*)m_strReadableVersion; } const tchar_t* GetLastError() const { return (const tchar_t*)m_strLastError; } + const tchar_t* GetDownloadAddress() const { return m_strDownloadAddress; } + ECheckResult GetResult() const { return m_eResult; } + protected: + CString m_strSite; CString m_strLastError; - CString m_strRemoteVersion; + CString m_strNumericVersion; + CString m_strReadableVersion; + CString m_strDownloadAddress; + ECheckResult m_eResult; }; #endif Index: src/ch/UpdaterDlg.cpp =================================================================== diff -u -r53cb62334fc09a404726d92af726eca6141ad177 -rd9982d1ee462dceb76298ef4216f0b6122d004a6 --- src/ch/UpdaterDlg.cpp (.../UpdaterDlg.cpp) (revision 53cb62334fc09a404726d92af726eca6141ad177) +++ src/ch/UpdaterDlg.cpp (.../UpdaterDlg.cpp) (revision d9982d1ee462dceb76298ef4216f0b6122d004a6) @@ -6,19 +6,23 @@ #include "UpdaterDlg.h" #include "UpdateChecker.h" #include "../common/version.h" -#include "StaticEx.h" +#include +#define UPDATER_TIMER 639 + +BEGIN_MESSAGE_MAP(CUpdaterDlg, ictranslate::CLanguageDialog) + ON_BN_CLICKED(IDC_OPEN_WEBPAGE_BUTTON, &CUpdaterDlg::OnBnClickedOpenWebpageButton) + ON_WM_TIMER() +END_MESSAGE_MAP() + + // CUpdaterDlg dialog IMPLEMENT_DYNAMIC(CUpdaterDlg, ictranslate::CLanguageDialog) -CUpdaterDlg::CUpdaterDlg(CUpdateChecker::ECheckResult eResult, PCTSTR pszVersion, PCTSTR pszError, CWnd* pParent /*=NULL*/) - : ictranslate::CLanguageDialog(CUpdaterDlg::IDD, pParent), - m_eResult(eResult), - m_strVersion(pszVersion), - m_strError(pszError) +CUpdaterDlg::CUpdaterDlg(CWnd* pParent /*=NULL*/) +: ictranslate::CLanguageDialog(CUpdaterDlg::IDD, pParent) { - RegisterStaticExControl(AfxGetInstanceHandle()); } CUpdaterDlg::~CUpdaterDlg() @@ -31,56 +35,68 @@ DDX_Control(pDX, IDC_INFO_STATIC, m_ctlText); } -BEGIN_MESSAGE_MAP(CUpdaterDlg, ictranslate::CLanguageDialog) -END_MESSAGE_MAP() - - -// CUpdaterDlg message handlers BOOL CUpdaterDlg::OnInitDialog() { ictranslate::CLanguageDialog::OnInitDialog(); - ictranslate::CFormat fmt; + + ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_UPDATER_WAITING_STRING)); + fmt.SetParam(_t("%site"), _T(PRODUCT_SITE)); + m_ctlText.SetWindowText(fmt); + + SetTimer(UPDATER_TIMER, 10, NULL); + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +void CUpdaterDlg::StartChecking() +{ + m_ucChecker.CheckForUpdates(_T(PRODUCT_SITE), false); + ictranslate::CResourceManager* pResManager = GetResManager(); - _ASSERTE(pResManager); + BOOST_ASSERT(pResManager); if(!pResManager) - return FALSE; + return; + ictranslate::CFormat fmt; + CString strFmt; - switch(m_eResult) + switch(m_ucChecker.GetResult()) { case CUpdateChecker::eResult_Error: strFmt = pResManager->LoadString(IDS_UPDATER_ERROR_STRING); - fmt.SetFormat(strFmt); - fmt.SetParam(_t("%errdesc"), m_strError); - - m_ctlText.SetWindowText(fmt); break; case CUpdateChecker::eResult_VersionNewer: strFmt = pResManager->LoadString(IDS_UPDATER_NEW_VERSION_STRING); - fmt.SetFormat(strFmt); - fmt.SetParam(_t("%thisver"), _T(PRODUCT_VERSION)); - fmt.SetParam(_t("%officialver"), m_strVersion); - - m_ctlText.SetWindowText(fmt); break; case CUpdateChecker::eResult_VersionCurrent: strFmt = pResManager->LoadString(IDS_UPDATER_EQUAL_VERSION_STRING); - fmt.SetFormat(strFmt); - fmt.SetParam(_t("%thisver"), _T(PRODUCT_VERSION)); - fmt.SetParam(_t("%officialver"), m_strVersion); - - m_ctlText.SetWindowText(fmt); break; case CUpdateChecker::eResult_VersionOlder: strFmt = pResManager->LoadString(IDS_UPDATER_OLD_VERSION_STRING); - fmt.SetFormat(strFmt); - fmt.SetParam(_t("%thisver"), _T(PRODUCT_VERSION)); - fmt.SetParam(_t("%officialver"), m_strVersion); - - m_ctlText.SetWindowText(fmt); break; } - return TRUE; // return TRUE unless you set the focus to a control - // EXCEPTION: OCX Property Pages should return FALSE + fmt.SetFormat(strFmt); + fmt.SetParam(_t("%errdesc"), m_ucChecker.GetLastError()); + fmt.SetParam(_t("%thisver"), _T(PRODUCT_VERSION)); + fmt.SetParam(_t("%officialver"), m_ucChecker.GetReadableVersion()); + + m_ctlText.SetWindowText(fmt); } + +void CUpdaterDlg::OnBnClickedOpenWebpageButton() +{ + ShellExecute(NULL, _T("open"), m_ucChecker.GetDownloadAddress(), NULL, NULL, SW_SHOW); +} + +void CUpdaterDlg::OnTimer(UINT_PTR nIDEvent) +{ + if(nIDEvent == UPDATER_TIMER) + { + KillTimer(UPDATER_TIMER); + StartChecking(); + } + + CLanguageDialog::OnTimer(nIDEvent); +} Index: src/ch/UpdaterDlg.h =================================================================== diff -u -r53cb62334fc09a404726d92af726eca6141ad177 -rd9982d1ee462dceb76298ef4216f0b6122d004a6 --- src/ch/UpdaterDlg.h (.../UpdaterDlg.h) (revision 53cb62334fc09a404726d92af726eca6141ad177) +++ src/ch/UpdaterDlg.h (.../UpdaterDlg.h) (revision d9982d1ee462dceb76298ef4216f0b6122d004a6) @@ -9,21 +9,25 @@ DECLARE_DYNAMIC(CUpdaterDlg) public: - CUpdaterDlg(CUpdateChecker::ECheckResult eResult, PCTSTR pszVersion, PCTSTR pszError, CWnd* pParent = NULL); // standard constructor + CUpdaterDlg(CWnd* pParent = NULL); // standard constructor virtual ~CUpdaterDlg(); -// Dialog Data + // Dialog Data enum { IDD = IDD_UPDATER_DIALOG }; + virtual BOOL OnInitDialog(); + void StartChecking(); + + afx_msg void OnBnClickedOpenWebpageButton(); + afx_msg void OnTimer(UINT_PTR nIDEvent); + protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support DECLARE_MESSAGE_MAP() + +protected: CStatic m_ctlText; + CUpdateChecker m_ucChecker; - CUpdateChecker::ECheckResult m_eResult; - CString m_strVersion; - CString m_strError; -public: - virtual BOOL OnInitDialog(); }; Index: src/ch/ch.rc =================================================================== diff -u -r53cb62334fc09a404726d92af726eca6141ad177 -rd9982d1ee462dceb76298ef4216f0b6122d004a6 --- src/ch/ch.rc (.../ch.rc) (revision 53cb62334fc09a404726d92af726eca6141ad177) +++ src/ch/ch.rc (.../ch.rc) (revision d9982d1ee462dceb76298ef4216f0b6122d004a6) @@ -86,8 +86,12 @@ MENUITEM "Monitor clipboard", ID_POPUP_MONITORING, CHECKED MENUITEM "Shutdown after finished", ID_POPUP_SHUTAFTERFINISHED, CHECKED MENUITEM SEPARATOR + POPUP "&Tools|ID_POPUP_TOOLS" + BEGIN + MENUITEM "&Check for updates...", ID_POPUP_CHECKFORUPDATES + END + MENUITEM SEPARATOR MENUITEM "&Options...", ID_POPUP_OPTIONS - MENUITEM "&Check for updates...", ID_POPUP_CHECKFORUPDATES MENUITEM "&Help...", ID_POPUP_HELP MENUITEM "About...", ID_APP_ABOUT MENUITEM SEPARATOR @@ -563,16 +567,14 @@ EDITTEXT IDC_LOCATION_EDIT,119,65,190,46,ES_MULTILINE | ES_READONLY | NOT WS_BORDER END -IDD_UPDATER_DIALOG DIALOGEX 0, 0, 316, 83 +IDD_UPDATER_DIALOG DIALOGEX 0, 0, 259, 83 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "Version information" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - DEFPUSHBUTTON "OK",IDOK,259,62,50,14 - LTEXT "",IDC_INFO_STATIC,7,7,302,23 - CONTROL "http://www.copyhandler.com|http://www.copyhandler.com",IDC_HOMEPAGELINK_STATIC, - "STATICEX",0x1,204,49,105,8 - LTEXT "The newest version is always available at Copy Handler official web page:",IDC_STATIC00,7,36,302,8 + DEFPUSHBUTTON "&Close",IDOK,202,62,50,14 + LTEXT "",IDC_INFO_STATIC,7,7,245,48 + PUSHBUTTON "&Download latest version...",IDC_OPEN_WEBPAGE_BUTTON,85,62,112,14 END @@ -723,7 +725,7 @@ IDD_UPDATER_DIALOG, DIALOG BEGIN LEFTMARGIN, 7 - RIGHTMARGIN, 309 + RIGHTMARGIN, 252 TOPMARGIN, 7 BOTTOMMARGIN, 76 END @@ -1097,9 +1099,9 @@ IDS_GE_STRING ">=" IDS_GT_STRING ">" IDS_UPDATER_NEW_VERSION_STRING - "There is a new version of Copy Handler (%officialver) available on the official web page. Your current version is %thisver." + "There is a new version of Copy Handler available on the official web page.\n\nYour current version: %thisver\nVersion available on site: %officialver." IDS_UPDATER_OLD_VERSION_STRING - "You have a newer version of Copy Handler (%thisver) than is available on the official web page (%officialver)." + "You have a newer version of Copy Handler than is available on the official web page.\n\nYour current version: %thisver\nVersion available on site: %officialver." END STRINGTABLE @@ -1286,9 +1288,11 @@ STRINGTABLE BEGIN IDS_UPDATER_EQUAL_VERSION_STRING - "You already have the newest version of Copy Handler (%thisver)." + "You already have the newest version of Copy Handler.\n\nYour current version: %thisver\nVersion available on site: %officialver." IDS_UPDATER_ERROR_STRING "There was an error when trying to retrieve version information from the official web page (%errdesc)." + IDS_UPDATER_WAITING_STRING + "Please wait for the connection with %site to be established..." END #endif // English (U.S.) resources Index: src/ch/resource.h =================================================================== diff -u -r53cb62334fc09a404726d92af726eca6141ad177 -rd9982d1ee462dceb76298ef4216f0b6122d004a6 --- src/ch/resource.h (.../resource.h) (revision 53cb62334fc09a404726d92af726eca6141ad177) +++ src/ch/resource.h (.../resource.h) (revision d9982d1ee462dceb76298ef4216f0b6122d004a6) @@ -296,9 +296,9 @@ #define IDC_VERSION_STATIC 1276 #define IDC_VERSIONINFO_STATIC 1278 #define IDC_LOCATIONINFO_STATIC 1279 -#define IDC_EDIT1 1280 #define IDC_LOCATION_EDIT 1280 #define IDC_INFO_STATIC 1282 +#define IDC_OPEN_WEBPAGE_BUTTON 1283 #define IDS_APPNAME_STRING 5000 #define IDS_PRIORITY0_STRING 5001 #define IDS_PRIORITY1_STRING 5002 @@ -325,6 +325,7 @@ #define IDS_UPDATER_OLD_VERSION_STRING 5023 #define IDS_UPDATER_EQUAL_VERSION_STRING 5024 #define IDS_UPDATER_ERROR_STRING 5025 +#define IDS_UPDATER_WAITING_STRING 5026 #define IDS_ONECOPY_STRING 6000 #define IDS_REGISTEROK_STRING 6001 #define IDS_REGISTERERR_STRING 6002 @@ -629,15 +630,16 @@ #define ID_POPUP_HELP 32814 #define ID_POPUP_TEMP 32815 #define ID_POPUP_CHECKFORUPDATES 32816 +#define ID_POPUP_TOOLS 32817 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_3D_CONTROLS 1 #define _APS_NEXT_RESOURCE_VALUE 214 -#define _APS_NEXT_COMMAND_VALUE 32817 -#define _APS_NEXT_CONTROL_VALUE 1283 +#define _APS_NEXT_COMMAND_VALUE 32818 +#define _APS_NEXT_CONTROL_VALUE 1284 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif Index: src/common/version.h =================================================================== diff -u -rf83654b1b3aefc8ad8502695f7fbfb9b93575fa0 -rd9982d1ee462dceb76298ef4216f0b6122d004a6 --- src/common/version.h (.../version.h) (revision f83654b1b3aefc8ad8502695f7fbfb9b93575fa0) +++ src/common/version.h (.../version.h) (revision d9982d1ee462dceb76298ef4216f0b6122d004a6) @@ -5,30 +5,28 @@ // in this case the SETUP_COMPILER is defined with value 1 // Product name #define PRODUCT_NAME "Copy Handler" +// shell extension +#define SHELLEXT_PRODUCT_NAME "Copy Handler Shell Extension" // Version of program #define PRODUCT_VERSION1 1 -#define PRODUCT_VERSION2 30 -#define PRODUCT_VERSION3 119 +#define PRODUCT_VERSION2 31 +#define PRODUCT_VERSION3 129 #define PRODUCT_VERSION4 0 -#define PRODUCT_VERSION "1.30 Final" +#define PRODUCT_VERSION "1.31beta-svn129" -// Full product information (concatenation of the three above informations) #if SETUP_COMPILER != 1 + #define SHELLEXT_PRODUCT_FULL_VERSION SHELLEXT_PRODUCT_NAME " " PRODUCT_VERSION + #define SHELLEXT_PRODUCT_FULL_VERSION_T _T(SHELLEXT_PRODUCT_NAME) _T(" ") _T(PRODUCT_VERSION) + #define PRODUCT_FULL_VERSION PRODUCT_NAME " " PRODUCT_VERSION #define PRODUCT_FULL_VERSION_T _T(PRODUCT_NAME) _T(" ") _T(PRODUCT_VERSION) #endif // copyright information #define COPYRIGHT_INFO "Copyright (C) 2001-2008 J�zef Starosczyk" +#define PRODUCT_SITE "http://www.copyhandler.com" -// shell extension -#define SHELLEXT_PRODUCT_NAME "Copy Handler Shell Extension" -#if SETUP_COMPILER != 1 - #define SHELLEXT_PRODUCT_FULL_VERSION SHELLEXT_PRODUCT_NAME " " PRODUCT_VERSION - #define SHELLEXT_PRODUCT_FULL_VERSION_T _T(SHELLEXT_PRODUCT_NAME) _T(" ") _T(PRODUCT_VERSION) #endif - -#endif