diff --git a/CMakeLists.txt b/CMakeLists.txt index a90c977..6d06124 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,18 +20,7 @@ set(IMGUI_BACKEND_SRC external/imgui/backends/imgui_impl_opengl3.cpp ) -if(WIN32) - # fetch curl - include(FetchContent) - FetchContent_Declare( - curl - URL https://curl.se/download/curl-8.5.0.tar.gz - DOWNLOAD_EXTRACT_TIMESTAMP true - OVERRIDE_FIND_PACKAGE - ) - FetchContent_MakeAvailable(curl) -else() -# On Linux, we can use the system's libcurl +if(LINUX) find_package(CURL REQUIRED) endif() @@ -75,7 +64,11 @@ target_link_libraries(ui PUBLIC core imgui glad glfw imguifiledialog imgui_gradi # --- App library --- add_library(app STATIC src/app.cpp src/update.cpp) target_include_directories(app PUBLIC include ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(app PUBLIC core cache ui imgui glad glfw hex_display_feature_manager CURL::libcurl) +if(LINUX) + target_link_libraries(app PUBLIC core cache ui imgui glad glfw hex_display_feature_manager CURL::libcurl) +else() + target_link_libraries(app PUBLIC core cache ui imgui glad glfw hex_display_feature_manager winhttp.lib) +endif() if(WIN32) add_executable(EntropyVisualizer WIN32 main.cpp) diff --git a/VERSION.txt b/VERSION.txt index 9ab8337..8fdcf38 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -1.9.1 +1.9.2 diff --git a/include/entropy/version.h b/include/entropy/version.h index 8938da6..0dda571 100644 --- a/include/entropy/version.h +++ b/include/entropy/version.h @@ -2,7 +2,7 @@ namespace entropy { -#define EV_VERSION "1.9.1" +#define EV_VERSION "1.9.2" #define EV_DATE "09.03.2026" } // namespace entropy \ No newline at end of file diff --git a/src/update.cpp b/src/update.cpp index ad0a95c..cbfae43 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -2,12 +2,20 @@ #include #include -#include #include #include #include #include +#ifdef _WIN32 +#include +#include +#endif + +#if __linux__ +#include +#endif + namespace entropy { static size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp) { @@ -55,13 +63,14 @@ void startUpdateCheck(UiState &uiState, const std::string &file_path, bool manua const std::string full_url = base + file_path; const std::string release_page = "https://github.com/maede97/EntropyVisualizer/releases"; + std::string response; +#ifdef __linux__ CURL *curl = curl_easy_init(); if (!curl) { uiState.updateChecked = true; return; } - std::string response; curl_easy_setopt(curl, CURLOPT_URL, full_url.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); @@ -78,6 +87,89 @@ void startUpdateCheck(UiState &uiState, const std::string &file_path, bool manua } curl_easy_cleanup(curl); +#endif +#ifdef _WIN32 + DWORD dwSize = 0; + DWORD dwDownloaded = 0; + BOOL bResults = FALSE; + + HINTERNET hSession = NULL; + HINTERNET hConnect = NULL; + HINTERNET hRequest = NULL; + + URL_COMPONENTS urlComp{}; + urlComp.dwStructSize = sizeof(urlComp); + urlComp.dwHostNameLength = (DWORD)-1; + urlComp.dwUrlPathLength = (DWORD)-1; + + std::wstring wurl(full_url.begin(), full_url.end()); + + if (!WinHttpCrackUrl(wurl.c_str(), (DWORD)wurl.size(), 0, &urlComp)) { + uiState.updateChecked = true; + return; + } + + // Open session + hSession = WinHttpOpen(L"EntropyVisualizer Update Checker/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, + WINHTTP_NO_PROXY_BYPASS, 0); + + // Connect + if (hSession) { + std::wstring host(urlComp.lpszHostName, urlComp.dwHostNameLength); + + hConnect = WinHttpConnect(hSession, host.c_str(), urlComp.nPort, 0); + } + + // Open request + if (hConnect) { + std::wstring path(urlComp.lpszUrlPath, urlComp.dwUrlPathLength); + + hRequest = WinHttpOpenRequest(hConnect, L"GET", path.c_str(), NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, + (urlComp.nScheme == INTERNET_SCHEME_HTTPS) ? WINHTTP_FLAG_SECURE : 0); + } + + // Send request + if (hRequest) { + bResults = WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0); + } + + // Receive response + if (bResults) + bResults = WinHttpReceiveResponse(hRequest, NULL); + + // Read response + if (bResults) { + do { + dwSize = 0; + + if (!WinHttpQueryDataAvailable(hRequest, &dwSize)) + break; + + if (!dwSize) + break; + + std::vector buffer(dwSize + 1); + ZeroMemory(buffer.data(), dwSize + 1); + + if (!WinHttpReadData(hRequest, buffer.data(), dwSize, &dwDownloaded)) { + break; + } + + response.append(buffer.data(), dwDownloaded); + + } while (dwSize > 0); + } + + // Cleanup + if (hRequest) + WinHttpCloseHandle(hRequest); + if (hConnect) + WinHttpCloseHandle(hConnect); + if (hSession) + WinHttpCloseHandle(hSession); + + uiState.updateChecked = true; +#endif // Trim whitespace std::string trimmed = response;