#include #include "util.h" Util::Util(){ //downloading = true; //downloading = down; } string Util::clrStringTostring(String^ strIn) { char cStr[256]; sprintf(cStr, "%s", strIn); string stlString(cStr); return stlString; } bool Util::checkNet() { try { WebRequest^ request = WebRequest::Create( "http://vlibras.lavid.ufpb.br" ); // If required by the server, set the credentials. //request->Credentials = CredentialCache::DefaultCredentials; // Get the response. HttpWebResponse^ response = dynamic_cast(request->GetResponse()); if (response->StatusDescription == "OK"){ return true; } return false; response->Close(); } catch ( WebException^ e ) { return false; } } vector Util::checkVersion(bool atualize) { XmlDocument^ xmlDoc; XmlNodeList^ files; XmlDocument^ xmlDocLocal; XmlNodeList^ filesLocal; vector updates; vector localversion = localVersion(); try { xmlDoc = (gcnew XmlDocument()); xmlDocLocal = (gcnew XmlDocument()); string url = "http://vlibras.lavid.ufpb.br/api/dicionario/"+localversion[3]+"?type=windows"; WebRequest^ request = WebRequest::Create( gcnew String(url.c_str())); // If required by the server, set the credentials. request->Credentials = CredentialCache::DefaultCredentials; // Get the response. HttpWebResponse^ response = dynamic_cast(request->GetResponse()); if (!(response->StatusDescription == "OK")) goto erro; // Get the stream containing content returned by the server. Stream^ dataStream = response->GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader^ reader = gcnew StreamReader( dataStream ); // Read the content. String^ responseFromServer = reader->ReadToEnd(); xmlDoc->LoadXml(responseFromServer); files = xmlDoc->GetElementsByTagName("version"); long numitems = files->Count; //for (int i=0;i0) { String^ playerVersion = files[0]["playerVersion"]->InnerText; String^ dictionaryVersion = files[0]["dictionaryVersion"]->InnerText; if(String::Compare( playerVersion, gcnew String(localversion[1].c_str()))) { updates.push_back("playerVersion"); updates.push_back(clrStringTostring(playerVersion)); updates.push_back(clrStringTostring(files[0]["playerUrl"]->InnerText)); } if(String::Compare(dictionaryVersion,gcnew String(localversion[3].c_str()))) { updates.push_back("dictionaryVersion"); updates.push_back(clrStringTostring(dictionaryVersion)); updates.push_back(clrStringTostring(files[0]["dictionaryUrl"]->InnerText)); } //if(atualize) //saveNewXmlVersion(playerVersion,dictionaryVersion); } erro: // Cleanup the streams and the response. reader->Close(); dataStream->Close(); }catch(Exception^ e) { updates.push_back("faill"); return updates; } return updates; } vector Util::localVersion() { XmlDocument^ xmlDocLocal; XmlNodeList^ filesLocal; vector updates; try { xmlDocLocal = (gcnew XmlDocument()); //xml version local StreamReader^ readerLocal = gcnew StreamReader("c:\\vlibras-libs\\update\\updateVersion.xml"); String^ responseLocal = readerLocal->ReadToEnd(); xmlDocLocal->LoadXml(responseLocal); filesLocal = xmlDocLocal->GetElementsByTagName("version"); updates.push_back("playerVersion"); String^ playerVersion = filesLocal[0]["playerVersion"]->InnerText; updates.push_back(clrStringTostring(playerVersion)); updates.push_back("dictionaryVersion"); String^ dictionaryVersion = filesLocal[0]["dictionaryVersion"]->InnerText; updates.push_back(clrStringTostring(dictionaryVersion)); // Cleanup the streams and the response. readerLocal->Close(); }catch(Exception^ e) { return updates; } return updates; }