Index: src/ch/UpdaterDlg.cpp =================================================================== diff -u -r50ad2dc9f0b42ba432bb54e4a042582277410773 -r50007f112b77cba170e6c427fee5428bda2d9dc5 --- src/ch/UpdaterDlg.cpp (.../UpdaterDlg.cpp) (revision 50ad2dc9f0b42ba432bb54e4a042582277410773) +++ src/ch/UpdaterDlg.cpp (.../UpdaterDlg.cpp) (revision 50007f112b77cba170e6c427fee5428bda2d9dc5) @@ -7,11 +7,16 @@ #include "UpdateChecker.h" #include "../common/version.h" #include "StaticEx.h" +#include +#include +#include "WindowsVersion.h" #define UPDATER_TIMER 639 BEGIN_MESSAGE_MAP(CUpdaterDlg, ictranslate::CLanguageDialog) ON_BN_CLICKED(IDC_OPEN_WEBPAGE_BUTTON, &CUpdaterDlg::OnBnClickedOpenWebpageButton) + ON_CBN_SELCHANGE(IDC_UPDATESFREQ_COMBO, OnSelchangeFreqCombo) + ON_CBN_SELCHANGE(IDC_UPDATECHANNEL_COMBO, OnSelchangeChannelCombo) ON_WM_TIMER() END_MESSAGE_MAP() @@ -39,30 +44,30 @@ DDX_Control(pDX, IDC_ICON_STATIC, m_ctlImage); DDX_Control(pDX, IDC_MAINUPDATEINFO_CUSTOM, m_ctlMainText); DDX_Control(pDX, IDC_CHANGELOG_RICHEDIT, m_ctlRichEdit); + DDX_Control(pDX, IDC_UPDATESFREQ_COMBO, m_ctlUpdateFreq); + DDX_Control(pDX, IDC_UPDATECHANNEL_COMBO, m_ctlUpdateChannel); + } BOOL CUpdaterDlg::OnInitDialog() { ictranslate::CLanguageDialog::OnInitDialog(); -/* - ictranslate::CFormat fmt(GetResManager().LoadString(IDS_UPDATER_WAITING_STRING)); - fmt.SetParam(_t("%site"), _T(PRODUCT_SITE)); - m_ctlText.SetWindowText(fmt);*/ + InitRichEdit(); + InitUpdateFreqCombo(); + InitUpdateChannelCombo(); // disable button initially - CWnd* pWnd = GetDlgItem(IDC_OPEN_WEBPAGE_BUTTON); - if(pWnd) - pWnd->EnableWindow(FALSE); + EnableOpenWebPageButton(false); if(!m_bBackgroundMode) ShowWindow(SW_SHOW); // start the updater - m_ucChecker.AsyncCheckForUpdates(_T(PRODUCT_SITE), GetPropValue(GetConfig()), (UpdateVersionInfo::EVersionType)GetPropValue(GetConfig()), m_bBackgroundMode); + CheckForUpdates(); // start a timer to display progress - SetTimer(UPDATER_TIMER, 10, NULL); + SetTimer(UPDATER_TIMER, 50, NULL); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE @@ -98,11 +103,13 @@ CUpdateChecker::ECheckResult eResult = m_ucChecker.GetResult(); CString strFmt; EBkModeResult eBkMode = eRes_None; - bool bEnableButton = false; if(eResult != m_eLastState) { - switch(m_ucChecker.GetResult()) + bool bEnableButton = false; + m_eLastState = eResult; + + switch(eResult) { case CUpdateChecker::eResult_Undefined: TRACE(_T("CUpdateChecker::eResult_Undefined\n")); @@ -160,23 +167,30 @@ } fmt.SetFormat(strFmt); - fmt.SetParam(_t("%site"), _t(PRODUCT_SITE)); - fmt.SetParam(_t("%thisver"), _T(PRODUCT_VERSION)); - fmt.SetParam(L"%numericver", PRODUCT_NUMERIC_VERSION); - fmt.SetParam(_t("%officialver"), m_ucChecker.GetReadableVersion()); + fmt.SetParam(_T("%site"), _T(PRODUCT_SITE)); + fmt.SetParam(_T("%thisver"), _T(PRODUCT_VERSION)); + fmt.SetParam(L"%thisnumericver", PRODUCT_NUMERIC_VERSION); + fmt.SetParam(L"%numericver", m_ucChecker.GetNumericVersion()); + fmt.SetParam(_T("%officialver"), m_ucChecker.GetReadableVersion()); fmt.SetParam(L"%reldate", m_ucChecker.GetReleaseDate()); CString strEntireText = fmt; - strEntireText += L"\r\n\r\nRelease notes:\n" + CString(m_ucChecker.GetReleaseNotes()); + CString strReleaseNotes = m_ucChecker.GetReleaseNotes(); + strReleaseNotes = strReleaseNotes.Trim(); + if(!strReleaseNotes.IsEmpty()) + { + fmt.SetFormat(L"\n\n%relnoteshdr\n%relnotestxt"); + fmt.SetParam(L"%relnoteshdr", rResManager.LoadString(IDS_UPDATER_RELEASENOTES)); + fmt.SetParam(L"%relnotestxt", m_ucChecker.GetReleaseNotes()); + strEntireText += fmt; + } + UpdateSecondaryText(strEntireText); // Update button state - CWnd* pWnd = GetDlgItem(IDC_OPEN_WEBPAGE_BUTTON); - if(pWnd) - pWnd->EnableWindow(bEnableButton); + EnableOpenWebPageButton(bEnableButton); + EnableUpdateRelatedControls(eResult > CUpdateChecker::eResult_Pending); - m_eLastState = eResult; - // handle background mode if(m_bBackgroundMode) { @@ -190,6 +204,8 @@ return; case eRes_Show: ShowWindow(SW_SHOW); + m_bBackgroundMode = false; // when we show this window for the first time the user is responsible for closing the dialog; + // otherwise window might close by itself when checking for updates from within the open window break; default: BOOST_ASSERT(FALSE); @@ -232,3 +248,108 @@ { m_ctlRichEdit.SetWindowText(pszText); } + +void CUpdaterDlg::InitRichEdit() +{ + COLORREF crTextColor = GetSysColor(COLOR_BTNTEXT); + CHARFORMAT2 cf; + cf.cbSize = sizeof(CHARFORMAT2); + + m_ctlRichEdit.GetDefaultCharFormat(cf); + cf.dwMask |= CFM_COLOR; + cf.dwEffects &= ~CFE_AUTOCOLOR; + cf.crTextColor = crTextColor; + m_ctlRichEdit.SetDefaultCharFormat(cf); +} + +void CUpdaterDlg::InitUpdateChannelCombo() +{ + ictranslate::CResourceManager& rResManager = GetResManager(); + + std::wstring strText = rResManager.LoadString(IDS_CFGUPDATECHANNELITEMS_STRING); + std::vector vItems; + for(std::wstring strItem : boost::split(vItems, strText, boost::is_any_of(L"!"))) + { + m_ctlUpdateChannel.AddString(strItem.c_str()); + } + + UpdateVersionInfo::EVersionType eUpdateChannel = (UpdateVersionInfo::EVersionType)GetPropValue(GetConfig()); + if(eUpdateChannel < vItems.size()) + m_ctlUpdateChannel.SetCurSel(eUpdateChannel); + else + m_ctlUpdateChannel.SetCurSel(0); +} + +void CUpdaterDlg::InitUpdateFreqCombo() +{ + ictranslate::CResourceManager& rResManager = GetResManager(); + + std::wstring strText = rResManager.LoadString(IDS_UPDATE_FREQUENCIES); + std::vector vItems; + for(std::wstring strItem : boost::split(vItems, strText, boost::is_any_of(L"!"))) + { + m_ctlUpdateFreq.AddString(strItem.c_str()); + } + + EUpdatesFrequency eFrequency = (EUpdatesFrequency)GetPropValue(GetConfig()); + if(eFrequency < vItems.size()) + m_ctlUpdateFreq.SetCurSel(eFrequency); + else + m_ctlUpdateFreq.SetCurSel(0); +} + +void CUpdaterDlg::OnSelchangeFreqCombo() +{ + int iCurSel = m_ctlUpdateFreq.GetCurSel(); + if(iCurSel == CB_ERR) + return; + + EUpdatesFrequency eFrequency = eFreq_Weekly; + if(iCurSel < EUpdatesFrequency::eFreq_Max) + eFrequency = (EUpdatesFrequency)iCurSel; + + SetPropValue(GetConfig(), eFrequency); + GetConfig().Write(); +} + +void CUpdaterDlg::OnSelchangeChannelCombo() +{ + int iCurSel = m_ctlUpdateChannel.GetCurSel(); + if(iCurSel == CB_ERR) + return; + + UpdateVersionInfo::EVersionType eFrequency = UpdateVersionInfo::eReleaseCandidate; + if(iCurSel < UpdateVersionInfo::EVersionType::eMax) + eFrequency = (UpdateVersionInfo::EVersionType)iCurSel; + + SetPropValue(GetConfig(), eFrequency); + GetConfig().Write(); + + CheckForUpdates(); +} + +void CUpdaterDlg::EnableOpenWebPageButton(bool bEnable) +{ + CWnd* pWnd = GetDlgItem(IDC_OPEN_WEBPAGE_BUTTON); + if(pWnd) + pWnd->EnableWindow(bEnable ? TRUE : FALSE); +} + +void CUpdaterDlg::CheckForUpdates() +{ + EnableUpdateRelatedControls(false); + m_eLastState = CUpdateChecker::eResult_Undefined; + + bool bIsWinXP = WindowsVersion::IsWindowsXP(); + + CString strSite = _T(UPDATE_CHECK_LINK_SECURE); + if(bIsWinXP) + strSite = _T(UPDATE_CHECK_LINK_NONSECURE); + + m_ucChecker.AsyncCheckForUpdates(strSite, GetPropValue(GetConfig()), (UpdateVersionInfo::EVersionType)GetPropValue(GetConfig()), m_bBackgroundMode, !bIsWinXP); +} + +void CUpdaterDlg::EnableUpdateRelatedControls(bool bEnable) +{ + m_ctlUpdateChannel.EnableWindow(bEnable ? TRUE : FALSE); +}