Index: src/ch/UpdateChecker.h =================================================================== diff -u -rd5c3edd0d167db9b5d47d04248820fda49499a5e -r4fe995b304ea342b50293f92d3c1992b43b820f7 --- src/ch/UpdateChecker.h (.../UpdateChecker.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) +++ src/ch/UpdateChecker.h (.../UpdateChecker.h) (revision 4fe995b304ea342b50293f92d3c1992b43b820f7) @@ -1,37 +1,108 @@ +// ============================================================================ +// Copyright (C) 2001-2009 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +/// @file UpdateChecker.h +/// @date 2009/04/18 +/// @brief Contains declaration of update checker class. +// ============================================================================ #ifndef __UPDATECHECKER_H__ #define __UPDATECHECKER_H__ -class CUpdateChecker +#include "AsyncHttpFile.h" +#include "UpdateHeaders.h" +#include "UpdateVersionInfo.h" + +class CUpdateChecker : protected CInternetSession { public: enum ECheckResult { eResult_Undefined, - eResult_VersionOlder, + eResult_Pending, + eResult_Killed, + eResult_Error, eResult_VersionCurrent, - eResult_VersionNewer, - eResult_Error + eResult_RemoteVersionNewer }; + public: - CUpdateChecker() : m_eResult(eResult_Undefined) { }; - ~CUpdateChecker() { }; + /// Constructs the update checker object + CUpdateChecker(); + /// Destructs the update checker object + ~CUpdateChecker(); - ECheckResult CheckForUpdates(const tchar_t* pszSite, bool bCheckBeta); + /// Starts the 'check for updates' thread + bool AsyncCheckForUpdates(const wchar_t* pszSite, const wchar_t* pszLanguage, UpdateVersionInfo::EVersionType eUpdateChannel, bool bOnlyIfConnected, bool bSendHeaders); - 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; } + /// Stops checking and cleanups the object + void Cleanup(); - ECheckResult GetResult() const { return m_eResult; } + /// Retrieves the update result + ECheckResult GetResult() const; + // methods for retrieving state + const wchar_t* GetNumericVersion() const { return (const wchar_t*)m_strNumericVersion; } + const wchar_t* GetReadableVersion() const { return (const wchar_t*)m_strReadableVersion; } + const wchar_t* GetLastError() const { return (const wchar_t*)m_strLastError; } + const wchar_t* GetDownloadAddress() const { return m_strDownloadAddress; } + const wchar_t* GetReleaseDate() const { return m_strReleaseDate; } + const wchar_t* GetReleaseNotes() const { return m_strReleaseNotes; } + bool GetSendHeaders() const { return m_bSendHeaders; } + protected: + /// Thread function (handles most of the internet connection operation) + static DWORD WINAPI UpdateCheckThread(LPVOID pParam); + + /// Sets the result in mt-safe way + void SetResult(ECheckResult eCheckResult, DWORD dwError); + /// Sets the last error + void SetLastError(PCTSTR pszError); + /// Sets the versions and download address + void SetVersionsAndAddress(PCTSTR pszAddress, PCTSTR pszNumericVersion, PCTSTR pszReadableVersion, PCTSTR pszReleaseDate, PCTSTR pszReleaseNotes); + /// Retrieves the site address + CString GetSiteAddress() const; + + void SetSendHeaders(bool bSendHeaders); + + /// Returns information if we're interested in beta versions + UpdateVersionInfo::EVersionType GetUpdateChannel(); + static std::wstring FormatDate(const boost::gregorian::date& date); + +protected: CString m_strSite; + UpdateVersionInfo::EVersionType m_eUpdateChannel; + CString m_strLanguage; CString m_strLastError; CString m_strNumericVersion; CString m_strReadableVersion; CString m_strDownloadAddress; + CString m_strReleaseDate; + CString m_strReleaseNotes; + bool m_bSendHeaders = true; + ECheckResult m_eResult; + + CAsyncHttpFile m_httpFile; + UpdateHeaders m_tUpdateHeaders; + + HANDLE m_hThread; + HANDLE m_hKillEvent; + mutable CRITICAL_SECTION m_cs; }; #endif