// ============================================================================ // Copyright (C) 2001-2015 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. // ============================================================================ #include "stdafx.h" #include "UpdateResponse.h" #pragma warning(push) #pragma warning(disable: 4244) #include #include #include #include #include #include #include #pragma warning(pop) UpdateResponse::UpdateResponse(std::stringstream& tDataStream) { std::wstring_convert, wchar_t> conversion; std::wstringstream wssData(conversion.from_bytes(tDataStream.str())); using namespace boost::property_tree; wiptree pt; read_xml(wssData, pt); // add version information; note that assumption here that we receive version informations // sorted by stability (decreasing) - that way we only present the user suggestions to download // newest versions with highest stability unsigned long long ullLastVersionNumber = 0; for(const wiptree::value_type& node : pt.get_child(L"UpdateInfo")) { try { UpdateVersionInfo::EVersionType eType = ParseVersionName(node.first); UpdateVersionInfo vi = ParseVersionInfo(node.second); if(vi.GetFullNumericVersion() > ullLastVersionNumber) m_tVersions.Add(eType, std::move(vi)); ullLastVersionNumber = vi.GetFullNumericVersion(); } catch(const std::exception&) // ignore exceptions from version parsing code { } } } UpdateMultipleVersionInfo& UpdateResponse::GetVersions() { return m_tVersions; } UpdateVersionInfo::EVersionType UpdateResponse::ParseVersionName(const std::wstring& strVersionName) { if(boost::iequals(strVersionName, L"Stable")) return UpdateVersionInfo::eStable; if(boost::iequals(strVersionName, L"RC")) return UpdateVersionInfo::eReleaseCandidate; if(boost::iequals(strVersionName, L"Beta")) return UpdateVersionInfo::eBeta; if(boost::iequals(strVersionName, L"Alpha")) return UpdateVersionInfo::eAlpha; throw std::runtime_error("Unknown version received"); } UpdateVersionInfo UpdateResponse::ParseVersionInfo(const boost::property_tree::wiptree& node) { return UpdateVersionInfo(node.get(L"NumericVersion"), node.get(L"ReadableVersion"), ConvertDate(node.get(L"ReleaseDateUtc")), node.get(L"DownloadLink"), node.get(L"ReleaseNotes")); } boost::gregorian::date UpdateResponse::ConvertDate(const std::wstring& wstrReleaseDate) { using namespace boost::gregorian; std::wstringstream ss; wdate_input_facet * fac = new wdate_input_facet(L"%Y-%m-%d"); ss.imbue(std::locale(std::locale::classic(), fac)); boost::gregorian::date dtRelease; ss << wstrReleaseDate; ss >> dtRelease; return dtRelease; }