#include "checkVersion.h" using namespace std; CheckVersion::CheckVersion() { //reset(); } void CheckVersion::checkRefresh() { reset(); checkLocal(); checkApi(); if(!(localDictVersion == -1 || dictVersion == -1 || localPlayerVersion == -1 || playerVersion == -1)) { vstatus = 0; if(localDictVersion < dictVersion && localPlayerVersion < playerVersion) vstatus=1; else if(localPlayerVersion < playerVersion) vstatus = 1; else if(localDictVersion < dictVersion) vstatus = 2; } else vstatus = -1; } void find_and_replace(string& source, string const& find, string const& replace) { for(string::size_type i = 0; (i = source.find(find, i)) != string::npos;) { source.replace(i, find.length(), replace); i += replace.length(); } } void CheckVersion::checkLocal() { int result = 0; string line; ifstream myfile ("c:\\vlibras-libs\\update\\updateVersion.xml"); if (myfile.is_open()) { while ( getline(myfile,line) ) { if(strstr(line.c_str(),"")) { string version; int ia = line.find("")+19; int ib = line.find("")-23; version = line.substr(ia,ib); dictCallVersion = version; find_and_replace(version,".",""); find_and_replace(version,"_",""); find_and_replace(version," ",""); localDictVersion = atoi(version.c_str()); } else if(strstr(line.c_str(),"")) { string version; int ia = line.find("")+15; int ib = line.find("")-19; version = line.substr(ia,ib); find_and_replace(version,".",""); find_and_replace(version,"_",""); find_and_replace(version," ",""); localPlayerVersion = atoi(version.c_str()); } } myfile.close(); } } void CheckVersion::checkApi() { cout << "dictCallVersion ====> " << dictCallVersion<< endl; string url = "http://vlibras.lavid.ufpb.br/api/dicionario/"; url.append(dictCallVersion); url.append("?type=windows"); HRESULT hr = URLDownloadToFile ( NULL, _T(url.c_str()), _T("c:\\vlibras-libs\\update\\netVersion.xml"), 0, NULL ); if(SUCCEEDED(hr)){ string line; ifstream myfile ("c:\\vlibras-libs\\update\\netVersion.xml"); if (myfile.is_open()) { while ( getline(myfile,line) ) { if(strstr(line.c_str(),"")) { string version; int ia = line.find("")+19; int ib = line.find("")-23; version = line.substr(ia,ib); dictVersionFull = version; find_and_replace(version,".",""); find_and_replace(version,"_",""); find_and_replace(version," ",""); dictVersion = atoi(version.c_str()); } else if(strstr(line.c_str(),"")) { string version; int ia = line.find("")+15; int ib = line.find("")-19; version = line.substr(ia,ib); playerVersionFull = version; find_and_replace(version,".",""); find_and_replace(version,"_",""); find_and_replace(version," ",""); playerVersion = atoi(version.c_str()); } else if(strstr(line.c_str(),"")) { string version; int ia = line.find("")+11; int ib = line.find("")-15; version = line.substr(ia,ib); playerUrl = version; } else if(strstr(line.c_str(),"")) { string version; int ia = line.find("")+15; int ib = line.find("")-19; version = line.substr(ia,ib); dictUrl = version; } } myfile.close(); } } } void CheckVersion::reset() { playerVersion = -1; dictVersion = -1; localPlayerVersion = -1; localDictVersion = -1; playerUrl = ""; dictUrl = ""; vstatus = -1; } //return // -1 se erro //0 se não necessita de atualização // 1 se tiver para player // 2 se dicionario