#include "stdafx.h"
#include "CVersion.h"

CVersion::CVersion()
{
}

CVersion::~CVersion()
{
}

bool CVersion::Inti(std::string data)
{
	if (data.empty())
	{
		return false;
	}

	try
	{
		nlohmann::json j = nlohmann::json::parse(data.begin(), data.end());

		if (j["ret"].get<int>() == 1)
		{
			//
			this->appversion = j["data"]["appversion"].get<std::string>();
			this->appdownload = j["data"]["appdownload"].get<std::string>();
			this->appmsg = j["data"]["appmsg"].get<std::string>();
			this->versionupdate = j["data"]["versionupdate"].get<int>();
			return true;

		}
		else
		{
			SStringW msg;
			msg.Format(L"当前版本号:%s", VERSION, S_CA2W(j["msg"].get<std::string>().c_str(), CP_UTF8));
			this->m_error_msg = msg.GetBuffer(0);
			return false;
		}


	}
	catch (...)
	{
		this->m_error_msg = L"解析数据错误";
		return false;
	}
	return false;
}
