Index: src/ch/MainWnd.cpp =================================================================== diff -u -r336bb030d9b4bff561ff100563725213ed6703c9 -r53cb62334fc09a404726d92af726eca6141ad177 --- src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 336bb030d9b4bff561ff100563725213ed6703c9) +++ src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 53cb62334fc09a404726d92af726eca6141ad177) @@ -48,6 +48,8 @@ #include "..\common\ipcstructs.h" #include #include "af_defs.h" +#include "UpdateChecker.h" +#include "UpdaterDlg.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -146,6 +148,7 @@ ON_COMMAND(ID_POPUP_HELP, OnPopupHelp) //}}AFX_MSG_MAP ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification) + ON_COMMAND(ID_POPUP_CHECKFORUPDATES, &CMainWnd::OnPopupCheckForUpdates) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// @@ -2327,4 +2330,15 @@ void CMainWnd::OnPopupHelp() { GetApp()->HtmlHelp(HH_DISPLAY_TOPIC, NULL); -} \ No newline at end of file +} + +void CMainWnd::OnPopupCheckForUpdates() +{ + CUpdateChecker uc; + CUpdateChecker::ECheckResult eResult = uc.CheckForUpdates(true); + + CString strVer; + uc.GetRemoteVersion(strVer); + CUpdaterDlg dlg(eResult, strVer, uc.GetLastError()); + dlg.DoModal(); +} Index: src/ch/MainWnd.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -r53cb62334fc09a404726d92af726eca6141ad177 --- src/ch/MainWnd.h (.../MainWnd.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/MainWnd.h (.../MainWnd.h) (revision 53cb62334fc09a404726d92af726eca6141ad177) @@ -98,6 +98,8 @@ //}}AFX_MSG afx_msg LRESULT OnTrayNotification(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() +public: + afx_msg void OnPopupCheckForUpdates(); }; ///////////////////////////////////////////////////////////////////////////// Index: src/ch/UpdateChecker.cpp =================================================================== diff -u -ra3019fc815b1cf8697777e432338a3b8eb0cb820 -r53cb62334fc09a404726d92af726eca6141ad177 --- src/ch/UpdateChecker.cpp (.../UpdateChecker.cpp) (revision a3019fc815b1cf8697777e432338a3b8eb0cb820) +++ src/ch/UpdateChecker.cpp (.../UpdateChecker.cpp) (revision 53cb62334fc09a404726d92af726eca6141ad177) @@ -22,17 +22,31 @@ if(!pHttpFile->SendRequest()) return eResult_Error; - char szBuf[256]; - UINT uiRD = pHttpFile->Read(szBuf, 255); + char szBuf[512]; + UINT uiRD = pHttpFile->Read(szBuf, 511); if(uiRD > 0) szBuf[uiRD] = _T('\0'); // convert text to unicode CA2CT a2ct(szBuf); + CString strVersion = a2ct; + CString strNumericVersion; + CString strReadableVersion; + int iPos = strVersion.Find(_t('|')); + if(iPos != -1) + { + strNumericVersion = strVersion.Mid(0, iPos); + strReadableVersion = strVersion.Mid(iPos + 1); + } + else + strNumericVersion = strVersion; + + m_strRemoteVersion = strReadableVersion; + // and compare to current version ushort_t usVer[4]; - if(_stscanf(a2ct, _t("%hu.%hu.%hu.%hu"), &usVer[0], &usVer[1], &usVer[2], &usVer[3]) != 4) + if(_stscanf(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; @@ -42,11 +56,11 @@ 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_VersionOlder; + return eResult_VersionNewer; else if(ullCurrentVersion == ullSiteVersion) return eResult_VersionCurrent; else - return eResult_VersionNewer; + return eResult_VersionOlder; } catch(CInternetException* e) { Index: src/ch/UpdateChecker.h =================================================================== diff -u -ra3019fc815b1cf8697777e432338a3b8eb0cb820 -r53cb62334fc09a404726d92af726eca6141ad177 --- src/ch/UpdateChecker.h (.../UpdateChecker.h) (revision a3019fc815b1cf8697777e432338a3b8eb0cb820) +++ src/ch/UpdateChecker.h (.../UpdateChecker.h) (revision 53cb62334fc09a404726d92af726eca6141ad177) @@ -16,10 +16,12 @@ ~CUpdateChecker() { }; ECheckResult CheckForUpdates(bool bCheckBeta); + void GetRemoteVersion(CString& rVersion) { rVersion = m_strRemoteVersion; } const tchar_t* GetLastError() const { return (const tchar_t*)m_strLastError; } protected: CString m_strLastError; + CString m_strRemoteVersion; }; #endif Index: src/ch/UpdaterDlg.cpp =================================================================== diff -u --- src/ch/UpdaterDlg.cpp (revision 0) +++ src/ch/UpdaterDlg.cpp (revision 53cb62334fc09a404726d92af726eca6141ad177) @@ -0,0 +1,86 @@ +// UpdaterDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "ch.h" +#include "UpdaterDlg.h" +#include "UpdateChecker.h" +#include "../common/version.h" +#include "StaticEx.h" + +// 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) +{ + RegisterStaticExControl(AfxGetInstanceHandle()); +} + +CUpdaterDlg::~CUpdaterDlg() +{ +} + +void CUpdaterDlg::DoDataExchange(CDataExchange* pDX) +{ + ictranslate::CLanguageDialog::DoDataExchange(pDX); + 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::CResourceManager* pResManager = GetResManager(); + _ASSERTE(pResManager); + if(!pResManager) + return FALSE; + + CString strFmt; + switch(m_eResult) + { + 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 +} Index: src/ch/UpdaterDlg.h =================================================================== diff -u --- src/ch/UpdaterDlg.h (revision 0) +++ src/ch/UpdaterDlg.h (revision 53cb62334fc09a404726d92af726eca6141ad177) @@ -0,0 +1,29 @@ +#pragma once +#include "afxwin.h" +#include "UpdateChecker.h" + +// CUpdaterDlg dialog + +class CUpdaterDlg : public ictranslate::CLanguageDialog +{ + DECLARE_DYNAMIC(CUpdaterDlg) + +public: + CUpdaterDlg(CUpdateChecker::ECheckResult eResult, PCTSTR pszVersion, PCTSTR pszError, CWnd* pParent = NULL); // standard constructor + virtual ~CUpdaterDlg(); + +// Dialog Data + enum { IDD = IDD_UPDATER_DIALOG }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + + DECLARE_MESSAGE_MAP() + CStatic m_ctlText; + + CUpdateChecker::ECheckResult m_eResult; + CString m_strVersion; + CString m_strError; +public: + virtual BOOL OnInitDialog(); +}; Index: src/ch/ch.rc =================================================================== diff -u -r336bb030d9b4bff561ff100563725213ed6703c9 -r53cb62334fc09a404726d92af726eca6141ad177 --- src/ch/ch.rc (.../ch.rc) (revision 336bb030d9b4bff561ff100563725213ed6703c9) +++ src/ch/ch.rc (.../ch.rc) (revision 53cb62334fc09a404726d92af726eca6141ad177) @@ -87,6 +87,7 @@ MENUITEM "Shutdown after finished", ID_POPUP_SHUTAFTERFINISHED, CHECKED 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 @@ -562,7 +563,19 @@ EDITTEXT IDC_LOCATION_EDIT,119,65,190,46,ES_MULTILINE | ES_READONLY | NOT WS_BORDER END +IDD_UPDATER_DIALOG DIALOGEX 0, 0, 316, 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 +END + ///////////////////////////////////////////////////////////////////////////// // // DESIGNINFO @@ -706,6 +719,14 @@ TOPMARGIN, 7 BOTTOMMARGIN, 131 END + + IDD_UPDATER_DIALOG, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 309 + TOPMARGIN, 7 + BOTTOMMARGIN, 76 + END END #endif // APSTUDIO_INVOKED @@ -1054,7 +1075,8 @@ IDS_STATUS9_STRING "Waiting" IDS_STATUS10_STRING "Only files" IDS_STATUS11_STRING "Without contents" - IDS_SHELLEXECUTEERROR_STRING "Error #%errno calling ShellExecute for file %path" + IDS_SHELLEXECUTEERROR_STRING + "Error #%errno calling ShellExecute for file %path" IDS_BSDEFAULT_STRING "Default: " END @@ -1074,6 +1096,10 @@ IDS_EQ_STRING "=" 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." + IDS_UPDATER_OLD_VERSION_STRING + "You have a newer version of Copy Handler (%thisver) than is available on the official web page (%officialver)." END STRINGTABLE @@ -1257,6 +1283,14 @@ IDS_NERPATH_STRING "There is not enough room in %path to copy or move:" END +STRINGTABLE +BEGIN + IDS_UPDATER_EQUAL_VERSION_STRING + "You already have the newest version of Copy Handler (%thisver)." + IDS_UPDATER_ERROR_STRING + "There was an error when trying to retrieve version information from the official web page (%errdesc)." +END + #endif // English (U.S.) resources ///////////////////////////////////////////////////////////////////////////// Index: src/ch/ch.vc90.vcproj =================================================================== diff -u -ra3019fc815b1cf8697777e432338a3b8eb0cb820 -r53cb62334fc09a404726d92af726eca6141ad177 --- src/ch/ch.vc90.vcproj (.../ch.vc90.vcproj) (revision a3019fc815b1cf8697777e432338a3b8eb0cb820) +++ src/ch/ch.vc90.vcproj (.../ch.vc90.vcproj) (revision 53cb62334fc09a404726d92af726eca6141ad177) @@ -715,6 +715,10 @@ RelativePath=".\UpdateChecker.cpp" > + + + +