checkVersion.cpp
4.35 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#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(),"<dictionaryVersion>"))
{
string version;
int ia = line.find("<dictionaryVersion>")+19;
int ib = line.find("</dictionaryVersion>")-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(),"<playerVersion>"))
{
string version;
int ia = line.find("<playerVersion>")+15;
int ib = line.find("</playerVersion>")-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(),"<dictionaryVersion>"))
{
string version;
int ia = line.find("<dictionaryVersion>")+19;
int ib = line.find("</dictionaryVersion>")-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(),"<playerVersion>"))
{
string version;
int ia = line.find("<playerVersion>")+15;
int ib = line.find("</playerVersion>")-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(),"<playerUrl>"))
{
string version;
int ia = line.find("<playerUrl>")+11;
int ib = line.find("</playerUrl>")-15;
version = line.substr(ia,ib);
playerUrl = version;
}
else if(strstr(line.c_str(),"<dictionaryUrl>"))
{
string version;
int ia = line.find("<dictionaryUrl>")+15;
int ib = line.find("</dictionaryUrl>")-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