util.cpp
3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <windows.h>
#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<HttpWebResponse^>(request->GetResponse());
if (response->StatusDescription == "OK"){
return true;
}
return false;
response->Close();
}
catch ( WebException^ e )
{
return false;
}
}
vector<string> Util::checkVersion(bool atualize)
{
XmlDocument^ xmlDoc;
XmlNodeList^ files;
XmlDocument^ xmlDocLocal;
XmlNodeList^ filesLocal;
vector<string> updates;
vector<string> 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<HttpWebResponse^>(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;i<numitems;i++)
if(numitems>0)
{
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<string> Util::localVersion()
{
XmlDocument^ xmlDocLocal;
XmlNodeList^ filesLocal;
vector<string> 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;
}