@@ -16,13 +16,14 @@ using json = nlohmann::json;
1616static const std::string errors[] = {
1717 " Internal error: " ,
1818 " Server responded with error: " ,
19- " HTTP request failed : " ,
19+ " HTTP request error : " ,
2020 " Malformed server response" ,
2121
2222 // Internal errors
23- " failed to initialize WinInet" ,
24- " InternetOpenUrl failed" ,
25- " HttpQueryInfo failed"
23+ " failed to initialize WinInet " ,
24+ " InternetOpenUrl failed " ,
25+ " HttpQueryInfo failed " ,
26+ " HttpReadFile faield "
2627};
2728
2829static HINTERNET hInternet = NULL ;
@@ -39,12 +40,17 @@ void UpdatesController::Stop(void) {
3940
4041static HINTERNET open_request (std::string url, std::string headers) {
4142 return InternetOpenUrl (hInternet, url.c_str (), headers.c_str (), headers.length (),
42- INTERNET_FLAG_SECURE | INTERNET_FLAG_NO_UI | INTERNET_FLAG_NO_COOKIES, 0 );
43+ INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_PRAGMA_NOCACHE, 0 );
44+ }
45+
46+ static std::string build_error (int t1, int t2) {
47+ std::string str = errors[t1] + errors[t2];
48+ return str + std::to_string (GetLastError ());
4349}
4450
4551bool UpdatesController::CheckRedLua (std::string &ret) {
4652 if (!Prepare ()) {
47- ret = errors[ 0 ] + errors[ 4 ] ;
53+ ret = build_error ( 0 , 4 ) ;
4854 return false ;
4955 }
5056
@@ -56,13 +62,15 @@ bool UpdatesController::CheckRedLua(std::string &ret) {
5662
5763 HINTERNET hRequest;
5864 do {
59- hRequest = open_request (REDLUA_TAGS_URL, " Accept: application/json" );
60- if (hRequest == NULL ) break ;
65+ if ((hRequest = open_request (REDLUA_TAGS_URL, " Accept: application/json" )) == NULL ) {
66+ ret = build_error (0 , 5 );
67+ break ;
68+ }
6169
6270 while ((success = InternetReadFile (hRequest, buf, BUFSIZE, &read)) && read > 0 )
6371 temp.append ((const char *)buf, read);
6472 if (!success) {
65- ret = errors[ 2 ] + std::to_string ( GetLastError () );
73+ ret = build_error ( 2 , 7 );
6674 break ;
6775 }
6876
@@ -119,13 +127,13 @@ bool UpdatesController::CheckNativeDB(std::string &ret, bool force_update) {
119127 if (!force_update)
120128 headers.append (" \r\n If-None-Match: " + Settings.Read (" nativedb_etag" , etag));
121129 if ((hRequest = open_request (REDLUA_NATIVEDB_URL, headers)) == NULL ) {
122- ret = errors[ 0 ] + errors[ 5 ] ;
130+ ret = build_error ( 0 , 5 ) ;
123131 break ;
124132 }
125133
126134 DWORD code = 0 ; DWORD codelen = sizeof (DWORD);
127135 if (!HttpQueryInfo (hRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &code, &codelen, NULL )) {
128- ret = errors[ 0 ] + errors[ 6 ] ;
136+ ret = build_error ( 0 , 6 ) ;
129137 break ;
130138 }
131139
@@ -144,7 +152,7 @@ bool UpdatesController::CheckNativeDB(std::string &ret, bool force_update) {
144152
145153 DWORD bufsize = BUFSIZE;
146154 if (!HttpQueryInfoA (hRequest, HTTP_QUERY_ETAG, buf, &bufsize, NULL )) {
147- ret = errors[ 0 ] + errors[ 6 ] ;
155+ ret = build_error ( 0 , 6 ) ;
148156 break ;
149157 }
150158
0 commit comments