From 454776ae4ebcef5108c70648601e1b4c06667f5a Mon Sep 17 00:00:00 2001 From: Zezula Ladislav Date: Mon, 30 Oct 2017 14:31:52 +0100 Subject: + Fixed an AlwaysTrue condition --- src/FileStream.cpp | 86 +++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 47 deletions(-) (limited to 'src/FileStream.cpp') diff --git a/src/FileStream.cpp b/src/FileStream.cpp index 4910cac..b2370ff 100644 --- a/src/FileStream.cpp +++ b/src/FileStream.cpp @@ -611,8 +611,6 @@ static bool BaseHttp_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD HINTERNET hRequest; DWORD dwTemp = 0; - bool bFileAvailable = false; - int nError = ERROR_SUCCESS; // Keep compiler happy dwStreamFlags = dwStreamFlags; @@ -627,11 +625,7 @@ static bool BaseHttp_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD NULL, NULL, 0); - if(pStream->Base.Http.hInternet == NULL) - return false; - - // Connect to the server - if(nError == ERROR_SUCCESS) + if(pStream->Base.Http.hInternet != NULL) { TCHAR szServerName[MAX_PATH]; DWORD dwFlags = INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_UI | INTERNET_FLAG_NO_CACHE_WRITE; @@ -646,57 +640,55 @@ static bool BaseHttp_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD INTERNET_SERVICE_HTTP, dwFlags, 0); - if(pStream->Base.Http.hConnect == NULL) - { - InternetCloseHandle(pStream->Base.Http.hInternet); - return false; - } - } - - // Now try to query the file size - if(nError == ERROR_SUCCESS) - { - // Open HTTP request to the file - hRequest = HttpOpenRequest(pStream->Base.Http.hConnect, _T("GET"), szFileName, NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0); - if(hRequest != NULL) + if(pStream->Base.Http.hConnect != NULL) { - if(HttpSendRequest(hRequest, NULL, 0, NULL, 0)) + // Open HTTP request to the file + hRequest = HttpOpenRequest(pStream->Base.Http.hConnect, _T("GET"), szFileName, NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0); + if(hRequest != NULL) { - ULONGLONG FileTime = 0; - DWORD dwFileSize = 0; - DWORD dwDataSize; - DWORD dwIndex = 0; - - // Check if the MPQ has Last Modified field - dwDataSize = sizeof(ULONGLONG); - if(HttpQueryInfo(hRequest, HTTP_QUERY_LAST_MODIFIED | HTTP_QUERY_FLAG_SYSTEMTIME, &FileTime, &dwDataSize, &dwIndex)) - pStream->Base.Http.FileTime = FileTime; - - // Verify if the server supports random access - dwDataSize = sizeof(DWORD); - if(HttpQueryInfo(hRequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &dwFileSize, &dwDataSize, &dwIndex)) + if(HttpSendRequest(hRequest, NULL, 0, NULL, 0)) { - if(dwFileSize != 0) + ULONGLONG FileTime = 0; + DWORD dwFileSize = 0; + DWORD dwDataSize; + DWORD dwIndex = 0; + + // Check if the MPQ has Last Modified field + dwDataSize = sizeof(ULONGLONG); + if(HttpQueryInfo(hRequest, HTTP_QUERY_LAST_MODIFIED | HTTP_QUERY_FLAG_SYSTEMTIME, &FileTime, &dwDataSize, &dwIndex)) + pStream->Base.Http.FileTime = FileTime; + + // Verify if the server supports random access + dwDataSize = sizeof(DWORD); + if(HttpQueryInfo(hRequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &dwFileSize, &dwDataSize, &dwIndex)) { - pStream->Base.Http.FileSize = dwFileSize; - pStream->Base.Http.FilePos = 0; - bFileAvailable = true; + if(dwFileSize != 0) + { + InternetCloseHandle(hRequest); + pStream->Base.Http.FileSize = dwFileSize; + pStream->Base.Http.FilePos = 0; + return true; + } } } + + // Close the request + InternetCloseHandle(hRequest); } - InternetCloseHandle(hRequest); + + // Close the connection handle + InternetCloseHandle(pStream->Base.Http.hConnect); + pStream->Base.Http.hConnect = NULL; } - } - // If the file is not there and is not available for random access, - // report error - if(bFileAvailable == false) - { - pStream->BaseClose(pStream); - return false; + // Close the internet handle + InternetCloseHandle(pStream->Base.Http.hInternet); + pStream->Base.Http.hInternet = NULL; } - return true; + // If the file is not there or is not available for random access, report error + pStream->BaseClose(pStream); + return false; #else -- cgit v1.2.3